zephyr/lib/os
Nicolas Pitre 099850e916 ring_buffer: the great simplification
This code is rather hairy. When I look at it I don't like the way it
stares back at me.

First, the rewind business looks fishy. It has to die.

And we don't have to rely on modulus either. Not even for non-power-of-2
buffers. Let's kill that distinction too and make all sizes always
"high performance".

The code is now entirely relying only on simple ALU operations (add,
sub and compare).

The key assumption: 32-bit values do wrap around after max range has
been reached. No saturation. All architectures supported by Zephyr
do that.

Some stats:

lib/os/ring_buffer.c: 62 insertions(+), 124 deletions(-)

ring_buffer.c.obj       before   after    diff
----------------------------------------------
frdm_k64f                 1224    1136     -88
m2gl025_miv               2485    2079    -406
mps2_an385                1228    1132     -96
mps2_an521                1228    1132     -96
native_posix              1546    1496     -50
native_posix_64           1598    1595      -3
nsim_hs_mpuv6             1252    1192     -60
nsim_hs_smp               1252    1192     -60
nsim_sem                  1252    1192     -60
qemu_arc_em               1324    1192    -132
qemu_arc_hs6x             1824    1620    -204
qemu_arc_hs               1252    1192     -60
qemu_cortex_a53_smp       2154    1888    -266
qemu_cortex_a53           2154    1888    -266
qemu_cortex_a9            1938    1792    -146

Before (qemu_cortex_a53):
START - test_ringbuffer_performance
1 byte put-get, avg cycles: 52
4 byte put-get, avg cycles: 47
1 byte put claim-finish, avg cycles: 39
5 byte put claim-finish, avg cycles: 41
5 byte get claim-finish, avg cycles: 52
 PASS - test_ringbuffer_performance in 0.8 seconds

After (qemu_cortex_a53):
START - test_ringbuffer_performance
1 byte put-get, avg cycles: 34
4 byte put-get, avg cycles: 41
1 byte put claim-finish, avg cycles: 27
5 byte put claim-finish, avg cycles: 29
5 byte get claim-finish, avg cycles: 29
 PASS - test_ringbuffer_performance in 0.4 seconds

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2022-02-24 14:49:00 -08:00
..
assert.c lib: os: remove @return doc for void functions 2022-01-12 16:02:16 -05:00
base64.c zephyr: replace zephyr integer types with C99 types 2020-06-08 08:23:57 -05:00
bitarray.c sys: bitarray: remove set but unused variable 2022-02-24 08:38:38 -06:00
cbprintf.c lib: cbprintf: add libc f/printf substitutes 2021-01-27 13:34:06 -05:00
cbprintf_complete.c lib: add default labels and comments to switch statements 2021-06-04 16:22:23 -05:00
cbprintf_nano.c lib/os/cbprintf_nano.c: avoid sign extension on unsigned formats 2021-09-02 19:37:06 -04:00
cbprintf_packaged.c lib: os: cbprintf: Use rodata section on sparc 2022-02-08 09:41:37 -05:00
CMakeLists.txt lib/os: Add sys_winstream lockless shared memory byte stream IPC 2022-01-13 14:01:23 -05:00
crc7_sw.c zephyr: replace zephyr integer types with C99 types 2020-06-08 08:23:57 -05:00
crc8_sw.c zephyr: replace zephyr integer types with C99 types 2020-06-08 08:23:57 -05:00
crc16_sw.c lib: os: crc: Rework the crc16() implementation 2022-02-04 12:33:22 -05:00
crc32_sw.c lib: os: cast to the same size composite expression 2021-07-23 15:53:30 -04:00
crc32c_sw.c lib: os: cast to the same size composite expression 2021-07-23 15:53:30 -04:00
dec.c zephyr: replace zephyr integer types with C99 types 2020-06-08 08:23:57 -05:00
fdtable.c lib/os: fdtable: add locking to posix api 2022-02-10 10:59:03 +01:00
heap-validate.c lib/os/heap: use BIT() and BIT_MASK() on bit fields 2021-12-13 17:16:07 -05:00
heap.c lib: os/heap: fix bytes freed calculation for heap listener 2022-01-10 21:27:28 -05:00
heap.h heap: add functions to get heap runtime statistics 2021-11-11 16:21:43 -05:00
heap_listener.c sys: heap_listener: extend to cover more events 2022-01-10 10:28:04 -05:00
hex.c lib: hex: Remove constant expression 2020-09-02 13:45:50 -04:00
json.c json: Fix rule 5.7 violations (Tag name should be unique) 2021-12-01 12:21:19 -05:00
Kconfig lib/os: Add sys_winstream lockless shared memory byte stream IPC 2022-01-13 14:01:23 -05:00
Kconfig.cbprintf lib: os: cbprintf: Add dependency to cbprintf Kconfig 2021-07-21 07:46:39 -04:00
Kconfig.heap lib: os: mem_blocks: add alloc/free event notifications 2022-01-11 16:10:53 -05:00
mem_blocks.c lib: os: mem_blocks: add alloc/free event notifications 2022-01-11 16:10:53 -05:00
mpsc_pbuf.c lib: os: mpsc_pbuf: Add usage tracking 2022-02-21 20:41:17 -05:00
multi_heap.c lib/os: Add sys_multi_heap utility 2021-10-01 20:38:35 -04:00
mutex.c lib: os: Simplify z_impl_z_sys_mutex_kernel_unlock 2021-03-10 05:42:06 -05:00
notify.c lib: os: assign sys_notify callback default to NULL... 2021-04-29 07:16:37 -04:00
onoff.c lib: os: add final else where missing in onoff, p4wq, sem 2021-04-28 20:28:19 -04:00
p4wq.c toolchain: migrate iterable sections calls to the external API 2021-08-12 17:47:04 -04:00
printk.c logging: printk: Fix LOG_PRINTK for v2 2022-01-27 10:02:21 +01:00
rb.c lib: rb: Fix violations to rule 12.1 2021-04-20 15:50:49 -04:00
reboot.c drivers: timer: improve sys_timer_disable usage 2021-12-04 07:34:53 -05:00
ring_buffer.c ring_buffer: the great simplification 2022-02-24 14:49:00 -08:00
sem.c lib: os: add final else where missing in onoff, p4wq, sem 2021-04-28 20:28:19 -04:00
shared_multi_heap.c multi_heap: Introduce shared multi-heap memory pool manager 2021-10-12 07:44:46 -04:00
thread_entry.c kernel: make k_current_get() work without syscall 2021-07-30 20:16:47 -04:00
timeutil.c lib: timeutil: fix implicit conversions from float to double 2021-09-20 19:47:57 -04:00
user_work.c kernel: provide functional equivalent to old userspace work queue API 2021-03-03 20:06:00 -05:00
utf8.c zephyr: Add UTF-8 truncating strlcpy variant 2022-01-11 11:50:15 +01:00
winstream.c lib/os: Add sys_winstream lockless shared memory byte stream IPC 2022-01-13 14:01:23 -05:00