atomic: multi-backend framework + builtin + API rename - #19867
atomic: multi-backend framework + builtin + API rename#19867zhangyu-duck wants to merge 10 commits into
Conversation
|
748b13e to
4084ae2
Compare
4175fc5 to
469409e
Compare
469409e to
11a8d03
Compare
11a8d03 to
8f4e0a4
Compare
🔗 Cross-repo PR dependenciesThe read-only Build run reported the following dependent PR(s) and fetched head SHA(s): CI run: https://github.com/apache/nuttx/actions/runs/32223697536 |
|
breaking change commits and PR must me preceded by ! |
8f4e0a4 to
eba0b06
Compare
The atomic implementation of machine/arch_atomic.c is achieved by switching interrupts. This version does not support SMP. Signed-off-by: zhangyu117 <zhangyu117@xiaomi.com>
Tricore gcc does not support atomic interface but some users need to use atomic operations, so support atomic function using tricore arch instructions (__cmpAndSwap/__swap/__ld32). Signed-off-by: zhangyu117 <zhangyu117@xiaomi.com>
eba0b06 to
110b0b1
Compare
🔗 Cross-repo PR dependenciesThe read-only Build run reported the following dependent PR(s) and fetched head SHA(s): CI run: https://github.com/apache/nuttx/actions/runs/32266949770 |
Refine the atomic Kconfig to support multiple backends: LIBC_ATOMIC_TOOLCHAIN (compiler builtins), LIBC_ATOMIC_ARCH (arch instructions), and LIBC_ATOMIC_IRQ (interrupt disable). Rename arch_atomic.c to arch_atomic_irq.c since it supports the IRQ backend. Signed-off-by: zhangyu117 <zhangyu117@xiaomi.com>
110b0b1 to
154ec47
Compare
…c64.c Split the atomic implementation into three files: - arch_atomic.h: Shared macros (STORE, LOAD, etc.) using atomic_lock()/ atomic_unlock() abstraction - arch_atomic_irq.c: 32-bit atomic functions using IRQ disable (conditional on CONFIG_LIBC_ATOMIC_IRQ via Make.defs) - arch_atomic64.c: 64-bit atomic functions using spinlock (always compiled, multi-core safe). The __atomic_* functions are always provided (GCC runtime helpers), while nx_atomic_* functions are conditional on !CONFIG_LIBC_ATOMIC_TOOLCHAIN. Signed-off-by: zhangyu117 <zhangyu117@xiaomi.com>
Select LIBC_ATOMIC_IRQ at the architecture level (ARM7TDMI, ARM926EJS, ARMv6M) for chips that do not support atomic operations natively. This covers all ARM7TDMI, ARM926EJS, and Cortex-M0 based chips automatically. Also select LIBC_ATOMIC_IRQ for specific non-ARM architectures (AVR, RISC-V, SPARC, Xtensa) that lack atomic instruction support. Signed-off-by: zhangyu117 <zhangyu117@xiaomi.com>
Replace atomic_load with atomic_read in call sites to use the unified interface defined in <nuttx/atomic.h>. Signed-off-by: zhangyu117 <zhangyu117@xiaomi.com>
1. for tasking, map __c11_atomic_xxx as tasking_atomic_xxx 2. for msvc, map _Interlocked_xxx as msvc_atomic_xxx 3. if no special map, use gcc/clang as default as they are most widely used. Signed-off-by: zhangyu117 <zhangyu117@xiaomi.com>
The reason for using builtin atomic is that in C++, when include <atomic> in <nuttx/atomic.h> easily conflicts with third-party function libraries. We wanted to completely separate the implementation of <nuttx/atomic.h>. There are two points: 1. use builtin function directly. 2. Without the standard library implementation, need implement "atomic_fetch_xxx", leading conflicts with the standard library used by third-party programs, introducing redefinition issues and requiring name changes. Signed-off-by: zhangyu117 <zhangyu117@xiaomi.com>
Rename atomic_fetch_add/sub/or/and/xor to atomic_add/sub/or/and/xor to avoid conflicts with the C/C++ standard library naming. The atomic_fetch_xxx naming is reserved by the standard; keeping it causes function name conflicts when source files indirectly include both <nuttx/atomic.h> and <atomic>/<stdatomic.h>. Signed-off-by: zhangyu117 <zhangyu117@xiaomi.com>
1. use _atomic as wrapper because if _Atomic empty, may affects the compilation of other files: 2. for clang builtin function, it donot accept param with keyword "_Atomic" Signed-off-by: zhangyu117 <zhangyu117@xiaomi.com>
154ec47 to
2aa1e74
Compare
🔗 Cross-repo PR dependenciesThe read-only Build run reported the following dependent PR(s) and fetched head SHA(s): CI run: https://github.com/apache/nuttx/actions/runs/32450732020 |
|
Hi everyone, I have a question. The Build workflow supports fetching companion apps via depends-on, but the MemBrowse workflow doesn't seem to support this. Is there a way to enable it for MemBrowse as well? Now build process is Ok, Thanks! |
@zhangning21 could you look at this problem? before this issue get fixed, let's ignore it. |
@xiaoxiang781216 @zhangyu-duck The Depends-On support was only added to I can add it there as well if that's wanted. |
Summary
Rework the atomic implementation to support multiple selectable backends via Kconfig:
LIBC_ATOMIC_TOOLCHAIN- compiler builtins (default, lock-free)LIBC_ATOMIC_ARCH- arch-native atomic instructions (lock-free)LIBC_ATOMIC_HWSPINLOCK- hardware spinlock wrapping critical section (cross-core)LIBC_ATOMIC_IRQ- IRQ disable wrapping critical section (single-core fallback)Switch
<nuttx/atomic.h>to call toolchain builtin atomic functions directly (__atomic_*/__c11_atomic_*/_Interlocked*), avoiding conflicts with third-party C/C++ standard libraries.Rename
atomic_fetch_xxx->atomic_xxx(e.g.,atomic_fetch_add->atomic_add) because theatomic_fetch_xxxnaming is reserved by the C/C++ standard and conflicts with standard library declarations.Use
_Atomicqualifier foratomic_ttypedef when supported, with a__Atomic(t)wrapper for clang/C++ compatibility.Breaking change
This is a breaking API change. A companion PR in the apps tree renames call sites (
atomic_fetch_add->atomic_add, etc.).depends-on: apache/nuttx-apps/pull/3733
Stacked PR chain
Depends on #19866. This is PR 2 of 3:
Test
CI testbuild across ARM/RISC-V/SIM targets.