-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
posix: use sys_sem instead of k_spinlock for pool synch #71832
posix: use sys_sem instead of k_spinlock for pool synch #71832
Conversation
a69dcc7
to
d4b9019
Compare
5ece3aa
to
b25d612
Compare
|
b25d612
to
b32cb40
Compare
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.
Still +1 from me. Blocking IPC definitely seems like a better choice here.
I enabled userspace in the test suite so there are a bunch of fun new corner cases, hehe. Will get to them shortly. It makes things a bit more interesting at least, but it should be more robust in the end, which is good. |
This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time. |
This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time. |
Add SYS_SEM_LOCK() and SYS_SEM_LOCK_BREAK which are mostly the same as K_SPINLOCK() and K_SPINLOCK_BREAK. Signed-off-by: Chris Friedt <[email protected]>
SYS_SEM_LOCK() is a for-loop-like macro similar inspired by K_SPINLOCK(). Add an entry to .clang-format so that autoformatting works as expected. Signed-off-by: Chris Friedt <[email protected]>
Based on Andy's talk at eoss 2024, use the sys/sem.h api instead of the spinlock.h api to synchronize pooled elements since it has minimal overhead like semaphores but also works from userspace. Signed-off-by: Chris Friedt <[email protected]>
b32cb40
to
60c8a88
Compare
Ensure that userspace is tested in the common posix testsuite. Signed-off-by: Chris Friedt <[email protected]>
60c8a88
to
ebf29ab
Compare
5 months and 2 releases later 😅 There was maybe a minor time warp, but I hope that @andyross will re-approve 🙏 😁 |
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.
Still looks good 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.
Nice.
* @param sem Semaphore (@ref sys_sem) used to guard the enclosed code block. | ||
*/ | ||
#define SYS_SEM_LOCK(sem) \ | ||
for (int __rc SYS_SEM_LOCK_ONEXIT = sys_sem_take((sem), K_FOREVER); ({ \ |
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.
@andyross Your pattern is getting popular. :-) Maybe we need some macro soon to generate it w/o repeating ourselves?
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.
Yeah, though (and I know I introduced it), I worry about the "deadlock on break/continue" problem with non-GNU toolchains, which do exist. We don't really have a clean answer for how to prevent/detect that misuse. When it was just the one helper macro in the scheduler it seemed maintainable, but now that it's everywhere I'm getting cold feet and mostly hoping someone else decides what to do :)
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.
Is that an LLVM issue too then? And is the root cause use of statement expressions?
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.
Looks good
This is a repeat of #71718.
changelog:
sys_sem
(extremely improbably) fails to be takenplatform_key
field and do away withintegration_platforms
foruserspace
tests, providing easily scalable test coverage across architecturesFixes #79278