-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
semaphore: Fix a few regressions #14755
Conversation
Regressions caused by signedness issues in "sem: change sem wait to atomic operation". (apache#14465) An alternative would be to make these atomic macros propagate signedness using the typeof() GCC/clang extension. I'm not inclined to do so because typeof is not so portable though. As we can unlikely require "real" C11 atomics in the foreseeable future, maybe we should use a different set of names from C11 to avoid confusions.
fdafc8e
to
ee3f119
Compare
[Experimental Bot, please feedback here] No, this PR does not fully meet the NuttX requirements. While it provides a summary of the why and how, it lacks detail in several crucial sections:
Specifically, the author needs to:
Without these changes, the PR is incomplete and difficult to review properly. |
@@ -880,7 +880,7 @@ void nxsem_canceled(FAR struct tcb_s *stcb, FAR sem_t *sem) | |||
{ | |||
/* Check our assumptions */ | |||
|
|||
DEBUGASSERT(atomic_load(NXSEM_COUNT(sem)) <= 0); | |||
DEBUGASSERT((int16_t)atomic_load(NXSEM_COUNT(sem)) <= 0); |
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 need cast int16_t if NXSEM_COUNT return atomic_short?
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.
atomic_load returns uint64_t.
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.
see
nuttx/include/nuttx/lib/stdatomic.h
Lines 75 to 81 in daab676
#define atomic_load_n(obj, type) \ | |
(sizeof(*(obj)) == 1 ? __atomic_load_1(obj, type) : \ | |
sizeof(*(obj)) == 2 ? __atomic_load_2(obj, type) : \ | |
sizeof(*(obj)) == 4 ? __atomic_load_4(obj, type) : \ | |
__atomic_load_8(obj, type)) | |
#define atomic_load(obj) atomic_load_n(obj, __ATOMIC_RELAXED) |
nuttx/include/nuttx/lib/stdatomic.h
Lines 201 to 204 in daab676
uint8_t __atomic_load_1(FAR const volatile void *ptr, int memorder); | |
uint16_t __atomic_load_2(FAR const volatile void *ptr, int memorder); | |
uint32_t __atomic_load_4(FAR const volatile void *ptr, int memorder); | |
uint64_t __atomic_load_8(FAR const volatile void *ptr, int memorder); |
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.
but the spec requires it return the same base type:
https://en.cppreference.com/w/c/atomic/atomic_load
we should fix the implementation instead. @crafcat7
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.
IMO, we should not pretend to have generic selection.
it's simpler to use concrete-type apis like, say, nx_atomic_load_int16.
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.
@crafcat7 please fix this ASAP.
We can consider whether there is a better way to reorganize arch_atomic & nuttx/stdatomic.c so that they can directly go to the atomic processing of the corresponding type, in other words, it can return the same result type as the input type parameter.
This work should take some time.
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.
IMO, we should not pretend to have generic selection. it's simpler to use concrete-type apis like, say, nx_atomic_load_int16.
Yes, but it's this is the standard defined prototype:(
my suggestion is to use nuttx-specific, non-standard prototype.
besides that, we can provide c11 stdatomic to user applications where possible.
but our own code (eg. semaphore implementation) should not use it, IMO.
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.
This work should take some time.
that's my expection too.
in the meantime, IMO, we should make band-aid fixes (like this PR) or a revert.
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.
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.
i'd suggest to revert the change in question for now because it would take some time to fix regressions: #14804
So that it can be used in more situations. The primary motivation here is to avoid crashes introduced by apache#14722. Tested: - esp32-devkitc:wifi_smp (smp) - esp32s3-devkit:smp (ostest, smp) (with apache#14755)
This reverts commit befe298. Because a few regressions have been reported and it likely will take some time to fix them: * for some configurations, semaphore can be used on the special memory region, where atomic access is not available. cf. apache#14625 * include/nuttx/lib/stdatomic.h is not compatible with the C11 semantics, which the change in question relies on. cf. apache#14755
i marked this draft because i'm now inclined to think it's simpler to make a revert. #14804 |
This reverts commit befe298. Because a few regressions have been reported and it likely will take some time to fix them: * for some configurations, semaphore can be used on the special memory region, where atomic access is not available. cf. #14625 * include/nuttx/lib/stdatomic.h is not compatible with the C11 semantics, which the change in question relies on. cf. #14755
Summary
Regressions caused by signedness issues in
"sem: change sem wait to atomic operation".
(#14465)
An alternative would be to make these atomic macros propagate signedness using the typeof() GCC/clang extension. I'm not inclined to do so because typeof is not so portable though. As we can unlikely require "real" C11 atomics in the foreseeable future, maybe we should use a different set of names from C11 to avoid confusions.
Impact
Testing
esp32s3-devkit:smp ostest, with a few unrelated local changes.