-
Notifications
You must be signed in to change notification settings - Fork 349
Exception dump update #10654
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jsarha
wants to merge
6
commits into
thesofproject:main
Choose a base branch
from
jsarha:exception_dump_update
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+123
−40
Open
Exception dump update #10654
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a3c44b3
debug_stream: text_msg: Align to latest changes to Zephyr PR changes
f2388f1
debug_stream: text_msg: collect per-CPU state into cacheline-aligned …
8b8450f
debug_stream: text_msg: Add CONFIG_SOF_DEBUG_STREAM_SLOT_FORCE_MAX_CPUS
cd33717
debug_stream: text_msg: add va_list-based logging helper
0a3e1fb
debug_stream: text_msg: add optional assert_print() forwarding
ae17802
app: debug_stream_overlay.conf: Add new debug_stream Kconfig options
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,18 +15,15 @@ | |
|
|
||
| LOG_MODULE_REGISTER(debug_stream_text_msg); | ||
|
|
||
| void ds_msg(const char *format, ...) | ||
| void ds_vamsg(const char *format, va_list args) | ||
| { | ||
| va_list args; | ||
| struct { | ||
| struct debug_stream_text_msg msg; | ||
| char text[128]; | ||
| } __packed buf = { 0 }; | ||
| ssize_t len; | ||
|
|
||
| va_start(args, format); | ||
| len = vsnprintf(buf.text, sizeof(buf.text), format, args); | ||
| va_end(args); | ||
|
|
||
| if (len < 0) | ||
| return; | ||
|
|
@@ -38,6 +35,15 @@ void ds_msg(const char *format, ...) | |
| debug_stream_slot_send_record(&buf.msg.hdr); | ||
| } | ||
|
|
||
| void ds_msg(const char *format, ...) | ||
| { | ||
| va_list args; | ||
|
|
||
| va_start(args, format); | ||
| ds_vamsg(format, args); | ||
| va_end(args); | ||
| } | ||
|
|
||
| #if defined(CONFIG_EXCEPTION_DUMP_HOOK) | ||
| /* The debug stream debug window slot is 4k, and when it is split | ||
| * between the cores and the header/other overhead is removed, with 5 | ||
|
|
@@ -49,39 +55,46 @@ void ds_msg(const char *format, ...) | |
| * in bursts, and sending more than one record in short time makes the | ||
| * host-side decoder lose track of things. | ||
| */ | ||
| static struct { | ||
| struct debug_stream_text_msg msg; | ||
| char text[640]; | ||
| } __packed ds_buf[CONFIG_MP_MAX_NUM_CPUS]; | ||
| static int reports_sent_cpu[CONFIG_MP_MAX_NUM_CPUS]; | ||
| static size_t ds_pos[CONFIG_MP_MAX_NUM_CPUS]; | ||
|
|
||
| /* Per-CPU state for exception dump and assert_print(). | ||
| * Cache-line aligned to avoid false sharing between cores. | ||
| */ | ||
| static struct ds_cpu_state { | ||
| struct { | ||
| struct debug_stream_text_msg msg; | ||
| char text[640]; | ||
| } __packed buf; | ||
| int reports_sent; | ||
| size_t pos; | ||
| } __aligned(CONFIG_DCACHE_LINE_SIZE) ds_cpu[CONFIG_MP_MAX_NUM_CPUS]; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is placed into |
||
|
|
||
| static void ds_exception_drain(bool flush) | ||
| { | ||
| unsigned int cpu = arch_proc_id(); | ||
| struct ds_cpu_state *cs = &ds_cpu[cpu]; | ||
|
|
||
| if (flush) { | ||
| ds_pos[cpu] = 0; | ||
| reports_sent_cpu[cpu] = 0; | ||
| cs->pos = 0; | ||
| return; | ||
| } | ||
|
|
||
| if (ds_pos[cpu] == 0) | ||
| if (cs->pos == 0) | ||
| return; | ||
|
|
||
| if (reports_sent_cpu[cpu] > 0) | ||
| if (cs->reports_sent > 0) | ||
| return; | ||
|
|
||
| ds_buf[cpu].msg.hdr.id = DEBUG_STREAM_RECORD_ID_TEXT_MSG; | ||
| ds_buf[cpu].msg.hdr.size_words = | ||
| SOF_DIV_ROUND_UP(sizeof(ds_buf[cpu].msg) + ds_pos[cpu], | ||
| sizeof(ds_buf[cpu].msg.hdr.data[0])); | ||
| cs->buf.msg.hdr.id = DEBUG_STREAM_RECORD_ID_TEXT_MSG; | ||
| cs->buf.msg.hdr.size_words = | ||
| SOF_DIV_ROUND_UP(sizeof(cs->buf.msg) + cs->pos, | ||
| sizeof(cs->buf.msg.hdr.data[0])); | ||
|
|
||
jsarha marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /* Make sure the possible up to 3 extra bytes at end of msg are '\0' */ | ||
| memset(ds_buf[cpu].text + ds_pos[cpu], 0, | ||
| ds_buf[cpu].msg.hdr.size_words * sizeof(ds_buf[cpu].msg.hdr.data[0]) - ds_pos[cpu]); | ||
| debug_stream_slot_send_record(&ds_buf[cpu].msg.hdr); | ||
| reports_sent_cpu[cpu] = 1; | ||
| ds_pos[cpu] = 0; | ||
| memset(cs->buf.text + cs->pos, 0, | ||
| cs->buf.msg.hdr.size_words * sizeof(cs->buf.msg.hdr.data[0]) - cs->pos); | ||
| debug_stream_slot_send_record(&cs->buf.msg.hdr); | ||
| cs->reports_sent = 1; | ||
| cs->pos = 0; | ||
| } | ||
|
|
||
| static void ds_exception_dump(const char *format, va_list args) | ||
|
|
@@ -90,11 +103,12 @@ static void ds_exception_dump(const char *format, va_list args) | |
| size_t avail; | ||
| size_t written; | ||
| unsigned int cpu = arch_proc_id(); | ||
| struct ds_cpu_state *cs = &ds_cpu[cpu]; | ||
|
|
||
| if (reports_sent_cpu[cpu] > 0) | ||
| if (cs->reports_sent > 0) | ||
| return; | ||
|
|
||
| avail = sizeof(ds_buf[cpu].text) - ds_pos[cpu]; | ||
| avail = sizeof(cs->buf.text) - cs->pos; | ||
| if (avail == 0) { | ||
| ds_exception_drain(false); | ||
| return; | ||
|
|
@@ -108,9 +122,9 @@ static void ds_exception_dump(const char *format, va_list args) | |
| format[0] == ' ' && format[1] == '*' && format[2] == '*' && format[3] == ' ') | ||
| format += 4; | ||
|
|
||
| len = vsnprintf(ds_buf[cpu].text + ds_pos[cpu], avail, format, args); | ||
| len = vsnprintf(cs->buf.text + cs->pos, avail, format, args); | ||
| if (len < 0) { | ||
| ds_pos[cpu] = 0; | ||
| cs->pos = 0; | ||
| return; | ||
| } | ||
|
|
||
|
|
@@ -122,18 +136,46 @@ static void ds_exception_dump(const char *format, va_list args) | |
| else | ||
| written = (size_t)len; | ||
|
|
||
| ds_pos[cpu] += written; | ||
| cs->pos += written; | ||
|
|
||
| if (ds_pos[cpu] >= sizeof(ds_buf[cpu].text)) | ||
| if (cs->pos >= sizeof(cs->buf.text)) | ||
| ds_exception_drain(false); | ||
| } | ||
|
|
||
| static int init_exception_dump_hook(void) | ||
| { | ||
| set_exception_dump_hook(ds_exception_dump, ds_exception_drain); | ||
| arch_exception_set_dump_hook(ds_exception_dump, ds_exception_drain); | ||
| LOG_INF("exception_dump_hook set"); | ||
| return 0; | ||
| } | ||
|
|
||
| SYS_INIT(init_exception_dump_hook, APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT); | ||
|
|
||
| #if defined(CONFIG_SOF_DEBUG_STREAM_TEXT_MSG_ASSERT_PRINT) | ||
| void assert_print(const char *fmt, ...) | ||
| { | ||
| va_list ap; | ||
|
|
||
| /* Do not print assert after exception has been dumped */ | ||
| if (ds_cpu[arch_proc_id()].reports_sent > 0) | ||
| return; | ||
|
|
||
| va_start(ap, fmt); | ||
| #if !defined(CONFIG_EXCEPTION_DUMP_HOOK_ONLY) | ||
| { | ||
| va_list ap2; | ||
|
|
||
| va_copy(ap2, ap); | ||
| #endif | ||
| ds_vamsg(fmt, ap); | ||
| #if !defined(CONFIG_EXCEPTION_DUMP_HOOK_ONLY) | ||
| vprintk(fmt, ap2); | ||
| va_end(ap2); | ||
| } | ||
| #endif | ||
| ds_vamsg(fmt, ap); | ||
| va_end(ap); | ||
| } | ||
| EXPORT_SYMBOL(assert_print); | ||
| #endif | ||
| #endif | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this be done at run-time? If yes, you could use a CPU-mask here instead. Where static arrays are allocated, allocate
CONFIG_CORE_COUNTof them, but at run-time count bits in the mask and divide the window in as many sections?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything is possible, but the amount of refactoring needed is IMO not at all proportional to the benefit. The original design principle was to initialize everything at boot time, and then be a totally passive and light weight system to pass debug information from DSP to the host. Nor is this feature enabled by default, there is not even debug slots available for it unless some other features are turned off, which makes runtime configuration quite useless. One anyway needs to rebuild the FW to use this feature.
Run time reconfiguration would require almost complete rewrite of both the FW side implementation and the host side decoding and invention of new APIs on how to change the configuration at runtime.
The CPU mask style stuff would be slightly more feasible, but I do not see any significant benefit over this low hanging fruit. In 90% of cases one wants to debug core 0 incidents, and the remaining 10% fall to three first cores (ATM our topologies do not utilize more than 3 cores). So most of the time setting this value to 1 or 3 is enough. And if one wants to test some multicore case with max debug_stream bandwidth he/she can make a custom topology for the case to fit the event to as low number of cores as possible.