aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util
diff options
context:
space:
mode:
authorIngo Molnar <mingo@kernel.org>2019-08-27 04:22:25 -0400
committerIngo Molnar <mingo@kernel.org>2019-08-27 04:22:25 -0400
commit794b8bedca9341569e1081bc880e7ea209dbca5c (patch)
treeaccdfe136daf45dea3ee62567a53ae2bfb0f7fd8 /tools/perf/util
parent39152ee51b77851689f9b23fde6f610d13566c39 (diff)
parent74a1e863eb73dcc9f069b671dfb40650f3832116 (diff)
Merge tag 'perf-core-for-mingo-5.4-20190826' 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: perf report: Andi Kleen: - Make --ns time sort key output column wide enough for nanoseconds. perf script: Gustavo A. R. Silva: - Fix memory leaks in list_scripts() perf tests: James Clark: - Fixes hang in zstd compression test by changing the source of random data. perf trace: Arnaldo Carvalho de Melo: - augmented_raw_syscalls.c BPF helper improvements. Benjamin Peterson: - Fix off-by-one error in ioctl cmd->string table. libperf: Jiri Olsa: - Move most PERF_RECORD_ structs to perf/event.h. headers: Arnaldo Carvalho de Melo: - Move cacheline related routines to separate source files. - Move record_opts and other record declarations to separate files. - Explicitly add some more needed headers here and there. Souptick Joarder: - Remove some duplicate include directives. Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'tools/perf/util')
-rw-r--r--tools/perf/util/Build1
-rw-r--r--tools/perf/util/annotate.c2
-rw-r--r--tools/perf/util/auxtrace.c2
-rw-r--r--tools/perf/util/bpf-event.c36
-rw-r--r--tools/perf/util/bpf-event.h10
-rw-r--r--tools/perf/util/cacheline.c26
-rw-r--r--tools/perf/util/cacheline.h21
-rw-r--r--tools/perf/util/callchain.c1
-rw-r--r--tools/perf/util/cpumap.h2
-rw-r--r--tools/perf/util/data.c1
-rw-r--r--tools/perf/util/event.c35
-rw-r--r--tools/perf/util/event.h149
-rw-r--r--tools/perf/util/evlist.c2
-rw-r--r--tools/perf/util/evsel.c22
-rw-r--r--tools/perf/util/evsel.h4
-rw-r--r--tools/perf/util/get_current_dir_name.c1
-rw-r--r--tools/perf/util/hist.c5
-rw-r--r--tools/perf/util/intel-bts.c2
-rw-r--r--tools/perf/util/kvm-stat.h2
-rw-r--r--tools/perf/util/machine.c25
-rw-r--r--tools/perf/util/machine.h1
-rw-r--r--tools/perf/util/namespaces.c2
-rw-r--r--tools/perf/util/namespaces.h4
-rw-r--r--tools/perf/util/python.c58
-rw-r--r--tools/perf/util/record.c1
-rw-r--r--tools/perf/util/record.h74
-rw-r--r--tools/perf/util/session.c16
-rw-r--r--tools/perf/util/sort.c12
-rw-r--r--tools/perf/util/sort.h27
-rw-r--r--tools/perf/util/stat-display.c1
-rw-r--r--tools/perf/util/stat.c1
-rw-r--r--tools/perf/util/stat.h7
-rw-r--r--tools/perf/util/thread.c4
-rw-r--r--tools/perf/util/thread.h4
-rw-r--r--tools/perf/util/tool.h2
-rw-r--r--tools/perf/util/top.h1
-rw-r--r--tools/perf/util/util.c20
-rw-r--r--tools/perf/util/util.h1
38 files changed, 289 insertions, 296 deletions
diff --git a/tools/perf/util/Build b/tools/perf/util/Build
index b922c8c297ca..2e3856471e61 100644
--- a/tools/perf/util/Build
+++ b/tools/perf/util/Build
@@ -1,6 +1,7 @@
1perf-y += annotate.o 1perf-y += annotate.o
2perf-y += block-range.o 2perf-y += block-range.o
3perf-y += build-id.o 3perf-y += build-id.o
4perf-y += cacheline.o
4perf-y += config.o 5perf-y += config.o
5perf-y += ctype.o 6perf-y += ctype.o
6perf-y += db-export.o 7perf-y += db-export.o
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index e0518dc4c4d2..3bd1691f0be7 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -22,6 +22,7 @@
22#include "cache.h" 22#include "cache.h"
23#include "map.h" 23#include "map.h"
24#include "symbol.h" 24#include "symbol.h"
25#include "srcline.h"
25#include "units.h" 26#include "units.h"
26#include "debug.h" 27#include "debug.h"
27#include "annotate.h" 28#include "annotate.h"
@@ -37,6 +38,7 @@
37#include <linux/kernel.h> 38#include <linux/kernel.h>
38#include <linux/string.h> 39#include <linux/string.h>
39#include <bpf/libbpf.h> 40#include <bpf/libbpf.h>
41#include <subcmd/parse-options.h>
40 42
41/* FIXME: For the HE_COLORSET */ 43/* FIXME: For the HE_COLORSET */
42#include "ui/browser.h" 44#include "ui/browser.h"
diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c
index 094e6ceb3cf2..12e9b7acbb2c 100644
--- a/tools/perf/util/auxtrace.c
+++ b/tools/perf/util/auxtrace.c
@@ -26,7 +26,6 @@
26#include <linux/list.h> 26#include <linux/list.h>
27#include <linux/zalloc.h> 27#include <linux/zalloc.h>
28 28
29#include "../perf.h"
30#include "evlist.h" 29#include "evlist.h"
31#include "dso.h" 30#include "dso.h"
32#include "map.h" 31#include "map.h"
@@ -41,6 +40,7 @@
41#include <linux/hash.h> 40#include <linux/hash.h>
42 41
43#include "event.h" 42#include "event.h"
43#include "record.h"
44#include "session.h" 44#include "session.h"
45#include "debug.h" 45#include "debug.h"
46#include <subcmd/parse-options.h> 46#include <subcmd/parse-options.h>
diff --git a/tools/perf/util/bpf-event.c b/tools/perf/util/bpf-event.c
index 5a5dcc6d8f85..2d6d500c9af7 100644
--- a/tools/perf/util/bpf-event.c
+++ b/tools/perf/util/bpf-event.c
@@ -14,6 +14,7 @@
14#include "session.h" 14#include "session.h"
15#include "map.h" 15#include "map.h"
16#include "evlist.h" 16#include "evlist.h"
17#include "record.h"
17 18
18#define ptr_to_u64(ptr) ((__u64)(unsigned long)(ptr)) 19#define ptr_to_u64(ptr) ((__u64)(unsigned long)(ptr))
19 20
@@ -34,7 +35,7 @@ static int machine__process_bpf_event_load(struct machine *machine,
34 struct bpf_prog_info_linear *info_linear; 35 struct bpf_prog_info_linear *info_linear;
35 struct bpf_prog_info_node *info_node; 36 struct bpf_prog_info_node *info_node;
36 struct perf_env *env = machine->env; 37 struct perf_env *env = machine->env;
37 int id = event->bpf_event.id; 38 int id = event->bpf.id;
38 unsigned int i; 39 unsigned int i;
39 40
40 /* perf-record, no need to handle bpf-event */ 41 /* perf-record, no need to handle bpf-event */
@@ -63,14 +64,13 @@ static int machine__process_bpf_event_load(struct machine *machine,
63 return 0; 64 return 0;
64} 65}
65 66
66int machine__process_bpf_event(struct machine *machine __maybe_unused, 67int machine__process_bpf(struct machine *machine, union perf_event *event,
67 union perf_event *event, 68 struct perf_sample *sample)
68 struct perf_sample *sample __maybe_unused)
69{ 69{
70 if (dump_trace) 70 if (dump_trace)
71 perf_event__fprintf_bpf_event(event, stdout); 71 perf_event__fprintf_bpf(event, stdout);
72 72
73 switch (event->bpf_event.type) { 73 switch (event->bpf.type) {
74 case PERF_BPF_EVENT_PROG_LOAD: 74 case PERF_BPF_EVENT_PROG_LOAD:
75 return machine__process_bpf_event_load(machine, event, sample); 75 return machine__process_bpf_event_load(machine, event, sample);
76 76
@@ -82,8 +82,7 @@ int machine__process_bpf_event(struct machine *machine __maybe_unused,
82 */ 82 */
83 break; 83 break;
84 default: 84 default:
85 pr_debug("unexpected bpf_event type of %d\n", 85 pr_debug("unexpected bpf event type of %d\n", event->bpf.type);
86 event->bpf_event.type);
87 break; 86 break;
88 } 87 }
89 return 0; 88 return 0;
@@ -160,8 +159,8 @@ static int perf_event__synthesize_one_bpf_prog(struct perf_session *session,
160 union perf_event *event, 159 union perf_event *event,
161 struct record_opts *opts) 160 struct record_opts *opts)
162{ 161{
163 struct ksymbol_event *ksymbol_event = &event->ksymbol_event; 162 struct perf_record_ksymbol *ksymbol_event = &event->ksymbol;
164 struct bpf_event *bpf_event = &event->bpf_event; 163 struct perf_record_bpf_event *bpf_event = &event->bpf;
165 struct bpf_prog_info_linear *info_linear; 164 struct bpf_prog_info_linear *info_linear;
166 struct perf_tool *tool = session->tool; 165 struct perf_tool *tool = session->tool;
167 struct bpf_prog_info_node *info_node; 166 struct bpf_prog_info_node *info_node;
@@ -229,10 +228,10 @@ static int perf_event__synthesize_one_bpf_prog(struct perf_session *session,
229 __u64 *prog_addrs = (__u64 *)(uintptr_t)(info->jited_ksyms); 228 __u64 *prog_addrs = (__u64 *)(uintptr_t)(info->jited_ksyms);
230 int name_len; 229 int name_len;
231 230
232 *ksymbol_event = (struct ksymbol_event){ 231 *ksymbol_event = (struct perf_record_ksymbol) {
233 .header = { 232 .header = {
234 .type = PERF_RECORD_KSYMBOL, 233 .type = PERF_RECORD_KSYMBOL,
235 .size = offsetof(struct ksymbol_event, name), 234 .size = offsetof(struct perf_record_ksymbol, name),
236 }, 235 },
237 .addr = prog_addrs[i], 236 .addr = prog_addrs[i],
238 .len = prog_lens[i], 237 .len = prog_lens[i],
@@ -253,10 +252,10 @@ static int perf_event__synthesize_one_bpf_prog(struct perf_session *session,
253 252
254 if (!opts->no_bpf_event) { 253 if (!opts->no_bpf_event) {
255 /* Synthesize PERF_RECORD_BPF_EVENT */ 254 /* Synthesize PERF_RECORD_BPF_EVENT */
256 *bpf_event = (struct bpf_event){ 255 *bpf_event = (struct perf_record_bpf_event) {
257 .header = { 256 .header = {
258 .type = PERF_RECORD_BPF_EVENT, 257 .type = PERF_RECORD_BPF_EVENT,
259 .size = sizeof(struct bpf_event), 258 .size = sizeof(struct perf_record_bpf_event),
260 }, 259 },
261 .type = PERF_BPF_EVENT_PROG_LOAD, 260 .type = PERF_BPF_EVENT_PROG_LOAD,
262 .flags = 0, 261 .flags = 0,
@@ -301,7 +300,7 @@ int perf_event__synthesize_bpf_events(struct perf_session *session,
301 int err; 300 int err;
302 int fd; 301 int fd;
303 302
304 event = malloc(sizeof(event->bpf_event) + KSYM_NAME_LEN + machine->id_hdr_size); 303 event = malloc(sizeof(event->bpf) + KSYM_NAME_LEN + machine->id_hdr_size);
305 if (!event) 304 if (!event)
306 return -1; 305 return -1;
307 while (true) { 306 while (true) {
@@ -398,9 +397,9 @@ static int bpf_event__sb_cb(union perf_event *event, void *data)
398 if (event->header.type != PERF_RECORD_BPF_EVENT) 397 if (event->header.type != PERF_RECORD_BPF_EVENT)
399 return -1; 398 return -1;
400 399
401 switch (event->bpf_event.type) { 400 switch (event->bpf.type) {
402 case PERF_BPF_EVENT_PROG_LOAD: 401 case PERF_BPF_EVENT_PROG_LOAD:
403 perf_env__add_bpf_info(env, event->bpf_event.id); 402 perf_env__add_bpf_info(env, event->bpf.id);
404 403
405 case PERF_BPF_EVENT_PROG_UNLOAD: 404 case PERF_BPF_EVENT_PROG_UNLOAD:
406 /* 405 /*
@@ -410,8 +409,7 @@ static int bpf_event__sb_cb(union perf_event *event, void *data)
410 */ 409 */
411 break; 410 break;
412 default: 411 default:
413 pr_debug("unexpected bpf_event type of %d\n", 412 pr_debug("unexpected bpf event type of %d\n", event->bpf.type);
414 event->bpf_event.type);
415 break; 413 break;
416 } 414 }
417 415
diff --git a/tools/perf/util/bpf-event.h b/tools/perf/util/bpf-event.h
index 26ab9239f986..417b78835ea0 100644
--- a/tools/perf/util/bpf-event.h
+++ b/tools/perf/util/bpf-event.h
@@ -30,8 +30,8 @@ struct btf_node {
30}; 30};
31 31
32#ifdef HAVE_LIBBPF_SUPPORT 32#ifdef HAVE_LIBBPF_SUPPORT
33int machine__process_bpf_event(struct machine *machine, union perf_event *event, 33int machine__process_bpf(struct machine *machine, union perf_event *event,
34 struct perf_sample *sample); 34 struct perf_sample *sample);
35 35
36int perf_event__synthesize_bpf_events(struct perf_session *session, 36int perf_event__synthesize_bpf_events(struct perf_session *session,
37 perf_event__handler_t process, 37 perf_event__handler_t process,
@@ -43,9 +43,9 @@ void bpf_event__print_bpf_prog_info(struct bpf_prog_info *info,
43 struct perf_env *env, 43 struct perf_env *env,
44 FILE *fp); 44 FILE *fp);
45#else 45#else
46static inline int machine__process_bpf_event(struct machine *machine __maybe_unused, 46static inline int machine__process_bpf(struct machine *machine __maybe_unused,
47 union perf_event *event __maybe_unused, 47 union perf_event *event __maybe_unused,
48 struct perf_sample *sample __maybe_unused) 48 struct perf_sample *sample __maybe_unused)
49{ 49{
50 return 0; 50 return 0;
51} 51}
diff --git a/tools/perf/util/cacheline.c b/tools/perf/util/cacheline.c
new file mode 100644
index 000000000000..9361d3f61f75
--- /dev/null
+++ b/tools/perf/util/cacheline.c
@@ -0,0 +1,26 @@
1// SPDX-License-Identifier: GPL-2.0
2#include "cacheline.h"
3#include "../perf.h"
4#include <unistd.h>
5
6#ifdef _SC_LEVEL1_DCACHE_LINESIZE
7#define cache_line_size(cacheline_sizep) *cacheline_sizep = sysconf(_SC_LEVEL1_DCACHE_LINESIZE)
8#else
9#include <api/fs/fs.h>
10#include "debug.h"
11static void cache_line_size(int *cacheline_sizep)
12{
13 if (sysfs__read_int("devices/system/cpu/cpu0/cache/index0/coherency_line_size", cacheline_sizep))
14 pr_debug("cannot determine cache line size");
15}
16#endif
17
18int cacheline_size(void)
19{
20 static int size;
21
22 if (!size)
23 cache_line_size(&size);
24
25 return size;
26}
diff --git a/tools/perf/util/cacheline.h b/tools/perf/util/cacheline.h
new file mode 100644
index 000000000000..dec8c0fb1f4a
--- /dev/null
+++ b/tools/perf/util/cacheline.h
@@ -0,0 +1,21 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef PERF_CACHELINE_H
3#define PERF_CACHELINE_H
4
5#include <linux/compiler.h>
6
7int __pure cacheline_size(void);
8
9static inline u64 cl_address(u64 address)
10{
11 /* return the cacheline of the address */
12 return (address & ~(cacheline_size() - 1));
13}
14
15static inline u64 cl_offset(u64 address)
16{
17 /* return the cacheline of the address */
18 return (address & (cacheline_size() - 1));
19}
20
21#endif // PERF_CACHELINE_H
diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c
index d077704f9afa..dd6e01000385 100644
--- a/tools/perf/util/callchain.c
+++ b/tools/perf/util/callchain.c
@@ -20,6 +20,7 @@
20 20
21#include "asm/bug.h" 21#include "asm/bug.h"
22 22
23#include "debug.h"
23#include "hist.h" 24#include "hist.h"
24#include "sort.h" 25#include "sort.h"
25#include "machine.h" 26#include "machine.h"
diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h
index d0c5bbfd91af..c2519e7ea958 100644
--- a/tools/perf/util/cpumap.h
+++ b/tools/perf/util/cpumap.h
@@ -7,8 +7,6 @@
7#include <internal/cpumap.h> 7#include <internal/cpumap.h>
8#include <perf/cpumap.h> 8#include <perf/cpumap.h>
9 9
10#include "perf.h"
11
12struct cpu_map_data; 10struct cpu_map_data;
13 11
14struct perf_cpu_map *perf_cpu_map__empty_new(int nr); 12struct perf_cpu_map *perf_cpu_map__empty_new(int nr);
diff --git a/tools/perf/util/data.c b/tools/perf/util/data.c
index 1d1b97a92c3f..74aafe0df506 100644
--- a/tools/perf/util/data.c
+++ b/tools/perf/util/data.c
@@ -9,7 +9,6 @@
9#include <unistd.h> 9#include <unistd.h>
10#include <string.h> 10#include <string.h>
11#include <asm/bug.h> 11#include <asm/bug.h>
12#include <sys/types.h>
13#include <dirent.h> 12#include <dirent.h>
14 13
15#include "data.h" 14#include "data.h"
diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index 332edef8d394..33616ea62a47 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -387,7 +387,7 @@ int perf_event__synthesize_mmap_events(struct perf_tool *tool,
387 strcpy(execname, ""); 387 strcpy(execname, "");
388 388
389 /* 00400000-0040c000 r-xp 00000000 fd:01 41038 /bin/cat */ 389 /* 00400000-0040c000 r-xp 00000000 fd:01 41038 /bin/cat */
390 n = sscanf(bf, "%"PRIx64"-%"PRIx64" %s %"PRIx64" %x:%x %u %[^\n]\n", 390 n = sscanf(bf, "%"PRI_lx64"-%"PRI_lx64" %s %"PRI_lx64" %x:%x %u %[^\n]\n",
391 &event->mmap2.start, &event->mmap2.len, prot, 391 &event->mmap2.start, &event->mmap2.len, prot,
392 &event->mmap2.pgoff, &event->mmap2.maj, 392 &event->mmap2.pgoff, &event->mmap2.maj,
393 &event->mmap2.min, 393 &event->mmap2.min,
@@ -1343,17 +1343,17 @@ int perf_event__process_ksymbol(struct perf_tool *tool __maybe_unused,
1343 return machine__process_ksymbol(machine, event, sample); 1343 return machine__process_ksymbol(machine, event, sample);
1344} 1344}
1345 1345
1346int perf_event__process_bpf_event(struct perf_tool *tool __maybe_unused, 1346int perf_event__process_bpf(struct perf_tool *tool __maybe_unused,
1347 union perf_event *event, 1347 union perf_event *event,
1348 struct perf_sample *sample __maybe_unused, 1348 struct perf_sample *sample,
1349 struct machine *machine) 1349 struct machine *machine)
1350{ 1350{
1351 return machine__process_bpf_event(machine, event, sample); 1351 return machine__process_bpf(machine, event, sample);
1352} 1352}
1353 1353
1354size_t perf_event__fprintf_mmap(union perf_event *event, FILE *fp) 1354size_t perf_event__fprintf_mmap(union perf_event *event, FILE *fp)
1355{ 1355{
1356 return fprintf(fp, " %d/%d: [%#" PRIx64 "(%#" PRIx64 ") @ %#" PRIx64 "]: %c %s\n", 1356 return fprintf(fp, " %d/%d: [%#" PRI_lx64 "(%#" PRI_lx64 ") @ %#" PRI_lx64 "]: %c %s\n",
1357 event->mmap.pid, event->mmap.tid, event->mmap.start, 1357 event->mmap.pid, event->mmap.tid, event->mmap.start,
1358 event->mmap.len, event->mmap.pgoff, 1358 event->mmap.len, event->mmap.pgoff,
1359 (event->header.misc & PERF_RECORD_MISC_MMAP_DATA) ? 'r' : 'x', 1359 (event->header.misc & PERF_RECORD_MISC_MMAP_DATA) ? 'r' : 'x',
@@ -1362,8 +1362,8 @@ size_t perf_event__fprintf_mmap(union perf_event *event, FILE *fp)
1362 1362
1363size_t perf_event__fprintf_mmap2(union perf_event *event, FILE *fp) 1363size_t perf_event__fprintf_mmap2(union perf_event *event, FILE *fp)
1364{ 1364{
1365 return fprintf(fp, " %d/%d: [%#" PRIx64 "(%#" PRIx64 ") @ %#" PRIx64 1365 return fprintf(fp, " %d/%d: [%#" PRI_lx64 "(%#" PRI_lx64 ") @ %#" PRI_lx64
1366 " %02x:%02x %"PRIu64" %"PRIu64"]: %c%c%c%c %s\n", 1366 " %02x:%02x %"PRI_lu64" %"PRI_lu64"]: %c%c%c%c %s\n",
1367 event->mmap2.pid, event->mmap2.tid, event->mmap2.start, 1367 event->mmap2.pid, event->mmap2.tid, event->mmap2.start,
1368 event->mmap2.len, event->mmap2.pgoff, event->mmap2.maj, 1368 event->mmap2.len, event->mmap2.pgoff, event->mmap2.maj,
1369 event->mmap2.min, event->mmap2.ino, 1369 event->mmap2.min, event->mmap2.ino,
@@ -1480,22 +1480,21 @@ size_t perf_event__fprintf_switch(union perf_event *event, FILE *fp)
1480 1480
1481static size_t perf_event__fprintf_lost(union perf_event *event, FILE *fp) 1481static size_t perf_event__fprintf_lost(union perf_event *event, FILE *fp)
1482{ 1482{
1483 return fprintf(fp, " lost %" PRIu64 "\n", event->lost.lost); 1483 return fprintf(fp, " lost %" PRI_lu64 "\n", event->lost.lost);
1484} 1484}
1485 1485
1486size_t perf_event__fprintf_ksymbol(union perf_event *event, FILE *fp) 1486size_t perf_event__fprintf_ksymbol(union perf_event *event, FILE *fp)
1487{ 1487{
1488 return fprintf(fp, " addr %" PRIx64 " len %u type %u flags 0x%x name %s\n", 1488 return fprintf(fp, " addr %" PRI_lx64 " len %u type %u flags 0x%x name %s\n",
1489 event->ksymbol_event.addr, event->ksymbol_event.len, 1489 event->ksymbol.addr, event->ksymbol.len,
1490 event->ksymbol_event.ksym_type, 1490 event->ksymbol.ksym_type,
1491 event->ksymbol_event.flags, event->ksymbol_event.name); 1491 event->ksymbol.flags, event->ksymbol.name);
1492} 1492}
1493 1493
1494size_t perf_event__fprintf_bpf_event(union perf_event *event, FILE *fp) 1494size_t perf_event__fprintf_bpf(union perf_event *event, FILE *fp)
1495{ 1495{
1496 return fprintf(fp, " type %u, flags %u, id %u\n", 1496 return fprintf(fp, " type %u, flags %u, id %u\n",
1497 event->bpf_event.type, event->bpf_event.flags, 1497 event->bpf.type, event->bpf.flags, event->bpf.id);
1498 event->bpf_event.id);
1499} 1498}
1500 1499
1501size_t perf_event__fprintf(union perf_event *event, FILE *fp) 1500size_t perf_event__fprintf(union perf_event *event, FILE *fp)
@@ -1537,7 +1536,7 @@ size_t perf_event__fprintf(union perf_event *event, FILE *fp)
1537 ret += perf_event__fprintf_ksymbol(event, fp); 1536 ret += perf_event__fprintf_ksymbol(event, fp);
1538 break; 1537 break;
1539 case PERF_RECORD_BPF_EVENT: 1538 case PERF_RECORD_BPF_EVENT:
1540 ret += perf_event__fprintf_bpf_event(event, fp); 1539 ret += perf_event__fprintf_bpf(event, fp);
1541 break; 1540 break;
1542 default: 1541 default:
1543 ret += fprintf(fp, "\n"); 1542 ret += fprintf(fp, "\n");
diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h
index 0e164e8ae28d..429a3fe52d6c 100644
--- a/tools/perf/util/event.h
+++ b/tools/perf/util/event.h
@@ -7,108 +7,26 @@
7#include <linux/kernel.h> 7#include <linux/kernel.h>
8#include <linux/bpf.h> 8#include <linux/bpf.h>
9#include <linux/perf_event.h> 9#include <linux/perf_event.h>
10#include <perf/event.h>
10 11
11#include "../perf.h" 12#include "../perf.h"
12#include "build-id.h" 13#include "build-id.h"
13#include "perf_regs.h" 14#include "perf_regs.h"
14 15
15struct mmap_event { 16#ifdef __LP64__
16 struct perf_event_header header;
17 u32 pid, tid;
18 u64 start;
19 u64 len;
20 u64 pgoff;
21 char filename[PATH_MAX];
22};
23
24struct mmap2_event {
25 struct perf_event_header header;
26 u32 pid, tid;
27 u64 start;
28 u64 len;
29 u64 pgoff;
30 u32 maj;
31 u32 min;
32 u64 ino;
33 u64 ino_generation;
34 u32 prot;
35 u32 flags;
36 char filename[PATH_MAX];
37};
38
39struct comm_event {
40 struct perf_event_header header;
41 u32 pid, tid;
42 char comm[16];
43};
44
45struct namespaces_event {
46 struct perf_event_header header;
47 u32 pid, tid;
48 u64 nr_namespaces;
49 struct perf_ns_link_info link_info[];
50};
51
52struct fork_event {
53 struct perf_event_header header;
54 u32 pid, ppid;
55 u32 tid, ptid;
56 u64 time;
57};
58
59struct lost_event {
60 struct perf_event_header header;
61 u64 id;
62 u64 lost;
63};
64
65struct lost_samples_event {
66 struct perf_event_header header;
67 u64 lost;
68};
69
70/* 17/*
71 * PERF_FORMAT_ENABLED | PERF_FORMAT_RUNNING | PERF_FORMAT_ID 18 * /usr/include/inttypes.h uses just 'lu' for PRIu64, but we end up defining
19 * __u64 as long long unsigned int, and then -Werror=format= kicks in and
20 * complains of the mismatched types, so use these two special extra PRI
21 * macros to overcome that.
72 */ 22 */
73struct read_event { 23#define PRI_lu64 "l" PRIu64
74 struct perf_event_header header; 24#define PRI_lx64 "l" PRIx64
75 u32 pid, tid; 25#else
76 u64 value; 26#define PRI_lu64 PRIu64
77 u64 time_enabled; 27#define PRI_lx64 PRIx64
78 u64 time_running;
79 u64 id;
80};
81
82struct throttle_event {
83 struct perf_event_header header;
84 u64 time;
85 u64 id;
86 u64 stream_id;
87};
88
89#ifndef KSYM_NAME_LEN
90#define KSYM_NAME_LEN 256
91#endif 28#endif
92 29
93struct ksymbol_event {
94 struct perf_event_header header;
95 u64 addr;
96 u32 len;
97 u16 ksym_type;
98 u16 flags;
99 char name[KSYM_NAME_LEN];
100};
101
102struct bpf_event {
103 struct perf_event_header header;
104 u16 type;
105 u16 flags;
106 u32 id;
107
108 /* for bpf_prog types */
109 u8 tag[BPF_TAG_SIZE]; // prog tag
110};
111
112#define PERF_SAMPLE_MASK \ 30#define PERF_SAMPLE_MASK \
113 (PERF_SAMPLE_IP | PERF_SAMPLE_TID | \ 31 (PERF_SAMPLE_IP | PERF_SAMPLE_TID | \
114 PERF_SAMPLE_TIME | PERF_SAMPLE_ADDR | \ 32 PERF_SAMPLE_TIME | PERF_SAMPLE_ADDR | \
@@ -119,11 +37,6 @@ struct bpf_event {
119/* perf sample has 16 bits size limit */ 37/* perf sample has 16 bits size limit */
120#define PERF_SAMPLE_MAX_SIZE (1 << 16) 38#define PERF_SAMPLE_MAX_SIZE (1 << 16)
121 39
122struct sample_event {
123 struct perf_event_header header;
124 u64 array[];
125};
126
127struct regs_dump { 40struct regs_dump {
128 u64 abi; 41 u64 abi;
129 u64 mask; 42 u64 mask;
@@ -392,18 +305,18 @@ static inline void *perf_synth__raw_data(void *p)
392 * when possible sends this number in a PERF_RECORD_LOST event. The number of 305 * when possible sends this number in a PERF_RECORD_LOST event. The number of
393 * such "chunks" of lost events is stored in .nr_events[PERF_EVENT_LOST] while 306 * such "chunks" of lost events is stored in .nr_events[PERF_EVENT_LOST] while
394 * total_lost tells exactly how many events the kernel in fact lost, i.e. it is 307 * total_lost tells exactly how many events the kernel in fact lost, i.e. it is
395 * the sum of all struct lost_event.lost fields reported. 308 * the sum of all struct perf_record_lost.lost fields reported.
396 * 309 *
397 * The kernel discards mixed up samples and sends the number in a 310 * The kernel discards mixed up samples and sends the number in a
398 * PERF_RECORD_LOST_SAMPLES event. The number of lost-samples events is stored 311 * PERF_RECORD_LOST_SAMPLES event. The number of lost-samples events is stored
399 * in .nr_events[PERF_RECORD_LOST_SAMPLES] while total_lost_samples tells 312 * in .nr_events[PERF_RECORD_LOST_SAMPLES] while total_lost_samples tells
400 * exactly how many samples the kernel in fact dropped, i.e. it is the sum of 313 * exactly how many samples the kernel in fact dropped, i.e. it is the sum of
401 * all struct lost_samples_event.lost fields reported. 314 * all struct perf_record_lost_samples.lost fields reported.
402 * 315 *
403 * The total_period is needed because by default auto-freq is used, so 316 * The total_period is needed because by default auto-freq is used, so
404 * multipling nr_events[PERF_EVENT_SAMPLE] by a frequency isn't possible to get 317 * multipling nr_events[PERF_EVENT_SAMPLE] by a frequency isn't possible to get
405 * the total number of low level events, it is necessary to to sum all struct 318 * the total number of low level events, it is necessary to to sum all struct
406 * sample_event.period and stash the result in total_period. 319 * perf_record_sample.period and stash the result in total_period.
407 */ 320 */
408struct events_stats { 321struct events_stats {
409 u64 total_period; 322 u64 total_period;
@@ -637,16 +550,18 @@ struct compressed_event {
637 550
638union perf_event { 551union perf_event {
639 struct perf_event_header header; 552 struct perf_event_header header;
640 struct mmap_event mmap; 553 struct perf_record_mmap mmap;
641 struct mmap2_event mmap2; 554 struct perf_record_mmap2 mmap2;
642 struct comm_event comm; 555 struct perf_record_comm comm;
643 struct namespaces_event namespaces; 556 struct perf_record_namespaces namespaces;
644 struct fork_event fork; 557 struct perf_record_fork fork;
645 struct lost_event lost; 558 struct perf_record_lost lost;
646 struct lost_samples_event lost_samples; 559 struct perf_record_lost_samples lost_samples;
647 struct read_event read; 560 struct perf_record_read read;
648 struct throttle_event throttle; 561 struct perf_record_throttle throttle;
649 struct sample_event sample; 562 struct perf_record_sample sample;
563 struct perf_record_bpf_event bpf;
564 struct perf_record_ksymbol ksymbol;
650 struct attr_event attr; 565 struct attr_event attr;
651 struct event_update_event event_update; 566 struct event_update_event event_update;
652 struct event_type_event event_type; 567 struct event_type_event event_type;
@@ -666,8 +581,6 @@ union perf_event {
666 struct stat_round_event stat_round; 581 struct stat_round_event stat_round;
667 struct time_conv_event time_conv; 582 struct time_conv_event time_conv;
668 struct feature_event feat; 583 struct feature_event feat;
669 struct ksymbol_event ksymbol_event;
670 struct bpf_event bpf_event;
671 struct compressed_event pack; 584 struct compressed_event pack;
672}; 585};
673 586
@@ -770,10 +683,10 @@ int perf_event__process_ksymbol(struct perf_tool *tool,
770 union perf_event *event, 683 union perf_event *event,
771 struct perf_sample *sample, 684 struct perf_sample *sample,
772 struct machine *machine); 685 struct machine *machine);
773int perf_event__process_bpf_event(struct perf_tool *tool, 686int perf_event__process_bpf(struct perf_tool *tool,
774 union perf_event *event, 687 union perf_event *event,
775 struct perf_sample *sample, 688 struct perf_sample *sample,
776 struct machine *machine); 689 struct machine *machine);
777int perf_tool__process_synth_event(struct perf_tool *tool, 690int perf_tool__process_synth_event(struct perf_tool *tool,
778 union perf_event *event, 691 union perf_event *event,
779 struct machine *machine, 692 struct machine *machine,
@@ -838,7 +751,7 @@ size_t perf_event__fprintf_thread_map(union perf_event *event, FILE *fp);
838size_t perf_event__fprintf_cpu_map(union perf_event *event, FILE *fp); 751size_t perf_event__fprintf_cpu_map(union perf_event *event, FILE *fp);
839size_t perf_event__fprintf_namespaces(union perf_event *event, FILE *fp); 752size_t perf_event__fprintf_namespaces(union perf_event *event, FILE *fp);
840size_t perf_event__fprintf_ksymbol(union perf_event *event, FILE *fp); 753size_t perf_event__fprintf_ksymbol(union perf_event *event, FILE *fp);
841size_t perf_event__fprintf_bpf_event(union perf_event *event, FILE *fp); 754size_t perf_event__fprintf_bpf(union perf_event *event, FILE *fp);
842size_t perf_event__fprintf(union perf_event *event, FILE *fp); 755size_t perf_event__fprintf(union perf_event *event, FILE *fp);
843 756
844int kallsyms__get_function_start(const char *kallsyms_filename, 757int kallsyms__get_function_start(const char *kallsyms_filename,
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index ff415680fe0a..47bc54111f57 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -587,7 +587,7 @@ struct evsel *perf_evlist__id2evsel_strict(struct evlist *evlist,
587static int perf_evlist__event2id(struct evlist *evlist, 587static int perf_evlist__event2id(struct evlist *evlist,
588 union perf_event *event, u64 *id) 588 union perf_event *event, u64 *id)
589{ 589{
590 const u64 *array = event->sample.array; 590 const __u64 *array = event->sample.array;
591 ssize_t n; 591 ssize_t n;
592 592
593 n = (event->header.size - sizeof(event->header)) >> 3; 593 n = (event->header.size - sizeof(event->header)) >> 3;
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index e983e721beca..fa676355559e 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -34,6 +34,7 @@
34#include "thread_map.h" 34#include "thread_map.h"
35#include "target.h" 35#include "target.h"
36#include "perf_regs.h" 36#include "perf_regs.h"
37#include "record.h"
37#include "debug.h" 38#include "debug.h"
38#include "trace-event.h" 39#include "trace-event.h"
39#include "stat.h" 40#include "stat.h"
@@ -116,7 +117,7 @@ int __perf_evsel__sample_size(u64 sample_type)
116 * 117 *
117 * This function returns the position of the event id (PERF_SAMPLE_ID or 118 * This function returns the position of the event id (PERF_SAMPLE_ID or
118 * PERF_SAMPLE_IDENTIFIER) in a sample event i.e. in the array of struct 119 * PERF_SAMPLE_IDENTIFIER) in a sample event i.e. in the array of struct
119 * sample_event. 120 * perf_record_sample.
120 */ 121 */
121static int __perf_evsel__calc_id_pos(u64 sample_type) 122static int __perf_evsel__calc_id_pos(u64 sample_type)
122{ 123{
@@ -1071,8 +1072,7 @@ void perf_evsel__config(struct evsel *evsel, struct record_opts *opts,
1071 attr->mmap2 = track && !perf_missing_features.mmap2; 1072 attr->mmap2 = track && !perf_missing_features.mmap2;
1072 attr->comm = track; 1073 attr->comm = track;
1073 attr->ksymbol = track && !perf_missing_features.ksymbol; 1074 attr->ksymbol = track && !perf_missing_features.ksymbol;
1074 attr->bpf_event = track && !opts->no_bpf_event && 1075 attr->bpf_event = track && !opts->no_bpf_event && !perf_missing_features.bpf;
1075 !perf_missing_features.bpf_event;
1076 1076
1077 if (opts->record_namespaces) 1077 if (opts->record_namespaces)
1078 attr->namespaces = track; 1078 attr->namespaces = track;
@@ -1802,7 +1802,7 @@ fallback_missing_features:
1802 evsel->core.attr.read_format &= ~(PERF_FORMAT_GROUP|PERF_FORMAT_ID); 1802 evsel->core.attr.read_format &= ~(PERF_FORMAT_GROUP|PERF_FORMAT_ID);
1803 if (perf_missing_features.ksymbol) 1803 if (perf_missing_features.ksymbol)
1804 evsel->core.attr.ksymbol = 0; 1804 evsel->core.attr.ksymbol = 0;
1805 if (perf_missing_features.bpf_event) 1805 if (perf_missing_features.bpf)
1806 evsel->core.attr.bpf_event = 0; 1806 evsel->core.attr.bpf_event = 0;
1807retry_sample_id: 1807retry_sample_id:
1808 if (perf_missing_features.sample_id_all) 1808 if (perf_missing_features.sample_id_all)
@@ -1919,8 +1919,8 @@ try_fallback:
1919 perf_missing_features.aux_output = true; 1919 perf_missing_features.aux_output = true;
1920 pr_debug2("Kernel has no attr.aux_output support, bailing out\n"); 1920 pr_debug2("Kernel has no attr.aux_output support, bailing out\n");
1921 goto out_close; 1921 goto out_close;
1922 } else if (!perf_missing_features.bpf_event && evsel->core.attr.bpf_event) { 1922 } else if (!perf_missing_features.bpf && evsel->core.attr.bpf_event) {
1923 perf_missing_features.bpf_event = true; 1923 perf_missing_features.bpf = true;
1924 pr_debug2("switching off bpf_event\n"); 1924 pr_debug2("switching off bpf_event\n");
1925 goto fallback_missing_features; 1925 goto fallback_missing_features;
1926 } else if (!perf_missing_features.ksymbol && evsel->core.attr.ksymbol) { 1926 } else if (!perf_missing_features.ksymbol && evsel->core.attr.ksymbol) {
@@ -2008,7 +2008,7 @@ static int perf_evsel__parse_id_sample(const struct evsel *evsel,
2008 struct perf_sample *sample) 2008 struct perf_sample *sample)
2009{ 2009{
2010 u64 type = evsel->core.attr.sample_type; 2010 u64 type = evsel->core.attr.sample_type;
2011 const u64 *array = event->sample.array; 2011 const __u64 *array = event->sample.array;
2012 bool swapped = evsel->needs_swap; 2012 bool swapped = evsel->needs_swap;
2013 union u64_swap u; 2013 union u64_swap u;
2014 2014
@@ -2098,7 +2098,7 @@ int perf_evsel__parse_sample(struct evsel *evsel, union perf_event *event,
2098{ 2098{
2099 u64 type = evsel->core.attr.sample_type; 2099 u64 type = evsel->core.attr.sample_type;
2100 bool swapped = evsel->needs_swap; 2100 bool swapped = evsel->needs_swap;
2101 const u64 *array; 2101 const __u64 *array;
2102 u16 max_size = event->header.size; 2102 u16 max_size = event->header.size;
2103 const void *endp = (void *)event + max_size; 2103 const void *endp = (void *)event + max_size;
2104 u64 sz; 2104 u64 sz;
@@ -2377,7 +2377,7 @@ int perf_evsel__parse_sample_timestamp(struct evsel *evsel,
2377 u64 *timestamp) 2377 u64 *timestamp)
2378{ 2378{
2379 u64 type = evsel->core.attr.sample_type; 2379 u64 type = evsel->core.attr.sample_type;
2380 const u64 *array; 2380 const __u64 *array;
2381 2381
2382 if (!(type & PERF_SAMPLE_TIME)) 2382 if (!(type & PERF_SAMPLE_TIME))
2383 return -1; 2383 return -1;
@@ -2419,7 +2419,7 @@ int perf_evsel__parse_sample_timestamp(struct evsel *evsel,
2419size_t perf_event__sample_event_size(const struct perf_sample *sample, u64 type, 2419size_t perf_event__sample_event_size(const struct perf_sample *sample, u64 type,
2420 u64 read_format) 2420 u64 read_format)
2421{ 2421{
2422 size_t sz, result = sizeof(struct sample_event); 2422 size_t sz, result = sizeof(struct perf_record_sample);
2423 2423
2424 if (type & PERF_SAMPLE_IDENTIFIER) 2424 if (type & PERF_SAMPLE_IDENTIFIER)
2425 result += sizeof(u64); 2425 result += sizeof(u64);
@@ -2528,7 +2528,7 @@ int perf_event__synthesize_sample(union perf_event *event, u64 type,
2528 u64 read_format, 2528 u64 read_format,
2529 const struct perf_sample *sample) 2529 const struct perf_sample *sample)
2530{ 2530{
2531 u64 *array; 2531 __u64 *array;
2532 size_t sz; 2532 size_t sz;
2533 /* 2533 /*
2534 * used for cross-endian analysis. See git commit 65014ab3 2534 * used for cross-endian analysis. See git commit 65014ab3
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index 5a351cae66df..fd60caced4fc 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -107,7 +107,7 @@ struct xyarray;
107 * show the name used, not some alias. 107 * show the name used, not some alias.
108 * @id_pos: the position of the event id (PERF_SAMPLE_ID or 108 * @id_pos: the position of the event id (PERF_SAMPLE_ID or
109 * PERF_SAMPLE_IDENTIFIER) in a sample event i.e. in the array of 109 * PERF_SAMPLE_IDENTIFIER) in a sample event i.e. in the array of
110 * struct sample_event 110 * struct perf_record_sample
111 * @is_pos: the position (counting backwards) of the event id (PERF_SAMPLE_ID or 111 * @is_pos: the position (counting backwards) of the event id (PERF_SAMPLE_ID or
112 * PERF_SAMPLE_IDENTIFIER) in a non-sample event i.e. if sample_id_all 112 * PERF_SAMPLE_IDENTIFIER) in a non-sample event i.e. if sample_id_all
113 * is used there is an id sample appended to non-sample events 113 * is used there is an id sample appended to non-sample events
@@ -194,7 +194,7 @@ struct perf_missing_features {
194 bool write_backward; 194 bool write_backward;
195 bool group_read; 195 bool group_read;
196 bool ksymbol; 196 bool ksymbol;
197 bool bpf_event; 197 bool bpf;
198 bool aux_output; 198 bool aux_output;
199}; 199};
200 200
diff --git a/tools/perf/util/get_current_dir_name.c b/tools/perf/util/get_current_dir_name.c
index 01f32f26552d..b205d929245f 100644
--- a/tools/perf/util/get_current_dir_name.c
+++ b/tools/perf/util/get_current_dir_name.c
@@ -5,7 +5,6 @@
5#include "get_current_dir_name.h" 5#include "get_current_dir_name.h"
6#include <unistd.h> 6#include <unistd.h>
7#include <stdlib.h> 7#include <stdlib.h>
8#include <stdlib.h>
9 8
10/* Android's 'bionic' library, for one, doesn't have this */ 9/* Android's 'bionic' library, for one, doesn't have this */
11 10
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index 8efbf58dc3d0..33702675073c 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -193,7 +193,10 @@ void hists__calc_col_len(struct hists *hists, struct hist_entry *h)
193 hists__new_col_len(hists, HISTC_MEM_LVL, 21 + 3); 193 hists__new_col_len(hists, HISTC_MEM_LVL, 21 + 3);
194 hists__new_col_len(hists, HISTC_LOCAL_WEIGHT, 12); 194 hists__new_col_len(hists, HISTC_LOCAL_WEIGHT, 12);
195 hists__new_col_len(hists, HISTC_GLOBAL_WEIGHT, 12); 195 hists__new_col_len(hists, HISTC_GLOBAL_WEIGHT, 12);
196 hists__new_col_len(hists, HISTC_TIME, 12); 196 if (symbol_conf.nanosecs)
197 hists__new_col_len(hists, HISTC_TIME, 16);
198 else
199 hists__new_col_len(hists, HISTC_TIME, 12);
197 200
198 if (h->srcline) { 201 if (h->srcline) {
199 len = MAX(strlen(h->srcline), strlen(sort_srcline.se_header)); 202 len = MAX(strlen(h->srcline), strlen(sort_srcline.se_header));
diff --git a/tools/perf/util/intel-bts.c b/tools/perf/util/intel-bts.c
index 7eb9e6dc27dd..8dc6408206b9 100644
--- a/tools/perf/util/intel-bts.c
+++ b/tools/perf/util/intel-bts.c
@@ -818,7 +818,7 @@ static int intel_bts_synth_events(struct intel_bts *bts,
818 * We only use sample types from PERF_SAMPLE_MASK so we can use 818 * We only use sample types from PERF_SAMPLE_MASK so we can use
819 * __perf_evsel__sample_size() here. 819 * __perf_evsel__sample_size() here.
820 */ 820 */
821 bts->branches_event_size = sizeof(struct sample_event) + 821 bts->branches_event_size = sizeof(struct perf_record_sample) +
822 __perf_evsel__sample_size(attr.sample_type); 822 __perf_evsel__sample_size(attr.sample_type);
823 } 823 }
824 824
diff --git a/tools/perf/util/kvm-stat.h b/tools/perf/util/kvm-stat.h
index a09c495f866b..46913637085b 100644
--- a/tools/perf/util/kvm-stat.h
+++ b/tools/perf/util/kvm-stat.h
@@ -2,9 +2,9 @@
2#ifndef __PERF_KVM_STAT_H 2#ifndef __PERF_KVM_STAT_H
3#define __PERF_KVM_STAT_H 3#define __PERF_KVM_STAT_H
4 4
5#include "../perf.h"
6#include "tool.h" 5#include "tool.h"
7#include "stat.h" 6#include "stat.h"
7#include "record.h"
8 8
9struct evsel; 9struct evsel;
10struct evlist; 10struct evlist;
diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index 5734460fc89e..93483f1764d3 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -10,10 +10,13 @@
10#include "hist.h" 10#include "hist.h"
11#include "machine.h" 11#include "machine.h"
12#include "map.h" 12#include "map.h"
13#include "srcline.h"
13#include "symbol.h" 14#include "symbol.h"
14#include "sort.h" 15#include "sort.h"
15#include "strlist.h" 16#include "strlist.h"
17#include "target.h"
16#include "thread.h" 18#include "thread.h"
19#include "util.h"
17#include "vdso.h" 20#include "vdso.h"
18#include <stdbool.h> 21#include <stdbool.h>
19#include <sys/types.h> 22#include <sys/types.h>
@@ -642,7 +645,7 @@ int machine__process_namespaces_event(struct machine *machine __maybe_unused,
642int machine__process_lost_event(struct machine *machine __maybe_unused, 645int machine__process_lost_event(struct machine *machine __maybe_unused,
643 union perf_event *event, struct perf_sample *sample __maybe_unused) 646 union perf_event *event, struct perf_sample *sample __maybe_unused)
644{ 647{
645 dump_printf(": id:%" PRIu64 ": lost:%" PRIu64 "\n", 648 dump_printf(": id:%" PRI_lu64 ": lost:%" PRI_lu64 "\n",
646 event->lost.id, event->lost.lost); 649 event->lost.id, event->lost.lost);
647 return 0; 650 return 0;
648} 651}
@@ -650,7 +653,7 @@ int machine__process_lost_event(struct machine *machine __maybe_unused,
650int machine__process_lost_samples_event(struct machine *machine __maybe_unused, 653int machine__process_lost_samples_event(struct machine *machine __maybe_unused,
651 union perf_event *event, struct perf_sample *sample) 654 union perf_event *event, struct perf_sample *sample)
652{ 655{
653 dump_printf(": id:%" PRIu64 ": lost samples :%" PRIu64 "\n", 656 dump_printf(": id:%" PRIu64 ": lost samples :%" PRI_lu64 "\n",
654 sample->id, event->lost_samples.lost); 657 sample->id, event->lost_samples.lost);
655 return 0; 658 return 0;
656} 659}
@@ -710,20 +713,20 @@ static int machine__process_ksymbol_register(struct machine *machine,
710 struct symbol *sym; 713 struct symbol *sym;
711 struct map *map; 714 struct map *map;
712 715
713 map = map_groups__find(&machine->kmaps, event->ksymbol_event.addr); 716 map = map_groups__find(&machine->kmaps, event->ksymbol.addr);
714 if (!map) { 717 if (!map) {
715 map = dso__new_map(event->ksymbol_event.name); 718 map = dso__new_map(event->ksymbol.name);
716 if (!map) 719 if (!map)
717 return -ENOMEM; 720 return -ENOMEM;
718 721
719 map->start = event->ksymbol_event.addr; 722 map->start = event->ksymbol.addr;
720 map->end = map->start + event->ksymbol_event.len; 723 map->end = map->start + event->ksymbol.len;
721 map_groups__insert(&machine->kmaps, map); 724 map_groups__insert(&machine->kmaps, map);
722 } 725 }
723 726
724 sym = symbol__new(map->map_ip(map, map->start), 727 sym = symbol__new(map->map_ip(map, map->start),
725 event->ksymbol_event.len, 728 event->ksymbol.len,
726 0, 0, event->ksymbol_event.name); 729 0, 0, event->ksymbol.name);
727 if (!sym) 730 if (!sym)
728 return -ENOMEM; 731 return -ENOMEM;
729 dso__insert_symbol(map->dso, sym); 732 dso__insert_symbol(map->dso, sym);
@@ -736,7 +739,7 @@ static int machine__process_ksymbol_unregister(struct machine *machine,
736{ 739{
737 struct map *map; 740 struct map *map;
738 741
739 map = map_groups__find(&machine->kmaps, event->ksymbol_event.addr); 742 map = map_groups__find(&machine->kmaps, event->ksymbol.addr);
740 if (map) 743 if (map)
741 map_groups__remove(&machine->kmaps, map); 744 map_groups__remove(&machine->kmaps, map);
742 745
@@ -750,7 +753,7 @@ int machine__process_ksymbol(struct machine *machine __maybe_unused,
750 if (dump_trace) 753 if (dump_trace)
751 perf_event__fprintf_ksymbol(event, stdout); 754 perf_event__fprintf_ksymbol(event, stdout);
752 755
753 if (event->ksymbol_event.flags & PERF_RECORD_KSYMBOL_FLAGS_UNREGISTER) 756 if (event->ksymbol.flags & PERF_RECORD_KSYMBOL_FLAGS_UNREGISTER)
754 return machine__process_ksymbol_unregister(machine, event, 757 return machine__process_ksymbol_unregister(machine, event,
755 sample); 758 sample);
756 return machine__process_ksymbol_register(machine, event, sample); 759 return machine__process_ksymbol_register(machine, event, sample);
@@ -1919,7 +1922,7 @@ int machine__process_event(struct machine *machine, union perf_event *event,
1919 case PERF_RECORD_KSYMBOL: 1922 case PERF_RECORD_KSYMBOL:
1920 ret = machine__process_ksymbol(machine, event, sample); break; 1923 ret = machine__process_ksymbol(machine, event, sample); break;
1921 case PERF_RECORD_BPF_EVENT: 1924 case PERF_RECORD_BPF_EVENT:
1922 ret = machine__process_bpf_event(machine, event, sample); break; 1925 ret = machine__process_bpf(machine, event, sample); break;
1923 default: 1926 default:
1924 ret = -1; 1927 ret = -1;
1925 break; 1928 break;
diff --git a/tools/perf/util/machine.h b/tools/perf/util/machine.h
index 8b9d7157276d..7d69119d0b5d 100644
--- a/tools/perf/util/machine.h
+++ b/tools/perf/util/machine.h
@@ -14,6 +14,7 @@ struct branch_stack;
14struct evsel; 14struct evsel;
15struct perf_sample; 15struct perf_sample;
16struct symbol; 16struct symbol;
17struct target;
17struct thread; 18struct thread;
18union perf_event; 19union perf_event;
19 20
diff --git a/tools/perf/util/namespaces.c b/tools/perf/util/namespaces.c
index 46d3a7754897..99be15dd2b6b 100644
--- a/tools/perf/util/namespaces.c
+++ b/tools/perf/util/namespaces.c
@@ -19,7 +19,7 @@
19#include <asm/bug.h> 19#include <asm/bug.h>
20#include <linux/zalloc.h> 20#include <linux/zalloc.h>
21 21
22struct namespaces *namespaces__new(struct namespaces_event *event) 22struct namespaces *namespaces__new(struct perf_record_namespaces *event)
23{ 23{
24 struct namespaces *namespaces; 24 struct namespaces *namespaces;
25 u64 link_info_size = ((event ? event->nr_namespaces : NR_NAMESPACES) * 25 u64 link_info_size = ((event ? event->nr_namespaces : NR_NAMESPACES) *
diff --git a/tools/perf/util/namespaces.h b/tools/perf/util/namespaces.h
index 004430c0de93..40edef56cb52 100644
--- a/tools/perf/util/namespaces.h
+++ b/tools/perf/util/namespaces.h
@@ -17,7 +17,7 @@
17int setns(int fd, int nstype); 17int setns(int fd, int nstype);
18#endif 18#endif
19 19
20struct namespaces_event; 20struct perf_record_namespaces;
21 21
22struct namespaces { 22struct namespaces {
23 struct list_head list; 23 struct list_head list;
@@ -25,7 +25,7 @@ struct namespaces {
25 struct perf_ns_link_info link_info[]; 25 struct perf_ns_link_info link_info[];
26}; 26};
27 27
28struct namespaces *namespaces__new(struct namespaces_event *event); 28struct namespaces *namespaces__new(struct perf_record_namespaces *event);
29void namespaces__free(struct namespaces *namespaces); 29void namespaces__free(struct namespaces *namespaces);
30 30
31struct nsinfo { 31struct nsinfo {
diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
index 75ecc32a4427..59974e901232 100644
--- a/tools/perf/util/python.c
+++ b/tools/perf/util/python.c
@@ -116,12 +116,12 @@ static PyMemberDef pyrf_mmap_event__members[] = {
116 sample_members 116 sample_members
117 member_def(perf_event_header, type, T_UINT, "event type"), 117 member_def(perf_event_header, type, T_UINT, "event type"),
118 member_def(perf_event_header, misc, T_UINT, "event misc"), 118 member_def(perf_event_header, misc, T_UINT, "event misc"),
119 member_def(mmap_event, pid, T_UINT, "event pid"), 119 member_def(perf_record_mmap, pid, T_UINT, "event pid"),
120 member_def(mmap_event, tid, T_UINT, "event tid"), 120 member_def(perf_record_mmap, tid, T_UINT, "event tid"),
121 member_def(mmap_event, start, T_ULONGLONG, "start of the map"), 121 member_def(perf_record_mmap, start, T_ULONGLONG, "start of the map"),
122 member_def(mmap_event, len, T_ULONGLONG, "map length"), 122 member_def(perf_record_mmap, len, T_ULONGLONG, "map length"),
123 member_def(mmap_event, pgoff, T_ULONGLONG, "page offset"), 123 member_def(perf_record_mmap, pgoff, T_ULONGLONG, "page offset"),
124 member_def(mmap_event, filename, T_STRING_INPLACE, "backing store"), 124 member_def(perf_record_mmap, filename, T_STRING_INPLACE, "backing store"),
125 { .name = NULL, }, 125 { .name = NULL, },
126}; 126};
127 127
@@ -130,8 +130,8 @@ static PyObject *pyrf_mmap_event__repr(struct pyrf_event *pevent)
130 PyObject *ret; 130 PyObject *ret;
131 char *s; 131 char *s;
132 132
133 if (asprintf(&s, "{ type: mmap, pid: %u, tid: %u, start: %#" PRIx64 ", " 133 if (asprintf(&s, "{ type: mmap, pid: %u, tid: %u, start: %#" PRI_lx64 ", "
134 "length: %#" PRIx64 ", offset: %#" PRIx64 ", " 134 "length: %#" PRI_lx64 ", offset: %#" PRI_lx64 ", "
135 "filename: %s }", 135 "filename: %s }",
136 pevent->event.mmap.pid, pevent->event.mmap.tid, 136 pevent->event.mmap.pid, pevent->event.mmap.tid,
137 pevent->event.mmap.start, pevent->event.mmap.len, 137 pevent->event.mmap.start, pevent->event.mmap.len,
@@ -159,18 +159,18 @@ static char pyrf_task_event__doc[] = PyDoc_STR("perf task (fork/exit) event obje
159static PyMemberDef pyrf_task_event__members[] = { 159static PyMemberDef pyrf_task_event__members[] = {
160 sample_members 160 sample_members
161 member_def(perf_event_header, type, T_UINT, "event type"), 161 member_def(perf_event_header, type, T_UINT, "event type"),
162 member_def(fork_event, pid, T_UINT, "event pid"), 162 member_def(perf_record_fork, pid, T_UINT, "event pid"),
163 member_def(fork_event, ppid, T_UINT, "event ppid"), 163 member_def(perf_record_fork, ppid, T_UINT, "event ppid"),
164 member_def(fork_event, tid, T_UINT, "event tid"), 164 member_def(perf_record_fork, tid, T_UINT, "event tid"),
165 member_def(fork_event, ptid, T_UINT, "event ptid"), 165 member_def(perf_record_fork, ptid, T_UINT, "event ptid"),
166 member_def(fork_event, time, T_ULONGLONG, "timestamp"), 166 member_def(perf_record_fork, time, T_ULONGLONG, "timestamp"),
167 { .name = NULL, }, 167 { .name = NULL, },
168}; 168};
169 169
170static PyObject *pyrf_task_event__repr(struct pyrf_event *pevent) 170static PyObject *pyrf_task_event__repr(struct pyrf_event *pevent)
171{ 171{
172 return _PyUnicode_FromFormat("{ type: %s, pid: %u, ppid: %u, tid: %u, " 172 return _PyUnicode_FromFormat("{ type: %s, pid: %u, ppid: %u, tid: %u, "
173 "ptid: %u, time: %" PRIu64 "}", 173 "ptid: %u, time: %" PRI_lu64 "}",
174 pevent->event.header.type == PERF_RECORD_FORK ? "fork" : "exit", 174 pevent->event.header.type == PERF_RECORD_FORK ? "fork" : "exit",
175 pevent->event.fork.pid, 175 pevent->event.fork.pid,
176 pevent->event.fork.ppid, 176 pevent->event.fork.ppid,
@@ -194,9 +194,9 @@ static char pyrf_comm_event__doc[] = PyDoc_STR("perf comm event object.");
194static PyMemberDef pyrf_comm_event__members[] = { 194static PyMemberDef pyrf_comm_event__members[] = {
195 sample_members 195 sample_members
196 member_def(perf_event_header, type, T_UINT, "event type"), 196 member_def(perf_event_header, type, T_UINT, "event type"),
197 member_def(comm_event, pid, T_UINT, "event pid"), 197 member_def(perf_record_comm, pid, T_UINT, "event pid"),
198 member_def(comm_event, tid, T_UINT, "event tid"), 198 member_def(perf_record_comm, tid, T_UINT, "event tid"),
199 member_def(comm_event, comm, T_STRING_INPLACE, "process name"), 199 member_def(perf_record_comm, comm, T_STRING_INPLACE, "process name"),
200 { .name = NULL, }, 200 { .name = NULL, },
201}; 201};
202 202
@@ -223,18 +223,18 @@ static char pyrf_throttle_event__doc[] = PyDoc_STR("perf throttle event object."
223static PyMemberDef pyrf_throttle_event__members[] = { 223static PyMemberDef pyrf_throttle_event__members[] = {
224 sample_members 224 sample_members
225 member_def(perf_event_header, type, T_UINT, "event type"), 225 member_def(perf_event_header, type, T_UINT, "event type"),
226 member_def(throttle_event, time, T_ULONGLONG, "timestamp"), 226 member_def(perf_record_throttle, time, T_ULONGLONG, "timestamp"),
227 member_def(throttle_event, id, T_ULONGLONG, "event id"), 227 member_def(perf_record_throttle, id, T_ULONGLONG, "event id"),
228 member_def(throttle_event, stream_id, T_ULONGLONG, "event stream id"), 228 member_def(perf_record_throttle, stream_id, T_ULONGLONG, "event stream id"),
229 { .name = NULL, }, 229 { .name = NULL, },
230}; 230};
231 231
232static PyObject *pyrf_throttle_event__repr(struct pyrf_event *pevent) 232static PyObject *pyrf_throttle_event__repr(struct pyrf_event *pevent)
233{ 233{
234 struct throttle_event *te = (struct throttle_event *)(&pevent->event.header + 1); 234 struct perf_record_throttle *te = (struct perf_record_throttle *)(&pevent->event.header + 1);
235 235
236 return _PyUnicode_FromFormat("{ type: %sthrottle, time: %" PRIu64 ", id: %" PRIu64 236 return _PyUnicode_FromFormat("{ type: %sthrottle, time: %" PRI_lu64 ", id: %" PRI_lu64
237 ", stream_id: %" PRIu64 " }", 237 ", stream_id: %" PRI_lu64 " }",
238 pevent->event.header.type == PERF_RECORD_THROTTLE ? "" : "un", 238 pevent->event.header.type == PERF_RECORD_THROTTLE ? "" : "un",
239 te->time, te->id, te->stream_id); 239 te->time, te->id, te->stream_id);
240} 240}
@@ -253,8 +253,8 @@ static char pyrf_lost_event__doc[] = PyDoc_STR("perf lost event object.");
253 253
254static PyMemberDef pyrf_lost_event__members[] = { 254static PyMemberDef pyrf_lost_event__members[] = {
255 sample_members 255 sample_members
256 member_def(lost_event, id, T_ULONGLONG, "event id"), 256 member_def(perf_record_lost, id, T_ULONGLONG, "event id"),
257 member_def(lost_event, lost, T_ULONGLONG, "number of lost events"), 257 member_def(perf_record_lost, lost, T_ULONGLONG, "number of lost events"),
258 { .name = NULL, }, 258 { .name = NULL, },
259}; 259};
260 260
@@ -263,8 +263,8 @@ static PyObject *pyrf_lost_event__repr(struct pyrf_event *pevent)
263 PyObject *ret; 263 PyObject *ret;
264 char *s; 264 char *s;
265 265
266 if (asprintf(&s, "{ type: lost, id: %#" PRIx64 ", " 266 if (asprintf(&s, "{ type: lost, id: %#" PRI_lx64 ", "
267 "lost: %#" PRIx64 " }", 267 "lost: %#" PRI_lx64 " }",
268 pevent->event.lost.id, pevent->event.lost.lost) < 0) { 268 pevent->event.lost.id, pevent->event.lost.lost) < 0) {
269 ret = PyErr_NoMemory(); 269 ret = PyErr_NoMemory();
270 } else { 270 } else {
@@ -288,8 +288,8 @@ static char pyrf_read_event__doc[] = PyDoc_STR("perf read event object.");
288 288
289static PyMemberDef pyrf_read_event__members[] = { 289static PyMemberDef pyrf_read_event__members[] = {
290 sample_members 290 sample_members
291 member_def(read_event, pid, T_UINT, "event pid"), 291 member_def(perf_record_read, pid, T_UINT, "event pid"),
292 member_def(read_event, tid, T_UINT, "event tid"), 292 member_def(perf_record_read, tid, T_UINT, "event tid"),
293 { .name = NULL, }, 293 { .name = NULL, },
294}; 294};
295 295
diff --git a/tools/perf/util/record.c b/tools/perf/util/record.c
index 51bbd0714e6d..574507d46c98 100644
--- a/tools/perf/util/record.c
+++ b/tools/perf/util/record.c
@@ -9,6 +9,7 @@
9#include <perf/cpumap.h> 9#include <perf/cpumap.h>
10#include "util.h" 10#include "util.h"
11#include "cloexec.h" 11#include "cloexec.h"
12#include "record.h"
12 13
13typedef void (*setup_probe_fn_t)(struct evsel *evsel); 14typedef void (*setup_probe_fn_t)(struct evsel *evsel);
14 15
diff --git a/tools/perf/util/record.h b/tools/perf/util/record.h
new file mode 100644
index 000000000000..00275afc524d
--- /dev/null
+++ b/tools/perf/util/record.h
@@ -0,0 +1,74 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _PERF_RECORD_H
3#define _PERF_RECORD_H
4
5#include <time.h>
6#include <stdbool.h>
7#include <linux/types.h>
8#include <linux/stddef.h>
9#include <linux/perf_event.h>
10#include "util/target.h"
11
12struct option;
13
14struct record_opts {
15 struct target target;
16 bool group;
17 bool inherit_stat;
18 bool no_buffering;
19 bool no_inherit;
20 bool no_inherit_set;
21 bool no_samples;
22 bool raw_samples;
23 bool sample_address;
24 bool sample_phys_addr;
25 bool sample_weight;
26 bool sample_time;
27 bool sample_time_set;
28 bool sample_cpu;
29 bool period;
30 bool period_set;
31 bool running_time;
32 bool full_auxtrace;
33 bool auxtrace_snapshot_mode;
34 bool auxtrace_snapshot_on_exit;
35 bool record_namespaces;
36 bool record_switch_events;
37 bool all_kernel;
38 bool all_user;
39 bool kernel_callchains;
40 bool user_callchains;
41 bool tail_synthesize;
42 bool overwrite;
43 bool ignore_missing_thread;
44 bool strict_freq;
45 bool sample_id;
46 bool no_bpf_event;
47 unsigned int freq;
48 unsigned int mmap_pages;
49 unsigned int auxtrace_mmap_pages;
50 unsigned int user_freq;
51 u64 branch_stack;
52 u64 sample_intr_regs;
53 u64 sample_user_regs;
54 u64 default_interval;
55 u64 user_interval;
56 size_t auxtrace_snapshot_size;
57 const char *auxtrace_snapshot_opts;
58 bool sample_transaction;
59 unsigned initial_delay;
60 bool use_clockid;
61 clockid_t clockid;
62 u64 clockid_res_ns;
63 int nr_cblocks;
64 int affinity;
65 int mmap_flush;
66 unsigned int comp_level;
67};
68
69extern const char * const *record_usage;
70extern struct option *record_options;
71
72int record__parse_freq(const struct option *opt, const char *str, int unset);
73
74#endif // _PERF_RECORD_H
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 82e0438a9160..5786e9c807c5 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -473,8 +473,8 @@ void perf_tool__fill_defaults(struct perf_tool *tool)
473 tool->context_switch = perf_event__process_switch; 473 tool->context_switch = perf_event__process_switch;
474 if (tool->ksymbol == NULL) 474 if (tool->ksymbol == NULL)
475 tool->ksymbol = perf_event__process_ksymbol; 475 tool->ksymbol = perf_event__process_ksymbol;
476 if (tool->bpf_event == NULL) 476 if (tool->bpf == NULL)
477 tool->bpf_event = perf_event__process_bpf_event; 477 tool->bpf = perf_event__process_bpf;
478 if (tool->read == NULL) 478 if (tool->read == NULL)
479 tool->read = process_event_sample_stub; 479 tool->read = process_event_sample_stub;
480 if (tool->throttle == NULL) 480 if (tool->throttle == NULL)
@@ -1254,13 +1254,13 @@ static void dump_sample(struct evsel *evsel, union perf_event *event,
1254 1254
1255static void dump_read(struct evsel *evsel, union perf_event *event) 1255static void dump_read(struct evsel *evsel, union perf_event *event)
1256{ 1256{
1257 struct read_event *read_event = &event->read; 1257 struct perf_record_read *read_event = &event->read;
1258 u64 read_format; 1258 u64 read_format;
1259 1259
1260 if (!dump_trace) 1260 if (!dump_trace)
1261 return; 1261 return;
1262 1262
1263 printf(": %d %d %s %" PRIu64 "\n", event->read.pid, event->read.tid, 1263 printf(": %d %d %s %" PRI_lu64 "\n", event->read.pid, event->read.tid,
1264 perf_evsel__name(evsel), 1264 perf_evsel__name(evsel),
1265 event->read.value); 1265 event->read.value);
1266 1266
@@ -1270,13 +1270,13 @@ static void dump_read(struct evsel *evsel, union perf_event *event)
1270 read_format = evsel->core.attr.read_format; 1270 read_format = evsel->core.attr.read_format;
1271 1271
1272 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) 1272 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED)
1273 printf("... time enabled : %" PRIu64 "\n", read_event->time_enabled); 1273 printf("... time enabled : %" PRI_lu64 "\n", read_event->time_enabled);
1274 1274
1275 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) 1275 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING)
1276 printf("... time running : %" PRIu64 "\n", read_event->time_running); 1276 printf("... time running : %" PRI_lu64 "\n", read_event->time_running);
1277 1277
1278 if (read_format & PERF_FORMAT_ID) 1278 if (read_format & PERF_FORMAT_ID)
1279 printf("... id : %" PRIu64 "\n", read_event->id); 1279 printf("... id : %" PRI_lu64 "\n", read_event->id);
1280} 1280}
1281 1281
1282static struct machine *machines__find_for_cpumode(struct machines *machines, 1282static struct machine *machines__find_for_cpumode(struct machines *machines,
@@ -1452,7 +1452,7 @@ static int machines__deliver_event(struct machines *machines,
1452 case PERF_RECORD_KSYMBOL: 1452 case PERF_RECORD_KSYMBOL:
1453 return tool->ksymbol(tool, event, sample, machine); 1453 return tool->ksymbol(tool, event, sample, machine);
1454 case PERF_RECORD_BPF_EVENT: 1454 case PERF_RECORD_BPF_EVENT:
1455 return tool->bpf_event(tool, event, sample, machine); 1455 return tool->bpf(tool, event, sample, machine);
1456 default: 1456 default:
1457 ++evlist->stats.nr_unknown_events; 1457 ++evlist->stats.nr_unknown_events;
1458 return -1; 1458 return -1;
diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c
index f9a38a1dd4d1..83eb3fa6f941 100644
--- a/tools/perf/util/sort.c
+++ b/tools/perf/util/sort.c
@@ -6,12 +6,14 @@
6#include <linux/time64.h> 6#include <linux/time64.h>
7#include "sort.h" 7#include "sort.h"
8#include "hist.h" 8#include "hist.h"
9#include "cacheline.h"
9#include "comm.h" 10#include "comm.h"
10#include "map.h" 11#include "map.h"
11#include "symbol.h" 12#include "symbol.h"
12#include "thread.h" 13#include "thread.h"
13#include "evsel.h" 14#include "evsel.h"
14#include "evlist.h" 15#include "evlist.h"
16#include "srcline.h"
15#include "strlist.h" 17#include "strlist.h"
16#include "strbuf.h" 18#include "strbuf.h"
17#include <traceevent/event-parse.h> 19#include <traceevent/event-parse.h>
@@ -668,17 +670,11 @@ sort__time_cmp(struct hist_entry *left, struct hist_entry *right)
668static int hist_entry__time_snprintf(struct hist_entry *he, char *bf, 670static int hist_entry__time_snprintf(struct hist_entry *he, char *bf,
669 size_t size, unsigned int width) 671 size_t size, unsigned int width)
670{ 672{
671 unsigned long secs;
672 unsigned long long nsecs;
673 char he_time[32]; 673 char he_time[32];
674 674
675 nsecs = he->time;
676 secs = nsecs / NSEC_PER_SEC;
677 nsecs -= secs * NSEC_PER_SEC;
678
679 if (symbol_conf.nanosecs) 675 if (symbol_conf.nanosecs)
680 snprintf(he_time, sizeof he_time, "%5lu.%09llu: ", 676 timestamp__scnprintf_nsec(he->time, he_time,
681 secs, nsecs); 677 sizeof(he_time));
682 else 678 else
683 timestamp__scnprintf_usec(he->time, he_time, 679 timestamp__scnprintf_usec(he->time, he_time,
684 sizeof(he_time)); 680 sizeof(he_time));
diff --git a/tools/perf/util/sort.h b/tools/perf/util/sort.h
index 5e34676a98e8..3d7cef73924c 100644
--- a/tools/perf/util/sort.h
+++ b/tools/perf/util/sort.h
@@ -1,29 +1,18 @@
1/* SPDX-License-Identifier: GPL-2.0 */ 1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef __PERF_SORT_H 2#ifndef __PERF_SORT_H
3#define __PERF_SORT_H 3#define __PERF_SORT_H
4#include "../builtin.h"
5
6#include <regex.h> 4#include <regex.h>
7 5#include <stdbool.h>
8#include "color.h"
9#include <linux/list.h> 6#include <linux/list.h>
10#include "cache.h"
11#include <linux/rbtree.h> 7#include <linux/rbtree.h>
12#include "map_symbol.h" 8#include "map_symbol.h"
13#include "symbol_conf.h" 9#include "symbol_conf.h"
14#include "string.h"
15#include "callchain.h" 10#include "callchain.h"
16#include "values.h" 11#include "values.h"
17 12
18#include "../perf.h"
19#include "debug.h"
20#include "header.h"
21
22#include <subcmd/parse-options.h>
23#include "parse-events.h"
24#include "hist.h" 13#include "hist.h"
25#include "srcline.h"
26 14
15struct option;
27struct thread; 16struct thread;
28 17
29extern regex_t parent_regex; 18extern regex_t parent_regex;
@@ -204,18 +193,6 @@ static inline float hist_entry__get_percent_limit(struct hist_entry *he)
204 return period * 100.0 / total_period; 193 return period * 100.0 / total_period;
205} 194}
206 195
207static inline u64 cl_address(u64 address)
208{
209 /* return the cacheline of the address */
210 return (address & ~(cacheline_size() - 1));
211}
212
213static inline u64 cl_offset(u64 address)
214{
215 /* return the cacheline of the address */
216 return (address & (cacheline_size() - 1));
217}
218
219enum sort_mode { 196enum sort_mode {
220 SORT_MODE__NORMAL, 197 SORT_MODE__NORMAL,
221 SORT_MODE__BRANCH, 198 SORT_MODE__BRANCH,
diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c
index 51d6781aa90d..1461dac2322d 100644
--- a/tools/perf/util/stat-display.c
+++ b/tools/perf/util/stat-display.c
@@ -14,7 +14,6 @@
14#include "string2.h" 14#include "string2.h"
15#include <linux/ctype.h> 15#include <linux/ctype.h>
16#include "cgroup.h" 16#include "cgroup.h"
17#include <math.h>
18#include <api/fs/fs.h> 17#include <api/fs/fs.h>
19 18
20#define CNTR_NOT_SUPPORTED "<not supported>" 19#define CNTR_NOT_SUPPORTED "<not supported>"
diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c
index 0cbfd1eca1dd..f985336b3a22 100644
--- a/tools/perf/util/stat.c
+++ b/tools/perf/util/stat.c
@@ -4,6 +4,7 @@
4#include <math.h> 4#include <math.h>
5#include "counts.h" 5#include "counts.h"
6#include "stat.h" 6#include "stat.h"
7#include "target.h"
7#include "evlist.h" 8#include "evlist.h"
8#include "evsel.h" 9#include "evsel.h"
9#include "thread_map.h" 10#include "thread_map.h"
diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h
index bcb376e1b3a7..14fe3e548229 100644
--- a/tools/perf/util/stat.h
+++ b/tools/perf/util/stat.h
@@ -5,13 +5,12 @@
5#include <linux/types.h> 5#include <linux/types.h>
6#include <stdio.h> 6#include <stdio.h>
7#include <sys/types.h> 7#include <sys/types.h>
8#include <sys/time.h>
9#include <sys/resource.h> 8#include <sys/resource.h>
10#include <sys/wait.h>
11#include "rblist.h" 9#include "rblist.h"
12#include "perf.h"
13#include "event.h" 10#include "event.h"
14 11
12struct timespec;
13
15struct stats { 14struct stats {
16 double n, mean, M2; 15 double n, mean, M2;
17 u64 max, min; 16 u64 max, min;
@@ -199,6 +198,8 @@ int perf_stat_process_counter(struct perf_stat_config *config,
199struct perf_tool; 198struct perf_tool;
200union perf_event; 199union perf_event;
201struct perf_session; 200struct perf_session;
201struct target;
202
202int perf_event__process_stat_event(struct perf_session *session, 203int perf_event__process_stat_event(struct perf_session *session,
203 union perf_event *event); 204 union perf_event *event);
204 205
diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c
index bbf7816cba31..dbcb9cfb0f2f 100644
--- a/tools/perf/util/thread.c
+++ b/tools/perf/util/thread.c
@@ -169,7 +169,7 @@ struct namespaces *thread__namespaces(struct thread *thread)
169} 169}
170 170
171static int __thread__set_namespaces(struct thread *thread, u64 timestamp, 171static int __thread__set_namespaces(struct thread *thread, u64 timestamp,
172 struct namespaces_event *event) 172 struct perf_record_namespaces *event)
173{ 173{
174 struct namespaces *new, *curr = __thread__namespaces(thread); 174 struct namespaces *new, *curr = __thread__namespaces(thread);
175 175
@@ -193,7 +193,7 @@ static int __thread__set_namespaces(struct thread *thread, u64 timestamp,
193} 193}
194 194
195int thread__set_namespaces(struct thread *thread, u64 timestamp, 195int thread__set_namespaces(struct thread *thread, u64 timestamp,
196 struct namespaces_event *event) 196 struct perf_record_namespaces *event)
197{ 197{
198 int ret; 198 int ret;
199 199
diff --git a/tools/perf/util/thread.h b/tools/perf/util/thread.h
index bf06113be4f3..51bdb9a7af7f 100644
--- a/tools/perf/util/thread.h
+++ b/tools/perf/util/thread.h
@@ -16,7 +16,7 @@
16 16
17struct addr_location; 17struct addr_location;
18struct map; 18struct map;
19struct namespaces_event; 19struct perf_record_namespaces;
20struct thread_stack; 20struct thread_stack;
21struct unwind_libunwind_ops; 21struct unwind_libunwind_ops;
22 22
@@ -74,7 +74,7 @@ static inline void thread__exited(struct thread *thread)
74 74
75struct namespaces *thread__namespaces(struct thread *thread); 75struct namespaces *thread__namespaces(struct thread *thread);
76int thread__set_namespaces(struct thread *thread, u64 timestamp, 76int thread__set_namespaces(struct thread *thread, u64 timestamp,
77 struct namespaces_event *event); 77 struct perf_record_namespaces *event);
78 78
79int __thread__set_comm(struct thread *thread, const char *comm, u64 timestamp, 79int __thread__set_comm(struct thread *thread, const char *comm, u64 timestamp,
80 bool exec); 80 bool exec);
diff --git a/tools/perf/util/tool.h b/tools/perf/util/tool.h
index 7f95dd1d6883..2abbf668b8de 100644
--- a/tools/perf/util/tool.h
+++ b/tools/perf/util/tool.h
@@ -56,7 +56,7 @@ struct perf_tool {
56 throttle, 56 throttle,
57 unthrottle, 57 unthrottle,
58 ksymbol, 58 ksymbol,
59 bpf_event; 59 bpf;
60 60
61 event_attr_op attr; 61 event_attr_op attr;
62 event_attr_op event_update; 62 event_attr_op event_update;
diff --git a/tools/perf/util/top.h b/tools/perf/util/top.h
index dc4bb6e52a83..7367433e767a 100644
--- a/tools/perf/util/top.h
+++ b/tools/perf/util/top.h
@@ -5,6 +5,7 @@
5#include "tool.h" 5#include "tool.h"
6#include "evswitch.h" 6#include "evswitch.h"
7#include "annotate.h" 7#include "annotate.h"
8#include "record.h"
8#include <linux/types.h> 9#include <linux/types.h>
9#include <stddef.h> 10#include <stddef.h>
10#include <stdbool.h> 11#include <stdbool.h>
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c
index 6fd130a5d8f2..44211e483fbf 100644
--- a/tools/perf/util/util.c
+++ b/tools/perf/util/util.c
@@ -43,26 +43,6 @@ void perf_set_multithreaded(void)
43 43
44unsigned int page_size; 44unsigned int page_size;
45 45
46#ifdef _SC_LEVEL1_DCACHE_LINESIZE
47#define cache_line_size(cacheline_sizep) *cacheline_sizep = sysconf(_SC_LEVEL1_DCACHE_LINESIZE)
48#else
49static void cache_line_size(int *cacheline_sizep)
50{
51 if (sysfs__read_int("devices/system/cpu/cpu0/cache/index0/coherency_line_size", cacheline_sizep))
52 pr_debug("cannot determine cache line size");
53}
54#endif
55
56int cacheline_size(void)
57{
58 static int size;
59
60 if (!size)
61 cache_line_size(&size);
62
63 return size;
64}
65
66int sysctl_perf_event_max_stack = PERF_MAX_STACK_DEPTH; 46int sysctl_perf_event_max_stack = PERF_MAX_STACK_DEPTH;
67int sysctl_perf_event_max_contexts_per_stack = PERF_MAX_CONTEXTS_PER_STACK; 47int sysctl_perf_event_max_contexts_per_stack = PERF_MAX_CONTEXTS_PER_STACK;
68 48
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index 0dab140c6517..45a5c6f20197 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -34,7 +34,6 @@ int copyfile_offset(int ifd, loff_t off_in, int ofd, loff_t off_out, u64 size);
34size_t hex_width(u64 v); 34size_t hex_width(u64 v);
35 35
36extern unsigned int page_size; 36extern unsigned int page_size;
37int __pure cacheline_size(void);
38 37
39int sysctl__max_stack(void); 38int sysctl__max_stack(void);
40 39