Skip to content

Commit 2446042

Browse files
acmelIngo Molnar
authored andcommitted
perf symbols: Capture the running kernel buildid too
[root@doppio linux-2.6-tip]# perf record -a -f sleep 3s ; perf buildid-list | grep vmlinux [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.171 MB perf.data (~7489 samples) ] 18e7cc53db62a7d35e9d6f6c9ddc23017d38ee9a vmlinux [root@doppio linux-2.6-tip]# Several refactorings were needed so that we can have symmetry between dsos__load_modules() and dsos__load_kernel(), i.e. those functions will respectively create and add to the dsos list the loaded modules and kernel, with its buildids, but not load its symbols. That is something the subcomands that need will have to call dso__load_kernel_sym(), just like we do with modules with dsos__load_module_sym()/dso__load_module_sym(). Next csets will actually use this info to stop producing bogus results using mismatched vmlinux and .ko files. Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Roland McGrath <roland@redhat.com> Cc: Frédéric Weisbecker <fweisbec@gmail.com> Cc: Mike Galbraith <efault@gmx.de> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Paul Mackerras <paulus@samba.org> LKML-Reference: <1258582853-8579-4-git-send-email-acme@infradead.org> Signed-off-by: Ingo Molnar <mingo@elte.hu>
1 parent f1617b4 commit 2446042

4 files changed

Lines changed: 46 additions & 30 deletions

File tree

‎tools/perf/builtin-top.c‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,12 @@ static int symbol_filter(struct map *map, struct symbol *sym)
948948

949949
static int parse_symbols(void)
950950
{
951-
if (dsos__load_kernel(vmlinux_name, symbol_filter, 1) <= 0)
951+
struct dso *kernel = dsos__load_kernel();
952+
953+
if (kernel == NULL)
954+
return -1;
955+
956+
if (dso__load_kernel_sym(kernel, symbol_filter, 1) <= 0)
952957
return -1;
953958

954959
if (dump_symtab)

‎tools/perf/util/header.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ perf_header__adds_write(struct perf_header *self, int fd)
241241

242242
buildid_sec = &feat_sec[idx++];
243243

244+
dsos__load_kernel();
244245
/*
245246
* Read the list of loaded modules with its build_ids
246247
*/

‎tools/perf/util/symbol.c‎

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,17 +1352,11 @@ static int dso__load_vmlinux(struct dso *self, struct map *map,
13521352
return err;
13531353
}
13541354

1355-
int dsos__load_kernel(const char *vmlinux, symbol_filter_t filter,
1356-
int use_modules)
1355+
int dso__load_kernel_sym(struct dso *self, symbol_filter_t filter, int use_modules)
13571356
{
13581357
int err = -1;
1359-
struct dso *dso = dso__new(vmlinux);
13601358

1361-
if (dso == NULL)
1362-
return -1;
1363-
1364-
dso->short_name = "[kernel]";
1365-
kernel_map = map__new2(0, dso);
1359+
kernel_map = map__new2(0, self);
13661360
if (kernel_map == NULL)
13671361
goto out_delete_dso;
13681362

@@ -1374,39 +1368,36 @@ int dsos__load_kernel(const char *vmlinux, symbol_filter_t filter,
13741368
use_modules = 0;
13751369
}
13761370

1377-
if (vmlinux) {
1378-
err = dso__load_vmlinux(dso, kernel_map, vmlinux, filter);
1379-
if (err > 0 && use_modules) {
1380-
int syms = dsos__load_modules_sym(filter);
1371+
err = dso__load_vmlinux(self, kernel_map, self->name, filter);
1372+
if (err > 0 && use_modules) {
1373+
int syms = dsos__load_modules_sym(filter);
13811374

1382-
if (syms < 0)
1383-
pr_warning("Failed to read module symbols!"
1384-
" Continuing...\n");
1385-
else
1386-
err += syms;
1387-
}
1375+
if (syms < 0)
1376+
pr_warning("Failed to read module symbols!"
1377+
" Continuing...\n");
1378+
else
1379+
err += syms;
13881380
}
13891381

13901382
if (err <= 0)
13911383
err = kernel_maps__load_kallsyms(filter, use_modules);
13921384

13931385
if (err > 0) {
1394-
struct rb_node *node = rb_first(&dso->syms);
1386+
struct rb_node *node = rb_first(&self->syms);
13951387
struct symbol *sym = rb_entry(node, struct symbol, rb_node);
13961388

13971389
kernel_map->start = sym->start;
1398-
node = rb_last(&dso->syms);
1390+
node = rb_last(&self->syms);
13991391
sym = rb_entry(node, struct symbol, rb_node);
14001392
kernel_map->end = sym->end;
14011393

1402-
dso->origin = DSO__ORIG_KERNEL;
1394+
self->origin = DSO__ORIG_KERNEL;
14031395
kernel_maps__insert(kernel_map);
14041396
/*
14051397
* Now that we have all sorted out, just set the ->end of all
14061398
* maps:
14071399
*/
14081400
kernel_maps__fixup_end();
1409-
dsos__add(dso);
14101401

14111402
if (verbose)
14121403
kernel_maps__fprintf(stderr);
@@ -1415,7 +1406,7 @@ int dsos__load_kernel(const char *vmlinux, symbol_filter_t filter,
14151406
return err;
14161407

14171408
out_delete_dso:
1418-
dso__delete(dso);
1409+
dso__delete(self);
14191410
return -1;
14201411
}
14211412

@@ -1475,18 +1466,36 @@ size_t dsos__fprintf_buildid(FILE *fp)
14751466
return ret;
14761467
}
14771468

1478-
int load_kernel(symbol_filter_t filter)
1469+
struct dso *dsos__load_kernel(void)
14791470
{
1480-
if (dsos__load_kernel(vmlinux_name, filter, modules) <= 0)
1481-
return -1;
1471+
struct dso *kernel = dso__new(vmlinux_name);
14821472

1473+
if (kernel == NULL)
1474+
return NULL;
1475+
1476+
kernel->short_name = "[kernel]";
14831477
vdso = dso__new("[vdso]");
14841478
if (!vdso)
1485-
return -1;
1479+
return NULL;
1480+
1481+
if (sysfs__read_build_id("/sys/kernel/notes", kernel->build_id,
1482+
sizeof(kernel->build_id)) == 0)
1483+
kernel->has_build_id = true;
14861484

1485+
dsos__add(kernel);
14871486
dsos__add(vdso);
14881487

1489-
return 0;
1488+
return kernel;
1489+
}
1490+
1491+
int load_kernel(symbol_filter_t filter)
1492+
{
1493+
struct dso *kernel = dsos__load_kernel();
1494+
1495+
if (kernel == NULL)
1496+
return -1;
1497+
1498+
return dso__load_kernel_sym(kernel, filter, modules);
14901499
}
14911500

14921501
void symbol__init(unsigned int priv_size)

‎tools/perf/util/symbol.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ void dso__delete(struct dso *self);
7777

7878
struct symbol *dso__find_symbol(struct dso *self, u64 ip);
7979

80-
int dsos__load_kernel(const char *vmlinux, symbol_filter_t filter, int modules);
8180
int dsos__load_modules(void);
8281
struct dso *dsos__findnew(const char *name);
8382
int dso__load(struct dso *self, struct map *map, symbol_filter_t filter);
83+
int dso__load_kernel_sym(struct dso *self, symbol_filter_t filter, int modules);
8484
void dsos__fprintf(FILE *fp);
8585
size_t dsos__fprintf_buildid(FILE *fp);
8686

@@ -94,6 +94,7 @@ int sysfs__read_build_id(const char *filename, void *bf, size_t size);
9494
bool dsos__read_build_ids(void);
9595
int build_id__sprintf(u8 *self, int len, char *bf);
9696

97+
struct dso *dsos__load_kernel(void);
9798
int load_kernel(symbol_filter_t filter);
9899

99100
void symbol__init(unsigned int priv_size);

0 commit comments

Comments
 (0)