Zephyr Project API 4.5.0
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
rtio.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: Copyright (c) 2022 Intel Corporation
3 * SPDX-FileCopyrightText: Copyright (c) 2026 Infineon Technologies AG,
4 * SPDX-FileCopyrightText: or an affiliate of Infineon Technologies AG. All rights reserved.
5 *
6 * SPDX-License-Identifier: Apache-2.0
7 */
8
28
29#ifndef ZEPHYR_INCLUDE_RTIO_RTIO_H_
30#define ZEPHYR_INCLUDE_RTIO_RTIO_H_
31
32#include <string.h>
33
35#include <zephyr/device.h>
36#include <zephyr/kernel.h>
37#include <zephyr/sys/__assert.h>
38#include <zephyr/sys/atomic.h>
40#include <zephyr/sys/util.h>
42#include <zephyr/rtio/sqe.h>
43#include <zephyr/rtio/cqe.h>
44#include <zephyr/rtio/iodev.h>
45
46#ifdef __cplusplus
47extern "C" {
48#endif
49
50
59
60struct rtio;
61
70typedef void (*rtio_cqe_callback_t)(struct rtio *r, void *user_data);
71
83struct rtio {
84#ifdef CONFIG_RTIO_SUBMIT_SEM
85 /* A wait semaphore which may suspend the calling thread
86 * to wait for some number of completions when calling submit
87 */
88 struct k_sem *submit_sem;
89
90 uint32_t submit_count;
91#endif
92
93#ifdef CONFIG_RTIO_CONSUME_SEM
94 /* A wait semaphore which may suspend the calling thread
95 * to wait for some number of completions while consuming
96 * them from the completion queue
97 */
98 struct k_sem *consume_sem;
99#endif
100
103
106
108 struct rtio_sqe_pool *sqe_pool;
109
111 struct rtio_cqe_pool *cqe_pool;
112
113#ifdef CONFIG_RTIO_SYS_MEM_BLOCKS
114 /* Mem block pool */
115 struct sys_mem_blocks *block_pool;
116#endif
117
119 struct mpsc sq;
120
122 struct mpsc cq;
123
124#ifdef CONFIG_RTIO_CQE_CALLBACK
125 /* Completion queue event callback */
126 rtio_cqe_callback_t cqe_cb;
127
128 /* Completion queue event callback user data */
129 void *cqe_cb_user_data;
130#endif
131};
132
133/* @cond ignore */
134#define Z_RTIO_DEFINE(name, _sqe_pool, _cqe_pool, _block_pool) \
135 IF_ENABLED(CONFIG_RTIO_SUBMIT_SEM, \
136 (static K_SEM_DEFINE(CONCAT(_submit_sem_, name), 0, K_SEM_MAX_LIMIT))) \
137 IF_ENABLED(CONFIG_RTIO_CONSUME_SEM, \
138 (static K_SEM_DEFINE(CONCAT(_consume_sem_, name), 0, K_SEM_MAX_LIMIT))) \
139 STRUCT_SECTION_ITERABLE(rtio, name) = { \
140 IF_ENABLED(CONFIG_RTIO_SUBMIT_SEM, (.submit_sem = &CONCAT(_submit_sem_, name),)) \
141 IF_ENABLED(CONFIG_RTIO_SUBMIT_SEM, (.submit_count = 0,)) \
142 IF_ENABLED(CONFIG_RTIO_CONSUME_SEM, (.consume_sem = &CONCAT(_consume_sem_, name),))\
143 .cq_count = ATOMIC_INIT(0), \
144 .xcqcnt = ATOMIC_INIT(0), \
145 .sqe_pool = _sqe_pool, \
146 .cqe_pool = _cqe_pool, \
147 IF_ENABLED(CONFIG_RTIO_SYS_MEM_BLOCKS, (.block_pool = _block_pool,)) \
148 .sq = MPSC_INIT((name.sq)), \
149 .cq = MPSC_INIT((name.cq)), \
150 IF_ENABLED(CONFIG_RTIO_CQE_CALLBACK, (.cqe_cb = NULL, .cqe_cb_user_data = NULL,)) \
151 }
152/* @endcond */
153
161#define RTIO_DEFINE(name, sq_sz, cq_sz) \
162 Z_RTIO_SQE_POOL_DEFINE(CONCAT(name, _sqe_pool), sq_sz); \
163 Z_RTIO_CQE_POOL_DEFINE(CONCAT(name, _cqe_pool), cq_sz); \
164 Z_RTIO_DEFINE(name, &CONCAT(name, _sqe_pool), \
165 &CONCAT(name, _cqe_pool), NULL)
166
167
175static inline size_t rtio_mempool_block_size(const struct rtio *r)
176{
177#ifndef CONFIG_RTIO_SYS_MEM_BLOCKS
178 ARG_UNUSED(r);
179 return 0;
180#else
181 if (r == NULL || r->block_pool == NULL) {
182 return 0;
183 }
184 return BIT(r->block_pool->info.blk_sz_shift);
185#endif
186}
187
195#if defined(CONFIG_RTIO_SYS_MEM_BLOCKS) || defined(__DOXYGEN__)
196static inline uint16_t __rtio_compute_mempool_block_index(const struct rtio *r, const void *ptr)
197{
198 uintptr_t addr = (uintptr_t)ptr;
199 struct sys_mem_blocks *mem_pool = r->block_pool;
200 uint32_t block_size = rtio_mempool_block_size(r);
201
202 uintptr_t buff = (uintptr_t)mem_pool->buffer;
203 uint32_t buff_size = mem_pool->info.num_blocks * block_size;
204
205 if (addr < buff || addr >= buff + buff_size) {
206 return UINT16_MAX;
207 }
208 return (addr - buff) / block_size;
209}
210#endif
211
213
214static inline int rtio_block_pool_alloc(struct rtio *r, size_t min_sz,
215 size_t max_sz, uint8_t **buf, uint32_t *buf_len)
216{
217#ifndef CONFIG_RTIO_SYS_MEM_BLOCKS
218 ARG_UNUSED(r);
219 ARG_UNUSED(min_sz);
220 ARG_UNUSED(max_sz);
221 ARG_UNUSED(buf);
222 ARG_UNUSED(buf_len);
223 return -ENOTSUP;
224#else
225 const uint32_t block_size = rtio_mempool_block_size(r);
226 uint32_t bytes = max_sz;
227
228 /* Not every context has a block pool and the block size may return 0 in
229 * that case
230 */
231 if (block_size == 0) {
232 return -ENOMEM;
233 }
234
235 do {
236 size_t num_blks = DIV_ROUND_UP(bytes, block_size);
237 int rc = sys_mem_blocks_alloc_contiguous(r->block_pool, num_blks, (void **)buf);
238
239 if (rc == 0) {
240 *buf_len = num_blks * block_size;
241 return 0;
242 }
243
244 if (bytes <= block_size) {
245 break;
246 }
247
248 bytes -= block_size;
249 } while (bytes >= min_sz);
250
251 return -ENOMEM;
252#endif
253}
254
255static inline void rtio_block_pool_free(struct rtio *r, void *buf, uint32_t buf_len)
256{
257#ifndef CONFIG_RTIO_SYS_MEM_BLOCKS
258 ARG_UNUSED(r);
259 ARG_UNUSED(buf);
260 ARG_UNUSED(buf_len);
261#else
262 /* Round up, a caller may name the bytes it used rather than the whole buffer */
263 size_t num_blks = DIV_ROUND_UP(buf_len, BIT(r->block_pool->info.blk_sz_shift));
264
265 sys_mem_blocks_free_contiguous(r->block_pool, buf, num_blks);
266#endif
267}
268
270
271
273extern struct k_mem_partition rtio_partition;
274
275
276/* Do not try and reformat the macros */
277
287#if CONFIG_RTIO_BLOCK_POOL_PLACEMENT_DTCM
288#define RTIO_BMEM Z_GENERIC_SECTION(".dtcm_bss") static
289#elif defined(CONFIG_RTIO_BLOCK_POOL_PLACEMENT_NOCACHE)
290#define RTIO_BMEM __nocache static
291#else
292#define RTIO_BMEM COND_CODE_1(CONFIG_USERSPACE, (K_APP_BMEM(rtio_partition) static), (static))
293#endif
294
304#if CONFIG_RTIO_BLOCK_POOL_PLACEMENT_DTCM
305#define RTIO_DMEM Z_GENERIC_SECTION(".dtcm_data") static
306#elif defined(CONFIG_RTIO_BLOCK_POOL_PLACEMENT_NOCACHE)
307#define RTIO_DMEM __nocache_load static
308#else
309#define RTIO_DMEM COND_CODE_1(CONFIG_USERSPACE, (K_APP_DMEM(rtio_partition) static), (static))
310#endif
311
312/* clang-format off */
313/* @cond ignore */
314#define Z_RTIO_BLOCK_POOL_DEFINE(name, blk_sz, blk_cnt, blk_align) \
315 RTIO_BMEM uint8_t __aligned(WB_UP(blk_align)) \
316 CONCAT(_block_pool_, name)[(blk_cnt) * WB_UP(blk_sz)]; \
317 _SYS_MEM_BLOCKS_DEFINE_WITH_EXT_BUF(name, WB_UP(blk_sz), (blk_cnt), \
318 CONCAT(_block_pool_, name), RTIO_DMEM)
319
320/* @endcond */
321
322
323/* clang-format on */
324
335#define RTIO_DEFINE_WITH_MEMPOOL(name, sq_sz, cq_sz, num_blks, blk_size, balign) \
336 Z_RTIO_SQE_POOL_DEFINE(name##_sqe_pool, sq_sz); \
337 Z_RTIO_CQE_POOL_DEFINE(name##_cqe_pool, cq_sz); \
338 Z_RTIO_BLOCK_POOL_DEFINE(name##_block_pool, blk_size, num_blks, balign); \
339 Z_RTIO_DEFINE(name, &name##_sqe_pool, &name##_cqe_pool, &name##_block_pool)
340
341/* clang-format on */
342
350static inline uint32_t rtio_sqe_acquirable(struct rtio *r)
351{
352 return r->sqe_pool->pool_free;
353}
354
363static inline struct rtio_sqe *rtio_sqe_acquire(struct rtio *r)
364{
365 SYS_PORT_TRACING_FUNC_ENTER(rtio, sqe_acquire, r);
366 struct rtio_iodev_sqe *iodev_sqe = rtio_sqe_pool_alloc(r->sqe_pool);
367
368 if (iodev_sqe == NULL) {
369 SYS_PORT_TRACING_FUNC_EXIT(rtio, sqe_acquire, r, NULL);
370 return NULL;
371 }
372
373 mpsc_push(&r->sq, &iodev_sqe->q);
374
375 SYS_PORT_TRACING_FUNC_EXIT(rtio, sqe_acquire, r, &iodev_sqe->sqe);
376 return &iodev_sqe->sqe;
377}
378
391static inline int rtio_sqe_acquire_array(struct rtio *r, size_t n, struct rtio_sqe **sqes)
392{
393 struct rtio_iodev_sqe *iodev_sqe;
394 size_t i;
395
396 for (i = 0; i < n; i++) {
397 iodev_sqe = rtio_sqe_pool_alloc(r->sqe_pool);
398 if (iodev_sqe == NULL) {
399 break;
400 }
401 sqes[i] = &iodev_sqe->sqe;
402 }
403
404 /* Not enough SQEs in the pool */
405 if (i < n) {
406 while (i > 0) {
407 i--;
408 iodev_sqe = CONTAINER_OF(sqes[i], struct rtio_iodev_sqe, sqe);
409 rtio_sqe_pool_free(r->sqe_pool, iodev_sqe);
410 sqes[i] = NULL;
411 }
412
413 return -ENOMEM;
414 }
415
416 for (i = 0; i < n; i++) {
417 iodev_sqe = CONTAINER_OF(sqes[i], struct rtio_iodev_sqe, sqe);
418 mpsc_push(&r->sq, &iodev_sqe->q);
419 }
420
421 return 0;
422}
423
429static inline void rtio_sqe_drop_all(struct rtio *r)
430{
431 struct rtio_iodev_sqe *iodev_sqe;
432 struct mpsc_node *node = mpsc_pop(&r->sq);
433
434 while (node != NULL) {
435 iodev_sqe = CONTAINER_OF(node, struct rtio_iodev_sqe, q);
436 rtio_sqe_pool_free(r->sqe_pool, iodev_sqe);
437 node = mpsc_pop(&r->sq);
438 }
439}
440
444static inline struct rtio_cqe *rtio_cqe_acquire(struct rtio *r)
445{
446 SYS_PORT_TRACING_FUNC_ENTER(rtio, cqe_acquire, r);
447 struct rtio_cqe *cqe = rtio_cqe_pool_alloc(r->cqe_pool);
448
449 if (cqe == NULL) {
450 SYS_PORT_TRACING_FUNC_EXIT(rtio, cqe_acquire, r, NULL);
451 return NULL;
452 }
453
454 memset(cqe, 0, sizeof(struct rtio_cqe));
455
456 SYS_PORT_TRACING_FUNC_EXIT(rtio, cqe_acquire, r, cqe);
457 return cqe;
458}
459
476static inline int rtio_set_cqe_callback(struct rtio *r,
477 rtio_cqe_callback_t callback,
478 void *user_data)
479{
480#ifdef CONFIG_RTIO_CQE_CALLBACK
481 r->cqe_cb = callback;
482 r->cqe_cb_user_data = user_data;
483
484 return 0;
485#else
486 ARG_UNUSED(r);
487 ARG_UNUSED(callback);
488 ARG_UNUSED(user_data);
489
490 return -ENOTSUP;
491#endif
492}
493
497static inline void rtio_cqe_produce(struct rtio *r, struct rtio_cqe *cqe)
498{
499 mpsc_push(&r->cq, &cqe->q);
500}
501
513static inline struct rtio_cqe *rtio_cqe_consume(struct rtio *r)
514{
515 SYS_PORT_TRACING_FUNC_ENTER(rtio, cqe_consume, r);
516 struct mpsc_node *node;
517 struct rtio_cqe *cqe = NULL;
518
519#ifdef CONFIG_RTIO_CONSUME_SEM
520 if (k_sem_take(r->consume_sem, K_NO_WAIT) != 0) {
521 SYS_PORT_TRACING_FUNC_EXIT(rtio, cqe_consume, r, NULL);
522 return NULL;
523 }
524#endif
525
526 node = mpsc_pop(&r->cq);
527 if (node == NULL) {
528 SYS_PORT_TRACING_FUNC_EXIT(rtio, cqe_consume, r, NULL);
529 return NULL;
530 }
531 cqe = CONTAINER_OF(node, struct rtio_cqe, q);
532
533 SYS_PORT_TRACING_FUNC_EXIT(rtio, cqe_consume, r, cqe);
534 return cqe;
535}
536
547static inline struct rtio_cqe *rtio_cqe_consume_block(struct rtio *r)
548{
549 struct mpsc_node *node;
550 struct rtio_cqe *cqe;
551
552#ifdef CONFIG_RTIO_CONSUME_SEM
553 k_sem_take(r->consume_sem, K_FOREVER);
554#endif
555 node = mpsc_pop(&r->cq);
556 while (node == NULL) {
557 Z_SPIN_DELAY(1);
558 node = mpsc_pop(&r->cq);
559 }
560 cqe = CONTAINER_OF(node, struct rtio_cqe, q);
561
562 return cqe;
563}
564
571static inline void rtio_cqe_release(struct rtio *r, struct rtio_cqe *cqe)
572{
573 SYS_PORT_TRACING_FUNC(rtio, cqe_release, r, cqe);
574 rtio_cqe_pool_free(r->cqe_pool, cqe);
575}
576
585static inline int rtio_flush_completion_queue(struct rtio *r)
586{
587 struct rtio_cqe *cqe;
588 int res = 0;
589
590 do {
591 cqe = rtio_cqe_consume(r);
592 if (cqe != NULL) {
593 if ((cqe->result < 0) && (res == 0)) {
594 res = cqe->result;
595 }
596 rtio_cqe_release(r, cqe);
597 }
598 } while (cqe != NULL);
599
600 return res;
601}
602
614__syscall void rtio_sqe_signal(struct rtio_sqe *sqe);
615
616static inline void z_impl_rtio_sqe_signal(struct rtio_sqe *sqe)
617{
618 struct rtio_iodev_sqe *iodev_sqe = CONTAINER_OF(sqe, struct rtio_iodev_sqe, sqe);
619
620 if (!atomic_cas(&iodev_sqe->rt.await.ok, 0, 1)) {
621 iodev_sqe->rt.await.callback(iodev_sqe, iodev_sqe->rt.await.userdata);
622 }
623}
624
631static inline uint32_t rtio_cqe_compute_flags(struct rtio_iodev_sqe *iodev_sqe)
632{
633 uint32_t flags = 0;
634
635#ifdef CONFIG_RTIO_SYS_MEM_BLOCKS
636 if (iodev_sqe->sqe.op == RTIO_OP_RX && iodev_sqe->sqe.flags & RTIO_SQE_MEMPOOL_BUFFER) {
637 struct rtio *r = iodev_sqe->r;
638 struct sys_mem_blocks *mem_pool = r->block_pool;
639 unsigned int blk_index = 0;
640 unsigned int blk_count = 0;
641
642 if (iodev_sqe->rt.rx_bind.buf) {
643 blk_index = (iodev_sqe->rt.rx_bind.buf - mem_pool->buffer) >>
644 mem_pool->info.blk_sz_shift;
645 blk_count = iodev_sqe->rt.rx_bind.buf_len >> mem_pool->info.blk_sz_shift;
646 }
647 flags = RTIO_CQE_FLAG_PREP_MEMPOOL(blk_index, blk_count);
648 }
649#else
650 ARG_UNUSED(iodev_sqe);
651#endif
652
653 return flags;
654}
655
671__syscall int rtio_cqe_get_mempool_buffer(const struct rtio *r, struct rtio_cqe *cqe,
672 uint8_t **buff, uint32_t *buff_len);
673
674static inline int z_impl_rtio_cqe_get_mempool_buffer(const struct rtio *r, struct rtio_cqe *cqe,
675 uint8_t **buff, uint32_t *buff_len)
676{
677#ifdef CONFIG_RTIO_SYS_MEM_BLOCKS
679 unsigned int blk_idx = RTIO_CQE_FLAG_MEMPOOL_GET_BLK_IDX(cqe->flags);
680 unsigned int blk_count = RTIO_CQE_FLAG_MEMPOOL_GET_BLK_CNT(cqe->flags);
682
683 *buff_len = blk_count * blk_size;
684
685 if (blk_count > 0) {
686 *buff = r->block_pool->buffer + blk_idx * blk_size;
687
688 __ASSERT_NO_MSG(*buff >= r->block_pool->buffer);
689 __ASSERT_NO_MSG(*buff <
690 r->block_pool->buffer + blk_size * r->block_pool->info.num_blocks);
691 } else {
692 *buff = NULL;
693 }
694 return 0;
695 }
696 return -EINVAL;
697#else
698 ARG_UNUSED(r);
699 ARG_UNUSED(cqe);
700 ARG_UNUSED(buff);
701 ARG_UNUSED(buff_len);
702
703 return -ENOTSUP;
704#endif
705}
706
708
709void rtio_executor_submit(struct rtio *r);
710void rtio_executor_ok(struct rtio_iodev_sqe *iodev_sqe, int result);
711void rtio_executor_err(struct rtio_iodev_sqe *iodev_sqe, int result);
712
714
723static inline void rtio_iodev_sqe_ok(struct rtio_iodev_sqe *iodev_sqe, int result)
724{
725 rtio_executor_ok(iodev_sqe, result);
726}
727
736static inline void rtio_iodev_sqe_err(struct rtio_iodev_sqe *iodev_sqe, int result)
737{
738 rtio_executor_err(iodev_sqe, result);
739}
740
752static inline void rtio_cqe_submit(struct rtio *r, int result, void *userdata, uint32_t flags)
753{
754 SYS_PORT_TRACING_FUNC_ENTER(rtio, cqe_submit, r, result, flags);
755 struct rtio_cqe *cqe = rtio_cqe_acquire(r);
756
757 if (cqe == NULL) {
758 atomic_inc(&r->xcqcnt);
759 } else {
760 cqe->result = result;
761 cqe->userdata = userdata;
762 cqe->flags = flags;
763 rtio_cqe_produce(r, cqe);
764#ifdef CONFIG_RTIO_CONSUME_SEM
765 k_sem_give(r->consume_sem);
766#endif
767#ifdef CONFIG_RTIO_CQE_CALLBACK
768 if (r->cqe_cb != NULL) {
769 r->cqe_cb(r, r->cqe_cb_user_data);
770 }
771#endif
772 }
773
774 /* atomic_t isn't guaranteed to wrap correctly as it could be signed, so
775 * we must resort to a cas loop.
776 */
777 atomic_t val, new_val;
778
779 do {
780 val = atomic_get(&r->cq_count);
781 new_val = (atomic_t)((uintptr_t)val + 1);
782 } while (!atomic_cas(&r->cq_count, val, new_val));
783
784#ifdef CONFIG_RTIO_SUBMIT_SEM
785 if (r->submit_count > 0) {
786 r->submit_count--;
787 if (r->submit_count == 0) {
788 k_sem_give(r->submit_sem);
789 }
790 }
791#endif
792 SYS_PORT_TRACING_FUNC_EXIT(rtio, cqe_submit, r);
793}
794
795#define __RTIO_MEMPOOL_GET_NUM_BLKS(num_bytes, blk_size) (((num_bytes) + (blk_size)-1) / (blk_size))
796
809static inline int rtio_sqe_rx_buf(struct rtio_iodev_sqe *iodev_sqe, uint32_t min_buf_len,
810 uint32_t max_buf_len, uint8_t **buf, uint32_t *buf_len)
811{
812 const struct rtio_sqe *sqe = &iodev_sqe->sqe;
813
814#ifdef CONFIG_RTIO_SYS_MEM_BLOCKS
815 if (sqe->op == RTIO_OP_RX && sqe->flags & RTIO_SQE_MEMPOOL_BUFFER) {
816 struct rtio *r = iodev_sqe->r;
817
818 /* The mempool buffer is bound at runtime and kept in the wrapper so
819 * the submission description itself stays immutable.
820 */
821 if (iodev_sqe->rt.rx_bind.buf != NULL) {
822 if (iodev_sqe->rt.rx_bind.buf_len < min_buf_len) {
823 return -ENOMEM;
824 }
825 *buf = iodev_sqe->rt.rx_bind.buf;
826 *buf_len = iodev_sqe->rt.rx_bind.buf_len;
827 return 0;
828 }
829
830 int rc = rtio_block_pool_alloc(r, min_buf_len, max_buf_len, buf, buf_len);
831
832 if (rc == 0) {
833 iodev_sqe->rt.rx_bind.buf = *buf;
834 iodev_sqe->rt.rx_bind.buf_len = *buf_len;
835 return 0;
836 }
837
838 return -ENOMEM;
839 }
840#else
841 ARG_UNUSED(max_buf_len);
842#endif
843
844 if (sqe->rx.buf_len < min_buf_len) {
845 return -ENOMEM;
846 }
847
848 *buf = sqe->rx.buf;
849 *buf_len = sqe->rx.buf_len;
850 return 0;
851}
852
867__syscall void rtio_release_buffer(struct rtio *r, void *buff, uint32_t buff_len);
868
869static inline void z_impl_rtio_release_buffer(struct rtio *r, void *buff, uint32_t buff_len)
870{
871#ifdef CONFIG_RTIO_SYS_MEM_BLOCKS
872 if (r == NULL || buff == NULL || r->block_pool == NULL || buff_len == 0) {
873 return;
874 }
875
876 rtio_block_pool_free(r, buff, buff_len);
877#else
878 ARG_UNUSED(r);
879 ARG_UNUSED(buff);
880 ARG_UNUSED(buff_len);
881#endif
882}
883
890static inline void rtio_access_grant(struct rtio *r, struct k_thread *t)
891{
893
894#ifdef CONFIG_RTIO_SUBMIT_SEM
895 k_object_access_grant(r->submit_sem, t);
896#endif
897
898#ifdef CONFIG_RTIO_CONSUME_SEM
899 k_object_access_grant(r->consume_sem, t);
900#endif
901
902#ifdef CONFIG_RTIO_OP_DELAY
903 /* Delay submissions are dispatched to the shared timeout iodev, so a thread
904 * allowed to use this context must also be able to reference it.
905 */
906 k_object_access_grant(&rtio_timeout_iodev, t);
907#endif
908}
909
910
917static inline void rtio_access_revoke(struct rtio *r, struct k_thread *t)
918{
920
921#ifdef CONFIG_RTIO_SUBMIT_SEM
922 k_object_access_revoke(r->submit_sem, t);
923#endif
924
925#ifdef CONFIG_RTIO_CONSUME_SEM
926 k_object_access_revoke(r->consume_sem, t);
927#endif
928
929#ifdef CONFIG_RTIO_OP_DELAY
930 k_object_access_revoke(&rtio_timeout_iodev, t);
931#endif
932}
933
946static inline rtio_sqe_handle_t rtio_sqe_handle(const struct rtio *r, const struct rtio_sqe *sqe)
947{
948 const struct rtio_iodev_sqe *iodev_sqe = CONTAINER_OF(sqe, struct rtio_iodev_sqe, sqe);
949 uint32_t blk_index = (uint32_t)(iodev_sqe - r->sqe_pool->pool);
950 uint32_t gen = (uint32_t)(atomic_get(&iodev_sqe->status) & RTIO_SQE_GEN_MASK);
951
952 return (blk_index << 16) | gen;
953}
954
968static inline struct rtio_iodev_sqe *rtio_iodev_sqe_from_handle(struct rtio *r,
969 rtio_sqe_handle_t handle)
970{
971 uint32_t blk_index = handle >> 16;
972 uint32_t gen = handle & RTIO_SQE_GEN_MASK;
973
974 if (blk_index >= r->sqe_pool->pool_size) {
975 return NULL;
976 }
977
978 struct rtio_iodev_sqe *iodev_sqe = &r->sqe_pool->pool[blk_index];
979 atomic_val_t status = atomic_get(&iodev_sqe->status);
980
981 if ((status & RTIO_SQE_ALLOCD) == 0 || (uint32_t)(status & RTIO_SQE_GEN_MASK) != gen) {
982 return NULL;
983 }
984
985 return iodev_sqe;
986}
987
1019__syscall int rtio_sqe_cancel(struct rtio *r, rtio_sqe_handle_t handle);
1020
1021static inline int z_impl_rtio_sqe_cancel(struct rtio *r, rtio_sqe_handle_t handle)
1022{
1023 SYS_PORT_TRACING_FUNC(rtio, sqe_cancel, handle);
1024
1025 uint16_t blk_index = rtio_sqe_handle_index(handle);
1027
1028 if (blk_index >= r->sqe_pool->pool_size) {
1029 return 0;
1030 }
1031
1032 struct rtio_iodev_sqe *iodev_sqe = &r->sqe_pool->pool[blk_index];
1033
1034 /* Validate identity and mark canceled in one atomic step so a concurrent
1035 * completion cannot recycle the slot between the check and the mark: if
1036 * the entry is freed meanwhile the CAS fails and the re-read observes the
1037 * bumped generation, turning the cancel into a no-op.
1038 */
1039 while (true) {
1040 atomic_val_t status = atomic_get(&iodev_sqe->status);
1041
1042 if ((status & RTIO_SQE_ALLOCD) == 0 ||
1043 (uint16_t)(status & RTIO_SQE_GEN_MASK) != gen) {
1044 return 0;
1045 }
1046
1047 if (atomic_cas(&iodev_sqe->status, status,
1049 break;
1050 }
1051 }
1052
1053 /* Give the iodev a chance to abort a submission it is already sitting on,
1054 * which nothing else would wake.
1055 *
1056 * The entry is not owned here, so re-read the status after taking the iodev
1057 * out of it: every free bumps the generation, so an unchanged generation
1058 * proves no completion recycled the slot in between and the iodev really is
1059 * this submission's. The hook is handed the handle rather than the entry,
1060 * because the entry may still be completed before the hook runs; the iodev
1061 * resolves the handle under its own lock.
1062 */
1063 const struct rtio_iodev *iodev = iodev_sqe->sqe.iodev;
1064 atomic_val_t status = atomic_get(&iodev_sqe->status);
1065
1066 if ((status & RTIO_SQE_ALLOCD) == 0 || (uint16_t)(status & RTIO_SQE_GEN_MASK) != gen) {
1067 return 0;
1068 }
1069
1070 if (iodev != NULL && iodev->api->cancel != NULL) {
1071 iodev->api->cancel(iodev, r, handle);
1072 }
1073
1074 return 0;
1075}
1076
1096__syscall int rtio_sqe_copy_in_get_handles(struct rtio *r, const struct rtio_sqe *sqes,
1097 rtio_sqe_handle_t *handles, size_t sqe_count);
1098
1099static inline int z_impl_rtio_sqe_copy_in_get_handles(struct rtio *r, const struct rtio_sqe *sqes,
1100 rtio_sqe_handle_t *handles,
1101 size_t sqe_count)
1102{
1103 struct rtio_sqe *sqe;
1104 uint32_t acquirable = rtio_sqe_acquirable(r);
1105
1106 if (acquirable < sqe_count) {
1107 return -ENOMEM;
1108 }
1109
1110 for (unsigned long i = 0; i < sqe_count; i++) {
1111 sqe = rtio_sqe_acquire(r);
1112 __ASSERT_NO_MSG(sqe != NULL);
1113 if (handles != NULL) {
1114 handles[i] = rtio_sqe_handle(r, sqe);
1115 }
1116 *sqe = sqes[i];
1117 }
1118
1119 return 0;
1120}
1121
1138static inline int rtio_sqe_copy_in(struct rtio *r, const struct rtio_sqe *sqes, size_t sqe_count)
1139{
1140 return rtio_sqe_copy_in_get_handles(r, sqes, NULL, sqe_count);
1141}
1142
1158__syscall int rtio_cqe_copy_out(struct rtio *r,
1159 struct rtio_cqe *cqes,
1160 size_t cqe_count,
1161 k_timeout_t timeout);
1162static inline int z_impl_rtio_cqe_copy_out(struct rtio *r,
1163 struct rtio_cqe *cqes,
1164 size_t cqe_count,
1165 k_timeout_t timeout)
1166{
1167 size_t copied = 0;
1168 struct rtio_cqe *cqe;
1169 k_timepoint_t end = sys_timepoint_calc(timeout);
1170
1171 do {
1174 if (cqe == NULL) {
1175 Z_SPIN_DELAY(25);
1176 continue;
1177 }
1178 cqes[copied++] = *cqe;
1179 rtio_cqe_release(r, cqe);
1180 } while (copied < cqe_count && !sys_timepoint_expired(end));
1181
1182 return copied;
1183}
1184
1200__syscall int rtio_submit(struct rtio *r, uint32_t wait_count);
1201
1202#ifdef CONFIG_RTIO_SUBMIT_SEM
1203static inline int z_impl_rtio_submit(struct rtio *r, uint32_t wait_count)
1204{
1205 SYS_PORT_TRACING_FUNC_ENTER(rtio, submit, r, wait_count);
1206 int res = 0;
1207
1208 if (wait_count > 0) {
1209 __ASSERT(!k_is_in_isr(),
1210 "expected rtio submit with wait count to be called from a thread");
1211
1212 k_sem_reset(r->submit_sem);
1213 r->submit_count = wait_count;
1214 }
1215
1216 rtio_executor_submit(r);
1217
1218 if (wait_count > 0) {
1219 res = k_sem_take(r->submit_sem, K_FOREVER);
1220 __ASSERT(res == 0,
1221 "semaphore was reset or timed out while waiting on completions!");
1222 }
1223
1225 return res;
1226}
1227#else
1228static inline int z_impl_rtio_submit(struct rtio *r, uint32_t wait_count)
1229{
1230
1231 SYS_PORT_TRACING_FUNC_ENTER(rtio, submit, r, wait_count);
1232 int res = 0;
1233 uintptr_t cq_count = (uintptr_t)atomic_get(&r->cq_count);
1234 uintptr_t cq_complete_count = cq_count + wait_count;
1235 bool wraps = cq_complete_count < cq_count;
1236
1237 rtio_executor_submit(r);
1238
1239 if (wraps) {
1240 while ((uintptr_t)atomic_get(&r->cq_count) >= cq_count) {
1241 Z_SPIN_DELAY(10);
1242 k_yield();
1243 }
1244 }
1245
1246 while ((uintptr_t)atomic_get(&r->cq_count) < cq_complete_count) {
1247 Z_SPIN_DELAY(10);
1248 k_yield();
1249 }
1250
1252 return res;
1253}
1254#endif /* CONFIG_RTIO_SUBMIT_SEM */
1255
1262
1264 struct rtio **contexts;
1265
1268};
1269
1278__syscall struct rtio *rtio_pool_acquire(struct rtio_pool *pool);
1279
1280static inline struct rtio *z_impl_rtio_pool_acquire(struct rtio_pool *pool)
1281{
1282 struct rtio *r = NULL;
1283
1284 for (size_t i = 0; i < pool->pool_size; i++) {
1285 if (atomic_test_and_set_bit(pool->used, i) == 0) {
1286 r = pool->contexts[i];
1287 break;
1288 }
1289 }
1290
1291 if (r != NULL) {
1293 }
1294
1295 return r;
1296}
1297
1304__syscall void rtio_pool_release(struct rtio_pool *pool, struct rtio *r);
1305
1306static inline void z_impl_rtio_pool_release(struct rtio_pool *pool, struct rtio *r)
1307{
1308
1309 if (k_is_user_context()) {
1311 }
1312
1313 for (size_t i = 0; i < pool->pool_size; i++) {
1314 if (pool->contexts[i] == r) {
1315 atomic_clear_bit(pool->used, i);
1316 break;
1317 }
1318 }
1319}
1320
1321/* clang-format off */
1322
1324
1325#define Z_RTIO_POOL_NAME_N(n, name) \
1326 name##_##n
1327
1328#define Z_RTIO_POOL_DEFINE_N(n, name, sq_sz, cq_sz) \
1329 RTIO_DEFINE(Z_RTIO_POOL_NAME_N(n, name), sq_sz, cq_sz)
1330
1331#define Z_RTIO_POOL_REF_N(n, name) \
1332 &Z_RTIO_POOL_NAME_N(n, name)
1333
1335
1344#define RTIO_POOL_DEFINE(name, pool_sz, sq_sz, cq_sz) \
1345 LISTIFY(pool_sz, Z_RTIO_POOL_DEFINE_N, (;), name, sq_sz, cq_sz); \
1346 static struct rtio *name##_contexts[] = { \
1347 LISTIFY(pool_sz, Z_RTIO_POOL_REF_N, (,), name) \
1348 }; \
1349 ATOMIC_DEFINE(name##_used, pool_sz); \
1350 STRUCT_SECTION_ITERABLE(rtio_pool, name) = { \
1351 .pool_size = pool_sz, \
1352 .contexts = name##_contexts, \
1353 .used = name##_used, \
1354 }
1355
1356/* clang-format on */
1357
1361
1362#ifdef __cplusplus
1363}
1364#endif
1365
1366#include <zephyr/syscalls/rtio.h>
1367
1368#endif /* ZEPHYR_INCLUDE_RTIO_RTIO_H_ */
workaround assembler barfing for ST r
Definition asm-macro-32-bit-gnu.h:27
RTIO Completion Queue Events and Related Functions.
APIs and macros for the Zephyr device model.
long atomic_t
Atomic integer variable.
Definition atomic_types.h:34
static void atomic_clear_bit(atomic_t *target, int bit)
Atomically clear a bit.
Definition atomic.h:227
atomic_t atomic_val_t
Value type for atomic integer variables.
Definition atomic_types.h:41
atomic_val_t atomic_get(const atomic_t *target)
Atomic get.
static bool atomic_test_and_set_bit(atomic_t *target, int bit)
Atomically set a bit and test it.
Definition atomic.h:181
atomic_val_t atomic_inc(atomic_t *target)
Atomic increment.
bool atomic_cas(atomic_t *target, atomic_val_t old_value, atomic_val_t new_value)
Atomic compare-and-set.
#define K_FOREVER
Generate infinite timeout delay.
Definition kernel.h:1712
#define K_NO_WAIT
Generate null timeout delay.
Definition kernel.h:1602
k_timepoint_t sys_timepoint_calc(k_timeout_t timeout)
Calculate a timepoint value.
static bool sys_timepoint_expired(k_timepoint_t timepoint)
Indicates if timepoint is expired.
Definition clock.h:386
#define K_TIMEOUT_EQ(a, b)
Compare timeouts for equality.
Definition clock.h:80
bool k_is_in_isr(void)
Determine if code is running at interrupt level.
int sys_mem_blocks_free_contiguous(sys_mem_blocks_t *mem_block, void *block, size_t count)
Free contiguous multiple memory blocks.
int sys_mem_blocks_alloc_contiguous(sys_mem_blocks_t *mem_block, size_t count, void **out_block)
Allocate a contiguous set of memory blocks.
static ALWAYS_INLINE void mpsc_push(struct mpsc *q, struct mpsc_node *n)
Push a node.
Definition mpsc_lockfree.h:126
static struct mpsc_node * mpsc_pop(struct mpsc *q)
Pop a node off of the list.
Definition mpsc_lockfree.h:145
#define RTIO_CQE_FLAG_MEMPOOL_GET_BLK_CNT(flags)
Get the block count of a mempool flags.
Definition cqe.h:70
#define RTIO_CQE_FLAG_MEMPOOL_GET_BLK_IDX(flags)
Get the block index of a mempool flags.
Definition cqe.h:62
#define RTIO_CQE_FLAG_MEMPOOL_BUFFER
The entry's buffer was allocated from the RTIO's mempool.
Definition cqe.h:46
#define RTIO_CQE_FLAG_PREP_MEMPOOL(blk_idx, blk_cnt)
Prepare CQE flags for a mempool read.
Definition cqe.h:79
#define RTIO_CQE_FLAG_GET(flags)
Get the flag bits of a CQE flags value.
Definition cqe.h:54
#define RTIO_OP_RX
An operation that receives (reads).
Definition sqe.h:148
#define RTIO_SQE_MEMPOOL_BUFFER
The buffer should be allocated by the RTIO mempool.
Definition sqe.h:106
void rtio_pool_release(struct rtio_pool *pool, struct rtio *r)
Return an RTIO context to a pool.
static struct rtio_iodev_sqe * rtio_iodev_sqe_from_handle(struct rtio *r, rtio_sqe_handle_t handle)
Resolve a handle to a live submission, validating identity.
Definition rtio.h:968
static uint32_t rtio_sqe_acquirable(struct rtio *r)
Count of acquirable submission queue events.
Definition rtio.h:350
struct rtio * rtio_pool_acquire(struct rtio_pool *pool)
Obtain an RTIO context from a pool.
#define RTIO_SQE_ALLOCD
Set while the entry is allocated from the pool (i.e.
Definition sqe.h:427
static size_t rtio_mempool_block_size(const struct rtio *r)
Get the mempool block size of the RTIO context.
Definition rtio.h:175
static void rtio_cqe_submit(struct rtio *r, int result, void *userdata, uint32_t flags)
Submit a completion queue event with a given result and userdata.
Definition rtio.h:752
static rtio_sqe_handle_t rtio_sqe_handle(const struct rtio *r, const struct rtio_sqe *sqe)
Capture an opaque, validatable handle for a live submission.
Definition rtio.h:946
void rtio_release_buffer(struct rtio *r, void *buff, uint32_t buff_len)
Release memory that was allocated by the RTIO's memory pool.
static int rtio_sqe_copy_in(struct rtio *r, const struct rtio_sqe *sqes, size_t sqe_count)
Copy an array of SQEs into the queue.
Definition rtio.h:1138
void(* rtio_cqe_callback_t)(struct rtio *r, void *user_data)
RTIO completion queue event callback.
Definition rtio.h:70
static int rtio_sqe_rx_buf(struct rtio_iodev_sqe *iodev_sqe, uint32_t min_buf_len, uint32_t max_buf_len, uint8_t **buf, uint32_t *buf_len)
Get the buffer associate with the RX submission.
Definition rtio.h:809
static void rtio_cqe_produce(struct rtio *r, struct rtio_cqe *cqe)
Produce a complete queue event if available.
Definition rtio.h:497
#define RTIO_SQE_GEN_MASK
Generation counter; bumped on free, compared against a handle's generation.
Definition sqe.h:425
static uint32_t rtio_cqe_compute_flags(struct rtio_iodev_sqe *iodev_sqe)
Compute the CQE flags from the rtio_iodev_sqe entry.
Definition rtio.h:631
int rtio_sqe_copy_in_get_handles(struct rtio *r, const struct rtio_sqe *sqes, rtio_sqe_handle_t *handles, size_t sqe_count)
Copy an array of SQEs into the queue and get resulting handles back.
uint32_t rtio_sqe_handle_t
Opaque identity for a submission queue entry.
Definition sqe.h:322
struct k_mem_partition rtio_partition
The memory partition associated with all RTIO context information.
static struct rtio_sqe * rtio_sqe_acquire(struct rtio *r)
Acquire a single submission queue event if available.
Definition rtio.h:363
static uint16_t rtio_sqe_handle_generation(rtio_sqe_handle_t handle)
Generation counter encoded in a handle.
Definition sqe.h:449
static void rtio_sqe_drop_all(struct rtio *r)
Drop all previously acquired sqe.
Definition rtio.h:429
int rtio_cqe_copy_out(struct rtio *r, struct rtio_cqe *cqes, size_t cqe_count, k_timeout_t timeout)
Copy an array of CQEs from the queue.
static int rtio_flush_completion_queue(struct rtio *r)
Flush completion queue.
Definition rtio.h:585
static void rtio_access_revoke(struct rtio *r, struct k_thread *t)
Revoke access to an RTIO context from a user thread.
Definition rtio.h:917
static void rtio_access_grant(struct rtio *r, struct k_thread *t)
Grant access to an RTIO context to a user thread.
Definition rtio.h:890
int rtio_sqe_cancel(struct rtio *r, rtio_sqe_handle_t handle)
Attempt to cancel an SQE.
#define RTIO_SQE_STATUS_CANCELED
Set when cancellation of the submission has been requested.
Definition sqe.h:429
static void rtio_cqe_release(struct rtio *r, struct rtio_cqe *cqe)
Release consumed completion queue event.
Definition rtio.h:571
static uint16_t rtio_sqe_handle_index(rtio_sqe_handle_t handle)
Pool block index encoded in a handle.
Definition sqe.h:438
static int rtio_set_cqe_callback(struct rtio *r, rtio_cqe_callback_t callback, void *user_data)
Set the completion queue event callback.
Definition rtio.h:476
static void rtio_iodev_sqe_err(struct rtio_iodev_sqe *iodev_sqe, int result)
Inform the executor of a submissions completion with error.
Definition rtio.h:736
static void rtio_iodev_sqe_ok(struct rtio_iodev_sqe *iodev_sqe, int result)
Inform the executor of a submission completion with success.
Definition rtio.h:723
static struct rtio_cqe * rtio_cqe_acquire(struct rtio *r)
Acquire a complete queue event if available.
Definition rtio.h:444
static struct rtio_cqe * rtio_cqe_consume(struct rtio *r)
Consume a single completion queue event if available.
Definition rtio.h:513
void rtio_sqe_signal(struct rtio_sqe *sqe)
Signal an AWAIT SQE.
int rtio_cqe_get_mempool_buffer(const struct rtio *r, struct rtio_cqe *cqe, uint8_t **buff, uint32_t *buff_len)
Retrieve the mempool buffer that was allocated for the CQE.
static struct rtio_cqe * rtio_cqe_consume_block(struct rtio *r)
Wait for and consume a single completion queue event.
Definition rtio.h:547
static int rtio_sqe_acquire_array(struct rtio *r, size_t n, struct rtio_sqe **sqes)
Acquire a number of submission queue events if available.
Definition rtio.h:391
int rtio_submit(struct rtio *r, uint32_t wait_count)
Submit I/O requests to the underlying executor.
void k_sem_reset(struct k_sem *sem)
Resets a semaphore's count to zero.
void k_sem_give(struct k_sem *sem)
Give a semaphore.
int k_sem_take(struct k_sem *sem, k_timeout_t timeout)
Take a semaphore.
#define SYS_PORT_TRACING_FUNC_ENTER(type, func,...)
Tracing macro for the entry into a function that might or might not return a value.
Definition tracing_macros.h:246
#define SYS_PORT_TRACING_FUNC_EXIT(type, func,...)
Tracing macro for when a function ends its execution.
Definition tracing_macros.h:272
#define SYS_PORT_TRACING_FUNC(type, func,...)
Tracing macro for function calls which are not directly associated with a specific type of object.
Definition tracing_macros.h:233
#define BIT(n)
Unsigned integer with bit position n set (signed in assembly language).
Definition util_macro.h:44
#define CONTAINER_OF(ptr, type, field)
Get a pointer to a structure containing the element.
Definition util.h:281
#define DIV_ROUND_UP(n, d)
Divide and round up.
Definition util.h:348
#define EINVAL
Invalid argument.
Definition errno.h:61
#define ENOMEM
Not enough core.
Definition errno.h:51
#define ENOTSUP
Unsupported value.
Definition errno.h:115
void k_yield(void)
Yield the current thread.
static __attribute_const__ k_tid_t k_current_get(void)
Get thread ID of the current thread.
Definition kernel.h:859
void k_object_access_grant(const void *object, struct k_thread *thread)
Grant a thread access to a kernel object.
void k_object_access_revoke(const void *object, struct k_thread *thread)
Revoke a thread's access to a kernel object.
#define NULL
Definition iar_missing_defs.h:20
RTIO I/O Device and Related Functions.
Public kernel APIs.
Memory Blocks Allocator.
flags
Definition parser.h:86
RTIO Submission Queue Events and Related Functions.
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
#define UINT16_MAX
Definition stdint.h:28
__UINTPTR_TYPE__ uintptr_t
Definition stdint.h:105
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
void * memset(void *buf, int c, size_t n)
Memory Partition.
Definition mem_domain.h:55
Semaphore structure.
Definition kernel.h:3738
Thread Structure.
Definition thread.h:258
Kernel timeout type.
Definition clock.h:65
Kernel timepoint type.
Definition clock.h:289
Queue member.
Definition mpsc_lockfree.h:79
MPSC Queue.
Definition mpsc_lockfree.h:86
A completion queue event.
Definition cqe.h:90
void * userdata
Associated userdata with operation.
Definition cqe.h:96
uint32_t flags
Flags associated with the operation.
Definition cqe.h:97
int32_t result
Result from operation.
Definition cqe.h:95
void(* cancel)(const struct rtio_iodev *iodev, struct rtio *r, rtio_sqe_handle_t handle)
Attempt to actively cancel a previously submitted entry.
Definition iodev.h:77
IO device submission queue entry.
Definition sqe.h:459
struct rtio_iodev_sqe::@330064006263143366064036221227125351044336131221::@020376107202163366036113216314102104241220072312 await
OP_AWAIT signaling state.
struct rtio_iodev_sqe::@330064006263143366064036221227125351044336131221::@135022137027372164350061046374202042306257337314 rx_bind
OP_RX buffer bound at runtime (see RTIO_SQE_MEMPOOL_BUFFER).
struct rtio_sqe sqe
The submission queue entry this wraps.
Definition sqe.h:461
uint8_t * buf
Buffer allocated for the read.
Definition sqe.h:481
struct rtio * r
RTIO context that owns this entry.
Definition sqe.h:467
atomic_t ok
Set once the awaited signal arrives.
Definition sqe.h:487
void * userdata
Opaque pointer passed to the callback.
Definition sqe.h:489
uint32_t buf_len
Length of the allocated buffer.
Definition sqe.h:482
atomic_t status
Identity + lifetime word (generation | ALLOCD), see RTIO_SQE_* bits above.
Definition sqe.h:470
struct mpsc_node q
Node used to link the entry into the pool free list and iodev queues.
Definition sqe.h:463
union rtio_iodev_sqe::@330064006263143366064036221227125351044336131221 rt
Runtime scratch state that the subsystem/driver mutates while it owns the submission.
rtio_signaled_t callback
Invoked when the entry is signaled.
Definition sqe.h:488
An IO device with a function table for submitting requests.
Definition iodev.h:83
const struct rtio_iodev_api * api
Function pointer table.
Definition iodev.h:85
Pool of RTIO contexts to use with dynamically created threads.
Definition rtio.h:1259
struct rtio ** contexts
Array containing contexts of the pool.
Definition rtio.h:1264
atomic_t * used
Atomic bitmap to signal a member is used/unused.
Definition rtio.h:1267
size_t pool_size
Size of the pool.
Definition rtio.h:1261
A submission queue event.
Definition sqe.h:337
uint8_t op
Op code.
Definition sqe.h:338
uint32_t buf_len
Length of buffer.
Definition sqe.h:362
const struct rtio_iodev * iodev
Device to operation on.
Definition sqe.h:346
struct rtio_sqe::@342363352172076106335370162240320153276337137375::@110162343014114265152332336213215220201374200140 rx
OP_RX.
uint16_t flags
Op Flags.
Definition sqe.h:342
const uint8_t * buf
Buffer to write from.
Definition sqe.h:363
An RTIO context containing what can be viewed as a pair of queues.
Definition rtio.h:83
struct rtio_cqe_pool * cqe_pool
Completion queue object pool with free list.
Definition rtio.h:111
struct mpsc sq
Submission queue.
Definition rtio.h:119
atomic_t cq_count
Total number of completions.
Definition rtio.h:102
struct rtio_sqe_pool * sqe_pool
Submission queue object pool with free list.
Definition rtio.h:108
atomic_t xcqcnt
Number of completions dropped because no CQE was available.
Definition rtio.h:105
struct mpsc cq
Completion queue.
Definition rtio.h:122
Header file for the Atomic operations API.
Iterable sections helpers.
Misc utilities.
static bool k_is_user_context(void)
Indicate whether the CPU is currently in user mode.
Definition syscall.h:120