-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mem barrier v2 #3
base: barrier
Are you sure you want to change the base?
Conversation
@@ -30,6 +30,7 @@ | |||
#include <linker/sections.h> | |||
#include <sys/device_mmio.h> | |||
#include <sys/util.h> | |||
#include <errno.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had issue for some board here:
Line 790 in 4f284b2
return z_device_is_ready(dev) ? 0 : -ENODEV; |
Now CMSIS fallback changed, but I think that make sense to keep it because the only reason that don't fail for other board is because they include errno.h before device.h include.
To resume: -ENODEV
is used in this file, then include errno.h made sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NVM, I pass the CI without now and it's out of context, I removed it
include/arch/riscv/barrier.h
Outdated
#if defined(CONFIG_ARCH_HAS_MEMORY_BARRIER) | ||
|
||
#define arch_isb() __ISB() | ||
#define arch_mb() __DSB() | ||
#define arch_rmb() __asm__ volatile ("fence ir, ir" : : : "memory") | ||
#define arch_wmb() __asm__ volatile ("fence ow, ow" : : : "memory") | ||
#define arch_smp_mb() __DMB() | ||
#define arch_smp_rmb() __asm__ volatile ("fence r, r" : : : "memory") | ||
#define arch_smp_wmb() __asm__ volatile ("fence w, w" : : : "memory") | ||
|
||
#endif /* !CONFIG_ARCH_HAS_MEMORY_BARRIER */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I understand what you did here but I don't like it honestly. I have to think how to approach this better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK
4f284b2
to
41e959b
Compare
arch/Kconfig
Outdated
imply XIP | ||
select ARCH_HAS_MEMORY_BARRIER |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
swap these two lines
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack
arch/Kconfig
Outdated
bool "Enable architecture specific memory barrier support" | ||
help | ||
This option enable architecture specific function for | ||
the memory barrier API support. These functions can be | ||
implemented or builtin toolchain. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ARCH_HAS_*
symbols are usually hidden with no prompt.
bool "Enable architecture specific memory barrier support" | |
help | |
This option enable architecture specific function for | |
the memory barrier API support. These functions can be | |
implemented or builtin toolchain. | |
bool | |
help | |
This option signifies that the architecture does support and implement the | |
memory barrier functions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack
include/arch/arc/barrier.h
Outdated
|
||
#ifndef _ASMLANGUAGE | ||
|
||
/* Provide a default implementation for un-supported compilers. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need for this comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack
include/arch/arc/barrier.h
Outdated
@@ -0,0 +1,35 @@ | |||
/* | |||
* Copyright (c) 2022 Carlo Caione <ccaione@baylibre.com> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remember to change the copyright (if you are sending the PR your name must be here).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack
include/arch/arc/barrier.h
Outdated
|
||
#if defined(CONFIG_ARCH_HAS_MEMORY_BARRIER) | ||
/* Not implemented yet */ | ||
#error ARC arch has not memory barrier implementation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#error ARC arch has not memory barrier implementation | |
#error ARC arch does not have a memory barrier implementation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack
include/arch/arm/aarch32/barrier.h
Outdated
*/ | ||
#include <cmsis_compiler.h> | ||
|
||
/* Provide a default implementation for un-supported compilers. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/* Provide a default implementation for un-supported compilers. */ | |
/* | |
* Provide a default implementation for un-supported compilers. | |
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack
include/arch/riscv/barrier.h
Outdated
#ifndef __ISB | ||
#define __ISB() __asm__ volatile ("fence.i") | ||
#endif | ||
|
||
#ifndef __DSB | ||
#define __DSB() __asm__ volatile ("fence iorw, iorw" : : : "memory") | ||
#endif | ||
|
||
#ifndef __DMB | ||
#define __DMB() __asm__ volatile ("fence rw, rw" : : : "memory") | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stuck on one style for indentation (compare riscv indentation to other archs)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before this is ready please write a simple test build-only where you try to compile all the functions introduced for all the architectures.
|
Can you make this a test instead of a sample? |
41e959b
to
a2f1281
Compare
a2f1281
to
3eecd53
Compare
include/arch/arc/barrier.h
Outdated
#endif | ||
|
||
#if defined(CONFIG_ARCH_HAS_MEMORY_BARRIER) | ||
/* Not implemented yet */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove these comments, the error is enough
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ck
include/arch/arm/aarch32/barrier.h
Outdated
*/ | ||
|
||
#ifndef __ISB | ||
#define __ISB() __asm__ volatile ("isb 0xF":::"memory") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spacing volatile ("isb 0xF" ::: "memory")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack
#define arch_isb() __ISB() | ||
#define arch_mb() __DSB() | ||
#define arch_rmb() __asm__ volatile ("dsb ld" : : : "memory") | ||
#define arch_wmb() __asm__ volatile ("dsb st" : : : "memory") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keep a consistent spacing, you used one space for __ISB()
& co and now you are using tab / multiple spaces.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack
tests/kernel/mem_barrier/src/main.c
Outdated
__DMB(); | ||
arch_isb(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
space here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack
3eecd53
to
96570a5
Compare
include/arch/arm/aarch32/barrier.h
Outdated
*/ | ||
|
||
#ifndef __ISB | ||
#define __ISB() __asm__ volatile ("isb 0xF":::"memory") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's decide between ":::" and ": : :" and stick to it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack
include/arch/riscv/barrier.h
Outdated
#define arch_isb() __ISB() | ||
#define arch_mb() __DSB() | ||
#define arch_rmb() __asm__ volatile ("fence ir, ir" : : : "memory") | ||
#define arch_wmb() __asm__ volatile ("fence ow, ow" : : : "memory") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, this is ugly. Switch to a single tab for spacing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack
z_device_usable_check and device_usable_check functions return -ENODEV if device is not usable. Then, errno.h must be include to avoid build issue. Signed-off-by: Alexandre Mergnat <amergnat@baylibre.com>
96570a5
to
f80acae
Compare
I bring back the missing error define fix due to CI fail: https://github.com/zephyrproject-rtos/zephyr/runs/4870325901?check_suite_focus=true#step:11:659 |
include/barrier.h
Outdated
* This is used to guarantee that any subsequent instructions are fetched, so | ||
* that privilege and access are checked with the current MMU configuration. | ||
*/ | ||
#define arch_isb() __ISB() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alex, again, pick one single indenting style for macros and use that everywhere (we have now 1 space for __ISB()
& co, 1 tab for arch_*
in the arch headers and multiple tabs (??) here)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we have now 1 space for __ISB() & co
It's tab but wide as 1 space.
All arch headers use 1 Tab everywhere,
But you're right about this file, there are 2 Tabs and I will fix that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Introduce a new preprocessor based API for barriers. - Add HAS_ARCH_MEMORY_BARRIER option for memory barrier: The architecture must select it to use its own specific memory barrier functions. Signed-off-by: Alexandre Mergnat <amergnat@baylibre.com>
Add a basic implementation for ARM, ARM64 and RISC-V. Signed-off-by: Alexandre Mergnat <amergnat@baylibre.com>
- This test checks that the memory barrier API is fully defined to avoid build regression. Signed-off-by: Alexandre Mergnat <amergnat@baylibre.com>
f80acae
to
d29a618
Compare
This patch reworks how fragments are handled in the net_buf infrastructure. In particular, it removes the union around the node and frags members in the main net_buf structure. This is done so that both can be used at the same time, at a cost of 4 bytes per net_buf instance. This implies that the layout of net_buf instances changes whenever being inserted into a queue (fifo or lifo) or a linked list (slist). Until now, this is what happened when enqueueing a net_buf with frags in a queue or linked list: 1.1 Before enqueueing: +--------+ +--------+ +--------+ |#1 node|\ |#2 node|\ |#3 node|\ | | \ | | \ | | \ | frags |------| frags |------| frags |------NULL +--------+ +--------+ +--------+ net_buf #1 has 2 fragments, net_bufs #2 and #3. Both the node and frags pointers (they are the same, since they are unioned) point to the next fragment. 1.2 After enqueueing: +--------+ +--------+ +--------+ +--------+ +--------+ |q/slist |------|#1 node|------|#2 node|------|#3 node|------|q/slist | |node | | *flag | / | *flag | / | | / |node | | | | frags |/ | frags |/ | frags |/ | | +--------+ +--------+ +--------+ +--------+ +--------+ When enqueing a net_buf (in this case #1) that contains fragments, the current net_buf implementation actually enqueues all the fragments (in this case #2 and #3) as actual queue/slist items, since node and frags are one and the same in memory. This makes the enqueuing operation expensive and it makes it impossible to atomically dequeue. The `*flag` notation here means that the `flags` member has been set to `NET_BUF_FRAGS` in order to be able to reconstruct the frags pointers when dequeuing. After this patch, the layout changes considerably: 2.1 Before enqueueing: +--------+ +--------+ +--------+ |#1 node|--NULL |#2 node|--NULL |#3 node|--NULL | | | | | | | frags |-------| frags |-------| frags |------NULL +--------+ +--------+ +--------+ This is very similar to 1.1, except that now node and frags are different pointers, so node is just set to NULL. 2.2 After enqueueing: +--------+ +--------+ +--------+ |q/slist |-------|#1 node|-------|q/slist | |node | | | |node | | | | frags | | | +--------+ +--------+ +--------+ | +--------+ +--------+ | |#2 node|--NULL |#3 node|--NULL | | | | | +------------| frags |-------| frags |------NULL +--------+ +--------+ When enqueuing net_buf #1, now we only enqueue that very item, instead of enqueing the frags as well, since now node and frags are separate pointers. This simplifies the operation and makes it atomic. Resolves zephyrproject-rtos#52718. Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
Here is de CI result
zephyrproject-rtos#42549
For this proposal, ISB, DSB and DMB are, at least, defined for all arch. This allows to do a generic barrier API with. They are also definable in the toolchain.
The ARCH_HAS_MEMORY_BARRIER is more specific now. It seems the architecture have it own implementation of the barrier API.