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. |
| /* 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.
why need cast int16_t if NXSEM_COUNT return atomic_short?
There was a problem hiding this comment.
atomic_load returns uint64_t.
There was a problem hiding this comment.
see
nuttx/include/nuttx/lib/stdatomic.h
Lines 75 to 81 in daab676
nuttx/include/nuttx/lib/stdatomic.h
Lines 201 to 204 in daab676
There was a problem hiding this comment.
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.
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.
@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.
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.
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.
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
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
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
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.