Assert size optimizations#19061
Conversation
- Use shared string for "stack pointer out of range" to avoid duplicate in flash - Re-use already calculated stack_used instead of calling up_check_tcbstack again Signed-off-by: Jukka Laitinen <jukka.laitinen@tii.ae>
|
|
||
| _alert("IRQ Stack: base: %p size: %u\n", | ||
| (FAR void *)up_get_intstackbase(cpu), | ||
| (unsigned)CONFIG_ARCH_INTERRUPTSTACK); |
| #ifdef CONFIG_ARCH_KERNEL_STACK | ||
| _alert("Kernel Stack: base: %p size: %u\n", | ||
| rtcb->xcp.kstack, | ||
| (unsigned)CONFIG_ARCH_KERNEL_STACKSIZE); |
|
|
||
| _alert("User Stack: base: %p size: %zu\n", | ||
| rtcb->stack_base_ptr, | ||
| (size_t)rtcb->adj_stack_size); |
| @@ -168,6 +168,8 @@ static int assert_tracecallback(FAR struct usbtrace_s *trace, FAR void *arg) | |||
|
|
|||
| #ifdef CONFIG_ARCH_STACKDUMP | |||
There was a problem hiding this comment.
why do we need both CONFIG_ARCH_STACKDUMP and CONFIG_SCHED_DUMP_STACK?
There was a problem hiding this comment.
I interpreted the ARCH flag meaning that the architecture supports it, and not typically to be set in boards own config? It looks like I messed up something as this didn't pass the CI; I'll revisit this later today
There was a problem hiding this comment.
It seems that ARCH_STACKDUMP is indeed set for each board individually. So the difference here is just that disabling ARCH_STACKDUMP would remove printing the whole stack info.
I wanted to only suppress dumping the stack content, but leave the relatively lightweight printing of stack information.
Perhaps some other CONFIG_ syntax would be cleaner?
There was a problem hiding this comment.
yes, I think so. so, should we just keep one Kconfig? the basic stack info should be always printed, but the stack content is printed only Kconfig is enabled.
| int cpu = this_cpu(); | ||
| # endif | ||
|
|
||
| _alert("IRQ Stack: base: %p size: %u\n", |
There was a problem hiding this comment.
why not add #ifdef CONFIG_SCHED_DUMP_STACK/#endif in the origin code
There was a problem hiding this comment.
Just tried to make it as small as possible; I can refactor this for sure!
|
I like this optimization, and thanks @jlaitine for working on so many size improvements lately! Maybe you could add these two new options to the documentation somewhere so it is easier for other users to take advantage of them? |
4f8c4c6 to
339121d
Compare
|
I re-factored this to be a minimal code change. Total size reduction with reduced output is still > 1.3KB. This now always keeps the functionality for printing out the stack pointer info for user/kernel & irq stacks. Would this approach look better @xiaoxiang781216 ? If this is preferable to the previous version, I'll test tomorrow and add new test outputs here. I don't have all the HW at hand atm. |
…STACK Add more refined options for sched/misc/assert to control how verbose crash dumps are printed out: - SCHED_DUMP_TASKS - SCHED_DUMP_STACK These default to y unless DEFAULT_SMALL is defined. The options can be undefined to save flash space on a small system. Signed-off-by: Jukka Laitinen <jukka.laitinen@tii.ae>
339121d to
f93360b
Compare
Summary
Here is one proposal, how we could save a bit of flash on small systems.
First commit (not too significant one) doesn't change functionality, just cleans up a tiny amount of flash (64 bytes on 32-bit arm) by removing a duplicate string and an extra function call. The duplicate string was not cleaned up by linker because the string was only almost the same, the other one had one extra space.
The second one adds two new CONFIG flags giving more granularity to configure what to dump at crash:
CONFIG_SCHED_DUMP_STACK : Output stack dump at crash, consumes ~1kB flash ( If disabled, it still dumps the current stack, irq stack and kernel stack base and size )
CONFIG_SCHED_DUMP_TASKS : Output tasks dump at crash, consumes ~0.5kB flash
By removing these two, 1.6kB can be saved in flash size.
Both flags are defined !CONFIG_DEFAULT_SMALL, so with normal configurations the functionality is unchanged.
Impact
Impacts boards definining CONFIG_BUILD_SMALL, reducing flash consumption and output of kernel panic dump by default. On these systems, restoring the original panic dump would require adding CONFIG_SCHED_DUMP_STACK=y, CONFIG_SCHED_DUMP_TASKS=y to the defconfig.
Testing
Tested on stm32-f765II (pixhawk4 board)
With both the new flags disabled, the crash dump looks like this:
With CONFIG_SCHED_DUMP_TASKS=y, CONFIG_SCHED_DUMP_STACK=n:
And the current functionality, both flags = y: