Skip to content

Commit

Permalink
shell: show IRQ stack information
Browse files Browse the repository at this point in the history
This is placeholder code; better kernel support for dumping
exception/interrupt related stacks is forthcoming.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
  • Loading branch information
Andrew Boie authored and nashif committed Mar 14, 2020
1 parent 7cb8f5c commit 22b9167
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions subsys/shell/modules/kernel_service.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,40 @@ static void shell_stack_dump(const struct k_thread *thread, void *user_data)
size, unused, size - unused, size, pcnt);
}

extern K_THREAD_STACK_DEFINE(_interrupt_stack, CONFIG_ISR_STACK_SIZE);

static int cmd_kernel_stacks(const struct shell *shell,
size_t argc, char **argv)
{
u8_t *buf;
size_t size, unused = 0;

ARG_UNUSED(argc);
ARG_UNUSED(argv);
k_thread_foreach(shell_stack_dump, (void *)shell);

/* Placeholder logic for interrupt stack until we have better
* kernel support, including dumping all IRQ stacks for SMP systems
* and hooks to dump arch-specific exception-related stack buffers.
*
* For now, dump data for the first IRQ stack defined in init.c
*/
buf = Z_THREAD_STACK_BUFFER(_interrupt_stack);
size = K_THREAD_STACK_SIZEOF(_interrupt_stack);

for (size_t i = 0; i < K_THREAD_STACK_SIZEOF(_interrupt_stack); i++) {
if (buf[i] == 0xAAU) {
unused++;
} else {
break;
}
}

shell_print(shell,
"%p IRQ 0 (real size %zu):\tunused %zu\tusage %zu / %zu (%zu %%)",
_interrupt_stack, size, unused, size - unused, size,
((size - unused) * 100U) / size);

return 0;
}
#endif
Expand Down

0 comments on commit 22b9167

Please sign in to comment.