aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf
diff options
context:
space:
mode:
authorJiri Olsa <jolsa@redhat.com>2012-11-09 19:46:41 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2012-11-14 14:48:35 -0500
commit0a4e1ae6808a28a92573550603121b146b11312e (patch)
treea5c76536c56828bf7ecac3cb8e2877343b9b5217 /tools/perf
parent84e53ff77cb1e005f49966cd6789109d84acc9e2 (diff)
perf tests: Move test__vmlinux_matches_kallsyms into separate object
Separating test__vmlinux_matches_kallsyms test from the builtin-test into vmlinux-kallsyms object. Signed-off-by: Jiri Olsa <jolsa@redhat.com> Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Ingo Molnar <mingo@elte.hu> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Link: http://lkml.kernel.org/r/1352508412-16914-2-git-send-email-jolsa@redhat.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf')
-rw-r--r--tools/perf/Makefile1
-rw-r--r--tools/perf/tests/builtin-test.c223
-rw-r--r--tools/perf/tests/tests.h6
-rw-r--r--tools/perf/tests/vmlinux-kallsyms.c230
4 files changed, 239 insertions, 221 deletions
diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index cca5bb8334ad..7c7ba4d6dafd 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -431,6 +431,7 @@ LIB_OBJS += $(OUTPUT)arch/common.o
431LIB_OBJS += $(OUTPUT)tests/parse-events.o 431LIB_OBJS += $(OUTPUT)tests/parse-events.o
432LIB_OBJS += $(OUTPUT)tests/dso-data.o 432LIB_OBJS += $(OUTPUT)tests/dso-data.o
433LIB_OBJS += $(OUTPUT)tests/attr.o 433LIB_OBJS += $(OUTPUT)tests/attr.o
434LIB_OBJS += $(OUTPUT)tests/vmlinux-kallsyms.o
434 435
435BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o 436BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o
436BUILTIN_OBJS += $(OUTPUT)builtin-bench.o 437BUILTIN_OBJS += $(OUTPUT)builtin-bench.o
diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index 5d4354e24457..5bc9063bf30f 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -21,231 +21,12 @@
21 21
22#include <sys/mman.h> 22#include <sys/mman.h>
23 23
24static int vmlinux_matches_kallsyms_filter(struct map *map __maybe_unused,
25 struct symbol *sym)
26{
27 bool *visited = symbol__priv(sym);
28 *visited = true;
29 return 0;
30}
31
32static int test__vmlinux_matches_kallsyms(void)
33{
34 int err = -1;
35 struct rb_node *nd;
36 struct symbol *sym;
37 struct map *kallsyms_map, *vmlinux_map;
38 struct machine kallsyms, vmlinux;
39 enum map_type type = MAP__FUNCTION;
40 struct ref_reloc_sym ref_reloc_sym = { .name = "_stext", };
41
42 /*
43 * Step 1:
44 *
45 * Init the machines that will hold kernel, modules obtained from
46 * both vmlinux + .ko files and from /proc/kallsyms split by modules.
47 */
48 machine__init(&kallsyms, "", HOST_KERNEL_ID);
49 machine__init(&vmlinux, "", HOST_KERNEL_ID);
50
51 /*
52 * Step 2:
53 *
54 * Create the kernel maps for kallsyms and the DSO where we will then
55 * load /proc/kallsyms. Also create the modules maps from /proc/modules
56 * and find the .ko files that match them in /lib/modules/`uname -r`/.
57 */
58 if (machine__create_kernel_maps(&kallsyms) < 0) {
59 pr_debug("machine__create_kernel_maps ");
60 return -1;
61 }
62
63 /*
64 * Step 3:
65 *
66 * Load and split /proc/kallsyms into multiple maps, one per module.
67 */
68 if (machine__load_kallsyms(&kallsyms, "/proc/kallsyms", type, NULL) <= 0) {
69 pr_debug("dso__load_kallsyms ");
70 goto out;
71 }
72
73 /*
74 * Step 4:
75 *
76 * kallsyms will be internally on demand sorted by name so that we can
77 * find the reference relocation * symbol, i.e. the symbol we will use
78 * to see if the running kernel was relocated by checking if it has the
79 * same value in the vmlinux file we load.
80 */
81 kallsyms_map = machine__kernel_map(&kallsyms, type);
82
83 sym = map__find_symbol_by_name(kallsyms_map, ref_reloc_sym.name, NULL);
84 if (sym == NULL) {
85 pr_debug("dso__find_symbol_by_name ");
86 goto out;
87 }
88
89 ref_reloc_sym.addr = sym->start;
90
91 /*
92 * Step 5:
93 *
94 * Now repeat step 2, this time for the vmlinux file we'll auto-locate.
95 */
96 if (machine__create_kernel_maps(&vmlinux) < 0) {
97 pr_debug("machine__create_kernel_maps ");
98 goto out;
99 }
100
101 vmlinux_map = machine__kernel_map(&vmlinux, type);
102 map__kmap(vmlinux_map)->ref_reloc_sym = &ref_reloc_sym;
103
104 /*
105 * Step 6:
106 *
107 * Locate a vmlinux file in the vmlinux path that has a buildid that
108 * matches the one of the running kernel.
109 *
110 * While doing that look if we find the ref reloc symbol, if we find it
111 * we'll have its ref_reloc_symbol.unrelocated_addr and then
112 * maps__reloc_vmlinux will notice and set proper ->[un]map_ip routines
113 * to fixup the symbols.
114 */
115 if (machine__load_vmlinux_path(&vmlinux, type,
116 vmlinux_matches_kallsyms_filter) <= 0) {
117 pr_debug("machine__load_vmlinux_path ");
118 goto out;
119 }
120
121 err = 0;
122 /*
123 * Step 7:
124 *
125 * Now look at the symbols in the vmlinux DSO and check if we find all of them
126 * in the kallsyms dso. For the ones that are in both, check its names and
127 * end addresses too.
128 */
129 for (nd = rb_first(&vmlinux_map->dso->symbols[type]); nd; nd = rb_next(nd)) {
130 struct symbol *pair, *first_pair;
131 bool backwards = true;
132
133 sym = rb_entry(nd, struct symbol, rb_node);
134
135 if (sym->start == sym->end)
136 continue;
137
138 first_pair = machine__find_kernel_symbol(&kallsyms, type, sym->start, NULL, NULL);
139 pair = first_pair;
140
141 if (pair && pair->start == sym->start) {
142next_pair:
143 if (strcmp(sym->name, pair->name) == 0) {
144 /*
145 * kallsyms don't have the symbol end, so we
146 * set that by using the next symbol start - 1,
147 * in some cases we get this up to a page
148 * wrong, trace_kmalloc when I was developing
149 * this code was one such example, 2106 bytes
150 * off the real size. More than that and we
151 * _really_ have a problem.
152 */
153 s64 skew = sym->end - pair->end;
154 if (llabs(skew) < page_size)
155 continue;
156
157 pr_debug("%#" PRIx64 ": diff end addr for %s v: %#" PRIx64 " k: %#" PRIx64 "\n",
158 sym->start, sym->name, sym->end, pair->end);
159 } else {
160 struct rb_node *nnd;
161detour:
162 nnd = backwards ? rb_prev(&pair->rb_node) :
163 rb_next(&pair->rb_node);
164 if (nnd) {
165 struct symbol *next = rb_entry(nnd, struct symbol, rb_node);
166
167 if (next->start == sym->start) {
168 pair = next;
169 goto next_pair;
170 }
171 }
172
173 if (backwards) {
174 backwards = false;
175 pair = first_pair;
176 goto detour;
177 }
178
179 pr_debug("%#" PRIx64 ": diff name v: %s k: %s\n",
180 sym->start, sym->name, pair->name);
181 }
182 } else
183 pr_debug("%#" PRIx64 ": %s not on kallsyms\n", sym->start, sym->name);
184
185 err = -1;
186 }
187
188 if (!verbose)
189 goto out;
190
191 pr_info("Maps only in vmlinux:\n");
192
193 for (nd = rb_first(&vmlinux.kmaps.maps[type]); nd; nd = rb_next(nd)) {
194 struct map *pos = rb_entry(nd, struct map, rb_node), *pair;
195 /*
196 * If it is the kernel, kallsyms is always "[kernel.kallsyms]", while
197 * the kernel will have the path for the vmlinux file being used,
198 * so use the short name, less descriptive but the same ("[kernel]" in
199 * both cases.
200 */
201 pair = map_groups__find_by_name(&kallsyms.kmaps, type,
202 (pos->dso->kernel ?
203 pos->dso->short_name :
204 pos->dso->name));
205 if (pair)
206 pair->priv = 1;
207 else
208 map__fprintf(pos, stderr);
209 }
210
211 pr_info("Maps in vmlinux with a different name in kallsyms:\n");
212
213 for (nd = rb_first(&vmlinux.kmaps.maps[type]); nd; nd = rb_next(nd)) {
214 struct map *pos = rb_entry(nd, struct map, rb_node), *pair;
215
216 pair = map_groups__find(&kallsyms.kmaps, type, pos->start);
217 if (pair == NULL || pair->priv)
218 continue;
219
220 if (pair->start == pos->start) {
221 pair->priv = 1;
222 pr_info(" %" PRIx64 "-%" PRIx64 " %" PRIx64 " %s in kallsyms as",
223 pos->start, pos->end, pos->pgoff, pos->dso->name);
224 if (pos->pgoff != pair->pgoff || pos->end != pair->end)
225 pr_info(": \n*%" PRIx64 "-%" PRIx64 " %" PRIx64 "",
226 pair->start, pair->end, pair->pgoff);
227 pr_info(" %s\n", pair->dso->name);
228 pair->priv = 1;
229 }
230 }
231
232 pr_info("Maps only in kallsyms:\n");
233
234 for (nd = rb_first(&kallsyms.kmaps.maps[type]);
235 nd; nd = rb_next(nd)) {
236 struct map *pos = rb_entry(nd, struct map, rb_node);
237
238 if (!pos->priv)
239 map__fprintf(pos, stderr);
240 }
241out:
242 return err;
243}
244
245#include "util/cpumap.h" 24#include "util/cpumap.h"
246#include "util/evsel.h" 25#include "util/evsel.h"
247#include <sys/types.h> 26#include <sys/types.h>
248 27
28#include "tests.h"
29
249static int trace_event__id(const char *evname) 30static int trace_event__id(const char *evname)
250{ 31{
251 char *filename; 32 char *filename;
diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h
new file mode 100644
index 000000000000..2223de5ad299
--- /dev/null
+++ b/tools/perf/tests/tests.h
@@ -0,0 +1,6 @@
1#ifndef TESTS_H
2#define TESTS_H
3
4int test__vmlinux_matches_kallsyms(void);
5
6#endif /* TESTS_H */
diff --git a/tools/perf/tests/vmlinux-kallsyms.c b/tools/perf/tests/vmlinux-kallsyms.c
new file mode 100644
index 000000000000..0d1cdbee2f59
--- /dev/null
+++ b/tools/perf/tests/vmlinux-kallsyms.c
@@ -0,0 +1,230 @@
1#include <linux/compiler.h>
2#include <linux/rbtree.h>
3#include <string.h>
4#include "map.h"
5#include "symbol.h"
6#include "util.h"
7#include "tests.h"
8#include "debug.h"
9#include "machine.h"
10
11static int vmlinux_matches_kallsyms_filter(struct map *map __maybe_unused,
12 struct symbol *sym)
13{
14 bool *visited = symbol__priv(sym);
15 *visited = true;
16 return 0;
17}
18
19int test__vmlinux_matches_kallsyms(void)
20{
21 int err = -1;
22 struct rb_node *nd;
23 struct symbol *sym;
24 struct map *kallsyms_map, *vmlinux_map;
25 struct machine kallsyms, vmlinux;
26 enum map_type type = MAP__FUNCTION;
27 struct ref_reloc_sym ref_reloc_sym = { .name = "_stext", };
28
29 /*
30 * Step 1:
31 *
32 * Init the machines that will hold kernel, modules obtained from
33 * both vmlinux + .ko files and from /proc/kallsyms split by modules.
34 */
35 machine__init(&kallsyms, "", HOST_KERNEL_ID);
36 machine__init(&vmlinux, "", HOST_KERNEL_ID);
37
38 /*
39 * Step 2:
40 *
41 * Create the kernel maps for kallsyms and the DSO where we will then
42 * load /proc/kallsyms. Also create the modules maps from /proc/modules
43 * and find the .ko files that match them in /lib/modules/`uname -r`/.
44 */
45 if (machine__create_kernel_maps(&kallsyms) < 0) {
46 pr_debug("machine__create_kernel_maps ");
47 return -1;
48 }
49
50 /*
51 * Step 3:
52 *
53 * Load and split /proc/kallsyms into multiple maps, one per module.
54 */
55 if (machine__load_kallsyms(&kallsyms, "/proc/kallsyms", type, NULL) <= 0) {
56 pr_debug("dso__load_kallsyms ");
57 goto out;
58 }
59
60 /*
61 * Step 4:
62 *
63 * kallsyms will be internally on demand sorted by name so that we can
64 * find the reference relocation * symbol, i.e. the symbol we will use
65 * to see if the running kernel was relocated by checking if it has the
66 * same value in the vmlinux file we load.
67 */
68 kallsyms_map = machine__kernel_map(&kallsyms, type);
69
70 sym = map__find_symbol_by_name(kallsyms_map, ref_reloc_sym.name, NULL);
71 if (sym == NULL) {
72 pr_debug("dso__find_symbol_by_name ");
73 goto out;
74 }
75
76 ref_reloc_sym.addr = sym->start;
77
78 /*
79 * Step 5:
80 *
81 * Now repeat step 2, this time for the vmlinux file we'll auto-locate.
82 */
83 if (machine__create_kernel_maps(&vmlinux) < 0) {
84 pr_debug("machine__create_kernel_maps ");
85 goto out;
86 }
87
88 vmlinux_map = machine__kernel_map(&vmlinux, type);
89 map__kmap(vmlinux_map)->ref_reloc_sym = &ref_reloc_sym;
90
91 /*
92 * Step 6:
93 *
94 * Locate a vmlinux file in the vmlinux path that has a buildid that
95 * matches the one of the running kernel.
96 *
97 * While doing that look if we find the ref reloc symbol, if we find it
98 * we'll have its ref_reloc_symbol.unrelocated_addr and then
99 * maps__reloc_vmlinux will notice and set proper ->[un]map_ip routines
100 * to fixup the symbols.
101 */
102 if (machine__load_vmlinux_path(&vmlinux, type,
103 vmlinux_matches_kallsyms_filter) <= 0) {
104 pr_debug("machine__load_vmlinux_path ");
105 goto out;
106 }
107
108 err = 0;
109 /*
110 * Step 7:
111 *
112 * Now look at the symbols in the vmlinux DSO and check if we find all of them
113 * in the kallsyms dso. For the ones that are in both, check its names and
114 * end addresses too.
115 */
116 for (nd = rb_first(&vmlinux_map->dso->symbols[type]); nd; nd = rb_next(nd)) {
117 struct symbol *pair, *first_pair;
118 bool backwards = true;
119
120 sym = rb_entry(nd, struct symbol, rb_node);
121
122 if (sym->start == sym->end)
123 continue;
124
125 first_pair = machine__find_kernel_symbol(&kallsyms, type, sym->start, NULL, NULL);
126 pair = first_pair;
127
128 if (pair && pair->start == sym->start) {
129next_pair:
130 if (strcmp(sym->name, pair->name) == 0) {
131 /*
132 * kallsyms don't have the symbol end, so we
133 * set that by using the next symbol start - 1,
134 * in some cases we get this up to a page
135 * wrong, trace_kmalloc when I was developing
136 * this code was one such example, 2106 bytes
137 * off the real size. More than that and we
138 * _really_ have a problem.
139 */
140 s64 skew = sym->end - pair->end;
141 if (llabs(skew) < page_size)
142 continue;
143
144 pr_debug("%#" PRIx64 ": diff end addr for %s v: %#" PRIx64 " k: %#" PRIx64 "\n",
145 sym->start, sym->name, sym->end, pair->end);
146 } else {
147 struct rb_node *nnd;
148detour:
149 nnd = backwards ? rb_prev(&pair->rb_node) :
150 rb_next(&pair->rb_node);
151 if (nnd) {
152 struct symbol *next = rb_entry(nnd, struct symbol, rb_node);
153
154 if (next->start == sym->start) {
155 pair = next;
156 goto next_pair;
157 }
158 }
159
160 if (backwards) {
161 backwards = false;
162 pair = first_pair;
163 goto detour;
164 }
165
166 pr_debug("%#" PRIx64 ": diff name v: %s k: %s\n",
167 sym->start, sym->name, pair->name);
168 }
169 } else
170 pr_debug("%#" PRIx64 ": %s not on kallsyms\n", sym->start, sym->name);
171
172 err = -1;
173 }
174
175 if (!verbose)
176 goto out;
177
178 pr_info("Maps only in vmlinux:\n");
179
180 for (nd = rb_first(&vmlinux.kmaps.maps[type]); nd; nd = rb_next(nd)) {
181 struct map *pos = rb_entry(nd, struct map, rb_node), *pair;
182 /*
183 * If it is the kernel, kallsyms is always "[kernel.kallsyms]", while
184 * the kernel will have the path for the vmlinux file being used,
185 * so use the short name, less descriptive but the same ("[kernel]" in
186 * both cases.
187 */
188 pair = map_groups__find_by_name(&kallsyms.kmaps, type,
189 (pos->dso->kernel ?
190 pos->dso->short_name :
191 pos->dso->name));
192 if (pair)
193 pair->priv = 1;
194 else
195 map__fprintf(pos, stderr);
196 }
197
198 pr_info("Maps in vmlinux with a different name in kallsyms:\n");
199
200 for (nd = rb_first(&vmlinux.kmaps.maps[type]); nd; nd = rb_next(nd)) {
201 struct map *pos = rb_entry(nd, struct map, rb_node), *pair;
202
203 pair = map_groups__find(&kallsyms.kmaps, type, pos->start);
204 if (pair == NULL || pair->priv)
205 continue;
206
207 if (pair->start == pos->start) {
208 pair->priv = 1;
209 pr_info(" %" PRIx64 "-%" PRIx64 " %" PRIx64 " %s in kallsyms as",
210 pos->start, pos->end, pos->pgoff, pos->dso->name);
211 if (pos->pgoff != pair->pgoff || pos->end != pair->end)
212 pr_info(": \n*%" PRIx64 "-%" PRIx64 " %" PRIx64 "",
213 pair->start, pair->end, pair->pgoff);
214 pr_info(" %s\n", pair->dso->name);
215 pair->priv = 1;
216 }
217 }
218
219 pr_info("Maps only in kallsyms:\n");
220
221 for (nd = rb_first(&kallsyms.kmaps.maps[type]);
222 nd; nd = rb_next(nd)) {
223 struct map *pos = rb_entry(nd, struct map, rb_node);
224
225 if (!pos->priv)
226 map__fprintf(pos, stderr);
227 }
228out:
229 return err;
230}