Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
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 <kernel.h>
10
11/* Zephyr Pooled Parallel Preemptible Priority-based Work Queues */
12
13struct k_p4wq_work;
14
19
29 /* Filled out by submitting code */
33 bool sync;
34 struct k_sem done_sem;
35
36 /* reserved for implementation */
37 union {
38 struct rbnode rbnode;
40 };
42 struct k_p4wq *queue;
43};
44
45#define K_P4WQ_QUEUE_PER_THREAD BIT(0)
46#define K_P4WQ_DELAYED_START BIT(1)
47#define K_P4WQ_USER_CPU_MASK BIT(2)
48
54struct k_p4wq {
56
57 /* Pending threads waiting for work items
58 *
59 * FIXME: a waitq isn't really the right data structure here.
60 * Wait queues are priority-sorted, but we don't want that
61 * sorting overhead since we're effectively doing it ourselves
62 * by directly mutating the priority when a thread is
63 * unpended. We just want "blocked threads on a list", but
64 * there's no clean scheduler API for that.
65 */
66 _wait_q_t waitq;
67
68 /* Work items waiting for processing */
69 struct rbtree queue;
70
71 /* Work items in progress */
73
74 /* K_P4WQ_* flags above */
76};
77
81 struct k_p4wq *queue;
83 struct z_thread_stack_element *stacks;
85};
86
98#define K_P4WQ_DEFINE(name, n_threads, stack_sz) \
99 static K_THREAD_STACK_ARRAY_DEFINE(_p4stacks_##name, \
100 n_threads, stack_sz); \
101 static struct k_thread _p4threads_##name[n_threads]; \
102 static struct k_p4wq name; \
103 static const STRUCT_SECTION_ITERABLE(k_p4wq_initparam, \
104 _init_##name) = { \
105 .num = n_threads, \
106 .stack_size = stack_sz, \
107 .threads = _p4threads_##name, \
108 .stacks = &(_p4stacks_##name[0][0]), \
109 .queue = &name, \
110 .flags = 0, \
111 }
112
125#define K_P4WQ_ARRAY_DEFINE(name, n_threads, stack_sz, flg) \
126 static K_THREAD_STACK_ARRAY_DEFINE(_p4stacks_##name, \
127 n_threads, stack_sz); \
128 static struct k_thread _p4threads_##name[n_threads]; \
129 static struct k_p4wq name[n_threads]; \
130 static const STRUCT_SECTION_ITERABLE(k_p4wq_initparam, \
131 _init_##name) = { \
132 .num = n_threads, \
133 .stack_size = stack_sz, \
134 .threads = _p4threads_##name, \
135 .stacks = &(_p4stacks_##name[0][0]), \
136 .queue = name, \
137 .flags = K_P4WQ_QUEUE_PER_THREAD | flg, \
138 }
139
150
165 size_t stack_size);
166
188void k_p4wq_submit(struct k_p4wq *queue, struct k_p4wq_work *item);
189
200bool k_p4wq_cancel(struct k_p4wq *queue, struct k_p4wq_work *item);
201
206
208 uint32_t cpu_mask);
209
210#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:44
static struct k_thread thread[2]
Definition: atomic.c:22
ZTEST_BMEM int timeout
Definition: main.c:31
void
Definition: eswifi_shell.c:15
struct _dnode sys_dlist_t
Definition: dlist.h:48
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)
Definition: p4wq.h:18
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.
static struct k_work work[2]
Definition: main.c:16
struct k_stack stack
Definition: test_stack_contexts.c:18
__UINT32_TYPE__ uint32_t
Definition: stdint.h:60
__INT32_TYPE__ int32_t
Definition: stdint.h:44
__UINTPTR_TYPE__ uintptr_t
Definition: stdint.h:75
Definition: p4wq.h:78
uint32_t num
Definition: p4wq.h:79
struct z_thread_stack_element * stacks
Definition: p4wq.h:83
uint32_t flags
Definition: p4wq.h:84
struct k_thread * threads
Definition: p4wq.h:82
struct k_p4wq * queue
Definition: p4wq.h:81
uintptr_t stack_size
Definition: p4wq.h:80
P4 Queue Work Item.
Definition: p4wq.h:28
bool sync
Definition: p4wq.h:33
int32_t deadline
Definition: p4wq.h:31
struct k_sem done_sem
Definition: p4wq.h:34
struct k_thread * thread
Definition: p4wq.h:41
sys_dlist_t dlnode
Definition: p4wq.h:39
int32_t priority
Definition: p4wq.h:30
k_p4wq_handler_t handler
Definition: p4wq.h:32
struct k_p4wq * queue
Definition: p4wq.h:42
P4 Queue.
Definition: p4wq.h:54
uint32_t flags
Definition: p4wq.h:75
_wait_q_t waitq
Definition: p4wq.h:66
struct rbtree queue
Definition: p4wq.h:69
struct k_spinlock lock
Definition: p4wq.h:55
sys_dlist_t active
Definition: p4wq.h:72
Kernel Spin Lock.
Definition: spinlock.h:29
Definition: thread.h:201
Kernel timeout type.
Definition: sys_clock.h:65
Definition: rb.h:49
Definition: rb.h:83
struct k_queue queue
Definition: test_queue_contexts.c:17