Skip to content

Commit 128e258

Browse files
author
Jyri Sarha
committed
debug_stream: text_msg: Set exception dump hooks if available
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 too 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: CPU 2 EXCCAUSE 13 (load/store PIF data error) PC 0xa06b24ba VADDR 0xa0031020 PS 0x60820 (INTLEVEL:0 EXCM: 0 UM:1 RING:0 WOE:1 OWB:8 CALLINC:2) A0 0xa06b10dd SP 0xa00f8b00 A2 0xa A3 0xa01a9354 A4 0xa01a922c A5 0x3c1 A6 0xa01a7ee4 A7 0xa01a7ec4 A8 0xa006e572 A9 0xa00f8ab0 A10 0x4018d8b0 A11 0xa A12 0x14 A13 0x1 A14 0xa A15 (nil) LBEG 0xa0044323 LEND 0xa0044330 LCOUNT 0xa006de66 SAR 0x5 THREADPTR (nil) BT 0xa06b24b7:0xa00f8b00 CORRUPTED Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
1 parent ba001a4 commit 128e258

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

src/debug/debug_stream/debug_stream_text_msg.c

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@
88
#include <soc.h>
99
#include <adsp_debug_window.h>
1010
#include <sof/common.h>
11+
#include <zephyr/logging/log.h>
12+
#include <zephyr/arch/exception.h>
1113

1214
#include <user/debug_stream_text_msg.h>
1315

16+
LOG_MODULE_REGISTER(debug_stream_text_msg);
17+
1418
void ds_msg(const char *format, ...)
1519
{
1620
va_list args;
@@ -33,3 +37,59 @@ void ds_msg(const char *format, ...)
3337
sizeof(buf.msg.hdr.data[0]));
3438
debug_stream_slot_send_record(&buf.msg.hdr);
3539
}
40+
41+
#if defined(CONFIG_EXCEPTION_DUMP_HOOK)
42+
static struct {
43+
struct debug_stream_text_msg msg;
44+
char text[512];
45+
} __packed ds_buf;
46+
static int reports_sent_cpu[CONFIG_MP_MAX_NUM_CPUS];
47+
static size_t ds_pos;
48+
49+
static void ds_exception_drain(bool flush)
50+
{
51+
if (flush) {
52+
ds_pos = 0;
53+
return;
54+
}
55+
56+
if (reports_sent_cpu[arch_proc_id()]++ > 0)
57+
return;
58+
59+
ds_buf.msg.hdr.id = DEBUG_STREAM_RECORD_ID_TEXT_MSG;
60+
ds_buf.msg.hdr.size_words = SOF_DIV_ROUND_UP(sizeof(ds_buf.msg) + ds_pos,
61+
sizeof(ds_buf.msg.hdr.data[0]));
62+
/* Make sure the possible upto 3 extra bytes at end of msg are '\0' */
63+
memset(ds_buf.text + ds_pos, 0, ds_buf.msg.hdr.size_words *
64+
sizeof(ds_buf.msg.hdr.data[0]) - ds_pos);
65+
debug_stream_slot_send_record(&ds_buf.msg.hdr);
66+
ds_pos = 0;
67+
}
68+
69+
static void ds_exception_dump(const char *format, va_list args)
70+
{
71+
ssize_t len;
72+
73+
if (reports_sent_cpu[arch_proc_id()] > 0)
74+
return;
75+
76+
len = vsnprintf(ds_buf.text + ds_pos, sizeof(ds_buf.text) - ds_pos, format, args);
77+
if (len < 0) {
78+
ds_pos = 0;
79+
return;
80+
}
81+
ds_pos += MIN(len, sizeof(ds_buf.text) - ds_pos);
82+
83+
if (ds_pos >= sizeof(ds_buf.text))
84+
ds_exception_drain(false);
85+
}
86+
87+
static int init_exception_dump_hook(void)
88+
{
89+
set_exception_dump_hook(ds_exception_dump, ds_exception_drain);
90+
LOG_INF("exception_dump_hook set");
91+
return 0;
92+
}
93+
94+
SYS_INIT(init_exception_dump_hook, APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT);
95+
#endif

0 commit comments

Comments
 (0)