-
Notifications
You must be signed in to change notification settings - Fork 8k
kernel: stack: Core thread stack usage logging #15856
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
Conversation
Add stack usage logging in idle thread. Enabled by CONFIG_INIT_STACKS and CONFIG_THREAD_MONITOR. Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
STACK_ANALYZE("interrupt stack", _interrupt_stack); | ||
STACK_ANALYZE("sys work q stack", sys_work_q_stack); | ||
STACK_ANALYZE("main stack", _main_stack); | ||
STACK_ANALYZE("idle stack", _idle_stack); |
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.
Why do the above four threads get special treatment? Wont they be included in the k_thread_foread()
?
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.
No, its not included... that what needs to be debugged. May the code owner for the thread monitor feature needs to intervene here.
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.
The above four threads might be "special" to the kernel? They are in any case essential to the RTOS so it's critical that we get their info printed
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.
it is worth to check why they are not included in k_treadh_foreach()
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.
#else | ||
for (;;) { | ||
#if defined(CONFIG_INIT_STACKS) | ||
if (k_uptime_get_32() - idle_ts > K_SECONDS(5)) { |
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.
For this kind of periodic logging the period should probably be made configurable through Kconfig. E.g. if the shell is enabled one might want to disable this completely and just rely on the explicit "kernel stacks" command.
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.
Agree. Will try to remember to fix once its figured out how to get all the threads enumerated.
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.
Yep, must be possible to configure it in build time. Make clear that this is an idle thread and there is not time guarantee.
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.
While I like the idea, I am not sure we should pollute the idle thread with this. Maybe it would be better to provide a thread-dumping kernel call that the user can then call at will from main()
? perhaps even a variant that never returns and uses k_sleep()
, so that the user can write:
main()
{
init_my_app()
k_stacks();
/* unreachable */
}
and then in k_stacks()
:
while(1) {
print_stack_info()
k_sleep(K_STACKS_FREQUENCY);
}
Or maybe even a Kconfig option that automatically calls |
#3082 for reference |
agree. We probably should have a stack monitoring thread that can be a bit more intelligent and send notifications only when things above a certain threshold . Does not mynewt have something like that btw? |
LOG_MODULE_DECLARE(kernel, CONFIG_KERNEL_LOG_LEVEL); | ||
|
||
const char *name = k_thread_name_get((struct k_thread *)thread); | ||
unsigned int size = thread->stack_info.size; |
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.
should use the same type of stack_info u32_t
. int size can change ...
agree, both options are better than introduce a new feature under the INIT_STACKS option. |
Nothing has happened since May 2019, closing this until this is picked up again for implementation. |
Add stack usage logging in idle thread. Enabled by
CONFIG_INIT_STACKS and CONFIG_THREAD_MONITOR.
Signed-off-by: Vinayak Kariappa Chettimada vich@nordicsemi.no