Skip to content

treewide: remove k_spinlock_init() - #11599

Draft
lgirdwood wants to merge 1 commit into
thesofproject:mainfrom
lgirdwood:topic/zn-rtos-spinlock-init
Draft

lgirdwood wants to merge 1 commit into
thesofproject:mainfrom
lgirdwood:topic/zn-rtos-spinlock-init

Conversation

@lgirdwood

Copy link
Copy Markdown
Member

Remove k_spinlock_init(). Part of #11517 (step 2).

Zephyr has no spinlock initializer: a struct k_spinlock is ready to use when its memory is zero. k_spinlock_init() is an SOF addition that clears the locked flag on SMP builds and does nothing on the host.

Why removing it is safe

Every lock it initializes is already zero:

Lock container Allocation
DAI (dai_get()), schedule domain (domain_init()) allocated, then memset() or rzalloc()
coherent objects, IPC, notifier, IRQ cascades rzalloc()
Dolby DAX adapter data mod_zalloc()
DMA table, AMD DAI and DMA tables, kcps budget, I/O performance monitor, pipeline position, IRQ cascade root static
KPB (non-Zephyr path), posix k_mutex_init() host only: the host spinlock is an empty struct

Where an init function can run again, the lock is not held at that point. Zephyr leaves an unlocked spinlock all zero (locked is 0, and the CONFIG_SPIN_VALIDATE owner is cleared on unlock), so the call did nothing there either.

The loops that only initialized the locks are removed with the calls.

Functional change

None. The Zephyr builds no longer store a zero into locks that are already zero.

Testing

  • Builds: tested as part of a stack with the other Wave C PRs on top of posix: host stubs for the Zephyr atomic, cache and assert APIs #11583 (this PR does not depend on them), first on main 829c0ac: every commit built incrementally and the tip from scratch, for tgl, tgl-h, mtl, lnl, ptl, wcl, nvl, nvl-s, imx8, imx8x, imx8m, imx8m_cm7, imx8ulp, imx93, imx95, qemu_xtensa, qemu_xtensa_mmu, native_sim, and the PTL userspace, LL-userspace and LLEXT, MTL LLEXT, TGL/PTL debug-stream and TGL/MTL/LNL/PTL CI overlay configurations.
  • Objects: every object hashed with the debug sections stripped and compared commit by commit. Objects change only in the edited files and in the inline users of domain_init() and the coherent API, where the zero stores are removed.
  • Platforms that already fail on main (acp_6_0, acp_7_0, acp_7_x, mt8186, mt8188, mt8195, mt8196, mt8365, phyboard): same error sets.
  • After the rebase on main bfa5201: ptl, ptl-us, mtl, lnl, tgl, imx8m and native_sim build.
  • Cadence xt-clang: MTL, PTL and NVL compile.
  • ZTest: 38 of 38 configurations pass, run as in CI.
  • Host: the host library builds, and the CI testbench steps (SOF alsa-lib/alsa-utils, test topologies, testbench build, host-testbench.sh) pass all 19 component tests.

🤖 Generated with Claude Code

Zephyr has no spinlock initializer: a struct k_spinlock is ready to use
when its memory is zero. k_spinlock_init() is an SOF addition that
clears the locked flag on SMP builds, and does nothing on the host.

Every lock it initializes is already zero: the containers come from
rzalloc() or mod_zalloc(), are memset() after allocation (dai_get(),
domain_init()) or are static (the DMA and AMD DAI tables, the kcps and
I/O performance monitor data, the pipeline position and IRQ cascade
root). Where an init function can run again, the lock is not held, and
Zephyr leaves an unlocked spinlock all zero.

Remove the calls and both definitions. Loops that only initialized the
locks go with them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants