Commit 8ad2914d9cc55be651ef3bd676981a72c9001a47

Authored by Randy Dunlap
Committed by Linus Torvalds
1 parent 5ec3e4b7ae

[PATCH] checkstack: print module names

Finding "init_module" high stack usage problems is challenging when there
are over 1600 "init_module" functions in the kernel tree, so make
checkstack.pl print out the filename where the stack usage occurs.  This is
useful for code built as loadable modules.

For built-in code, it just prints the kernel image file name, like
"vmlinux".  Examples:

(before patch:)
0x0000000d callback:					1928
0xffffffff81678c09 huft_build:				1560
0x0018 init_module:					1512

(after patch:)
0x0000000d callback [divacapi]:				1928
0xffffffff81678c09 huft_build [vmlinux]:		1560
0x0018 init_module [hdaps]:				1512

Also change one if-series to use elsif to cut down on unneeded tests.

Signed-off-by: Randy Dunlap <rdunlap@xenotime.net>
Acked-by: Joern Engel <joern@wh.fh-wedel.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

Showing 1 changed file with 12 additions and 2 deletions Inline Diff

scripts/checkstack.pl
1 #!/usr/bin/perl 1 #!/usr/bin/perl
2 2
3 # Check the stack usage of functions 3 # Check the stack usage of functions
4 # 4 #
5 # Copyright Joern Engel <joern@wh.fh-wedel.de> 5 # Copyright Joern Engel <joern@wh.fh-wedel.de>
6 # Inspired by Linus Torvalds 6 # Inspired by Linus Torvalds
7 # Original idea maybe from Keith Owens 7 # Original idea maybe from Keith Owens
8 # s390 port and big speedup by Arnd Bergmann <arnd@bergmann-dalldorf.de> 8 # s390 port and big speedup by Arnd Bergmann <arnd@bergmann-dalldorf.de>
9 # Mips port by Juan Quintela <quintela@mandrakesoft.com> 9 # Mips port by Juan Quintela <quintela@mandrakesoft.com>
10 # IA64 port via Andreas Dilger 10 # IA64 port via Andreas Dilger
11 # Arm port by Holger Schurig 11 # Arm port by Holger Schurig
12 # sh64 port by Paul Mundt 12 # sh64 port by Paul Mundt
13 # Random bits by Matt Mackall <mpm@selenic.com> 13 # Random bits by Matt Mackall <mpm@selenic.com>
14 # M68k port by Geert Uytterhoeven and Andreas Schwab 14 # M68k port by Geert Uytterhoeven and Andreas Schwab
15 # 15 #
16 # Usage: 16 # Usage:
17 # objdump -d vmlinux | stackcheck.pl [arch] 17 # objdump -d vmlinux | stackcheck.pl [arch]
18 # 18 #
19 # TODO : Port to all architectures (one regex per arch) 19 # TODO : Port to all architectures (one regex per arch)
20 20
21 # check for arch 21 # check for arch
22 # 22 #
23 # $re is used for two matches: 23 # $re is used for two matches:
24 # $& (whole re) matches the complete objdump line with the stack growth 24 # $& (whole re) matches the complete objdump line with the stack growth
25 # $1 (first bracket) matches the size of the stack growth 25 # $1 (first bracket) matches the size of the stack growth
26 # 26 #
27 # use anything else and feel the pain ;) 27 # use anything else and feel the pain ;)
28 my (@stack, $re, $x, $xs); 28 my (@stack, $re, $x, $xs);
29 { 29 {
30 my $arch = shift; 30 my $arch = shift;
31 if ($arch eq "") { 31 if ($arch eq "") {
32 $arch = `uname -m`; 32 $arch = `uname -m`;
33 } 33 }
34 34
35 $x = "[0-9a-f]"; # hex character 35 $x = "[0-9a-f]"; # hex character
36 $xs = "[0-9a-f ]"; # hex character or space 36 $xs = "[0-9a-f ]"; # hex character or space
37 if ($arch eq 'arm') { 37 if ($arch eq 'arm') {
38 #c0008ffc: e24dd064 sub sp, sp, #100 ; 0x64 38 #c0008ffc: e24dd064 sub sp, sp, #100 ; 0x64
39 $re = qr/.*sub.*sp, sp, #(([0-9]{2}|[3-9])[0-9]{2})/o; 39 $re = qr/.*sub.*sp, sp, #(([0-9]{2}|[3-9])[0-9]{2})/o;
40 } elsif ($arch =~ /^i[3456]86$/) { 40 } elsif ($arch =~ /^i[3456]86$/) {
41 #c0105234: 81 ec ac 05 00 00 sub $0x5ac,%esp 41 #c0105234: 81 ec ac 05 00 00 sub $0x5ac,%esp
42 $re = qr/^.*[as][du][db] \$(0x$x{1,8}),\%esp$/o; 42 $re = qr/^.*[as][du][db] \$(0x$x{1,8}),\%esp$/o;
43 } elsif ($arch eq 'x86_64') { 43 } elsif ($arch eq 'x86_64') {
44 # 2f60: 48 81 ec e8 05 00 00 sub $0x5e8,%rsp 44 # 2f60: 48 81 ec e8 05 00 00 sub $0x5e8,%rsp
45 $re = qr/^.*[as][du][db] \$(0x$x{1,8}),\%rsp$/o; 45 $re = qr/^.*[as][du][db] \$(0x$x{1,8}),\%rsp$/o;
46 } elsif ($arch eq 'ia64') { 46 } elsif ($arch eq 'ia64') {
47 #e0000000044011fc: 01 0f fc 8c adds r12=-384,r12 47 #e0000000044011fc: 01 0f fc 8c adds r12=-384,r12
48 $re = qr/.*adds.*r12=-(([0-9]{2}|[3-9])[0-9]{2}),r12/o; 48 $re = qr/.*adds.*r12=-(([0-9]{2}|[3-9])[0-9]{2}),r12/o;
49 } elsif ($arch eq 'm68k') { 49 } elsif ($arch eq 'm68k') {
50 # 2b6c: 4e56 fb70 linkw %fp,#-1168 50 # 2b6c: 4e56 fb70 linkw %fp,#-1168
51 # 1df770: defc ffe4 addaw #-28,%sp 51 # 1df770: defc ffe4 addaw #-28,%sp
52 $re = qr/.*(?:linkw %fp,|addaw )#-([0-9]{1,4})(?:,%sp)?$/o; 52 $re = qr/.*(?:linkw %fp,|addaw )#-([0-9]{1,4})(?:,%sp)?$/o;
53 } elsif ($arch eq 'mips64') { 53 } elsif ($arch eq 'mips64') {
54 #8800402c: 67bdfff0 daddiu sp,sp,-16 54 #8800402c: 67bdfff0 daddiu sp,sp,-16
55 $re = qr/.*daddiu.*sp,sp,-(([0-9]{2}|[3-9])[0-9]{2})/o; 55 $re = qr/.*daddiu.*sp,sp,-(([0-9]{2}|[3-9])[0-9]{2})/o;
56 } elsif ($arch eq 'mips') { 56 } elsif ($arch eq 'mips') {
57 #88003254: 27bdffe0 addiu sp,sp,-32 57 #88003254: 27bdffe0 addiu sp,sp,-32
58 $re = qr/.*addiu.*sp,sp,-(([0-9]{2}|[3-9])[0-9]{2})/o; 58 $re = qr/.*addiu.*sp,sp,-(([0-9]{2}|[3-9])[0-9]{2})/o;
59 } elsif ($arch eq 'ppc') { 59 } elsif ($arch eq 'ppc') {
60 #c00029f4: 94 21 ff 30 stwu r1,-208(r1) 60 #c00029f4: 94 21 ff 30 stwu r1,-208(r1)
61 $re = qr/.*stwu.*r1,-($x{1,8})\(r1\)/o; 61 $re = qr/.*stwu.*r1,-($x{1,8})\(r1\)/o;
62 } elsif ($arch eq 'ppc64') { 62 } elsif ($arch eq 'ppc64') {
63 #XXX 63 #XXX
64 $re = qr/.*stdu.*r1,-($x{1,8})\(r1\)/o; 64 $re = qr/.*stdu.*r1,-($x{1,8})\(r1\)/o;
65 } elsif ($arch =~ /^s390x?$/) { 65 } elsif ($arch =~ /^s390x?$/) {
66 # 11160: a7 fb ff 60 aghi %r15,-160 66 # 11160: a7 fb ff 60 aghi %r15,-160
67 $re = qr/.*ag?hi.*\%r15,-(([0-9]{2}|[3-9])[0-9]{2})/o; 67 $re = qr/.*ag?hi.*\%r15,-(([0-9]{2}|[3-9])[0-9]{2})/o;
68 } elsif ($arch =~ /^sh64$/) { 68 } elsif ($arch =~ /^sh64$/) {
69 #XXX: we only check for the immediate case presently, 69 #XXX: we only check for the immediate case presently,
70 # though we will want to check for the movi/sub 70 # though we will want to check for the movi/sub
71 # pair for larger users. -- PFM. 71 # pair for larger users. -- PFM.
72 #a00048e0: d4fc40f0 addi.l r15,-240,r15 72 #a00048e0: d4fc40f0 addi.l r15,-240,r15
73 $re = qr/.*addi\.l.*r15,-(([0-9]{2}|[3-9])[0-9]{2}),r15/o; 73 $re = qr/.*addi\.l.*r15,-(([0-9]{2}|[3-9])[0-9]{2}),r15/o;
74 } else { 74 } else {
75 print("wrong or unknown architecture\n"); 75 print("wrong or unknown architecture\n");
76 exit 76 exit
77 } 77 }
78 } 78 }
79 79
80 sub bysize($) { 80 sub bysize($) {
81 my ($asize, $bsize); 81 my ($asize, $bsize);
82 ($asize = $a) =~ s/.*: *(.*)$/$1/; 82 ($asize = $a) =~ s/.*: *(.*)$/$1/;
83 ($bsize = $b) =~ s/.*: *(.*)$/$1/; 83 ($bsize = $b) =~ s/.*: *(.*)$/$1/;
84 $bsize <=> $asize 84 $bsize <=> $asize
85 } 85 }
86 86
87 # 87 #
88 # main() 88 # main()
89 # 89 #
90 my $funcre = qr/^$x* <(.*)>:$/; 90 my $funcre = qr/^$x* <(.*)>:$/;
91 my $func; 91 my $func;
92 my $file, $lastslash;
93
92 while (my $line = <STDIN>) { 94 while (my $line = <STDIN>) {
93 if ($line =~ m/$funcre/) { 95 if ($line =~ m/$funcre/) {
94 $func = $1; 96 $func = $1;
95 } 97 }
96 if ($line =~ m/$re/) { 98 elsif ($line =~ m/(.*):\s*file format/) {
99 $file = $1;
100 $file =~ s/\.ko//;
101 $lastslash = rindex($file, "/");
102 if ($lastslash != -1) {
103 $file = substr($file, $lastslash + 1);
104 }
105 }
106 elsif ($line =~ m/$re/) {
97 my $size = $1; 107 my $size = $1;
98 $size = hex($size) if ($size =~ /^0x/); 108 $size = hex($size) if ($size =~ /^0x/);
99 109
100 if ($size > 0xf0000000) { 110 if ($size > 0xf0000000) {
101 $size = - $size; 111 $size = - $size;
102 $size += 0x80000000; 112 $size += 0x80000000;
103 $size += 0x80000000; 113 $size += 0x80000000;
104 } 114 }
105 next if ($size > 0x10000000); 115 next if ($size > 0x10000000);
106 116
107 next if $line !~ m/^($xs*)/; 117 next if $line !~ m/^($xs*)/;
108 my $addr = $1; 118 my $addr = $1;
109 $addr =~ s/ /0/g; 119 $addr =~ s/ /0/g;
110 $addr = "0x$addr"; 120 $addr = "0x$addr";
111 121
112 my $intro = "$addr $func:"; 122 my $intro = "$addr $func [$file]:";
113 my $padlen = 56 - length($intro); 123 my $padlen = 56 - length($intro);
114 while ($padlen > 0) { 124 while ($padlen > 0) {
115 $intro .= ' '; 125 $intro .= ' ';
116 $padlen -= 8; 126 $padlen -= 8;
117 } 127 }
118 next if ($size < 100); 128 next if ($size < 100);
119 push @stack, "$intro$size\n"; 129 push @stack, "$intro$size\n";
120 } 130 }
121 } 131 }
122 132
123 print sort bysize @stack; 133 print sort bysize @stack;
124 134