Skip to content

Commit 2996123

Browse files
author
Ingo Molnar
committed
Merge tag 'perf-core-for-mingo-4.18-20180519' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/core
Pull perf/core improvements and fixes from Arnaldo Carvalho de Melo: - Record min/max LBR cycles (>= Skylake) and add 'perf annotate' TUI hotkey to show it (c) (Jin Yao) - Fix machine->kernel_start for PTI on x86 (Adrian Hunter) - Make machine->env->arch always available, e.g. in 'perf top', not just when reading that info from perf.data files (Adrian Hunter) - Reduce the number of files read at 'perf' start, leaving information such as cacheline size, tracefs mount point determination, max_stack, etc, to be lazily read as tools needs then (Arnaldo Carvalho de Melo) - Fix up BPF include and examples install messages (Arnaldo Carvalho de Melo) - Fix up callchain addresses and symbol offsets in 'perf script', to help correlating with objdump output (Sandipan Das) Signed-off-by: Arnaldo Carvalho de Melo <[email protected]> Signed-off-by: Ingo Molnar <[email protected]>
2 parents 5aafae8 + 19422a9 commit 2996123

28 files changed

+279
-120
lines changed

tools/include/linux/compiler-gcc.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
/* &a[0] degrades to a pointer: a different type from an array */
2222
#define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0]))
2323

24+
#ifndef __pure
25+
#define __pure __attribute__((pure))
26+
#endif
2427
#define noinline __attribute__((noinline))
2528
#ifndef __packed
2629
#define __packed __attribute__((packed))

tools/lib/api/fs/tracing_path.c

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@
1313

1414
#include "tracing_path.h"
1515

16-
17-
char tracing_mnt[PATH_MAX] = "/sys/kernel/debug";
18-
char tracing_path[PATH_MAX] = "/sys/kernel/debug/tracing";
19-
char tracing_events_path[PATH_MAX] = "/sys/kernel/debug/tracing/events";
20-
16+
static char tracing_mnt[PATH_MAX] = "/sys/kernel/debug";
17+
static char tracing_path[PATH_MAX] = "/sys/kernel/debug/tracing";
18+
static char tracing_events_path[PATH_MAX] = "/sys/kernel/debug/tracing/events";
2119

2220
static void __tracing_path_set(const char *tracing, const char *mountpoint)
2321
{
@@ -76,7 +74,7 @@ char *get_tracing_file(const char *name)
7674
{
7775
char *file;
7876

79-
if (asprintf(&file, "%s/%s", tracing_path, name) < 0)
77+
if (asprintf(&file, "%s/%s", tracing_path_mount(), name) < 0)
8078
return NULL;
8179

8280
return file;
@@ -87,6 +85,34 @@ void put_tracing_file(char *file)
8785
free(file);
8886
}
8987

88+
char *get_events_file(const char *name)
89+
{
90+
char *file;
91+
92+
if (asprintf(&file, "%s/events/%s", tracing_path_mount(), name) < 0)
93+
return NULL;
94+
95+
return file;
96+
}
97+
98+
void put_events_file(char *file)
99+
{
100+
free(file);
101+
}
102+
103+
DIR *tracing_events__opendir(void)
104+
{
105+
DIR *dir = NULL;
106+
char *path = get_tracing_file("events");
107+
108+
if (path) {
109+
dir = opendir(path);
110+
put_events_file(path);
111+
}
112+
113+
return dir;
114+
}
115+
90116
int tracing_path__strerror_open_tp(int err, char *buf, size_t size,
91117
const char *sys, const char *name)
92118
{
@@ -129,7 +155,7 @@ int tracing_path__strerror_open_tp(int err, char *buf, size_t size,
129155
snprintf(buf, size,
130156
"Error:\tNo permissions to read %s/%s\n"
131157
"Hint:\tTry 'sudo mount -o remount,mode=755 %s'\n",
132-
tracing_events_path, filename, tracing_mnt);
158+
tracing_events_path, filename, tracing_path_mount());
133159
}
134160
break;
135161
default:

tools/lib/api/fs/tracing_path.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,20 @@
33
#define __API_FS_TRACING_PATH_H
44

55
#include <linux/types.h>
6+
#include <dirent.h>
67

7-
extern char tracing_path[];
8-
extern char tracing_events_path[];
8+
DIR *tracing_events__opendir(void);
99

1010
void tracing_path_set(const char *mountpoint);
1111
const char *tracing_path_mount(void);
1212

1313
char *get_tracing_file(const char *name);
1414
void put_tracing_file(char *file);
1515

16+
char *get_events_file(const char *name);
17+
void put_events_file(char *file);
18+
19+
#define zput_events_file(ptr) ({ free(*ptr); *ptr = NULL; })
20+
1621
int tracing_path__strerror_open_tp(int err, char *buf, size_t size, const char *sys, const char *name);
1722
#endif /* __API_FS_TRACING_PATH_H */

tools/perf/Makefile.perf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,9 +770,11 @@ endif
770770
ifndef NO_LIBBPF
771771
$(call QUIET_INSTALL, lib) \
772772
$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perf_include_instdir_SQ)/bpf'
773+
$(call QUIET_INSTALL, include/bpf) \
773774
$(INSTALL) include/bpf/*.h '$(DESTDIR_SQ)$(perf_include_instdir_SQ)/bpf'
774775
$(call QUIET_INSTALL, lib) \
775776
$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perf_examples_instdir_SQ)/bpf'
777+
$(call QUIET_INSTALL, examples/bpf) \
776778
$(INSTALL) examples/bpf/*.c '$(DESTDIR_SQ)$(perf_examples_instdir_SQ)/bpf'
777779
endif
778780
$(call QUIET_INSTALL, perf-archive) \

tools/perf/builtin-script.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ static struct {
153153
.fields = PERF_OUTPUT_COMM | PERF_OUTPUT_TID |
154154
PERF_OUTPUT_CPU | PERF_OUTPUT_TIME |
155155
PERF_OUTPUT_EVNAME | PERF_OUTPUT_IP |
156-
PERF_OUTPUT_SYM | PERF_OUTPUT_DSO |
157-
PERF_OUTPUT_PERIOD,
156+
PERF_OUTPUT_SYM | PERF_OUTPUT_SYMOFFSET |
157+
PERF_OUTPUT_DSO | PERF_OUTPUT_PERIOD,
158158

159159
.invalid_fields = PERF_OUTPUT_TRACE | PERF_OUTPUT_BPF_OUTPUT,
160160
},
@@ -165,8 +165,9 @@ static struct {
165165
.fields = PERF_OUTPUT_COMM | PERF_OUTPUT_TID |
166166
PERF_OUTPUT_CPU | PERF_OUTPUT_TIME |
167167
PERF_OUTPUT_EVNAME | PERF_OUTPUT_IP |
168-
PERF_OUTPUT_SYM | PERF_OUTPUT_DSO |
169-
PERF_OUTPUT_PERIOD | PERF_OUTPUT_BPF_OUTPUT,
168+
PERF_OUTPUT_SYM | PERF_OUTPUT_SYMOFFSET |
169+
PERF_OUTPUT_DSO | PERF_OUTPUT_PERIOD |
170+
PERF_OUTPUT_BPF_OUTPUT,
170171

171172
.invalid_fields = PERF_OUTPUT_TRACE,
172173
},
@@ -185,10 +186,10 @@ static struct {
185186
.fields = PERF_OUTPUT_COMM | PERF_OUTPUT_TID |
186187
PERF_OUTPUT_CPU | PERF_OUTPUT_TIME |
187188
PERF_OUTPUT_EVNAME | PERF_OUTPUT_IP |
188-
PERF_OUTPUT_SYM | PERF_OUTPUT_DSO |
189-
PERF_OUTPUT_PERIOD | PERF_OUTPUT_ADDR |
190-
PERF_OUTPUT_DATA_SRC | PERF_OUTPUT_WEIGHT |
191-
PERF_OUTPUT_PHYS_ADDR,
189+
PERF_OUTPUT_SYM | PERF_OUTPUT_SYMOFFSET |
190+
PERF_OUTPUT_DSO | PERF_OUTPUT_PERIOD |
191+
PERF_OUTPUT_ADDR | PERF_OUTPUT_DATA_SRC |
192+
PERF_OUTPUT_WEIGHT | PERF_OUTPUT_PHYS_ADDR,
192193

193194
.invalid_fields = PERF_OUTPUT_TRACE | PERF_OUTPUT_BPF_OUTPUT,
194195
},
@@ -199,8 +200,8 @@ static struct {
199200
.fields = PERF_OUTPUT_COMM | PERF_OUTPUT_TID |
200201
PERF_OUTPUT_CPU | PERF_OUTPUT_TIME |
201202
PERF_OUTPUT_EVNAME | PERF_OUTPUT_IP |
202-
PERF_OUTPUT_SYM | PERF_OUTPUT_DSO |
203-
PERF_OUTPUT_PERIOD,
203+
PERF_OUTPUT_SYM | PERF_OUTPUT_SYMOFFSET |
204+
PERF_OUTPUT_DSO | PERF_OUTPUT_PERIOD,
204205

205206
.invalid_fields = PERF_OUTPUT_TRACE | PERF_OUTPUT_BPF_OUTPUT,
206207
},
@@ -211,8 +212,8 @@ static struct {
211212
.fields = PERF_OUTPUT_COMM | PERF_OUTPUT_TID |
212213
PERF_OUTPUT_CPU | PERF_OUTPUT_TIME |
213214
PERF_OUTPUT_EVNAME | PERF_OUTPUT_IP |
214-
PERF_OUTPUT_SYM | PERF_OUTPUT_DSO |
215-
PERF_OUTPUT_SYNTH,
215+
PERF_OUTPUT_SYM | PERF_OUTPUT_SYMOFFSET |
216+
PERF_OUTPUT_DSO | PERF_OUTPUT_SYNTH,
216217

217218
.invalid_fields = PERF_OUTPUT_TRACE | PERF_OUTPUT_BPF_OUTPUT,
218219
},
@@ -544,6 +545,7 @@ static int perf_session__check_output_opt(struct perf_session *session)
544545
if (attr->sample_type & PERF_SAMPLE_CALLCHAIN) {
545546
output[j].fields |= PERF_OUTPUT_IP;
546547
output[j].fields |= PERF_OUTPUT_SYM;
548+
output[j].fields |= PERF_OUTPUT_SYMOFFSET;
547549
output[j].fields |= PERF_OUTPUT_DSO;
548550
set_print_ip_opts(attr);
549551
goto out;

tools/perf/builtin-top.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1264,7 +1264,7 @@ int cmd_top(int argc, const char **argv)
12641264
.proc_map_timeout = 500,
12651265
.overwrite = 1,
12661266
},
1267-
.max_stack = sysctl_perf_event_max_stack,
1267+
.max_stack = sysctl__max_stack(),
12681268
.sym_pcnt_filter = 5,
12691269
.nr_threads_synthesize = UINT_MAX,
12701270
};

tools/perf/builtin-trace.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3162,7 +3162,7 @@ int cmd_trace(int argc, const char **argv)
31623162
mmap_pages_user_set = false;
31633163

31643164
if (trace.max_stack == UINT_MAX) {
3165-
trace.max_stack = input_name ? PERF_MAX_STACK_DEPTH : sysctl_perf_event_max_stack;
3165+
trace.max_stack = input_name ? PERF_MAX_STACK_DEPTH : sysctl__max_stack();
31663166
max_stack_user_set = false;
31673167
}
31683168

tools/perf/perf.c

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
238238
(*argc)--;
239239
} else if (strstarts(cmd, CMD_DEBUGFS_DIR)) {
240240
tracing_path_set(cmd + strlen(CMD_DEBUGFS_DIR));
241-
fprintf(stderr, "dir: %s\n", tracing_path);
241+
fprintf(stderr, "dir: %s\n", tracing_path_mount());
242242
if (envchanged)
243243
*envchanged = 1;
244244
} else if (!strcmp(cmd, "--list-cmds")) {
@@ -421,52 +421,30 @@ void pthread__unblock_sigwinch(void)
421421
pthread_sigmask(SIG_UNBLOCK, &set, NULL);
422422
}
423423

424-
#ifdef _SC_LEVEL1_DCACHE_LINESIZE
425-
#define cache_line_size(cacheline_sizep) *cacheline_sizep = sysconf(_SC_LEVEL1_DCACHE_LINESIZE)
426-
#else
427-
static void cache_line_size(int *cacheline_sizep)
428-
{
429-
if (sysfs__read_int("devices/system/cpu/cpu0/cache/index0/coherency_line_size", cacheline_sizep))
430-
pr_debug("cannot determine cache line size");
431-
}
432-
#endif
433-
434424
int main(int argc, const char **argv)
435425
{
436426
int err;
437427
const char *cmd;
438428
char sbuf[STRERR_BUFSIZE];
439-
int value;
440429

441430
/* libsubcmd init */
442431
exec_cmd_init("perf", PREFIX, PERF_EXEC_PATH, EXEC_PATH_ENVIRONMENT);
443432
pager_init(PERF_PAGER_ENVIRONMENT);
444433

445434
/* The page_size is placed in util object. */
446435
page_size = sysconf(_SC_PAGE_SIZE);
447-
cache_line_size(&cacheline_size);
448-
449-
if (sysctl__read_int("kernel/perf_event_max_stack", &value) == 0)
450-
sysctl_perf_event_max_stack = value;
451-
452-
if (sysctl__read_int("kernel/perf_event_max_contexts_per_stack", &value) == 0)
453-
sysctl_perf_event_max_contexts_per_stack = value;
454436

455437
cmd = extract_argv0_path(argv[0]);
456438
if (!cmd)
457439
cmd = "perf-help";
458440

459441
srandom(time(NULL));
460442

461-
perf_config__init();
462443
err = perf_config(perf_default_config, NULL);
463444
if (err)
464445
return err;
465446
set_buildid_dir(NULL);
466447

467-
/* get debugfs/tracefs mount point from /proc/mounts */
468-
tracing_path_mount();
469-
470448
/*
471449
* "perf-xxxx" is the same as "perf xxxx", but we obviously:
472450
*

tools/perf/tests/parse-events.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,12 +1323,12 @@ static int count_tracepoints(void)
13231323
DIR *events_dir;
13241324
int cnt = 0;
13251325

1326-
events_dir = opendir(tracing_events_path);
1326+
events_dir = tracing_events__opendir();
13271327

13281328
TEST_ASSERT_VAL("Can't open events dir", events_dir);
13291329

13301330
while ((events_ent = readdir(events_dir))) {
1331-
char sys_path[PATH_MAX];
1331+
char *sys_path;
13321332
struct dirent *sys_ent;
13331333
DIR *sys_dir;
13341334

@@ -1339,8 +1339,8 @@ static int count_tracepoints(void)
13391339
|| !strcmp(events_ent->d_name, "header_page"))
13401340
continue;
13411341

1342-
scnprintf(sys_path, PATH_MAX, "%s/%s",
1343-
tracing_events_path, events_ent->d_name);
1342+
sys_path = get_events_file(events_ent->d_name);
1343+
TEST_ASSERT_VAL("Can't get sys path", sys_path);
13441344

13451345
sys_dir = opendir(sys_path);
13461346
TEST_ASSERT_VAL("Can't open sys dir", sys_dir);
@@ -1356,6 +1356,7 @@ static int count_tracepoints(void)
13561356
}
13571357

13581358
closedir(sys_dir);
1359+
put_events_file(sys_path);
13591360
}
13601361

13611362
closedir(events_dir);

tools/perf/tests/shell/record+probe_libc_inet_pton.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@ nm -g $libc 2>/dev/null | fgrep -q inet_pton || exit 254
1616
trace_libc_inet_pton_backtrace() {
1717
idx=0
1818
expected[0]="ping[][0-9 \.:]+probe_libc:inet_pton: \([[:xdigit:]]+\)"
19-
expected[1]=".*inet_pton[[:space:]]\($libc|inlined\)$"
19+
expected[1]=".*inet_pton\+0x[[:xdigit:]]+[[:space:]]\($libc|inlined\)$"
2020
case "$(uname -m)" in
2121
s390x)
2222
eventattr='call-graph=dwarf,max-stack=4'
23-
expected[2]="gaih_inet.*[[:space:]]\($libc|inlined\)$"
24-
expected[3]="(__GI_)?getaddrinfo[[:space:]]\($libc|inlined\)$"
25-
expected[4]="main[[:space:]]\(.*/bin/ping.*\)$"
23+
expected[2]="gaih_inet.*\+0x[[:xdigit:]]+[[:space:]]\($libc|inlined\)$"
24+
expected[3]="(__GI_)?getaddrinfo\+0x[[:xdigit:]]+[[:space:]]\($libc|inlined\)$"
25+
expected[4]="main\+0x[[:xdigit:]]+[[:space:]]\(.*/bin/ping.*\)$"
2626
;;
2727
*)
2828
eventattr='max-stack=3'
29-
expected[2]="getaddrinfo[[:space:]]\($libc\)$"
30-
expected[3]=".*\(.*/bin/ping.*\)$"
29+
expected[2]="getaddrinfo\+0x[[:xdigit:]]+[[:space:]]\($libc\)$"
30+
expected[3]=".*\+0x[[:xdigit:]]+[[:space:]]\(.*/bin/ping.*\)$"
3131
;;
3232
esac
3333

tools/perf/ui/browsers/annotate.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,7 @@ static int annotate_browser__run(struct annotate_browser *browser,
695695
"O Bump offset level (jump targets -> +call -> all -> cycle thru)\n"
696696
"s Toggle source code view\n"
697697
"t Circulate percent, total period, samples view\n"
698+
"c Show min/max cycle\n"
698699
"/ Search string\n"
699700
"k Toggle line numbers\n"
700701
"P Print to [symbol_name].annotation file.\n"
@@ -791,6 +792,13 @@ static int annotate_browser__run(struct annotate_browser *browser,
791792
notes->options->show_total_period = true;
792793
annotation__update_column_widths(notes);
793794
continue;
795+
case 'c':
796+
if (notes->options->show_minmax_cycle)
797+
notes->options->show_minmax_cycle = false;
798+
else
799+
notes->options->show_minmax_cycle = true;
800+
annotation__update_column_widths(notes);
801+
continue;
794802
case K_LEFT:
795803
case K_ESC:
796804
case 'q':

0 commit comments

Comments
 (0)