Repository navigation
Kernel/user partition, Phase 5 part 3: trigger DAI groups without the notifier - #11512
Conversation
lgirdwood
left a comment
There was a problem hiding this comment.
Can we add a ztest for dai groups and a group in the nocodec topology if possible for pr validation
db9aea9 to
9931d9c
Compare
lgirdwood
left a comment
There was a problem hiding this comment.
please add a ztest to test the group trigger feature - this can use virtual dai if needed
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>
9931d9c to
a974aa4
Compare
|
Added 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 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:
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:
I can fix both in a follow-up, with test cases, if wanted. |
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>
|
Updated with the two fixes and a native_sim test:
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 |
PR 11512: test resultsRun date: 2026-11-30 08:41 UTC Tested commit: b6ff4c71ca5e8c95eff115e6d77affd2133517a2 |
|
CI unrelated. |
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_TRIGGERevent 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
dai_assign_group()), anddai_common_free()removes it.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.NOTIFIER_ID_DAI_TRIGGERandstruct dai_group::trigger_ret.Both the Zephyr DAI (
dai-zephyr.c) and the legacy DAI (dai-legacy.c) change. They share the group code insrc/lib/dai.c.Fixes
With IPC4 the DAI is a copier, and
dai_assign_group()gets the copier device. Two things were wrong there: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
irq_local_disable()from user code.Patches
test: ztest: add DAI group trigger tests, on main's notifier-based code (see Unit tests below).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.notifier: removeNOTIFIER_ID_DAI_TRIGGER. The IDs after it are renumbered; they are internal to the firmware.dai: trigger a DAI group of one DAI. The first DAI to get a command set the count of DAIs still to get it tonum_dais - 1and 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.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.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 realdai_assign_group(),dai_common_trigger()and group code ofdai-zephyr.candlib/dai.con DAI component devices.Testing
internal_ci_overlay.conf;CONFIG_COMP_DAI_GROUP=y);CONFIG_SOF_USERSPACE_PROXY=n;os_linux_overlay.conf;llext_relocatable.conf;app/debug_stream_overlay.conf, and PTL with that overlay and user-space LL.dai-zephyr.candlib/dai.c, and the sources that usestruct dai_data, whose fields after the new list entry move (the copier DAI code, the DAI telemetry, andcpu.cthrough the inlinedresume_dais()). Built with the list entry at the end ofstruct dai_datainstead, only the group functions change, plus register-move encodings elsewhere indai-zephyr.c;notifier.c, because the notifier ID count changes.dai_common_trigger()anddai_group_put()change in the images.--strict, for the builds (same 16 baseline sources) and for the sources;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
🤖 Generated with Claude Code