Skip to content

Commit 0bdb3cc

Browse files
author
Ingo Molnar
committed
Merge tag 'perf-urgent-for-mingo' of git://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf into perf/urgent
Pull perf/urgent fixes from Jiri Olsa: * Fix kernel start address lookup in report code (Simon Que) * Fix segfault in cumulative.callchain report (Jiri Olsa) Signed-off-by: Jiri Olsa <jolsa@kernel.org> Signed-off-by: Ingo Molnar <mingo@kernel.org>
2 parents a497c3b + a93f0e5 commit 0bdb3cc

File tree

2 files changed

+38
-37
lines changed

2 files changed

+38
-37
lines changed

tools/perf/ui/browsers/hists.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "../util.h"
1818
#include "../ui.h"
1919
#include "map.h"
20+
#include "annotate.h"
2021

2122
struct hist_browser {
2223
struct ui_browser b;
@@ -1593,13 +1594,18 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,
15931594
bi->to.sym->name) > 0)
15941595
annotate_t = nr_options++;
15951596
} else {
1596-
15971597
if (browser->selection != NULL &&
15981598
browser->selection->sym != NULL &&
1599-
!browser->selection->map->dso->annotate_warned &&
1600-
asprintf(&options[nr_options], "Annotate %s",
1601-
browser->selection->sym->name) > 0)
1602-
annotate = nr_options++;
1599+
!browser->selection->map->dso->annotate_warned) {
1600+
struct annotation *notes;
1601+
1602+
notes = symbol__annotation(browser->selection->sym);
1603+
1604+
if (notes->src &&
1605+
asprintf(&options[nr_options], "Annotate %s",
1606+
browser->selection->sym->name) > 0)
1607+
annotate = nr_options++;
1608+
}
16031609
}
16041610

16051611
if (thread != NULL &&
@@ -1656,6 +1662,7 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,
16561662

16571663
if (choice == annotate || choice == annotate_t || choice == annotate_f) {
16581664
struct hist_entry *he;
1665+
struct annotation *notes;
16591666
int err;
16601667
do_annotate:
16611668
if (!objdump_path && perf_session_env__lookup_objdump(env))
@@ -1679,6 +1686,10 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,
16791686
he->ms.map = he->branch_info->to.map;
16801687
}
16811688

1689+
notes = symbol__annotation(he->ms.sym);
1690+
if (!notes->src)
1691+
continue;
1692+
16821693
/*
16831694
* Don't let this be freed, say, by hists__decay_entry.
16841695
*/

tools/perf/util/machine.c

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -496,18 +496,6 @@ struct process_args {
496496
u64 start;
497497
};
498498

499-
static int symbol__in_kernel(void *arg, const char *name,
500-
char type __maybe_unused, u64 start)
501-
{
502-
struct process_args *args = arg;
503-
504-
if (strchr(name, '['))
505-
return 0;
506-
507-
args->start = start;
508-
return 1;
509-
}
510-
511499
static void machine__get_kallsyms_filename(struct machine *machine, char *buf,
512500
size_t bufsz)
513501
{
@@ -517,27 +505,41 @@ static void machine__get_kallsyms_filename(struct machine *machine, char *buf,
517505
scnprintf(buf, bufsz, "%s/proc/kallsyms", machine->root_dir);
518506
}
519507

520-
/* Figure out the start address of kernel map from /proc/kallsyms */
521-
static u64 machine__get_kernel_start_addr(struct machine *machine)
508+
const char *ref_reloc_sym_names[] = {"_text", "_stext", NULL};
509+
510+
/* Figure out the start address of kernel map from /proc/kallsyms.
511+
* Returns the name of the start symbol in *symbol_name. Pass in NULL as
512+
* symbol_name if it's not that important.
513+
*/
514+
static u64 machine__get_kernel_start_addr(struct machine *machine,
515+
const char **symbol_name)
522516
{
523517
char filename[PATH_MAX];
524-
struct process_args args;
518+
int i;
519+
const char *name;
520+
u64 addr = 0;
525521

526522
machine__get_kallsyms_filename(machine, filename, PATH_MAX);
527523

528524
if (symbol__restricted_filename(filename, "/proc/kallsyms"))
529525
return 0;
530526

531-
if (kallsyms__parse(filename, &args, symbol__in_kernel) <= 0)
532-
return 0;
527+
for (i = 0; (name = ref_reloc_sym_names[i]) != NULL; i++) {
528+
addr = kallsyms__get_function_start(filename, name);
529+
if (addr)
530+
break;
531+
}
532+
533+
if (symbol_name)
534+
*symbol_name = name;
533535

534-
return args.start;
536+
return addr;
535537
}
536538

537539
int __machine__create_kernel_maps(struct machine *machine, struct dso *kernel)
538540
{
539541
enum map_type type;
540-
u64 start = machine__get_kernel_start_addr(machine);
542+
u64 start = machine__get_kernel_start_addr(machine, NULL);
541543

542544
for (type = 0; type < MAP__NR_TYPES; ++type) {
543545
struct kmap *kmap;
@@ -852,23 +854,11 @@ static int machine__create_modules(struct machine *machine)
852854
return 0;
853855
}
854856

855-
const char *ref_reloc_sym_names[] = {"_text", "_stext", NULL};
856-
857857
int machine__create_kernel_maps(struct machine *machine)
858858
{
859859
struct dso *kernel = machine__get_kernel(machine);
860-
char filename[PATH_MAX];
861860
const char *name;
862-
u64 addr = 0;
863-
int i;
864-
865-
machine__get_kallsyms_filename(machine, filename, PATH_MAX);
866-
867-
for (i = 0; (name = ref_reloc_sym_names[i]) != NULL; i++) {
868-
addr = kallsyms__get_function_start(filename, name);
869-
if (addr)
870-
break;
871-
}
861+
u64 addr = machine__get_kernel_start_addr(machine, &name);
872862
if (!addr)
873863
return -1;
874864

0 commit comments

Comments
 (0)