Skip to content

Commit fd97e52

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_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: ** FATAL EXCEPTION ** CPU 2 EXCCAUSE 63 (zephyr exception) ** PC 0xa00315db VADDR (nil) ** PS 0x60d20 ** (INTLEVEL:0 EXCM: 0 UM:1 RING:0 WOE:1 OWB:13 CALLINC:2) ** A0 0xa0074680 SP 0xa00e7b60 A2 0x4 A3 0xa00e7b70 ** A4 0xa00e7b50 A5 0x4 A6 0x1 A7 0x4 ** A8 0xa007459a A9 0xa00e7af0 A10 0xa00afe61 A11 0xa00e7b70 ** A12 0xa00e7b50 A13 0x4 A14 0xffffff3c A15 0xa00fb740 ** LBEG 0xa003ae05 LEND 0xa003ae14 LCOUNT 0xa0077bf3 ** SAR 0x14 ** THREADPTR (nil) Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
1 parent ba001a4 commit fd97e52

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

src/debug/debug_stream/debug_stream_text_msg.c

Lines changed: 58 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,57 @@ 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+
static struct {
42+
struct debug_stream_text_msg msg;
43+
char text[768];
44+
} __packed buf = { 0 };
45+
static int reports_sent_cpu[CONFIG_MP_MAX_NUM_CPUS] = { 0 };
46+
static size_t pos;
47+
48+
static void ds_exception_drain(bool flush)
49+
{
50+
if (flush) {
51+
pos = 0;
52+
return;
53+
}
54+
55+
if (reports_sent_cpu[arch_proc_id()]++ > 0)
56+
return;
57+
58+
buf.msg.hdr.id = DEBUG_STREAM_RECORD_ID_TEXT_MSG;
59+
buf.msg.hdr.size_words = SOF_DIV_ROUND_UP(sizeof(buf.msg) + pos,
60+
sizeof(buf.msg.hdr.data[0]));
61+
memset(buf.text + pos, 0, buf.msg.hdr.size_words * sizeof(uint32_t) - pos);
62+
debug_stream_slot_send_record(&buf.msg.hdr);
63+
pos = 0;
64+
}
65+
66+
static void ds_exception_dump(const char *format, va_list args)
67+
{
68+
ssize_t len;
69+
70+
if (reports_sent_cpu[arch_proc_id()] > 0)
71+
return;
72+
73+
len = vsnprintf(buf.text + pos, sizeof(buf.text) - pos, format, args);
74+
if (len < 0) {
75+
pos = 0;
76+
return;
77+
}
78+
pos += MIN(len, sizeof(buf.text));
79+
80+
if (pos >= sizeof(buf.text))
81+
ds_exception_drain(false);
82+
}
83+
84+
#if defined(CONFIG_EXCEPTION_DUMP_HOOK)
85+
static int init_exception_dump_hook(void)
86+
{
87+
set_exception_dump_hook(ds_exception_dump, ds_exception_drain);
88+
LOG_INF("exception_dump_hook set");
89+
return 0;
90+
}
91+
92+
SYS_INIT(init_exception_dump_hook, APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT);
93+
#endif

src/include/user/debug_stream_text_msg.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#define __SOC_DEBUG_STREAM_TEXT_MSG_H__
88

99
#include <user/debug_stream_slot.h>
10+
#include <stdarg.h>
1011

1112
/*
1213
* Debug Stream text message.

0 commit comments

Comments
 (0)