Zephyr API Documentation  3.6.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
p4wq.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 Intel Corporation
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6#ifndef ZEPHYR_INCLUDE_SYS_P4WQ_H_
7#define ZEPHYR_INCLUDE_SYS_P4WQ_H_
8
9#include <zephyr/kernel.h>
11
12/* Zephyr Pooled Parallel Preemptible Priority-based Work Queues */
13
14struct k_p4wq_work;
15
19typedef void (*k_p4wq_handler_t)(struct k_p4wq_work *work);
20
30 /* Filled out by submitting code */
34 bool sync;
35 struct k_sem done_sem;
36
37 /* reserved for implementation */
38 union {
39 struct rbnode rbnode;
41 };
43 struct k_p4wq *queue;
44};
45
46#define K_P4WQ_QUEUE_PER_THREAD BIT(0)
47#define K_P4WQ_DELAYED_START BIT(1)
48#define K_P4WQ_USER_CPU_MASK BIT(2)
49
55struct k_p4wq {
57
58 /* Pending threads waiting for work items
59 *
60 * FIXME: a waitq isn't really the right data structure here.
61 * Wait queues are priority-sorted, but we don't want that
62 * sorting overhead since we're effectively doing it ourselves
63 * by directly mutating the priority when a thread is
64 * unpended. We just want "blocked threads on a list", but
65 * there's no clean scheduler API for that.
66 */
67 _wait_q_t waitq;
68
69 /* Work items waiting for processing */
70 struct rbtree queue;
71
72 /* Work items in progress */
74
75 /* K_P4WQ_* flags above */
77};
78
82 struct k_p4wq *queue;
84 struct z_thread_stack_element *stacks;
86};
87
99#define K_P4WQ_DEFINE(name, n_threads, stack_sz) \
100 static K_THREAD_STACK_ARRAY_DEFINE(_p4stacks_##name, \
101 n_threads, stack_sz); \
102 static struct k_thread _p4threads_##name[n_threads]; \
103 static struct k_p4wq name; \
104 static const STRUCT_SECTION_ITERABLE(k_p4wq_initparam, \
105 _init_##name) = { \
106 .num = n_threads, \
107 .stack_size = stack_sz, \
108 .threads = _p4threads_##name, \
109 .stacks = &(_p4stacks_##name[0][0]), \
110 .queue = &name, \
111 .flags = 0, \
112 }
113
126#define K_P4WQ_ARRAY_DEFINE(name, n_threads, stack_sz, flg) \
127 static K_THREAD_STACK_ARRAY_DEFINE(_p4stacks_##name, \
128 n_threads, stack_sz); \
129 static struct k_thread _p4threads_##name[n_threads]; \
130 static struct k_p4wq name[n_threads]; \
131 static const STRUCT_SECTION_ITERABLE(k_p4wq_initparam, \
132 _init_##name) = { \
133 .num = n_threads, \
134 .stack_size = stack_sz, \
135 .threads = _p4threads_##name, \
136 .stacks = &(_p4stacks_##name[0][0]), \
137 .queue = name, \
138 .flags = K_P4WQ_QUEUE_PER_THREAD | flg, \
139 }
140
150void k_p4wq_init(struct k_p4wq *queue);
151
164void k_p4wq_add_thread(struct k_p4wq *queue, struct k_thread *thread,
165 k_thread_stack_t *stack,
166 size_t stack_size);
167
189void k_p4wq_submit(struct k_p4wq *queue, struct k_p4wq_work *item);
190
201bool k_p4wq_cancel(struct k_p4wq *queue, struct k_p4wq_work *item);
202
206int k_p4wq_wait(struct k_p4wq_work *work, k_timeout_t timeout);
207
208void k_p4wq_enable_static_thread(struct k_p4wq *queue, struct k_thread *thread,
209 uint32_t cpu_mask);
210
211#endif /* ZEPHYR_INCLUDE_SYS_P4WQ_H_ */
struct z_thread_stack_element k_thread_stack_t
Typedef of struct z_thread_stack_element.
Definition: arch_interface.h:45
struct _dnode sys_dlist_t
Doubly-linked list structure.
Definition: dlist.h:50
Public kernel APIs.
void k_p4wq_submit(struct k_p4wq *queue, struct k_p4wq_work *item)
Submit work item to a P4 queue.
int k_p4wq_wait(struct k_p4wq_work *work, k_timeout_t timeout)
Regain ownership of the work item, wait for completion if it's synchronous.
void k_p4wq_enable_static_thread(struct k_p4wq *queue, struct k_thread *thread, uint32_t cpu_mask)
void k_p4wq_add_thread(struct k_p4wq *queue, struct k_thread *thread, k_thread_stack_t *stack, size_t stack_size)
Dynamically add a thread object to a P4 Queue pool.
void(* k_p4wq_handler_t)(struct k_p4wq_work *work)
P4 Queue handler callback.
Definition: p4wq.h:19
void k_p4wq_init(struct k_p4wq *queue)
Initialize P4 Queue.
bool k_p4wq_cancel(struct k_p4wq *queue, struct k_p4wq_work *item)
Cancel submitted P4 work item.
__UINT32_TYPE__ uint32_t
Definition: stdint.h:90
__INT32_TYPE__ int32_t
Definition: stdint.h:74
__UINTPTR_TYPE__ uintptr_t
Definition: stdint.h:105
Definition: p4wq.h:79
uint32_t num
Definition: p4wq.h:80
struct z_thread_stack_element * stacks
Definition: p4wq.h:84
uint32_t flags
Definition: p4wq.h:85
struct k_thread * threads
Definition: p4wq.h:83
struct k_p4wq * queue
Definition: p4wq.h:82
uintptr_t stack_size
Definition: p4wq.h:81
P4 Queue Work Item.
Definition: p4wq.h:29
bool sync
Definition: p4wq.h:34
int32_t deadline
Definition: p4wq.h:32
struct k_sem done_sem
Definition: p4wq.h:35
struct k_thread * thread
Definition: p4wq.h:42
sys_dlist_t dlnode
Definition: p4wq.h:40
int32_t priority
Definition: p4wq.h:31
k_p4wq_handler_t handler
Definition: p4wq.h:33
struct k_p4wq * queue
Definition: p4wq.h:43
P4 Queue.
Definition: p4wq.h:55
uint32_t flags
Definition: p4wq.h:76
_wait_q_t waitq
Definition: p4wq.h:67
struct rbtree queue
Definition: p4wq.h:70
struct k_spinlock lock
Definition: p4wq.h:56
sys_dlist_t active
Definition: p4wq.h:73
Kernel Spin Lock.
Definition: spinlock.h:45
Thread Structure.
Definition: thread.h:259
Kernel timeout type.
Definition: sys_clock.h:65
Balanced red/black tree node structure.
Definition: rb.h:58
Balanced red/black tree structure.
Definition: rb.h:91