Skip to content

zephyr: use the Zephyr time and delay calls directly - #11570

Merged
lgirdwood merged 1 commit into
thesofproject:mainfrom
lgirdwood:topic/zn-rtos-time
Dec 2, 2026
Merged

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

Conversation

@lgirdwood

@lgirdwood lgirdwood commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

Use the Zephyr time and delay calls directly instead of the SOF wrappers that only forwarded to them. Part of #11517 (step 2, "Kernel-only code: switch to Zephyr APIs directly").

Changes

  • sys_cycle_get_64_rate() → sys_clock_hw_cycles_per_sec() for the DAI wallclock rate. It is the same constant unless the timer driver reads its rate at runtime, and then the wallclock rate matches the rate the cycle conversions use.
  • sof_cycle_get_64_atomic() → sof_cycle_get_64() in the two DMA domains, the last users. sof_cycle_get_64_safe() had no users. Both aliases are removed, and so are the unused host versions.
  • wait_delay(), wait_delay_us() and wait_delay_ms() → k_busy_wait() in the detect test, the AMD ACP 7.x clock code and poll_for_register_delay(). The Zephyr wrappers are removed.

Not in this PR

  • poll_for_register_delay() and wait_for_interrupt(): only the i.MX and AMD IPC drivers use them. They go when those drivers move to Zephyr ([FEATURE] Remove the remaining XTOS-era code and move SOF to native Zephyr APIs and drivers #11517 steps 9 and 13). poll_for_register_delay() keeps its current polling, so i.MX IPC init timing is unchanged.
  • sof_cycle_get_64(): kept, because k_cycle_get_64() asserts on platforms without a 64-bit counter.
  • platform_timer_stop(): kept, because the IPC handlers that call it are also built for the host, where it is a real function.
  • Host wait_delay*(): kept for the host k_sleep() stubs.

Functional change

None. With one inline function less, GCC allocates registers and lays out branches differently in default_detect_test() and poll_for_register_delay(); no other object changes.

Testing

  • Builds: tested with the other three PRs of this series (zephyr: call the Zephyr cache API directly in kernel-only code #11571, zephyr: use the Zephyr assert and panic macros in kernel-only code #11572 and zephyr: remove unused interrupt and debug linkage stubs #11573) stacked on main (7cff357), each commit built incrementally and the tip from scratch, and compared with main: 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. The only changes are the two functions above, plus the objects that embed the git version. With all four PRs applied, platform_dai_wallclock() in the NVL wrapper.c also gains three bytes of alignment padding before a branch target; its instructions are the same.
  • Platforms that already fail on main (acp_6_0, acp_7_0, acp_7_x, mt8186, mt8188, mt8195, mt8196, mt8365, phyboard): same error sets. acp_7_x fails at configure on main, so the clock code change could not be compiled; it is a plain rename.
  • Cadence xt-clang: MTL, PTL and NVL compile.
  • ZTest: 37 of 37 configurations pass, run as in CI.
  • Host: the host library builds.

🤖 Generated with Claude Code

The Zephyr versions of these SOF time and delay helpers only forwarded
to a Zephyr call:

- sys_cycle_get_64_rate() returned CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC,
  use sys_clock_hw_cycles_per_sec() instead. It is the same constant
  unless the timer driver reads its rate at runtime, in which case the
  wallclock rate now matches the rate that the cycle conversions use.
- sof_cycle_get_64_atomic() and sof_cycle_get_64_safe() were aliases of
  sof_cycle_get_64(). The two DMA domains were the last users of the
  first one, the second one had no users, and the host versions had no
  users either.
- wait_delay(), wait_delay_us() and wait_delay_ms() wrapped
  k_busy_wait(). Call k_busy_wait() in the detect test, the AMD ACP 7.x
  clock code and poll_for_register_delay().

poll_for_register_delay() and wait_for_interrupt() stay for the i.MX and
AMD IPC drivers until those move to Zephyr. The host keeps its own
wait_delay*() for its k_sleep() stubs.

No functional change. With one inline function less, GCC allocates
registers and lays out branches differently in default_detect_test()
and poll_for_register_delay(); the other objects are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>

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.

🟢 Approval recommended

There are no active review findings requiring changes.

No open issues 🎉

What changed in this PR

This PR advances #11517’s migration to native Zephyr APIs by removing redundant SOF time and delay wrappers while retaining required host support and the portable cycle-counter helper.

Changes:

  • Use Zephyr’s clock-rate and busy-wait APIs directly.
  • Replace DMA scheduler cycle-counter aliases with sof_cycle_get_64().
  • Remove unused timer aliases and Zephyr delay wrappers, retaining host delay helpers.
File Description
zephyr/​wrapper.c Use Zephyr APIs for wallclock frequency and polling delays.
zephyr/​include/​rtos/​wait.h Remove redundant Zephyr delay wrappers.
zephyr/​include/​rtos/​timer.h Remove the clock-rate wrapper and unused cycle-counter aliases.
src/​schedule/​dma_single_chan_domain.c Call sof_cycle_get_64() directly for scheduling checks.
src/​schedule/​dma_multi_chan_domain.c Call sof_cycle_get_64() directly for task readiness.
src/​samples/​audio/​detect_test.c Use Zephyr busy-wait calls for simulated processing load.
src/​kernel/​platform/​amd/​acp_7_x/​lib/​clk.c Replace delay wrappers with k_busy_wait().
posix/​include/​rtos/​timer.h Remove unused host cycle-counter helpers.

Review effort: Balanced

@intel-sofci

Copy link
Copy Markdown

PR 11570: test results

Run date: 2026-12-01 22:19 UTC

Tested commit: 3ffd7ea370bde84f67f81ee5f6e052364198dbf4

mtl pass rate lnl pass rate ptl pass rate wcl pass rate nvl pass rate

@lgirdwood

Copy link
Copy Markdown
Member Author

CI unrelated.

@lgirdwood
lgirdwood merged commit 026645a into thesofproject:main Dec 2, 2026
44 of 46 checks passed
@lgirdwood
lgirdwood deleted the topic/zn-rtos-time branch December 2, 2026 16:40
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.

5 participants