* [PATCH 0/3] checkstack: bug fix and minor improvements
@ 2023-11-20 18:37 Heiko Carstens
2023-11-20 18:37 ` [PATCH 1/3] checkstack: fix printed address Heiko Carstens
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Heiko Carstens @ 2023-11-20 18:37 UTC (permalink / raw)
To: Andrew Morton, Masahiro Yamada
Cc: Vaneet Narang, Maninder Singh, linux-kernel
While trying to use the checkstack script to print the stack usage of all
functions, I noticed that this is not possible without changing it. In
addition the current output contains a bug, and the output can be improved.
Therefore fix the bug and improve the script a bit.
Heiko Carstens (3):
checkstack: fix printed address
checkstack: sort output by size and function name
checkstack: allow to pass MINSTACKSIZE parameter
Makefile | 6 ++++--
scripts/checkstack.pl | 27 +++++++++++++++++++--------
2 files changed, 23 insertions(+), 10 deletions(-)
--
2.39.2
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/3] checkstack: fix printed address
2023-11-20 18:37 [PATCH 0/3] checkstack: bug fix and minor improvements Heiko Carstens
@ 2023-11-20 18:37 ` Heiko Carstens
2023-11-20 18:37 ` [PATCH 2/3] checkstack: sort output by size and function name Heiko Carstens
2023-11-20 18:37 ` [PATCH 3/3] checkstack: allow to pass MINSTACKSIZE parameter Heiko Carstens
2 siblings, 0 replies; 4+ messages in thread
From: Heiko Carstens @ 2023-11-20 18:37 UTC (permalink / raw)
To: Andrew Morton, Masahiro Yamada
Cc: Vaneet Narang, Maninder Singh, linux-kernel
All addresses printed by checkstack have an extra incorrect 0 appended at
the end.
This was introduced with commit 677f1410e058 ("scripts/checkstack.pl: don't
display $dre as different entity"): since then the address is taken from
the line which contains the function name, instead of the line which
contains stack consumption. E.g. on s390:
0000000000100a30 <do_one_initcall>:
...
100a44: e3 f0 ff 70 ff 71 lay %r15,-144(%r15)
So the used regex which matches spaces and hexadecimal numbers to extract
an address now matches a different substring. Subsequently replacing spaces
with 0 appends a zero at the and, instead of replacing leading spaces.
Fix this by using the proper regex, and simplify the code a bit.
Fixes: 677f1410e058 ("scripts/checkstack.pl: don't display $dre as different entity")
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
---
scripts/checkstack.pl | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/scripts/checkstack.pl b/scripts/checkstack.pl
index d83ba5d8f3f4..f27d552aec43 100755
--- a/scripts/checkstack.pl
+++ b/scripts/checkstack.pl
@@ -138,15 +138,11 @@ $total_size = 0;
while (my $line = <STDIN>) {
if ($line =~ m/$funcre/) {
$func = $1;
- next if $line !~ m/^($xs*)/;
+ next if $line !~ m/^($x*)/;
if ($total_size > $min_stack) {
push @stack, "$intro$total_size\n";
}
-
- $addr = $1;
- $addr =~ s/ /0/g;
- $addr = "0x$addr";
-
+ $addr = "0x$1";
$intro = "$addr $func [$file]:";
my $padlen = 56 - length($intro);
while ($padlen > 0) {
--
2.39.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/3] checkstack: sort output by size and function name
2023-11-20 18:37 [PATCH 0/3] checkstack: bug fix and minor improvements Heiko Carstens
2023-11-20 18:37 ` [PATCH 1/3] checkstack: fix printed address Heiko Carstens
@ 2023-11-20 18:37 ` Heiko Carstens
2023-11-20 18:37 ` [PATCH 3/3] checkstack: allow to pass MINSTACKSIZE parameter Heiko Carstens
2 siblings, 0 replies; 4+ messages in thread
From: Heiko Carstens @ 2023-11-20 18:37 UTC (permalink / raw)
To: Andrew Morton, Masahiro Yamada
Cc: Vaneet Narang, Maninder Singh, linux-kernel
Sort output by size and in addition by function name. This increases
readability for cases where there are many functions with the same stack
usage.
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
---
scripts/checkstack.pl | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
diff --git a/scripts/checkstack.pl b/scripts/checkstack.pl
index f27d552aec43..13408714ba0f 100755
--- a/scripts/checkstack.pl
+++ b/scripts/checkstack.pl
@@ -189,5 +189,20 @@ if ($total_size > $min_stack) {
push @stack, "$intro$total_size\n";
}
-# Sort output by size (last field)
-print sort { ($b =~ /:\t*(\d+)$/)[0] <=> ($a =~ /:\t*(\d+)$/)[0] } @stack;
+# Sort output by size (last field) and function name if size is the same
+sub sort_lines {
+ my ($a, $b) = @_;
+
+ my $num_a = $1 if $a =~ /:\t*(\d+)$/;
+ my $num_b = $1 if $b =~ /:\t*(\d+)$/;
+ my $func_a = $1 if $a =~ / (.*):/;
+ my $func_b = $1 if $b =~ / (.*):/;
+
+ if ($num_a != $num_b) {
+ return $num_b <=> $num_a;
+ } else {
+ return $func_a cmp $func_b;
+ }
+}
+
+print sort { sort_lines($a, $b) } @stack;
--
2.39.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 3/3] checkstack: allow to pass MINSTACKSIZE parameter
2023-11-20 18:37 [PATCH 0/3] checkstack: bug fix and minor improvements Heiko Carstens
2023-11-20 18:37 ` [PATCH 1/3] checkstack: fix printed address Heiko Carstens
2023-11-20 18:37 ` [PATCH 2/3] checkstack: sort output by size and function name Heiko Carstens
@ 2023-11-20 18:37 ` Heiko Carstens
2 siblings, 0 replies; 4+ messages in thread
From: Heiko Carstens @ 2023-11-20 18:37 UTC (permalink / raw)
To: Andrew Morton, Masahiro Yamada
Cc: Vaneet Narang, Maninder Singh, linux-kernel
The checkstack script omits all functions with a stack usage of less than
100 bytes. However the script already has support for a parameter which
allows to override the default, but it cannot be set with
$ make checkstack
Add a MINSTACKSIZE parameter which allows to change the default. This might
be useful in order to print the stack usage of all functions, or only those
with large stack usage:
$ make checkstack MINSTACKSIZE=0
$ make checkstack MINSTACKSIZE=800
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
---
Makefile | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/Makefile b/Makefile
index 724c79bebe72..b90413e7e590 100644
--- a/Makefile
+++ b/Makefile
@@ -1576,7 +1576,8 @@ help:
echo ' (default: $(INSTALL_HDR_PATH))'; \
echo ''
@echo 'Static analysers:'
- @echo ' checkstack - Generate a list of stack hogs'
+ @echo ' checkstack - Generate a list of stack hogs and consider all functions'
+ @echo ' with a stack size larger than MINSTACKSIZE (default: 100)'
@echo ' versioncheck - Sanity check on version.h usage'
@echo ' includecheck - Check for duplicate included header files'
@echo ' export_report - List the usages of all exported symbols'
@@ -2016,9 +2017,10 @@ CHECKSTACK_ARCH := $(SUBARCH)
else
CHECKSTACK_ARCH := $(ARCH)
endif
+MINSTACKSIZE ?= 100
checkstack:
$(OBJDUMP) -d vmlinux $$(find . -name '*.ko') | \
- $(PERL) $(srctree)/scripts/checkstack.pl $(CHECKSTACK_ARCH)
+ $(PERL) $(srctree)/scripts/checkstack.pl $(CHECKSTACK_ARCH) $(MINSTACKSIZE)
kernelrelease:
@$(filechk_kernel.release)
--
2.39.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-11-20 18:39 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-20 18:37 [PATCH 0/3] checkstack: bug fix and minor improvements Heiko Carstens
2023-11-20 18:37 ` [PATCH 1/3] checkstack: fix printed address Heiko Carstens
2023-11-20 18:37 ` [PATCH 2/3] checkstack: sort output by size and function name Heiko Carstens
2023-11-20 18:37 ` [PATCH 3/3] checkstack: allow to pass MINSTACKSIZE parameter Heiko Carstens
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox