Skip to content

atomic: hwspinlock backend for cxd56, rp2040, lc823450 - #19868

Draft
zhangyu-duck wants to merge 4 commits into
apache:masterfrom
zhangyu-duck:pr3-atomic-builtin
Draft

atomic: hwspinlock backend for cxd56, rp2040, lc823450#19868
zhangyu-duck wants to merge 4 commits into
apache:masterfrom
zhangyu-duck:pr3-atomic-builtin

Conversation

@zhangyu-duck

@zhangyu-duck zhangyu-duck commented Aug 16, 2026

Copy link
Copy Markdown

Summary

Add hwspinlock-based atomic backend for multi-core capable chips:

  • Add hwspinlock driver implementations for cxd56, rp2040, and lc823450
  • Implement atomic operations using hwspinlock when LIBC_ATOMIC_HWSPINLOCK is selected
  • Rename arch_atomic_irq.c back to arch_atomic.c with combined IRQ + hwspinlock implementation

This PR depends on #19867 (multi-backend framework + builtin + API rename).

Stacked PR chain

Depends on #19867. This is PR 3 of 3:

Test

testbuild across RP2040/CXD56XX/LC823450

@github-actions github-actions Bot added Area: Bluetooth Arch: arm Issues related to ARM (32-bit) architecture Arch: arm64 Issues related to ARM64 (64-bit) architecture Arch: avr Issues related to all AVR(8-bit or 32-bit) architectures Arch: risc-v Issues related to the RISC-V (32-bit or 64-bit) architecture Arch: simulator Issues related to the SIMulator Arch: sparc Issues related to the SPARC architecture Arch: xtensa Issues related to the Xtensa architecture Size: XL The size of the change in this PR is very large. Consider breaking down the PR into smaller pieces. labels Aug 16, 2026
@github-actions

github-actions Bot commented Aug 16, 2026

Copy link
Copy Markdown

MemBrowse Memory Report

No memory changes detected for:

@github-actions

Copy link
Copy Markdown

🔗 Cross-repo PR dependencies

The read-only Build run reported the following dependent PR(s) and fetched head SHA(s):

CI run: https://github.com/apache/nuttx/actions/runs/32090737453

@zhangyu-duck
zhangyu-duck force-pushed the pr3-atomic-builtin branch 3 times, most recently from f0c81bb to 8b63c5f Compare August 18, 2026 08:22
@github-actions

Copy link
Copy Markdown

🔗 Cross-repo PR dependencies

The read-only Build run reported the following dependent PR(s) and fetched head SHA(s):

CI run: https://github.com/apache/nuttx/actions/runs/32116047543

@github-actions

Copy link
Copy Markdown

🔗 Cross-repo PR dependencies

The read-only Build run reported the following dependent PR(s) and fetched head SHA(s):

CI run: https://github.com/apache/nuttx/actions/runs/32132885300

@zhangyu-duck zhangyu-duck changed the title atomic: use toolchain builtin and rename atomic_fetch_xxx to atomic_xxx atomic: hwspinlock backend for cxd56, rp2040, lc823450 Aug 19, 2026
@zhangyu-duck
zhangyu-duck marked this pull request as ready for review August 19, 2026 06:35
@zhangyu-duck
zhangyu-duck requested a review from jerpelea as a code owner August 19, 2026 06:35
@jerpelea

Copy link
Copy Markdown
Contributor

please split the PR in separate PRs
EX:

  1. driver and documentation
  2. ARM arch implementation and documentation

@zhangyu-duck
zhangyu-duck force-pushed the pr3-atomic-builtin branch 5 times, most recently from 9b1d55a to afb4c2c Compare August 24, 2026 06:51
Use irq-based critical sections instead of spinlock_irq to avoid
potential deadlock in atomic contexts.

Signed-off-by: zhangyu117 <zhangyu117@xiaomi.com>
@github-actions github-actions Bot added Area: OS Components OS Components issues Size: M The size of the change in this PR is medium and removed Area: Bluetooth Arch: arm64 Issues related to ARM64 (64-bit) architecture Arch: avr Issues related to all AVR(8-bit or 32-bit) architectures Arch: renesas Issues related to the Renesas chips Arch: risc-v Issues related to the RISC-V (32-bit or 64-bit) architecture Arch: simulator Issues related to the SIMulator Arch: sparc Issues related to the SPARC architecture Arch: xtensa Issues related to the Xtensa architecture Size: XL The size of the change in this PR is very large. Consider breaking down the PR into smaller pieces. Board: arm labels Aug 24, 2026
#include <stdint.h>
#include <nuttx/irq.h>
#include <nuttx/macro.h>
#if defined(CONFIG_LIBC_ATOMIC_HWSPINLOCK)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where you add LIBC_ATOMIC_HWSPINLOCK?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, now in libc/machine/kconfig file

@github-actions

Copy link
Copy Markdown

🔗 Cross-repo PR dependencies

The read-only Build run reported the following dependent PR(s) and fetched head SHA(s):

CI run: https://github.com/apache/nuttx/actions/runs/32701216081

@github-actions

Copy link
Copy Markdown

❌ Cross-repo dependency could not be applied

The Build report says the declared dependency PR(s) could not be applied, so CI did not run against the combined code:

Reason: cherry-pick failed (if your PR has merge commits, rebase instead)

CI run: https://github.com/apache/nuttx/actions/runs/32726917623

Add hardware spinlock driver implementations for cxd56, rp2040, and
lc823450 chips. These drivers provide the hwspinlock_ops_s interface
used by the atomic hwspinlock backend.

Signed-off-by: zhangyu117 <zhangyu117@xiaomi.com>
Implement atomic_lock/atomic_unlock using hwspinlock when
CONFIG_LIBC_ATOMIC_HWSPINLOCK is selected, and using up_irq_save/
up_irq_restore when CONFIG_LIBC_ATOMIC_IRQ is selected. Rename
arch_atomic_irq.c to arch_atomic.c.

The 64-bit atomic operations use spinlock (spin_lock_irqsave)
regardless of the selected backend, ensuring multi-core safety.

Signed-off-by: zhangyu117 <zhangyu117@xiaomi.com>
Add per-chip atomic hwspinlock device definitions for cxd56, rp2040,
and lc823450. Replace CXD56_TESTSET with CXD56_ATOMIC_WITH_HWSEM
which selects LIBC_ATOMIC_HWSPINLOCK.

RP2040: Cortex-M0+ no atomic, IRQ for non-SMP, hwspinlock for SMP.
CXD56XX: CXD56_USE_SYSBUS controls hwsem usage in SMP.
LC823450: toolchain supports atomic, hwspinlock optional for SMP.

Signed-off-by: zhangyu117 <zhangyu117@xiaomi.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Arch: arm Issues related to ARM (32-bit) architecture Area: OS Components OS Components issues Size: M The size of the change in this PR is medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants