Skip to content

Commit b32d133

Browse files
acmelIngo Molnar
authored andcommitted
perf symbols: Simplify symbol machinery setup
And also express its configuration toggles via a struct. Now all one has to do is to call symbol__init(NULL) if the defaults are OK, or pass a struct symbol_conf pointer with the desired configuration. If a tool uses kernel_maps__find_symbol() to look at the kernel and modules mappings for a symbol but didn't call symbol__init() first, that will generate a one time warning too, alerting the subcommand developer that symbol__init() must be called. Signed-off-by: Arnaldo Carvalho de Melo <acme@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: <1259071517-3242-2-git-send-email-acme@infradead.org> Signed-off-by: Ingo Molnar <mingo@elte.hu>
1 parent 7cc017e commit b32d133

12 files changed

Lines changed: 85 additions & 60 deletions

File tree

‎tools/perf/builtin-annotate.c‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,9 @@ static int input;
3434
static int full_paths;
3535

3636
static int print_line;
37-
static bool use_modules;
3837

3938
static unsigned long page_size;
4039
static unsigned long mmap_window = 32;
41-
const char *vmlinux_name;
4240

4341
struct sym_hist {
4442
u64 sum;
@@ -56,6 +54,11 @@ struct sym_priv {
5654
struct sym_ext *ext;
5755
};
5856

57+
static struct symbol_conf symbol_conf = {
58+
.priv_size = sizeof(struct sym_priv),
59+
.try_vmlinux_path = true,
60+
};
61+
5962
static const char *sym_hist_filter;
6063

6164
static int symbol_filter(struct map *map __used, struct symbol *sym)
@@ -586,11 +589,6 @@ static int __cmd_annotate(void)
586589
exit(0);
587590
}
588591

589-
if (kernel_maps__init(vmlinux_name, true, use_modules) < 0) {
590-
pr_err("failed to create kernel maps for symbol resolution\b");
591-
return -1;
592-
}
593-
594592
remap:
595593
buf = (char *)mmap(NULL, page_size * mmap_window, PROT_READ,
596594
MAP_SHARED, input, offset);
@@ -691,8 +689,9 @@ static const struct option options[] = {
691689
"be more verbose (show symbol address, etc)"),
692690
OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
693691
"dump raw trace in ASCII"),
694-
OPT_STRING('k', "vmlinux", &vmlinux_name, "file", "vmlinux pathname"),
695-
OPT_BOOLEAN('m', "modules", &use_modules,
692+
OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name,
693+
"file", "vmlinux pathname"),
694+
OPT_BOOLEAN('m', "modules", &symbol_conf.use_modules,
696695
"load module symbols - WARNING: use only with -k and LIVE kernel"),
697696
OPT_BOOLEAN('l', "print-line", &print_line,
698697
"print matching source lines (may be slow)"),
@@ -718,7 +717,8 @@ static void setup_sorting(void)
718717

719718
int cmd_annotate(int argc, const char **argv, const char *prefix __used)
720719
{
721-
symbol__init(sizeof(struct sym_priv));
720+
if (symbol__init(&symbol_conf) < 0)
721+
return -1;
722722

723723
page_size = getpagesize();
724724

‎tools/perf/builtin-kmem.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ static int read_events(void)
412412
register_idle_thread();
413413
register_perf_file_handler(&file_handler);
414414

415-
return mmap_dispatch_perf_file(&header, input_name, NULL, false, 0, 0,
415+
return mmap_dispatch_perf_file(&header, input_name, 0, 0,
416416
&cwdlen, &cwd);
417417
}
418418

‎tools/perf/builtin-report.c‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ static char *dso_list_str, *comm_list_str, *sym_list_str,
3939
static struct strlist *dso_list, *comm_list, *sym_list;
4040

4141
static int force;
42-
static bool use_modules;
4342

4443
static int full_paths;
4544
static int show_nr_samples;
@@ -53,12 +52,13 @@ static char *pretty_printing_style = default_pretty_printing_style;
5352
static int exclude_other = 1;
5453

5554
static char callchain_default_opt[] = "fractal,0.5";
56-
const char *vmlinux_name;
5755

5856
static struct perf_header *header;
5957

6058
static u64 sample_type;
6159

60+
struct symbol_conf symbol_conf;
61+
6262

6363
static size_t
6464
callchain__fprintf_left_margin(FILE *fp, int left_margin)
@@ -865,8 +865,7 @@ static int __cmd_report(void)
865865

866866
register_perf_file_handler(&file_handler);
867867

868-
ret = mmap_dispatch_perf_file(&header, input_name, vmlinux_name,
869-
!vmlinux_name, force,
868+
ret = mmap_dispatch_perf_file(&header, input_name, force,
870869
full_paths, &cwdlen, &cwd);
871870
if (ret)
872871
return ret;
@@ -963,9 +962,10 @@ static const struct option options[] = {
963962
"be more verbose (show symbol address, etc)"),
964963
OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
965964
"dump raw trace in ASCII"),
966-
OPT_STRING('k', "vmlinux", &vmlinux_name, "file", "vmlinux pathname"),
965+
OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name,
966+
"file", "vmlinux pathname"),
967967
OPT_BOOLEAN('f', "force", &force, "don't complain, do it"),
968-
OPT_BOOLEAN('m', "modules", &use_modules,
968+
OPT_BOOLEAN('m', "modules", &symbol_conf.use_modules,
969969
"load module symbols - WARNING: use only with -k and LIVE kernel"),
970970
OPT_BOOLEAN('n', "show-nr-samples", &show_nr_samples,
971971
"Show a column with the number of samples"),
@@ -1035,7 +1035,8 @@ static void setup_list(struct strlist **list, const char *list_str,
10351035

10361036
int cmd_report(int argc, const char **argv, const char *prefix __used)
10371037
{
1038-
symbol__init(0);
1038+
if (symbol__init(&symbol_conf) < 0)
1039+
return -1;
10391040

10401041
argc = parse_options(argc, argv, options, report_usage, 0);
10411042

‎tools/perf/builtin-sched.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1718,7 +1718,7 @@ static int read_events(void)
17181718
register_idle_thread();
17191719
register_perf_file_handler(&file_handler);
17201720

1721-
return mmap_dispatch_perf_file(&header, input_name, NULL, false, 0, 0,
1721+
return mmap_dispatch_perf_file(&header, input_name, 0, 0,
17221722
&cwdlen, &cwd);
17231723
}
17241724

‎tools/perf/builtin-top.c‎

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ static int dump_symtab = 0;
7979
static bool hide_kernel_symbols = false;
8080
static bool hide_user_symbols = false;
8181
static struct winsize winsize;
82-
const char *vmlinux_name;
82+
struct symbol_conf symbol_conf;
8383

8484
/*
8585
* Source
@@ -128,7 +128,7 @@ struct sym_entry {
128128

129129
static inline struct symbol *sym_entry__symbol(struct sym_entry *self)
130130
{
131-
return ((void *)self) + symbol__priv_size;
131+
return ((void *)self) + symbol_conf.priv_size;
132132
}
133133

134134
static void get_term_dimensions(struct winsize *ws)
@@ -695,7 +695,7 @@ static void print_mapped_keys(void)
695695

696696
fprintf(stdout, "\t[f] profile display filter (count). \t(%d)\n", count_filter);
697697

698-
if (vmlinux_name) {
698+
if (symbol_conf.vmlinux_name) {
699699
fprintf(stdout, "\t[F] annotate display filter (percent). \t(%d%%)\n", sym_pcnt_filter);
700700
fprintf(stdout, "\t[s] annotate symbol. \t(%s)\n", name?: "NULL");
701701
fprintf(stdout, "\t[S] stop annotation.\n");
@@ -732,7 +732,7 @@ static int key_mapped(int c)
732732
case 'F':
733733
case 's':
734734
case 'S':
735-
return vmlinux_name ? 1 : 0;
735+
return symbol_conf.vmlinux_name ? 1 : 0;
736736
default:
737737
break;
738738
}
@@ -1261,7 +1261,8 @@ static const struct option options[] = {
12611261
"system-wide collection from all CPUs"),
12621262
OPT_INTEGER('C', "CPU", &profile_cpu,
12631263
"CPU to profile on"),
1264-
OPT_STRING('k', "vmlinux", &vmlinux_name, "file", "vmlinux pathname"),
1264+
OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name,
1265+
"file", "vmlinux pathname"),
12651266
OPT_BOOLEAN('K', "hide_kernel_symbols", &hide_kernel_symbols,
12661267
"hide kernel symbols"),
12671268
OPT_INTEGER('m', "mmap-pages", &mmap_pages,
@@ -1295,7 +1296,7 @@ static const struct option options[] = {
12951296

12961297
int cmd_top(int argc, const char **argv, const char *prefix __used)
12971298
{
1298-
int counter, err;
1299+
int counter;
12991300

13001301
page_size = sysconf(_SC_PAGE_SIZE);
13011302

@@ -1313,15 +1314,16 @@ int cmd_top(int argc, const char **argv, const char *prefix __used)
13131314
if (!nr_counters)
13141315
nr_counters = 1;
13151316

1316-
symbol__init(sizeof(struct sym_entry) +
1317-
(nr_counters + 1) * sizeof(unsigned long));
1317+
symbol_conf.priv_size = (sizeof(struct sym_entry) +
1318+
(nr_counters + 1) * sizeof(unsigned long));
1319+
if (symbol_conf.vmlinux_name == NULL)
1320+
symbol_conf.try_vmlinux_path = true;
1321+
if (symbol__init(&symbol_conf) < 0)
1322+
return -1;
13181323

13191324
if (delay_secs < 1)
13201325
delay_secs = 1;
13211326

1322-
err = kernel_maps__init(vmlinux_name, !vmlinux_name, true);
1323-
if (err < 0)
1324-
return err;
13251327
parse_source(sym_filter_entry);
13261328

13271329
/*

‎tools/perf/builtin-trace.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ static int __cmd_trace(void)
131131
register_idle_thread();
132132
register_perf_file_handler(&file_handler);
133133

134-
return mmap_dispatch_perf_file(&header, input_name, NULL, false,
134+
return mmap_dispatch_perf_file(&header, input_name,
135135
0, 0, &cwdlen, &cwd);
136136
}
137137

‎tools/perf/util/data_map.c‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,6 @@ int perf_header__read_build_ids(int input, off_t offset, off_t size)
101101

102102
int mmap_dispatch_perf_file(struct perf_header **pheader,
103103
const char *input_name,
104-
const char *vmlinux_name,
105-
bool try_vmlinux_path,
106104
int force,
107105
int full_paths,
108106
int *cwdlen,
@@ -172,12 +170,6 @@ int mmap_dispatch_perf_file(struct perf_header **pheader,
172170
curr_handler->sample_type_check(sample_type) < 0)
173171
goto out_delete;
174172

175-
err = -ENOMEM;
176-
if (kernel_maps__init(vmlinux_name, try_vmlinux_path, true) < 0) {
177-
pr_err("failed to setup the kernel maps to resolve symbols\n");
178-
goto out_delete;
179-
}
180-
181173
if (!full_paths) {
182174
if (getcwd(__cwd, sizeof(__cwd)) == NULL) {
183175
pr_err("failed to get the current directory\n");

‎tools/perf/util/data_map.h‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ struct perf_file_handler {
2323
void register_perf_file_handler(struct perf_file_handler *handler);
2424
int mmap_dispatch_perf_file(struct perf_header **pheader,
2525
const char *input_name,
26-
const char *vmlinux_name,
27-
bool try_vmlinux_path,
2826
int force,
2927
int full_paths,
3028
int *cwdlen,

‎tools/perf/util/header.c‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -253,12 +253,6 @@ static int perf_header__adds_write(struct perf_header *self, int fd)
253253

254254
buildid_sec = &feat_sec[idx++];
255255

256-
/*
257-
* Read the kernel buildid nad the list of loaded modules with
258-
* its build_ids:
259-
*/
260-
kernel_maps__init(NULL, false, true);
261-
262256
/* Write build-ids */
263257
buildid_sec->offset = lseek(fd, 0, SEEK_CUR);
264258
err = dsos__write_buildid_table(fd);

‎tools/perf/util/include/asm/bug.h‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#ifndef _PERF_ASM_GENERIC_BUG_H
2+
#define _PERF_ASM_GENERIC_BUG_H
3+
4+
#define __WARN_printf(arg...) do { fprintf(stderr, arg); } while (0)
5+
6+
#define WARN(condition, format...) ({ \
7+
int __ret_warn_on = !!(condition); \
8+
if (unlikely(__ret_warn_on)) \
9+
__WARN_printf(format); \
10+
unlikely(__ret_warn_on); \
11+
})
12+
13+
#define WARN_ONCE(condition, format...) ({ \
14+
static int __warned; \
15+
int __ret_warn_once = !!(condition); \
16+
\
17+
if (unlikely(__ret_warn_once)) \
18+
if (WARN(!__warned, format)) \
19+
__warned = 1; \
20+
unlikely(__ret_warn_once); \
21+
})
22+
#endif

0 commit comments

Comments
 (0)