Skip to content

treewide: remove k_spinlock_init() - #11599

Merged
lgirdwood merged 1 commit into
thesofproject:mainfrom
lgirdwood:topic/zn-rtos-spinlock-init
Dec 4, 2026
Merged

lgirdwood merged 1 commit into
thesofproject:mainfrom
lgirdwood:topic/zn-rtos-spinlock-init

Conversation

@lgirdwood

@lgirdwood lgirdwood commented Dec 2, 2026 •

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.

The Zephyr rtos/spinlock.h now only notes that Zephyr has no spinlock initializer and that a zero-filled struct k_spinlock is unlocked.

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 aae1cef: ptl, ptl-us, mtl, lnl, tgl, tgl-h, wcl, nvl, imx8m and native_sim build, and ZTest passes 38 of 38.
  • PTL hardware: firmware built from this branch boots, and the SOF smoke tests pass (11 of 11: analog playback at 48 kHz S16/S24/S32 and 44.1 kHz, deep-buffer playback, analog capture S16/S32, full duplex, concurrent analog and deep-buffer playback, 10 start/stop cycles, 3 runtime D3 suspend/resume cycles with playback). These run on the primary core only.
  • After the review fix: mtl, lnl, tgl, tgl-h, wcl, nvl, imx8, imx8m, imx8ulp, native_sim, ptl-us and qemu_xtensa build, the host library builds, and ZTest passes 38 of 38.
  • 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

@lgirdwood
lgirdwood force-pushed the topic/zn-rtos-spinlock-init branch from 40d1b7e to cbadb44 Compare December 4, 2026 13:08
@lgirdwood
lgirdwood marked this pull request as ready for review December 4, 2026 13:49
Copilot AI balanced review requested due to automatic review settings December 4, 2026 13:49

Copilot AI left a comment

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.

🟡 Changes recommended

The spinlock header retains an orphaned Doxygen block that contradicts the zero-initialization contract and should be removed.

1 open issue
What changed in this PR

Removes SOF’s k_spinlock_init() wrapper as part of the transition to native Zephyr APIs in #11517, relying on existing zero-initialization.

Changes:

  • Removes the Zephyr initializer and host stub.
  • Deletes redundant initialization calls and lock-only loops.
  • Preserves mutex initialization where required.
File Description
zephyr/​lib/​dma.c Removes lock initialization loop; scopes remaining loop variable.
zephyr/​include/​rtos/​spinlock.h Removes Zephyr initializer wrapper.
src/​lib/​notifier.c Removes notifier lock initialization.
src/​kernel/​platform/​amd/​rembrandt/​lib/​dma.c Removes DMA lock initialization loop.
src/​kernel/​platform/​amd/​rembrandt/​lib/​dai.c Removes DAI lock initialization loops.
src/​kernel/​lib/​cpu-clk-manager.c Removes KCPS lock initialization.
src/​kernel/​ipc/​ipc-common-kernel.c Removes IPC lock initialization.
src/​kernel/​drivers/​interrupt.c Removes interrupt cascade lock initialization.
src/​kernel/​debug/​telemetry/​performance_monitor.c Removes monitor lock initialization.
src/​include/​sof/​schedule/​ll_schedule_domain.h Removes spinlock initialization; retains mutex setup.
src/​include/​sof/​coherent.h Removes coherent-object lock initialization.
src/​audio/​pipeline/​pipeline-graph.c Removes position spinlock initialization; retains mutex setup.
src/​audio/​module_adapter/​module/​dolby/​dax.c Removes DAX lock initialization.
src/​audio/​kpb.c Replaces host initializer call with explanatory comment.
src/​audio/​dai-zephyr.c Removes DAI lock initialization.
posix/​include/​rtos/​spinlock.h Removes no-op host initializer macro.
posix/​include/​rtos/​mutex.h Removes redundant host spinlock initializer call.

Review effort: Balanced

#endif
}

#endif /* __ZEPHYR_RTOS_SPINLOCK_H__ */

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in c58f933: the block is gone, the file brief no longer mentions initialization, and in its place the header notes that Zephyr has no spinlock initializer and that a zero-filled struct k_spinlock is unlocked. I also checked the other removed calls for leftover comments; there were none.

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>
@lgirdwood
lgirdwood force-pushed the topic/zn-rtos-spinlock-init branch from cbadb44 to c58f933 Compare December 4, 2026 16:10
@lgirdwood

Copy link
Copy Markdown
Member Author

CI infra issues on internal CI.

@lgirdwood
lgirdwood merged commit 184ad68 into thesofproject:main Dec 4, 2026
43 of 47 checks passed
@lgirdwood
lgirdwood deleted the topic/zn-rtos-spinlock-init branch December 4, 2026 19:01
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.

4 participants