Skip to content

Kernel/user partition, Phase 5 part 3: trigger DAI groups without the notifier - #11512

Merged
lgirdwood merged 6 commits into
thesofproject:mainfrom
lgirdwood:kernel-user/phase5c
Nov 29, 2026
Merged

lgirdwood merged 6 commits into
thesofproject:mainfrom
lgirdwood:kernel-user/phase5c

Conversation

@lgirdwood

@lgirdwood lgirdwood commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

Phase 5 of #11306 (kernel / user-space partition), third part: DAI groups no longer use the notifier.

Background

A DAI group starts and stops several DAIs together. Each DAI counts the trigger commands it gets. The last DAI of the group to receive the command triggers the whole group, with IRQs locked.

That trigger was a NOTIFIER_ID_DAI_TRIGGER event on the local core, which every DAI of the group registered for. The notifier is not usable from user space, and Phase 5 removes it.

What changes

  • The member list: a group keeps a list of its DAIs.
    • A DAI joins the list when it is assigned to the group (dai_assign_group()), and dai_common_free() removes it.
    • The last DAI to receive the command walks the list and triggers each DAI. The list is in the same order as the notifier list was.
  • Errors: the group still returns the error of the last trigger.
  • Locking: the DAIs are triggered with IRQs locked, as before. In user-space LL builds irq_local_disable() is privileged, so the group trigger takes the LL scheduler lock instead, as the copier does for its channel map update. The lock is re-entrant, so this is safe if the caller already holds it.
  • Removed: NOTIFIER_ID_DAI_TRIGGER and struct dai_group::trigger_ret.

Both the Zephyr DAI (dai-zephyr.c) and the legacy DAI (dai-legacy.c) change. They share the group code in src/lib/dai.c.

Fixes

With IPC4 the DAI is a copier, and dai_assign_group() gets the copier device. Two things were wrong there:

  • The notifier callback took the DAI data from comp_get_drvdata(). For a copier that is the module, not the DAI data.
  • copier_dai_free() did not unregister from the notifier, so a freed copier stayed registered.

The walk uses each member's DAI data and its component, and dai_common_free() removes the DAI from the group, so both are fixed.

In practice, IPC4 never sets a group ID: the Linux driver aggregates links with ALH multi-gateway instead. Only IPC3 hosts can send one, in sof_ipc_dai_config.group_id.

Behaviour changes

  • User-space LL builds: the group trigger is atomic against the LL tasks of its core, but not against interrupts. Before, these builds called the privileged irq_local_disable() from user code.
  • Other builds: none.

Patches

  1. test: ztest: add DAI group trigger tests, on main's notifier-based code (see Unit tests below).
  2. dai: trigger a DAI group by walking its DAIs instead of the notifier. The unit test no longer links the notifier; its cases are unchanged.
  3. notifier: remove NOTIFIER_ID_DAI_TRIGGER. The IDs after it are renumbered; they are internal to the firmware.
  4. dai: trigger a DAI group of one DAI. The first DAI to get a command set the count of DAIs still to get it to num_dais - 1 and never triggered, so a group of one DAI (for example, after the others were freed) never triggered. The first DAI now counts like the others. Groups of more DAIs behave as before. The same fix is applied in the legacy DAI.
  5. lib: dai: reset the trigger state of a released DAI group. A group released while a trigger was pending kept its counter and command when reused for another group ID, so it returned -EAGAIN or triggered early.
  6. test: ztest: dai_group: trigger a group on the native_sim models: the virtual DAI and the POSIX DMA model, whose channel state asserts catch a wrong sequence of DMA operations.

Patches 4 and 5 fix problems that are also on main; patch 1's tests found them. Each adds a test case that fails without its fix.

Unit tests

A new native_sim suite, test/ztest/unit/audio/dai_group, runs the real dai_assign_group(), dai_common_trigger() and group code of dai-zephyr.c and lib/dai.c on DAI component devices.

  • Hardware model: fake Zephyr DAI and DMA devices log every trigger and DMA config/start/stop/suspend/release call and can fail any of them, so the tests check the exact sequence of hardware operations.
  • Cases:
    • group get/put, and the reuse of an unused group;
    • assigning a DAI to a group, and the -EINVAL for a second group;
    • the atomic trigger for START, PAUSE, RELEASE and STOP: nothing until the last DAI gets the command, then every DAI once, most recently assigned first, with the DMA and DAI steps in order;
    • the group returning the last DAI's result;
    • -EAGAIN for another command while a trigger is pending;
    • a DAI outside any group triggering at once;
    • a freed DAI leaving its group.
  • Before and after: patch 1 adds the test on main's code, and the same 7 cases pass unchanged after patches 2 and 3, so the walk keeps the order, results and -EAGAIN handling of the notifier. Patches 4 to 6 add three cases (10 in total).
  • Checking the checks: mutations of the trigger order, the list order, the error result and the free path each make cases fail. Removing the group cleanup on free shows up as an ASan use-after-free.

Testing

  • Per commit, compared with main:
    • Builds: tgl, tgl-h, mtl, lnl, ptl, wcl, nvl, imx8, imx8x, imx8m, imx8m_cm7, imx8ulp, imx95 and qemu_xtensa, and the extra CI configurations:
      • PTL and WCL with internal_ci_overlay.conf;
      • native_sim IPC3/IPC4 stub builds;
      • imx93 64-bit;
      • PTL with each userspace overlay, including user-space LL, which builds DAI groups (CONFIG_COMP_DAI_GROUP=y);
      • PTL with CONFIG_SOF_USERSPACE_PROXY=n;
      • PTL and MTL with os_linux_overlay.conf;llext_relocatable.conf;
      • PTL and TGL with app/debug_stream_overlay.conf, and PTL with that overlay and user-space LL.
    • Object changes: as expected, and nothing else:
      • patch 1: dai-zephyr.c and lib/dai.c, and the sources that use struct dai_data, whose fields after the new list entry move (the copier DAI code, the DAI telemetry, and cpu.c through the inlined resume_dais()). Built with the list entry at the end of struct dai_data instead, only the group functions change, plus register-move encodings elsewhere in dai-zephyr.c;
      • patch 2: notifier.c, because the notifier ID count changes.
    • Signing: rimage runs for every Intel platform, and the generated configs are unchanged.
    • Cadence xt-clang (RI-2022.10): MTL, PTL and NVL compile.
    • ZTest: the unit tests pass, run as in CI (37 of 37 configurations at the tip, with the new suite); the DAI group suite passes at every commit.
    • Patches 4 and 5: only dai_common_trigger() and dai_group_put() change in the images.
    • Host: the host library builds. The CMocka tests were removed from main.
  • At the tip:
    • the testbench and the tools pass;
    • the host library builds;
    • the include checker passes with --strict, for the builds (same 16 baseline sources) and for the sources;
    • the platforms that already fail on main (acp_6_0, acp_7_0, acp_7_x, mt8186, mt8188, mt8195, mt8196, mt8365) have unchanged error sets. The legacy DAI (dai-legacy.c) is only built for some of them.

All of the above was run on 22c3d72 (current main).

Not tested on hardware

No board here uses DAI groups: IPC4 does not set a group ID, and the boards here run IPC4. The unit tests cover the path instead.

Changes since the last push

  • Review: new DAI group trigger unit tests, added before the change (patch 1), and a test on the native_sim DAI and DMA models (patch 6).
  • Two fixes for problems the tests found on main (patches 4 and 5).
  • Rebased onto current main. No conflicts.

🤖 Generated with Claude Code

@lgirdwood lgirdwood left a comment

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.

Can we add a ztest for dai groups and a group in the nocodec topology if possible for pr validation

@lgirdwood lgirdwood left a comment

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.

please add a ztest to test the group trigger feature - this can use virtual dai if needed

lrgirdwo and others added 3 commits November 29, 2026 13:57
Add native_sim unit tests of the DAI groups, which trigger several DAIs
atomically, on the real code of src/audio/dai-zephyr.c and src/lib/dai.c
with IPC4:

- dai_group_get() and dai_group_put(): one group per ID with a DAI count,
  group ID 0 is rejected, and a group that loses its last DAI is marked
  unused and reused for the next new ID.
- dai_assign_group(): assigning a DAI to its group again is a no-op, and
  to another group fails with -EINVAL.
- The group trigger: the DAIs that receive a START, PAUSE, RELEASE or STOP
  first trigger nothing, the last one triggers every DAI of the group
  once, most recently assigned first, with the DMA and DAI operations of
  each DAI in the order of dai_comp_trigger_internal().
- Its result: every DAI is triggered even if one fails, and the result is
  the one of the last DAI triggered.
- Another command while a group trigger is pending gets -EAGAIN and does
  not count for the pending trigger.
- A DAI that is not in a group triggers immediately.
- A freed DAI leaves its group, which then triggers only the others.

The DAIs are DAI component devices, created and freed by the DAI
component driver, and are triggered with dai_common_trigger(). The
hardware is modelled by fake Zephyr DAI and DMA devices that log their
trigger, DMA config, start, stop, suspend and channel release calls, and
can fail any of them, so the tests check the exact sequence of hardware
operations. The test provides the DAI and DMA lookup and stubs the
platform and IPC functions that the other DAI component operations need
to link, which the tests do not call.

The heap is the host heap, so that ASan and LSan cover it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
The last DAI of a group to receive a trigger command triggered the whole
group with a NOTIFIER_ID_DAI_TRIGGER event on the local core, which every
DAI of the group registered for. The notifier is not usable from user
space, and Phase 5 of the kernel / user-space partition removes it.

Keep the DAIs of a group in a list in the group instead. A DAI joins it
when it is assigned to the group and leaves it when it is freed, and the
last DAI to receive the command walks the list. The list is in the same
order as the notifier list, and the group still returns the error of the
last trigger.

This also fixes two problems with IPC4, where the DAI is a copier and
dai_assign_group() gets the copier device:
- the notifier callback took the DAI data from comp_get_drvdata(), which
  is the module and not the DAI data for a copier;
- copier_dai_free() did not unregister from the notifier.

The walk uses the DAI data of each member and its component, and
dai_common_free() removes the DAI from the group.

irq_local_disable() is privileged in user-space LL builds, so there the
group trigger takes the LL scheduler lock, as the copier does for its
channel map update. It is re-entrant, so this is safe if the caller holds
it. The other builds keep the IRQ lock.

The DAI group unit test no longer needs the notifier.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
DAI groups no longer use the notifier: the last DAI to receive a trigger
command walks the DAIs of its group. Remove the event ID.

The IDs after it are renumbered. They are internal to the firmware.

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

Copy link
Copy Markdown
Member Author

Added test/ztest/unit/audio/dai_group (patch 1), as asked in both reviews.

Placement: the test runs on main's notifier-based code, and the same 7 cases pass unchanged after the walk (patches 2 and 3). It is placed before the change so that it also shows the change keeps the behaviour.

What it runs: the real dai_assign_group(), dai_common_trigger() and group code, on DAI component devices.

Hardware model: fake Zephyr DAI and DMA devices log every hardware call and can fail any of them, so each case checks the exact sequence of hardware operations:

  • trigger order for START, PAUSE, RELEASE and STOP;
  • the error result;
  • -EAGAIN while a trigger is pending;
  • ungrouped DAIs;
  • freeing.

I used fakes rather than the native_sim virtual DAI because they record the calls.

ZTest: 37 of 37 configurations at the tip.

Topology: a group in the nocodec topology would not exercise this. IPC4 never sets a DAI group ID (the Linux driver aggregates links with ALH multi-gateway instead); only IPC3 hosts send one. So the unit test is the validation for this path.

Latent behaviour found while writing the tests: two things, both on main and unchanged here, so not tested as cases:

  • A one-DAI group never triggers. The first trigger sets trigger_counter = num_dais - 1 = 0 and returns without touching the hardware. This can happen when all but one DAI of a group are freed.
  • A reused group keeps its counter. A released group that is reused keeps its trigger_counter and trigger_cmd. If all DAIs of a group are freed while a trigger is pending, the next user of that group ID gets -EAGAIN.

I can fix both in a follow-up, with test cases, if wanted.

lrgirdwo and others added 3 commits November 29, 2026 14:21
The first DAI of a group to receive a trigger command set the number of
DAIs still to receive it to num_dais - 1, and only the later DAIs
counted down and triggered the group when the count reached 0. A group
of one DAI therefore never triggered: its DAI set the count to 0 and
returned without touching the hardware. This happens when all other
DAIs of a group are freed, or when the host puts a single DAI in a
group.

Count the first DAI like the others, so that the DAI that brings the
count to 0 triggers the group, including when it is the first. Groups
of more than one DAI are triggered as before. The same in the legacy
DAI.

Add a test case for a group of one DAI and for a group that only one
DAI is left in.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
A DAI group that loses its last DAI is marked unused and reused for the
next new group ID, but it kept its trigger counter and command. If its
DAIs were freed while a group trigger was pending, the reused group
started with that trigger still pending: a different command got
-EAGAIN, and the same command triggered the group before all its DAIs
had received it.

Drop the pending trigger when the group is released.

Add a test case that releases a group with a pending trigger and reuses
it for another group ID.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
The DAI group tests use fake DAI and DMA devices that log their calls,
to check the exact order of the hardware operations. Add a test that
triggers a group of two DAIs with START, PAUSE, RELEASE and STOP on the
native_sim models instead: the virtual DAI (dai_virtual.c, described in
app.overlay) and the POSIX DMA model (dma.c).

The DMA model asserts that a channel is configured and started only
when it is stopped, and suspended or stopped only when it is started.
With CONFIG_ASSERT, a wrong sequence of DMA operations in any trigger
step fails the test; triggering each DAI twice in the group walk, for
example, does. After STOP, both channels must accept a new
configuration.

CONFIG_DAI and CONFIG_DMA are enabled for the DAI init priority and for
the driver API sections that the API checks of CONFIG_ASSERT use.
CONFIG_SPIN_VALIDATE is off, as the DMA model takes its channel lock
again when it starts a channel. The DMA model devices are not in the
devicetree, so the test looks the DMA device up by name.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
@lgirdwood
lgirdwood marked this pull request as ready for review November 29, 2026 15:06
@lgirdwood

Copy link
Copy Markdown
Member Author

Updated with the two fixes and a native_sim test:

  • dai: trigger a DAI group of one DAI: the first DAI now counts like the others, so the DAI that brings the count to zero triggers the group, including a group of one. Groups of more DAIs behave as before. The same fix is applied in the legacy DAI.
  • lib: dai: reset the trigger state of a released DAI group: a group that loses its last DAI drops any pending trigger, so a reused group starts clean.
  • test: ztest: dai_group: trigger a group on the native_sim models: a group of two native_sim virtual DAIs on the POSIX DMA model goes through START, PAUSE, RELEASE and STOP. With CONFIG_ASSERT, the DMA model's channel state asserts catch a wrong sequence of DMA operations; triggering each DAI twice, for example, asserts on the double start.

The other cases keep the fake devices because those log the exact order of the hardware calls and can inject errors. The virtual DAI and DMA models cannot do either.

Tests: each fix adds a case that fails without it, and the suite now has 10 cases. ZTest passes 37 of 37 configurations.

Images: the fixes only change dai_common_trigger() and dai_group_put().

@intel-sofci

intel-sofci commented Nov 29, 2026 •

Copy link
Copy Markdown

PR 11512: test results

Run date: 2026-11-30 08:41 UTC

Tested commit: b6ff4c71ca5e8c95eff115e6d77affd2133517a2

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 4bdfa15 into thesofproject:main Nov 29, 2026
44 of 46 checks passed
@lgirdwood
lgirdwood deleted the kernel-user/phase5c branch November 29, 2026 16:25
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.

3 participants