Skip to content

zephyr: Replace critical-section implementation #81

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

d3zd3z
Copy link
Collaborator

@d3zd3z d3zd3z commented Apr 9, 2025

There is a fairly fundamental incompatibility between Zephyr spin locks and the Critical Section specification. Zephyr spin locks do not allow nesting from within a single spin lock. The critical section API only has an acquire and release entry, and provides no way (such as a stack frame) to have a unique context for different invocation places.

Unfortunately, this means we cannot use spin locks for critical sections.

Instead, this change implements critical sections using irq locking. The implementation of these macros on Zephyr does try to make them SMP safe, with a simple atomic lock, but there is still something preventing the riscv SMP from working.

Also, these entries cannot be called from user mode. There are various other reasons we don't support usermode, so at this time, just have a compile time assertion that usermode is not enabled in the build. If it is needed, we will have to come up with another way to implement this.

d3zd3z added 2 commits April 9, 2025 09:48
These are macros in Zephyr, so write explicit wrappers for them, that
bindgen will be able to directly use.

Signed-off-by: David Brown <[email protected]>
There is a fairly fundamental incompatibility between Zephyr spin locks
and the Critical Section specification.  Zephyr spin locks do not allow
nesting from within a single spin lock.  The critical section API only
has an `acquire` and `release` entry, and provides no way (such as a
stack frame) to have a unique context for different invocation places.

Unfortunately, this means we cannot use spin locks for critical
sections.

Instead, this change implements critical sections using irq locking.
The implementation of these macros on Zephyr does try to make them SMP
safe, with a simple atomic lock, but there is still something preventing
the riscv SMP from working.

Also, these entries cannot be called from user mode.  There are various
other reasons we don't support usermode, so at this time, just have a
compile time assertion that usermode is not enabled in the build.  If it
is needed, we will have to come up with another way to implement this.

Signed-off-by: David Brown <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant