Add C11 standard atomic support #1763
No reviewers
Labels
No labels
bazel
bluetooth
board settings
boot_stage2
bug
build
c++
can't reproduce
clang
clib-interface
cmsis
code cleanliness
code size
compiler version issues
cyw43_driver
debug
discussion
documentation
duplicate
dynamic_clock
elf2uf2
enhancement
errata
filesystem
flash layout
floating point
FreeRTOS
hardware_adc
hardware_claim
hardware_clocks
hardware_dma
hardware_exception
hardware_flash
hardware_gpio
hardware_i2c
hardware_irq
hardware_pio
hardware_pwm
hardware_rcp
hardware_rtc
hardware_spi
hardware_sync
hardware_uart
hardware_vreg
hardware_watchdog
hardware_xosc
help wanted
host
IAR
installation
invalid
linker scripts
lto
lwip
mbedtls
missing API
needs reporter detail
networking
newlib
newlib-multicore
non-c
non-cmake
non-gcc
openocd
orphan PR
OS integration
pico_async_context
pico_base
pico_binary_info
pico_flash
picolibc
pico_lwip
pico_malloc
pico_multicore
pico_printf
pico_runtime
pico_stdio
pico_stdio_usb
pico_sync
pico_time
pico_util
pioasm
port
question
review
review2
rtos interop
runtime init
static library
svd
test
tinyusb
vscode
wifi integration
wontfix
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-raspberrypi/pico-sdk!1763
Loading…
Reference in a new issue
No description provided.
Delete branch "add-atomic-support"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This new version of the PR #1645 which was merged, closed and reverted. This version removes all usage of the GCC specific optimize attribute.
@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
uint32_tandunsigned intare the same type on the ARMv6 arch and interesting the other atomic types do not generate compiler warnings.@ -0,0 +335,4 @@return result;}void __atomic_clear_m0(volatile void *mem, __unused int model) {It looks like this (and the similiar
foo_4functions) should probably have remained as?
Esepcially as the other functions have signatures like:
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.
@ -0,0 +335,4 @@return result;}void __atomic_clear_m0(volatile void *mem, __unused int model) {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.
@ -0,0 +335,4 @@return result;}void __atomic_clear_m0(volatile void *mem, __unused int model) {Ah, sorry! I made this comment from just looking at the
diffview on GitHub, before realising that you'd actually specifically commented on this already!! 🤦@ -0,0 +335,4 @@return result;}void __atomic_clear_m0(volatile void *mem, __unused int model) {No, no I was hacking up a comment at the same time as you were reviewing and commenting.
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
github.com/sgstreet/pico-toolkit@a9172fc666/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
atomic_loadabove and saw thedmb ishordmb sysinstructions. The generated load/store code is sufficient and there is no need to implement replacements. This is not the case for 8 byte quantities and atomic read/modify/write functions.If you replace
atomic_uint_fast32_twithatomic_uint_fast64_tyou should see in the disassembly a call to__atomic_load_8. Further, any call to a read/modify/write atomic function such asatomic_exchangewill generate a function call to one of the size matched functions in the library.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
Pull request closed