Conversation
Use spinlock instead of mutex to allow ISR context usage. Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
b3c5f35 to
fd97e52
Compare
@kv2019i its defined in zephyrproject-rtos/zephyr#103449 , without it this PR does not do much. |
fd97e52 to
1e537a2
Compare
|
The both PRs, this and zephyrproject-rtos/zephyr#103449 , are now updated and now they should work on PTL. The problem was that logging from the exception function hung the core in question, so that even debug_stream records could not be sent. Also the max dump size was too big for PTL. |
Set exception dump hooks if CONFIG_EXCEPTION_DUMP_HOOK=y. This enables sending a simple text report of fatal exceptions. To get this working one needs these config options: CONFIG_EXCEPTION_DUMP_HOOK=y CONFIG_EXCEPTION_DUMP_HOOK_ONLY=y CONFIG_SOF_DEBUG_STREAM_SLOT=y CONFIG_SOF_DEBUG_STREAM_TEXT_MSG=y CONFIG_SOF_DEBUG_STREAM_SLOT_NUMBER=2 CONFIG_SOF_TELEMETRY=n CONFIG_SOF_TELEMETRY_PERFORMANCE_MEASUREMENTS=n CONFIG_SOF_TELEMETRY_IO_PERFORMANCE_MEASUREMENTS=n If system hangs and an the exception is reported successfully the report can be seen with debug_stream.py (which should be installed in the same directory with cavstool.py). It does matter if the tool was not running at the time. The report should be available there in the debug slot window for debug_stream.py to decode as long as system remains up. The report should looks something like this: CPU 2: FATAL EXCEPTION CPU 2 EXCCAUSE 63 (zephyr exception) PC 0xa003048b VADDR 0xa0031020 PS 0x60220 (INTLEVEL:0 EXCM: 0 UM:1 RING:0 WOE:1 OWB:2 CALLINC:2) A0 0xa006c2b8 SP 0xa00dd160 A2 0x4 A3 0xa00dd170 A4 0xa00dd150 A5 0x4 A6 0x6 A7 0x4 A8 0xa006c109 A9 0xa00dd0f0 A10 0xa00a697d A11 0xa00dd170 A12 0xa00dd150 A13 0x4 A14 0x401a6b24 A15 0x401a6b24 LBEG 0xa0044323 LEND 0xa0044330 LCOUNT 0xa006de66 SAR 0x4 THREADPTR (nil) BT 0xa0030488:0xa00dd160 CORRUPTED Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
Skip useless " ** " prefix from exception dumps to save byte is in the debug_stream buffer. Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
The utf-8 decoder does not appear to be sensitive to '\0' in the buffer so cut from word boundary may produce unwanted characters at the end of the message. Make also the text message always star from the beginning of the line and not from the same line with "CPU X:" tag. Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
Enabling Zephyr exception hook directs Zephyr exceptions dumps to debug_stream text message. Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
1e537a2 to
ded889b
Compare
There was a problem hiding this comment.
Pull request overview
Adds a debug_stream-based exception dump handler so fatal exceptions (including backtraces) can be forwarded to the host via the debug window slot and decoded by debug_stream.py.
Changes:
- Update host-side
debug_stream.pytext message decoding/printing to handle NUL-terminated payloads and multi-line output. - Add a Zephyr
set_exception_dump_hook()implementation that aggregates exception text into a debug_stream text record. - Switch debug_stream slot record send locking from a mutex to a spinlock and enable relevant overlay Kconfig options.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| tools/debug_stream/debug_stream.py | Improves text record decoding (NUL termination, UTF-8 replace) and prints messages as multi-line. |
| src/debug/debug_stream/debug_stream_text_msg.c | Adds exception dump hook that formats exception output into a debug_stream text record. |
| src/debug/debug_stream/debug_stream_slot.c | Replaces k_mutex with k_spinlock for record send synchronization. |
| app/debug_stream_overlay.conf | Enables exception dump hook-related Kconfig options for the debug_stream overlay. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
|
|
||
| # Enable Zephyr exception printing hook, debug stream is sensitive to this option too | ||
| CONFIG_EXCEPTION_DUMP_HOOK=y | ||
| # Do not try to sen the exception prints through logs, this causes probles on PTL with mtrace |
There was a problem hiding this comment.
Typo in comment: "sen" → "send".
| # Do not try to sen the exception prints through logs, this causes probles on PTL with mtrace | |
| # Do not try to send the exception prints through logs, this causes problems on PTL with mtrace |
|
|
||
| # Enable Zephyr exception printing hook, debug stream is sensitive to this option too | ||
| CONFIG_EXCEPTION_DUMP_HOOK=y | ||
| # Do not try to sen the exception prints through logs, this causes probles on PTL with mtrace |
There was a problem hiding this comment.
Typo in comment: "probles" → "problems".
| # Do not try to sen the exception prints through logs, this causes probles on PTL with mtrace | |
| # Do not try to sen the exception prints through logs, this causes problems on PTL with mtrace |
| static struct { | ||
| struct debug_stream_text_msg msg; | ||
| char text[640]; | ||
| } __packed ds_buf; | ||
| static int reports_sent_cpu[CONFIG_MP_MAX_NUM_CPUS]; | ||
| static size_t ds_pos; |
There was a problem hiding this comment.
ds_buf and ds_pos are global across all CPUs, but reports_sent_cpu[] is per-CPU. If two cores hit an exception around the same time, both can write into the same ds_buf.text/ds_pos concurrently before reports_sent_cpu[arch_proc_id()] is incremented in ds_exception_drain(), producing a data race and corrupted/merged dumps. Make the buffer/position per-CPU (e.g., arrays indexed by arch_proc_id()) or protect updates with a lock that is safe in exception context.
| static struct { | ||
| struct debug_stream_text_msg msg; | ||
| char text[640]; | ||
| } __packed ds_buf; |
There was a problem hiding this comment.
ds_buf is declared __packed, which drops its alignment to 1. Because ds_buf.msg.hdr contains 32-bit fields that are accessed directly and passed to debug_stream_slot_send_record(), this can lead to unaligned accesses if the linker places ds_buf at a byte-aligned address. Consider removing __packed here and/or forcing at least 4-byte alignment for ds_buf.
| static struct { | |
| struct debug_stream_text_msg msg; | |
| char text[640]; | |
| } __packed ds_buf; | |
| static _Alignas(4) struct { | |
| struct debug_stream_text_msg msg; | |
| char text[640]; | |
| } ds_buf; |
I have no got all behavioral obscurity sorted out so this should now be as good as it gets. But zephyrproject-rtos/zephyr#103449 should go in before this one.
This is debug_stream exception dump handler. It is able to report fatal exceptions with backtrace through debug_stream using debug window slot and debug_stream.py.