-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add C11 standard atomic support #1763
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
Conversation
… lock state types
@kilograham @petrhosek Here is some fixes for the MacOS and Windows compilation failures. I also fixed a problem with the preinit section so it works as intended. Is is possible to launch the build checks so I can verify the fixes? |
FYI the error:
This is a GCC bug as |
volatile uint32_t *ptr = mem; | ||
uint32_t state = __atomic_lock(mem); | ||
uint32_t result = *ptr; | ||
unsigned int __atomic_fetch_add_4(volatile void *mem, unsigned int val, __unused int model) { |
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.
It looks like this (and the similiar foo_4
functions) should probably have remained as
uint32_t __atomic_fetch_add_4(volatile void *mem, uint32_t val, __unused int model) {
?
Esepcially as the other functions have signatures like:
uint8_t __atomic_fetch_add_1(volatile void *mem, uint8_t val, __unused int model) {
uint16_t __atomic_fetch_add_2(volatile void *mem, uint16_t val, __unused int model) {
uint64_t __atomic_fetch_add_8(volatile void *mem, uint64_t val, __unused int model) {
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 agree but there is a GCC bug here when -Wextra is enabled. Since uint32_t and unsigned int are the same type on ARMv6 this should not be a warning nor error. See https://github.com/raspberrypi/pico-sdk/actions/runs/9848449043/job/27190379443. The current linux cmake configuration does not enable -Wextra but I'm not clear how to enable it as my CMake skill are not great.
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.
Ah, sorry! I made this comment from just looking at the diff
view on GitHub, before realising that you'd actually specifically commented on this already!! 🤦
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, no I was hacking up a comment at the same time as you were reviewing and commenting.
Is the way the turn on -Wextra for the linux builds so that any further problems are exposed before I push more to the PR. |
Ah, sorry, a lot going on, so maybe didn't mention this yesterday: since when we have a rather different implementation from a separate source. |
So no interest in this? |
yup; no need for further fixes in this PR; we took it internally to fix the issues (compile, and things like "save" size that you have now fixed)...it will drop in as part of another PR |
@sgstreet did you actually verify that your functions are called by GCC; I saw that you #undefed a few functions, but I see on GCC that it just uses its own intrinsics by default |
Yes I tested it, the functions
are handled by GCC slightly differently than others, thus the overide. This following is an excerpt from my test map file:
Did you decide to take PR? |
I have used the extensively in a slightly different form pico-tookit See https://github.com/sgstreet/pico-toolkit/blob/a9172fc66659217560a13445877723b804a71347/test/atomic-test/atomic-test.c#L12. |
What functions was your test calling?
I am not taking the PR as Clang works somewhat differently; i'm trying to take the best parts of both (yours and another), but when i tried calling this on GCC
it uses its own non multi-core aware code; are you using explcit methods of the right size? also what GCC version? |
Disappointed you did not take the PR nor ask for a clang compatible solution as I would have researched it and built one. But to answer you question, please consider how the AHB Lite Bus operates. 1, 2 and 4 byte bus loads and stores are guaranteed atomic with respect to multi-masters. In some circumstances (not so important on ARMv6-m), a memory barrier will be required to ensure memory ordering. I'm sure you examined the generated code for the If you replace How are you implementing the multi-core awareness? Using the hardware semaphores? If so how many semaphore bits are you allocating? I have code which does this, but uses all 32 semaphore bits, not a big deal as once you have atomic variables the need for the raw hardware semaphores is reduced. This of course is not compatible with the SDK as current implemented. This could be reduced to 8 or 16 bits with minor impact to performance. Just curious really. Hope this helps. |
There is not a write buffer in front of the SRAM correct? |
Yes, sorry i wasn't thinking thru; CLang still emits calls on m0plus, and I was just comparing that with GCC.
I needed it yesterday, and when i first took the PR, there were a bunch of glaring bugs (which you have since fixed)... this interacts with some other stuff we're doing, so I didnt have time to go back and forth and fix the issues on github. thanks for your help, the spirit of your code is intact!! |
correct |
fixed in SDK 2.0.0 thanks for your PR |
This new version of the PR #1645 which was merged, closed and reverted. This version removes all usage of the GCC specific optimize attribute.