Skip to content

telemetry: add extended TEL2 and PMW2 telemetry window sections - #11407

Open
lgirdwood wants to merge 9 commits into
thesofproject:mainfrom
lgirdwood:topic/telemetry-v2-extended-windows
Open

lgirdwood wants to merge 9 commits into
thesofproject:mainfrom
lgirdwood:topic/telemetry-v2-extended-windows

Conversation

@lgirdwood

Copy link
Copy Markdown
Member

Summary

Adds extended telemetry sections to Memory Window 2 (TEL2 v2.0) and Memory Window 3 (PMW2 v2.0) to support real-time host monitoring tools such as sof-top (see thesofproject/sof-utils#2) without invasive IPC polling during active audio streaming.

Memory Window 2 (TEL2, 0x0100..0x0AFF)

  • Directory Header (0x0100, 64B): TEL2 magic, v2.0, seqlock counter, microsecond timestamp, and 5 section descriptors.
  • Hot-Path Cache Lines (0x0140..0x023F):
    • Line 0 (0x0140, 64B): per-core LL overruns, DP deadline misses, total/per-pipeline XRUNs, IPC count/max latency, and active LL task count.
    • Lines 1–2 (0x0180..0x01FF, 16 x 8B): per-gateway active bytes/frames, XRUN counts, and error flags.
  • Memory Allocators Section (0x0240, 256B):
    • L2 HP-SRAM runtime/system heaps, LPSRAM heap, fast-get pool, physical vpage pool, blob pool, shared memory, and Zephyr system heap (used, free, peak HWM, and largest free block).
  • Virtual Regions Section (0x0340, 512B):
    • Up to 20 vregion descriptors reporting virtual size, committed bytes, allocated bytes, free blocks, and peak HWM.
  • Pipelines & Per-Core Scheduler Section (0x0540, 384B):
    • Up to 16 active pipeline records (ID, core, priority, state, component count, period, scheduler ID, last XRUN bytes) and 4 per-core scheduler records (active KCPS budget, LL/DP task counts).
  • Gateways & DAIs Cold Section (0x06C0, 256B):
    • Up to 16 gateway cold descriptors (type, index, direction, DMA channel, component ID, state, group ID, period bytes, DMA buffer size).
  • Zephyr RTOS Threads Section (0x07C0, 832B):
    • Up to 24 Zephyr thread slots (thread ID, core affinity, priority, state, stack size/used/HWM, runtime cycle delta/total, and name).

Memory Window 3 (PMW2)

  • Extends the performance measurements window with a PMW2 trailer, per-module cold resource table (sof_perf_mod_cold_item: heap usage, heap HWM, configured CPC), and per-module hot counters (sof_perf_mod_hot_item: CPC violations and XRUN counts).

Systick / Idle Core Cycle Fix

  • Updates telemetry_update() to accumulate elapsed active LL tick cycles (current_stamp - begin_stamp) rather than inter-tick wall-clock ccount deltas, and resets idle core tick metrics when ll_task_count drops to zero.

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

Telemetry still permits MW3 table overflow and unsynchronized collection of objects that may be freed concurrently, creating critical memory-corruption and use-after-free risks.

17 open issues
What changed in this PR

Extends SOF’s shared telemetry windows to support host monitoring tools such as sof-top without additional IPC polling during audio streaming.

Changes:

  • Adds TEL2 sections for memory, virtual regions, pipelines, gateways, and Zephyr threads.
  • Adds PMW2 module resource records and hot counters, and relocates I/O performance data.
  • Changes systick accounting to measure active LL execution cycles and adds idle-metric resets.
File Description
zephyr/​lib/​vregion.c Registers virtual regions and collects their statistics.
zephyr/​lib/​vpage.c Tracks page allocation usage and failures.
zephyr/​lib/​regions_mm.c Exports virtual-heap block statistics.
zephyr/​lib/​fast-get.c Collects cache-pool usage and allocation counters.
zephyr/​lib/​alloc.c Collects heap usage, failures, and SRAM statistics.
zephyr/​include/​sof/​lib/​regions_mm.h Declares the virtual-heap telemetry interface.
src/​ipc/​ipc4/​helper.c Adds pipeline lifecycle notifications.
src/​include/​sof/​debug/​telemetry/​telemetry.h Defines TEL2 layouts and collection interfaces.
src/​include/​sof/​debug/​telemetry/​performance_monitor.h Defines PMW2 partitions and module records.
src/​debug/​telemetry/​telemetry.c Implements collection, publication, and revised tick accounting.
src/​debug/​telemetry/​performance_monitor.c Implements PMW2 resource tables and I/O storage.
src/​debug/​telemetry/​Kconfig Adds telemetry feature and capacity settings.
src/​audio/​pipeline/​pipeline-xrun.c Records pipeline and component XRUN events.
src/​audio/​pipeline/​pipeline-stream.c Notifies telemetry when triggers are submitted.
src/​audio/​module_adapter/​module/​generic.c Publishes module resource usage after allocations.
src/​audio/​host-zephyr.c Adds host gateway registration and transfer updates.
src/​audio/​dai-zephyr.c Adds DAI gateway registration and transfer updates.
src/​audio/​component.c Updates module resources and CPC violation counters.

Review effort: Balanced

Comment thread src/debug/telemetry/Kconfig Resolved
Comment thread src/kernel/debug/telemetry/telemetry.c Resolved
Comment thread src/debug/telemetry/telemetry.c Resolved
Comment thread zephyr/lib/vregion.c Resolved
Comment thread src/kernel/debug/telemetry/telemetry.c Resolved
Comment thread src/debug/telemetry/telemetry.c Resolved
Comment thread src/debug/telemetry/telemetry.c Resolved
Comment thread zephyr/lib/alloc.c Resolved
@lgirdwood
lgirdwood force-pushed the topic/telemetry-v2-extended-windows branch 4 times, most recently from c375760 to a01c94a Compare November 8, 2026 15:27
@lgirdwood
lgirdwood requested a balanced review from Copilot November 8, 2026 17:18

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

Critical issues include privileged spinlocks that can fault userspace IPC, telemetry scans that can stall audio processing, and failed initialization that can lead to scheduling an uninitialized work item.

10 open issues
17 resolved since last review

Review effort: Balanced

Comment thread src/ipc/ipc4/helper.c Resolved
Comment thread src/kernel/debug/telemetry/telemetry.c Resolved
Comment thread src/kernel/debug/telemetry/telemetry.c Resolved
Comment thread src/kernel/debug/telemetry/telemetry.c Resolved
Comment thread src/kernel/debug/telemetry/telemetry.c Resolved
Comment thread src/kernel/debug/telemetry/telemetry.c Resolved
Comment thread src/kernel/debug/telemetry/telemetry.c Resolved
Comment thread src/kernel/debug/telemetry/telemetry.c Resolved
Comment thread zephyr/lib/alloc.c Resolved
Comment thread zephyr/lib/fast-get.c Resolved
@lgirdwood
lgirdwood force-pushed the topic/telemetry-v2-extended-windows branch from a01c94a to 24436c4 Compare November 8, 2026 21:55
@lgirdwood
lgirdwood requested a balanced review from Copilot November 9, 2026 15:38
@lgirdwood
lgirdwood force-pushed the topic/telemetry-v2-extended-windows branch from 24436c4 to 983220e Compare November 9, 2026 15:38
@lgirdwood
lgirdwood requested a balanced review from Copilot and removed request for Copilot November 9, 2026 15:50

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.

Comment thread src/kernel/debug/telemetry/telemetry.c Resolved
Comment thread src/kernel/debug/telemetry/telemetry.c Resolved
Comment thread src/kernel/debug/telemetry/telemetry.c Resolved
Comment thread src/kernel/debug/telemetry/telemetry.c Resolved
Comment thread zephyr/lib/regions_mm.c Resolved
Comment thread zephyr/lib/vregion.c Resolved
@lgirdwood
lgirdwood force-pushed the topic/telemetry-v2-extended-windows branch from 983220e to e0b941d Compare November 9, 2026 16:16

@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.

Lets split this int a patch per susbsystem

@lgirdwood

lgirdwood commented Nov 9, 2026 •

Copy link
Copy Markdown
Member Author

Split the PR into a 9-patch series organized by subsystem (updated to remove all telemetry spinlocks/mutexes for userspace compatibility and replace magic heap index constants):

  1. 93ba65395 telemetry: headers: add extended TEL2 and PMW2 window definitions
  2. fc11e699b zephyr: lib: add heap, VMH, and fast-get memory telemetry
  3. 65bcac867 zephyr: vregion: add vpage and virtual region telemetry
  4. d8d8ca7a6 telemetry: implement extended TEL2 and PMW2 telemetry windows
  5. e5ebe5d96 ipc: unlink freed components/pipelines first and notify telemetry
  6. 493d841a8 schedule: report active LL task counts and DP deadline misses to telemetry
  7. 50608e37b pipeline: notify telemetry on pipeline state changes and XRUNs
  8. f72e6b724 audio: module_adapter: update per-module telemetry resource metrics
  9. 5cdfda192 audio: dai/host: wire DAI and Host DMA gateway telemetry

@lgirdwood
lgirdwood force-pushed the topic/telemetry-v2-extended-windows branch from e0b941d to e442b4a Compare November 9, 2026 18:33
@lgirdwood
lgirdwood marked this pull request as ready for review November 10, 2026 13:45

@kv2019i kv2019i left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks very useful! Only bigger one is this adds spinlocks to code paths that are running in user-space in SOF mainline. This isn't caught as CONFIG_SOF_TELEMETRY is disable in user builds. Is this intentional that this is only support in kernel builds?

Comment thread zephyr/lib/alloc.c Outdated
heap_fail_counts[0]++;
#if CONFIG_SOF_USERSPACE_USE_SHARED_HEAP
else if (h == &shared_buffer_heap)
heap_fail_counts[1]++;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This '1' is magic value linked to shared-heap in multiple places in this source file. Better to use a file local define of some sorts to increase readability.

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 fc11e699b — added file-local TEL_HEAP_SYS_IDX, TEL_HEAP_SHARED_IDX, TEL_HEAP_LL_USER_IDX, TEL_HEAP_L3_IMR_IDX, and TEL_HEAP_OTHER_IDX defines in zephyr/lib/alloc.c and replaced all magic heap array indices.

Comment thread src/ipc/ipc-helper.c Outdated
* ipc->comp_list never observe a freed component.
*/
struct comp_dev *cd = icd->cd;
k_spinlock_key_t key = telemetry_ipc_lock(ipc);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This code can be run in userspace, so using spinlocks here is a problem.

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.

Lets remove the spinlocks since this is read only data that is not used internally, they are probably not needed.

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 across the series (fc11e699b, 65bcac867, d8d8ca7a6, e5ebe5d96) — removed telemetry_ipc_lock() / telemetry_ipc_unlock() and all added spinlocks and mutexes (tel_lock, tel_cold_mutex, tel_vregion_lock, vpage_tel_lock, ipc->lock, h->lock, fast_get_data.lock, and vr->interim.heap.lock). Since telemetry windows export read-only diagnostic snapshots to the host and are not consumed internally by firmware control logic, unlinking icd->list / ipc_pipe->list and clearing icd->cd / ipc_pipe->pipeline prior to freeing (together with the TEL2 sequence counter) is sufficient and safe in both kernel and userspace (CONFIG_SOF_USERSPACE_LL) contexts.

@intel-sofci

Copy link
Copy Markdown

PR 11407: test results

Run date: 2026-11-10 14:51 UTC

Tested commit: e442b4a1e09a618e57e1db63b23981f365d973ed

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

Define the Memory Window 2 (TEL2 v2.0) self-describing directory header,
cache-line-aligned hot counter zone, and cold metadata sections (memory,
vregion, pipelines, gateways, and Zephyr threads), along with the
Memory Window 3 (PMW2) per-module cold resource and hot counter
structures and telemetry notification helper prototypes.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Implement memory telemetry collection and allocation failure tracking
across SOF system/shared/LL-user/L3 heaps, physical SRAM/LPSRAM page
tables, Virtual Memory Heap (VMH) block bundles, and the fast_get
DRAM-to-SRAM cache pool for the TEL2 memory telemetry section.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Track virtual page allocator utilization, fragmentation, minimum free
pages, and allocation failures in vpage.c, and snapshot active virtual
region lifetime and interim heap metrics in vregion.c for the TEL2
vregion telemetry section.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Implement the extended Memory Window 2 (TEL2) and Memory Window 3 (PMW2)
telemetry sections, seqlock publication protocol, uncached hot-counter
staging, periodic background cold-section and Zephyr thread snapshots,
and active LL tick cycle accounting in telemetry.c and
performance_monitor.c.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Unlink components and pipelines from ipc->comp_list and clear their
pointers before freeing them so concurrent telemetry readers never
observe a freed object, clear freed component performance data
pointers, and notify the telemetry subsystem when pipelines and
components are created or freed across IPC3 and IPC4.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
…metry

Notify telemetry when the per-core active Low-Latency (LL) task count
changes or when an LL tick overruns, and track Data Processing (DP)
task deadline misses across kernel, K_USER, and application worker
threads via scheduler_dp_check_deadline().

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Notify the telemetry subsystem on pipeline schedule, trigger, and reset
transitions and record pipeline and component XRUN events in the TEL2
and PMW2 telemetry windows.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Refresh per-module cold resource metrics (private heap usage, heap
high-water mark, and configured CPC) in Memory Window 3 during component
state transitions and module adapter lifecycle operations.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Register and unregister DAI and Host DMA gateways with the TEL2
telemetry window and update live gateway buffer fill levels, processed
byte counts, and XRUN/skip counters.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
@lgirdwood
lgirdwood force-pushed the topic/telemetry-v2-extended-windows branch from e442b4a to 5cdfda1 Compare November 10, 2026 16:11
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