task_stack.h: Add stack_not_used() support for dynamic stack
CONFIG_DEBUG_STACK_USAGE is enabled by default on most architectures.
Its purpose is to determine and print the maximum stack depth on
thread exit.
The way it works, is it starts from the buttom of the stack and
searches the first non-zero word in the stack. With dynamic stack it
does not work very well, as it means it faults every pages in every
stack.
Instead, add a specific version of stack_not_used() for dynamic stacks
where instead of starting from the buttom of the stack, we start from
the last page mapped in the stack.
In addition to not doing uncessary page faulting, this search is
optimized by skipping search through zero pages.
Also, because dynamic stack does not end with MAGIC_NUMBER, there is
no need to skeep the buttom most word in the stack.
Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
Link: https://lore.kernel.org/20240311164638.2015063-14-pasha.tatashin@soleen.com
[Rebased, Kasan oneliner needed preserving]
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
2 files changed