Commit graph

56 commits

Author SHA1 Message Date
Yong Cong Sin bbe5e1e6eb build: namespace the generated headers with zephyr/
Namespaced the generated headers with `zephyr` to prevent
potential conflict with other headers.

Introduce a temporary Kconfig `LEGACY_GENERATED_INCLUDE_PATH`
that is enabled by default. This allows the developers to
continue the use of the old include paths for the time being
until it is deprecated and eventually removed. The Kconfig will
generate a build-time warning message, similar to the
`CONFIG_TIMER_RANDOM_GENERATOR`.

Updated the includes path of in-tree sources accordingly.

Most of the changes here are scripted, check the PR for more
info.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-05-28 22:03:55 +02:00
Tom Burdick c2c95e18ed rtio: Use CONCAT in place of ## in macros
Found issues when using ## to concatenate tokens in macros where the
resulting symbolic names were including the ## tokens themselves. Using
CONCAT everywhere fixes the issue.

Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
2024-04-26 16:22:20 +02:00
Ederson de Souza 28d08ada28 include/zephyr: Add 'version' and 'since' tag to groups
Based on information from doc/develop/api/overview.rst, add current
version for some groups representing APIs, following the following
table:

  - Experimental:   0.1.0
  - Unstable:       0.8.0
  - Stable:         1.0.0

Also based on doc/develop/api/overview.rst, add 'since' tag to the
groups.

Signed-off-by: Ederson de Souza <ederson.desouza@intel.com>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2024-03-19 13:13:45 +01:00
Tom Burdick ab590fdb28 rtio: Drop include for toolchain.h
It's not needed and was likely accidently automatically included by
clangd lsp at some point.

Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
2024-03-05 09:43:38 -05:00
Tom Burdick 1fb449c9bc rtio: Align i2c flags with i2c.h flags
Aligns the flags in rtio.h for i2c with those in i2c.h

Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
2024-03-05 09:43:38 -05:00
Tom Burdick 4c8b1e2d1e rtio: Add I2C configure operation
In order to serialize all of the i2c functionality an added op code for
configuring the i2c controller was needed. Thankfully very simple.

Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
2024-03-05 09:43:38 -05:00
Tom Burdick 1fd7de6ade rtio: Add support for i2c recovery command
Adds support for the i2c recovery operation as an opcode in RTIO

Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
2024-03-05 09:43:38 -05:00
Marco Widmer 2e001dda6b rtio: Fix unused argument
When compiling with CONFIG_RTIO_SYS_MEM_BLOCKS=n, rtio.h causes unused
argument warnings. Align the implementation of rtio_block_pool_free with
rtio_block_pool_alloc and add ARG_UNUSED() statements for the arguments.

Signed-off-by: Marco Widmer <marco.widmer@bytesatwork.ch>
2024-01-31 22:12:36 +01:00
Tom Burdick 9369c6f8e1 rtio: Make coverity happy
Coverity reported (rightfully) a possible divide by zero when trying to
allocate from a pool. Return -ENOMEM in such scenarios as it means there
is no memory to allocate from.

Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
2023-11-20 09:22:46 +01:00
Yuval Peress 468973513a rtio: cleanup blocking loop
The current blocking model will try calling `rtio_mpsc_pop` twice in a
row without any delay. Probably not the actual intent.

Signed-off-by: Yuval Peress <peress@google.com>
2023-10-06 09:30:11 +01:00
Peter Mitsis baea37aeb4 kernel: Re-factor sys_mem_blocks definition
Rearranges the sys_mem_blocks fields so that information that describes
how much of the memory block is used is co-located. This will allow
easier of its statistics into the object core statistics reporting
framework.

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
2023-09-30 08:04:14 +03:00
Yuval Peress 23d051537b rtio: Simplify the mempool handling
It's not necessary to cache the block size, instead it can be computed
from blk_sz_shift

Signed-off-by: Yuval Peress <peress@google.com>
2023-09-13 17:34:47 -04:00
Benjamin Cabé f9e17b815f rtio: doc: clean bad doxygen references.
:c:func:, :c:macro: etc shoud not be used in Doxygen comments, as they
are Sphinx roles.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2023-08-28 13:43:55 -04:00
Daniel Leung 030223740f rtio: rename shadow variables
Rename shadow variables found by -Wshadow, as the ones in
the macros have a tendency to conflict with outer scope ones
when used. So they need to be more descriptive.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-08-22 11:39:58 +02:00
Tom Burdick 108b38b357 rtio: Fix signed compare warning
atomic_t is a machine word signed integer but cq_count is meant to be an
unsigned positive only count of total completions. Cast when needed to
ensure the correct math and comparisons are being done.

Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
2023-08-05 09:34:07 +00:00
Tom Burdick 0aaedf7205 docs: rtio: Show RTIO API Docs again
The RTIO API docs weren't being shown. I made a poor assumption thinking
I could simply include the top level doxygen group in index.rst which isn't
the case. Fix the groups, and remove a note about a poll function
that doesn't exist yet.

Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
2023-08-04 12:30:05 -04:00
Nicolas Pitre 531aa5786d drivers: move to timepoint API
Remove sys_clock_timeout_end_calc() usage.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2023-07-25 09:12:26 +02:00
Tom Burdick 49a97540dc rtio: Use an atomic completion counter
Rather than looking at the pool of completions for spinning use an
atomic counter of total completions ever done. The relative number of
completions being waited on by rtio_submit may then always be correctly
done.

Prior to this a race was possible, and understood, as
rtio_cqe_consumable was a likely but not guaranteed count of completions.
Sure enough on an SMP system the likely count was ahead of the actual
available completions and a race was caught by the simple test case.

Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
2023-07-24 09:04:43 +00:00
Yuval Peress 10be3a1263 rtio: Implement a NO_RESPONSE flag for SQEs
When added, the SQE's completion will not generate a CQE.
Fixes #59284

Signed-off-by: Yuval Peress <peress@google.com>
2023-06-23 12:31:09 -04:00
Cyril Fougeray 178130a336 rtio: fix unused warning
unused args

Signed-off-by: Cyril Fougeray <cyril.fougeray@worldcoin.org>
2023-06-19 08:39:28 +02:00
Wojciech Slenska ccfbac8b07 rtio: Fix cpp compatibility
Fixed comparison between signed(int64_t) and unsigned(uint64_t) variables.

Signed-off-by: Wojciech Slenska <wsl@trackunit.com>
2023-05-31 12:40:59 -07:00
Gerard Marull-Paretas 248137169a doc: doxygen: add some subsystems to os_services group
Add the following root Doxygen modules under the umbrella of "OS
Services" Doxygen group:

- Cache
- File system
- IPC
- RTIO
- CRC
- Iterable sections
- ZBus
- Task watchdog
- Shell
- Semihosting
- Logging
- System init

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-05-31 14:39:29 -04:00
Gerard Marull-Paretas dacb3dbfeb iterable_sections: move to specific header
Until now iterable sections APIs have been part of the toolchain
(common) headers. They are not strictly related to a toolchain, they
just rely on linker providing support for sections. Most files relied on
indirect includes to access the API, now, it is included as needed.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-05-22 10:42:30 +02:00
Tom Burdick 38dc226ff5 rtio: Add iodev specific flags
Flags are needed for i2c support to enable arbitrary stop and restart
setups where in a single i2c transaction the caller would like to direct
the hardware to either send a stop or not after any particular read/write.

These can be reused more generally to direct devices to use different
methods of performing the operations on an operation by operation basis
such as perhaps a hint to use a polling, interrupt, or dma read/write.

Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
2023-05-19 16:10:51 +02:00
Yuval Peress 7153157f88 rtio: Add support for multishot reads
- Introduce multishot reads which remain on the SQ until canceled

Signed-off-by: Yuval Peress <peress@google.com>
2023-05-15 10:10:12 -04:00
Yuval Peress 2c30920b40 rtio: add cancel support
- Add a new API `rtio_sqe_cancel` to attempt canceling a queued SQE
- Add a new syscall `rtio_sqe_copy_in_get_handles` which allows getting
  back the SQE handles generated by the copy_in operation so that they
  can be canceled.

Signed-off-by: Yuval Peress <peress@google.com>
2023-05-15 10:10:12 -04:00
Yuval Peress 66328f41a7 rtio: Clear sqe data before prep
Add a memset to clear out the sqe prior to running any of the
rtio_sqe_prep_* functions.

Signed-off-by: Yuval Peress <peress@google.com>
2023-05-15 10:10:12 -04:00
Tom Burdick ea8930bd78 rtio: Cleanup the various define macros
Reworks the zephyr macros and pools to be objects in their own right. Each
pool can be statically defined with a Z_ private macro. The objects can
then be initialized with an rtio instance statically.

This cleans up a lot of code that was otherwise doing little bits of
management around allocation/freeing and reduces the scope those functions
has to the data it needs.

This should enable sharing the pools of sqe, cqe, and mem blocks among rtio
instances in a future improvement easily.

Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
2023-05-10 00:39:43 +09:00
Tom Burdick d41c182e32 rtio: Make MPSC faster on non-smp systems
On non-smp systems where multiple cores aren't in play atomics aren't
really necessary and volatile can be used in stead.

Additionally marks the push function as ALWAYS_INLINE as I saw at times
it was not being inlined.

MPSC operation speed is crucial to the performance of rtio, these changes
provided a 30% throughput improvmement in the throughput test.

Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
2023-05-10 00:39:43 +09:00
Tom Burdick e4b10328b4 rtio: Use mpsc for submission and completion queue
Rather than the rings, which weren't shared between userspace and kernel
space in Zephyr like they are in Linux with io_uring, use atomic mpsc
queues for submission and completion queues.

Most importantly this removes a potential head of line blocker in the
submission queue as the sqe would be held until a task is completed.

As additional bonuses this avoids some additional locks and restrictions
about what can be submitted and where. It also removes the need for
two executors as all chains/transactions are done concurrently.

Lastly this opens up the possibility for a common pool of sqe's to
allocate from potentially saving lots of memory.

Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
2023-05-10 00:39:43 +09:00
Yuval Peress f3ee73a1b9 rtio: add missing app_memdomain header
Add the missing app_memdomain.h header needed if userspace is enabled.
This snuck in because the file that was using it already had included
the same header.

Signed-off-by: Yuval Peress <peress@google.com>
2023-05-01 09:26:06 -05:00
Yuval Peress 3fd0a1508b rtio: fix bug in mempool release API
It was previously assumed that the 'sys_mem_blocks' struct would maintain
information about contiguous blocks allocated so the release API only
took the starting address. This led to an issue where allocating 2+
blocks would end up with a memory leak because any block not being the
first would never be released.

Add the buffer length as an argument so the correct number of blocks can
be released. Also, ammend the tests to match and verify.

Signed-off-by: Yuval Peress <peress@google.com>
2023-05-01 09:26:06 -05:00
Yuval Peress c508ec7506 rtio: add convinience cast
Add a cast to the 'struct rtio_executor *' in the declaration macro for
ease of use.

Signed-off-by: Yuval Peress <peress@google.com>
2023-05-01 09:26:06 -05:00
Yuval Peress 00a7251613 rtio: rework RTIO mempool management
The previous RTIO mempool allocation was found to be faulty. Since the
map entries were indexed using the sqe, as soon as the sqe and cqe were
no longer in sync, there was a contention. Effectively a new sqe needing
memory would assume the entry was already consumed by themselves. This
was caused by 'rtio_sqe_rx_buf()' being effectively reentrant (i.e. if
called more than once, it'll return the same buffer). So when the map
entry was marked as allocated it was assumed that it belonged to the sqe
in question and used. This led to the producer writing to memory that
was actively being read by the consumer.

Instead, the sqe's own buf/buf_len fields are used to store the memory.
Once allocated, the memory is stored there and no mapping is needed.

Signed-off-by: Yuval Peress <peress@google.com>
2023-05-01 09:26:06 -05:00
Yuval Peress 83ec915b0f rtio: Update headers for C++ compatibility
- Fix initialization order (C++ requires struct fields to be
  initialized in the same order they were declared).
- Fix casting issue in 'for' loop conditions
- Fix casting issues when getting atomic values

Signed-off-by: Yuval Peress <peress@google.com>
2023-04-13 09:59:31 +02:00
Carles Cufi 943fc715a5 include: rtio: Remove use of deprecated ceiling_fraction macro
Commit 53da110dbf deprecated
ceiling_fraction in favor of DIV_ROUND_UP. Apply this to the rtio
header as well.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2023-04-11 13:59:26 +02:00
Yuval Peress dbb470ea7a rtio: Add a managed memory pool for reads
- Introduce a new Kconfig to enable mempool in RTIO
- Introduce a new RTIO_DEFINE_WITH_MEMPOOL to allocate an RTIO context
  with an associated memory pool.
- Add a new sqe read function rtio_sqe_read_with_pool() for memory pool
  enabled RTIO contexts
- Allow IODevs to allocate only the memory they need via rtio_sqe_rx_buf()
- Allow the consumer to get the allocated buffer via
  rtio_cqe_get_mempool_buffer()
- Consumers need to release the buffer via rtio_release_buffer() when
  processing is complete.

Signed-off-by: Yuval Peress <peress@google.com>
2023-04-10 18:34:43 -04:00
Tom Burdick a0e27f1edb rtio: Move spsc buffer to bss
This can save a sizeable region of rom depending on the number of
spsc instances and their size.

Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
2023-04-04 14:32:32 +02:00
Tom Burdick a539d9c904 rtio: Add transceive op
Adds the transceive op which is needed for full SPI support. Notably
in RTIO transceive is expected to be a balanced buffer pair of the same
length and have non-null tx/rx bufs.

Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
2023-04-03 09:51:02 +02:00
Tom Burdick 912e7ff863 rtio: Add callback op
Adds a callback op to RTIO enabling C logic to be interspersed with
I/O operations. This is not safe from userspace but allowable in kernel
space.

Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
2023-04-03 09:51:02 +02:00
Tom Burdick bb72809326 rtio: Add tiny write op
When sending small buffers out it makes sense to copy rather than
reference to avoid having to keep the small buffer around for the
lifetime of the write request.

Adjusts the op numbers to always be +1 from the previously defined op
id making it easier to re-arrange if needed in the future.

Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
2023-04-03 09:51:02 +02:00
Tom Burdick 2d1375f89d rtio: Fix consume semaphore usage
When the consume semaphore is enabled always give and take from the
semaphore. It's expected that rtio_cqe_consume and rtio_cqe_consume_block
will be used exclusively rather than directly poking at the SPSC queues.

Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
2023-03-17 12:49:57 -05:00
Tom Burdick debbb69eec rtio: Adds rtio_iodev_cancel_all
Ability to cancel all pending requests in the queue turns out to be
useful and shareable.

Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
2023-03-17 12:49:57 -05:00
Tom Burdick bfecb77fde rtio: Make rtio_mpsc.h C++ friendly
C++ requires casting void * as the implicit cast isn't enough and
the C++ sample app fails to build without duplicating type information
here. Do that, and wrap it in extern C allowing the C++ to include
rtio_mpsc.h directly or indirectly.

Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
2023-03-17 12:49:57 -05:00
Tom Burdick 610d307fa0 rtio: Properly track last sqe in the queue
The pending_sqe logic to track where in the ring queue the concurrent
executor had left off was slightly flawed. It didn't account for starting
all sqes in the queue and ending back up at the beginning.

Instead track the last SQE in the queue, from which the next one in the
queue will the one to start next.

If we happen to sweep the last known SQE in the queue, reset it to NULL
so the next time prepare is called we start at the beginning of the queue
again.

Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
2023-03-17 12:49:57 -05:00
Tom Burdick 3353342e5f rtio: Add transactional submissions
Transactional submissions treat a sequence of sqes as a single atomic
submission given to a single iodev and expect as a reply a single
completion.

This is useful for scatter gather like APIs that exist in Zephyr already
for I2C and SPI.

Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
2023-03-17 12:49:57 -05:00
Tom Burdick 22273e34d0 rtio: Clear flags in prep helpers
Tests were failing when the sqe was allocated on the stack for some
architectures. Initialization of variables on the stack is not guaranteed
to be zeroed like static data. This caused undefined behavior.

Secondly if the sqe is recycled and had a flag set, there would
unexpected behavior as well.

Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
2023-03-17 12:49:57 -05:00
Alberto Escolar Piedras a2541d6c82 util: Replace all POSIX arch busy_waits with Z_SPIN_DELAY
A new Z_SPIN_DELAY() macro has been added which
can be used to reduce a bit the amount of noise
due to the POSIX arch need to break busy loops with
k_busy_wait().
Use it.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2023-03-04 22:14:04 +01:00
Alberto Escolar Piedras 660e485b14 rtio: Fix for all POSIX arch platforms
The same k_busy_wait needed for native_posix is needed for
all POSIX arch platforms.
Also increase that busy wait a bit. There is no point of
waiting for just 1 microsecond at a time, and waiting a bit
longer speeds up the test.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2023-03-03 14:15:49 +01:00
Tom Burdick 3998f9f898 rtio: Shareable lock-free iodevs
By using an mpsc queue for each iodev, the iodev itself is shareable across
contexts. Since its lock free, submits may occur even from an ISR context.

Rather than a fixed size queue, and with it the possibility of running
out of pre-allocated spots, each iodev now holds a wait-free mpsc
queue head.

This changes the parameter of iodev submit to be a struct containing 4
pointers for the rtio context, the submission queue entry, and the mpsc
node for the iodevs submission queue.

This solves the problem involving busy iodevs working with real
devices. For example a busy SPI bus driver could enqueue, without locking,
a request to start once the current request is done.

The queue entries are expected to be owned and allocated by the
executor rather than the iodev. This helps simplify potential
tuning knobs to one place, the RTIO context and its executor an
application directly uses.

As the test case shows iodevs can operate effectively lock free
with the mpsc queue and a single atomic denoting the current task.

Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
2023-03-03 09:18:09 +01:00