]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.19.34/perf-annotate-fix-getting-source-line-failure.patch
Linux 4.14.111
[thirdparty/kernel/stable-queue.git] / releases / 4.19.34 / perf-annotate-fix-getting-source-line-failure.patch
1 From cfb96dcbe2e461e73228efa22e9698b08fad4afe Mon Sep 17 00:00:00 2001
2 From: Wei Li <liwei391@huawei.com>
3 Date: Thu, 21 Feb 2019 17:57:16 +0800
4 Subject: perf annotate: Fix getting source line failure
5
6 [ Upstream commit 11db1ad4513d6205d2519e1a30ff4cef746e3243 ]
7
8 The output of "perf annotate -l --stdio xxx" changed since commit 425859ff0de33
9 ("perf annotate: No need to calculate notes->start twice") removed notes->start
10 assignment in symbol__calc_lines(). It will get failed in
11 find_address_in_section() from symbol__tty_annotate() subroutine as the
12 a2l->addr is wrong. So the annotate summary doesn't report the line number of
13 source code correctly.
14
15 Before fix:
16
17 liwei@euler:~/main_code/hulk_work/hulk/tools/perf$ cat common_while_1.c
18 void hotspot_1(void)
19 {
20 volatile int i;
21
22 for (i = 0; i < 0x10000000; i++);
23 for (i = 0; i < 0x10000000; i++);
24 for (i = 0; i < 0x10000000; i++);
25 }
26
27 int main(void)
28 {
29 hotspot_1();
30
31 return 0;
32 }
33 liwei@euler:~/main_code/hulk_work/hulk/tools/perf$ gcc common_while_1.c -g -o common_while_1
34
35 liwei@euler:~/main_code/hulk_work/hulk/tools/perf$ sudo ./perf record ./common_while_1
36 [ perf record: Woken up 2 times to write data ]
37 [ perf record: Captured and wrote 0.488 MB perf.data (12498 samples) ]
38 liwei@euler:~/main_code/hulk_work/hulk/tools/perf$ sudo ./perf annotate -l -s hotspot_1 --stdio
39
40 Sorted summary for file /home/liwei/main_code/hulk_work/hulk/tools/perf/common_while_1
41 ----------------------------------------------
42
43 19.30 common_while_1[32]
44 19.03 common_while_1[4e]
45 19.01 common_while_1[16]
46 5.04 common_while_1[13]
47 4.99 common_while_1[4b]
48 4.78 common_while_1[2c]
49 4.77 common_while_1[10]
50 4.66 common_while_1[2f]
51 4.59 common_while_1[51]
52 4.59 common_while_1[35]
53 4.52 common_while_1[19]
54 4.20 common_while_1[56]
55 0.51 common_while_1[48]
56 Percent | Source code & Disassembly of common_while_1 for cycles:ppp (12480 samples, percent: local period)
57 -----------------------------------------------------------------------------------------------------------------
58 :
59 :
60 :
61 : Disassembly of section .text:
62 :
63 : 00000000000005fa <hotspot_1>:
64 : hotspot_1():
65 : void hotspot_1(void)
66 : {
67 0.00 : 5fa: push %rbp
68 0.00 : 5fb: mov %rsp,%rbp
69 : volatile int i;
70 :
71 : for (i = 0; i < 0x10000000; i++);
72 0.00 : 5fe: movl $0x0,-0x4(%rbp)
73 0.00 : 605: jmp 610 <hotspot_1+0x16>
74 0.00 : 607: mov -0x4(%rbp),%eax
75 common_while_1[10] 4.77 : 60a: add $0x1,%eax
76 common_while_1[13] 5.04 : 60d: mov %eax,-0x4(%rbp)
77 common_while_1[16] 19.01 : 610: mov -0x4(%rbp),%eax
78 common_while_1[19] 4.52 : 613: cmp $0xfffffff,%eax
79 0.00 : 618: jle 607 <hotspot_1+0xd>
80 : for (i = 0; i < 0x10000000; i++);
81 ...
82
83 After fix:
84
85 liwei@euler:~/main_code/hulk_work/hulk/tools/perf$ sudo ./perf record ./common_while_1
86 [ perf record: Woken up 2 times to write data ]
87 [ perf record: Captured and wrote 0.488 MB perf.data (12500 samples) ]
88 liwei@euler:~/main_code/hulk_work/hulk/tools/perf$ sudo ./perf annotate -l -s hotspot_1 --stdio
89
90 Sorted summary for file /home/liwei/main_code/hulk_work/hulk/tools/perf/common_while_1
91 ----------------------------------------------
92
93 33.34 common_while_1.c:5
94 33.34 common_while_1.c:6
95 33.32 common_while_1.c:7
96 Percent | Source code & Disassembly of common_while_1 for cycles:ppp (12482 samples, percent: local period)
97 -----------------------------------------------------------------------------------------------------------------
98 :
99 :
100 :
101 : Disassembly of section .text:
102 :
103 : 00000000000005fa <hotspot_1>:
104 : hotspot_1():
105 : void hotspot_1(void)
106 : {
107 0.00 : 5fa: push %rbp
108 0.00 : 5fb: mov %rsp,%rbp
109 : volatile int i;
110 :
111 : for (i = 0; i < 0x10000000; i++);
112 0.00 : 5fe: movl $0x0,-0x4(%rbp)
113 0.00 : 605: jmp 610 <hotspot_1+0x16>
114 0.00 : 607: mov -0x4(%rbp),%eax
115 common_while_1.c:5 4.70 : 60a: add $0x1,%eax
116 4.89 : 60d: mov %eax,-0x4(%rbp)
117 common_while_1.c:5 19.03 : 610: mov -0x4(%rbp),%eax
118 common_while_1.c:5 4.72 : 613: cmp $0xfffffff,%eax
119 0.00 : 618: jle 607 <hotspot_1+0xd>
120 : for (i = 0; i < 0x10000000; i++);
121 0.00 : 61a: movl $0x0,-0x4(%rbp)
122 0.00 : 621: jmp 62c <hotspot_1+0x32>
123 0.00 : 623: mov -0x4(%rbp),%eax
124 common_while_1.c:6 4.54 : 626: add $0x1,%eax
125 4.73 : 629: mov %eax,-0x4(%rbp)
126 common_while_1.c:6 19.54 : 62c: mov -0x4(%rbp),%eax
127 common_while_1.c:6 4.54 : 62f: cmp $0xfffffff,%eax
128 ...
129
130 Signed-off-by: Wei Li <liwei391@huawei.com>
131 Acked-by: Jiri Olsa <jolsa@kernel.org>
132 Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
133 Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
134 Cc: Jin Yao <yao.jin@linux.intel.com>
135 Cc: Namhyung Kim <namhyung@kernel.org>
136 Cc: Peter Zijlstra <peterz@infradead.org>
137 Fixes: 425859ff0de33 ("perf annotate: No need to calculate notes->start twice")
138 Link: http://lkml.kernel.org/r/20190221095716.39529-1-liwei391@huawei.com
139 Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
140 Signed-off-by: Sasha Levin <sashal@kernel.org>
141 ---
142 tools/perf/util/annotate.c | 4 ++--
143 1 file changed, 2 insertions(+), 2 deletions(-)
144
145 diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
146 index 28cd6a17491b..dfee110b3a58 100644
147 --- a/tools/perf/util/annotate.c
148 +++ b/tools/perf/util/annotate.c
149 @@ -1862,6 +1862,7 @@ int symbol__annotate(struct symbol *sym, struct map *map,
150 struct annotation_options *options,
151 struct arch **parch)
152 {
153 + struct annotation *notes = symbol__annotation(sym);
154 struct annotate_args args = {
155 .privsize = privsize,
156 .evsel = evsel,
157 @@ -1892,6 +1893,7 @@ int symbol__annotate(struct symbol *sym, struct map *map,
158
159 args.ms.map = map;
160 args.ms.sym = sym;
161 + notes->start = map__rip_2objdump(map, sym->start);
162
163 return symbol__disassemble(sym, &args);
164 }
165 @@ -2746,8 +2748,6 @@ int symbol__annotate2(struct symbol *sym, struct map *map, struct perf_evsel *ev
166
167 symbol__calc_percent(sym, evsel);
168
169 - notes->start = map__rip_2objdump(map, sym->start);
170 -
171 annotation__set_offsets(notes, size);
172 annotation__mark_jump_targets(notes, sym);
173 annotation__compute_ipc(notes, size);
174 --
175 2.19.1
176