diff options
69 files changed, 493 insertions, 427 deletions
diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/cs-etm.c index c73da3245b67..a185dab2d903 100644 --- a/tools/perf/arch/arm/util/cs-etm.c +++ b/tools/perf/arch/arm/util/cs-etm.c @@ -15,7 +15,7 @@ #include <linux/zalloc.h> #include "cs-etm.h" -#include "../../perf.h" +#include "../../util/record.h" #include "../../util/auxtrace.h" #include "../../util/cpumap.h" #include "../../util/evlist.h" diff --git a/tools/perf/arch/arm64/util/arm-spe.c b/tools/perf/arch/arm64/util/arm-spe.c index 00915b8fd05b..cdd5c0c84183 100644 --- a/tools/perf/arch/arm64/util/arm-spe.c +++ b/tools/perf/arch/arm64/util/arm-spe.c @@ -19,6 +19,7 @@ #include "../../util/pmu.h" #include "../../util/debug.h" #include "../../util/auxtrace.h" +#include "../../util/record.h" #include "../../util/arm-spe.h" #define KiB(x) ((x) * 1024) diff --git a/tools/perf/arch/s390/util/auxtrace.c b/tools/perf/arch/s390/util/auxtrace.c index cab46f517b83..f32d7a72d039 100644 --- a/tools/perf/arch/s390/util/auxtrace.c +++ b/tools/perf/arch/s390/util/auxtrace.c @@ -8,6 +8,7 @@ #include "../../util/evlist.h" #include "../../util/auxtrace.h" #include "../../util/evsel.h" +#include "../../util/record.h" #define PERF_EVENT_CPUM_SF 0xB0000 /* Event: Basic-sampling */ #define PERF_EVENT_CPUM_SF_DIAG 0xBD000 /* Event: Combined-sampling */ diff --git a/tools/perf/arch/x86/tests/perf-time-to-tsc.c b/tools/perf/arch/x86/tests/perf-time-to-tsc.c index 582182d98a7f..02776109ba46 100644 --- a/tools/perf/arch/x86/tests/perf-time-to-tsc.c +++ b/tools/perf/arch/x86/tests/perf-time-to-tsc.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 #include <errno.h> #include <inttypes.h> +#include <stdbool.h> #include <stdio.h> #include <unistd.h> #include <linux/types.h> @@ -13,6 +14,7 @@ #include "evsel.h" #include "thread_map.h" #include "cpumap.h" +#include "record.h" #include "tsc.h" #include "tests/tests.h" diff --git a/tools/perf/arch/x86/util/intel-bts.c b/tools/perf/arch/x86/util/intel-bts.c index 2d5d8a12dd1f..1f2cf612bc9c 100644 --- a/tools/perf/arch/x86/util/intel-bts.c +++ b/tools/perf/arch/x86/util/intel-bts.c @@ -17,6 +17,7 @@ #include "../../util/session.h" #include "../../util/pmu.h" #include "../../util/debug.h" +#include "../../util/record.h" #include "../../util/tsc.h" #include "../../util/auxtrace.h" #include "../../util/intel-bts.h" diff --git a/tools/perf/arch/x86/util/intel-pt.c b/tools/perf/arch/x86/util/intel-pt.c index c72a77a82b39..44cfe72c1a4c 100644 --- a/tools/perf/arch/x86/util/intel-pt.c +++ b/tools/perf/arch/x86/util/intel-pt.c @@ -13,7 +13,6 @@ #include <linux/zalloc.h> #include <cpuid.h> -#include "../../perf.h" #include "../../util/session.h" #include "../../util/event.h" #include "../../util/evlist.h" @@ -24,6 +23,8 @@ #include "../../util/pmu.h" #include "../../util/debug.h" #include "../../util/auxtrace.h" +#include "../../util/record.h" +#include "../../util/target.h" #include "../../util/tsc.h" #include "../../util/intel-pt.h" diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c index 211143720078..73782d99ee5a 100644 --- a/tools/perf/builtin-c2c.c +++ b/tools/perf/builtin-c2c.c @@ -26,6 +26,7 @@ #include "hist.h" #include "sort.h" #include "tool.h" +#include "cacheline.h" #include "data.h" #include "event.h" #include "evlist.h" diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c index e91c0d798181..51c37e53b3d8 100644 --- a/tools/perf/builtin-diff.c +++ b/tools/perf/builtin-diff.c @@ -15,6 +15,7 @@ #include "util/session.h" #include "util/tool.h" #include "util/sort.h" +#include "util/srcline.h" #include "util/symbol.h" #include "util/data.h" #include "util/config.h" @@ -22,6 +23,7 @@ #include "util/annotate.h" #include "util/map.h" #include <linux/zalloc.h> +#include <subcmd/parse-options.h> #include <errno.h> #include <inttypes.h> diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index f71631f2bcb5..359bb8f33e57 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -8,8 +8,6 @@ */ #include "builtin.h" -#include "perf.h" - #include "util/build-id.h" #include <subcmd/parse-options.h> #include "util/parse-events.h" @@ -22,9 +20,11 @@ #include "util/evlist.h" #include "util/evsel.h" #include "util/debug.h" +#include "util/target.h" #include "util/session.h" #include "util/tool.h" #include "util/symbol.h" +#include "util/record.h" #include "util/cpumap.h" #include "util/thread_map.h" #include "util/data.h" diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index 79dfb1139f94..318b0b95c14c 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c @@ -28,6 +28,7 @@ #include "util/evswitch.h" #include "util/header.h" #include "util/session.h" +#include "util/srcline.h" #include "util/tool.h" #include <subcmd/parse-options.h> diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index 0d6b4c3b1a51..025151dcb651 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c @@ -2643,7 +2643,7 @@ static int process_lost(struct perf_tool *tool __maybe_unused, timestamp__scnprintf_usec(sample->time, tstr, sizeof(tstr)); printf("%15s ", tstr); - printf("lost %" PRIu64 " events on cpu %d\n", event->lost.lost, sample->cpu); + printf("lost %" PRI_lu64 " events on cpu %d\n", event->lost.lost, sample->cpu); return 0; } diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 9b93ddeaeafa..51e7e6d0eee6 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -1,7 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 #include "builtin.h" -#include "perf.h" #include "util/cache.h" #include "util/counts.h" #include "util/debug.h" @@ -12,6 +11,7 @@ #include "util/session.h" #include "util/tool.h" #include "util/map.h" +#include "util/srcline.h" #include "util/symbol.h" #include "util/thread.h" #include "util/trace-event.h" @@ -51,6 +51,7 @@ #include <unistd.h> #include <subcmd/pager.h> #include <perf/evlist.h> +#include "util/record.h" #include <linux/ctype.h> @@ -2491,8 +2492,8 @@ static int __cmd_script(struct perf_script *script) script->tool.finished_round = process_finished_round_event; } if (script->show_bpf_events) { - script->tool.ksymbol = process_bpf_events; - script->tool.bpf_event = process_bpf_events; + script->tool.ksymbol = process_bpf_events; + script->tool.bpf = process_bpf_events; } if (perf_script__setup_per_event_dump(script)) { diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 8a4f1a7d0cba..6ab13f466827 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -40,7 +40,6 @@ * Jaswinder Singh Rajput <jaswinder@kernel.org> */ -#include "perf.h" #include "builtin.h" #include "util/cgroup.h" #include <subcmd/parse-options.h> @@ -62,6 +61,7 @@ #include "util/tool.h" #include "util/string2.h" #include "util/metricgroup.h" +#include "util/target.h" #include "util/top.h" #include "asm/bug.h" diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index de126258ca10..8ea62fd2591d 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -14,6 +14,7 @@ * http://lwn.net/Articles/415728/ ("Announcing a new utility: 'trace'") */ +#include "util/record.h" #include <traceevent/event-parse.h> #include <api/fs/tracing_path.h> #include <bpf/bpf.h> diff --git a/tools/perf/examples/bpf/augmented_raw_syscalls.c b/tools/perf/examples/bpf/augmented_raw_syscalls.c index 79787cf4fce9..b80437971d80 100644 --- a/tools/perf/examples/bpf/augmented_raw_syscalls.c +++ b/tools/perf/examples/bpf/augmented_raw_syscalls.c @@ -60,7 +60,7 @@ struct syscall_exit_args { long ret; }; -struct augmented_filename { +struct augmented_arg { unsigned int size; int err; char value[PATH_MAX]; @@ -72,41 +72,52 @@ struct augmented_args_payload { struct syscall_enter_args args; union { struct { - struct augmented_filename filename, - filename2; + struct augmented_arg arg, arg2; }; struct sockaddr_storage saddr; }; }; +// We need more tmp space than the BPF stack can give us bpf_map(augmented_args_tmp, PERCPU_ARRAY, int, struct augmented_args_payload, 1); +static inline struct augmented_args_payload *augmented_args_payload(void) +{ + int key = 0; + return bpf_map_lookup_elem(&augmented_args_tmp, &key); +} + +static inline int augmented__output(void *ctx, struct augmented_args_payload *args, int len) +{ + /* If perf_event_output fails, return non-zero so that it gets recorded unaugmented */ + return perf_event_output(ctx, &__augmented_syscalls__, BPF_F_CURRENT_CPU, args, len); +} + static inline -unsigned int augmented_filename__read(struct augmented_filename *augmented_filename, - const void *filename_arg, unsigned int filename_len) +unsigned int augmented_arg__read_str(struct augmented_arg *augmented_arg, const void *arg, unsigned int arg_len) { - unsigned int len = sizeof(*augmented_filename); - int size = probe_read_str(&augmented_filename->value, filename_len, filename_arg); + unsigned int augmented_len = sizeof(*augmented_arg); + int string_len = probe_read_str(&augmented_arg->value, arg_len, arg); - augmented_filename->size = augmented_filename->err = 0; + augmented_arg->size = augmented_arg->err = 0; /* * probe_read_str may return < 0, e.g. -EFAULT - * So we leave that in the augmented_filename->size that userspace will + * So we leave that in the augmented_arg->size that userspace will */ - if (size > 0) { - len -= sizeof(augmented_filename->value) - size; - len &= sizeof(augmented_filename->value) - 1; - augmented_filename->size = size; + if (string_len > 0) { + augmented_len -= sizeof(augmented_arg->value) - string_len; + augmented_len &= sizeof(augmented_arg->value) - 1; + augmented_arg->size = string_len; } else { /* * So that username notice the error while still being able * to skip this augmented arg record */ - augmented_filename->err = size; - len = offsetof(struct augmented_filename, value); + augmented_arg->err = string_len; + augmented_len = offsetof(struct augmented_arg, value); } - return len; + return augmented_len; } SEC("!raw_syscalls:unaugmented") @@ -124,8 +135,7 @@ int syscall_unaugmented(struct syscall_enter_args *args) SEC("!syscalls:sys_enter_connect") int sys_enter_connect(struct syscall_enter_args *args) { - int key = 0; - struct augmented_args_payload *augmented_args = bpf_map_lookup_elem(&augmented_args_tmp, &key); + struct augmented_args_payload *augmented_args = augmented_args_payload(); const void *sockaddr_arg = (const void *)args->args[1]; unsigned int socklen = args->args[2]; unsigned int len = sizeof(augmented_args->args); @@ -138,15 +148,13 @@ int sys_enter_connect(struct syscall_enter_args *args) probe_read(&augmented_args->saddr, socklen, sockaddr_arg); - /* If perf_event_output fails, return non-zero so that it gets recorded unaugmented */ - return perf_event_output(args, &__augmented_syscalls__, BPF_F_CURRENT_CPU, augmented_args, len + socklen); + return augmented__output(args, augmented_args, len + socklen); } SEC("!syscalls:sys_enter_sendto") int sys_enter_sendto(struct syscall_enter_args *args) { - int key = 0; - struct augmented_args_payload *augmented_args = bpf_map_lookup_elem(&augmented_args_tmp, &key); + struct augmented_args_payload *augmented_args = augmented_args_payload(); const void *sockaddr_arg = (const void *)args->args[4]; unsigned int socklen = args->args[5]; unsigned int len = sizeof(augmented_args->args); @@ -159,49 +167,43 @@ int sys_enter_sendto(struct syscall_enter_args *args) probe_read(&augmented_args->saddr, socklen, sockaddr_arg); - /* If perf_event_output fails, return non-zero so that it gets recorded unaugmented */ - return perf_event_output(args, &__augmented_syscalls__, BPF_F_CURRENT_CPU, augmented_args, len + socklen); + return augmented__output(args, augmented_args, len + socklen); } SEC("!syscalls:sys_enter_open") int sys_enter_open(struct syscall_enter_args *args) { - int key = 0; - struct augmented_args_payload *augmented_args = bpf_map_lookup_elem(&augmented_args_tmp, &key); + struct augmented_args_payload *augmented_args = augmented_args_payload(); const void *filename_arg = (const void *)args->args[0]; unsigned int len = sizeof(augmented_args->args); if (augmented_args == NULL) return 1; /* Failure: don't filter */ - len += augmented_filename__read(&augmented_args->filename, filename_arg, sizeof(augmented_args->filename.value)); + len += augmented_arg__read_str(&augmented_args->arg, filename_arg, sizeof(augmented_args->arg.value)); - /* If perf_event_output fails, return non-zero so that it gets recorded unaugmented */ - return perf_event_output(args, &__augmented_syscalls__, BPF_F_CURRENT_CPU, augmented_args, len); + return augmented__output(args, augmented_args, len); } SEC("!syscalls:sys_enter_openat") int sys_enter_openat(struct syscall_enter_args *args) { - int key = 0; - struct augmented_args_payload *augmented_args = bpf_map_lookup_elem(&augmented_args_tmp, &key); + struct augmented_args_payload *augmented_args = augmented_args_payload(); const void *filename_arg = (const void *)args->args[1]; unsigned int len = sizeof(augmented_args->args); if (augmented_args == NULL) return 1; /* Failure: don't filter */ - len += augmented_filename__read(&augmented_args->filename, filename_arg, sizeof(augmented_args->filename.value)); + len += augmented_arg__read_str(&augmented_args->arg, filename_arg, sizeof(augmented_args->arg.value)); - /* If perf_event_output fails, return non-zero so that it gets recorded unaugmented */ - return perf_event_output(args, &__augmented_syscalls__, BPF_F_CURRENT_CPU, augmented_args, len); + return augmented__output(args, augmented_args, len); } SEC("!syscalls:sys_enter_rename") int sys_enter_rename(struct syscall_enter_args *args) { - int key = 0; - struct augmented_args_payload *augmented_args = bpf_map_lookup_elem(&augmented_args_tmp, &key); + struct augmented_args_payload *augmented_args = augmented_args_payload(); const void *oldpath_arg = (const void *)args->args[0], *newpath_arg = (const void *)args->args[1]; unsigned int len = sizeof(augmented_args->args), oldpath_len; @@ -209,18 +211,16 @@ int sys_enter_rename(struct syscall_enter_args *args) if (augmented_args == NULL) return 1; /* Failure: don't filter */ - oldpath_len = augmented_filename__read(&augmented_args->filename, oldpath_arg, sizeof(augmented_args->filename.value)); - len += oldpath_len + augmented_filename__read((void *)(&augmented_args->filename) + oldpath_len, newpath_arg, sizeof(augmented_args->filename.value)); + oldpath_len = augmented_arg__read_str(&augmented_args->arg, oldpath_arg, sizeof(augmented_args->arg.value)); + len += oldpath_len + augmented_arg__read_str((void *)(&augmented_args->arg) + oldpath_len, newpath_arg, sizeof(augmented_args->arg.value)); - /* If perf_event_output fails, return non-zero so that it gets recorded unaugmented */ - return perf_event_output(args, &__augmented_syscalls__, BPF_F_CURRENT_CPU, augmented_args, len); + return augmented__output(args, augmented_args, len); } SEC("!syscalls:sys_enter_renameat") int sys_enter_renameat(struct syscall_enter_args *args) { - int key = 0; - struct augmented_args_payload *augmented_args = bpf_map_lookup_elem(&augmented_args_tmp, &key); + struct augmented_args_payload *augmented_args = augmented_args_payload(); const void *oldpath_arg = (const void *)args->args[1], *newpath_arg = (const void *)args->args[3]; unsigned int len = sizeof(augmented_args->args), oldpath_len; @@ -228,11 +228,10 @@ int sys_enter_renameat(struct syscall_enter_args *args) if (augmented_args == NULL) return 1; /* Failure: don't filter */ - oldpath_len = augmented_filename__read(&augmented_args->filename, oldpath_arg, sizeof(augmented_args->filename.value)); - len += oldpath_len + augmented_filename__read((void *)(&augmented_args->filename) + oldpath_len, newpath_arg, sizeof(augmented_args->filename.value)); + oldpath_len = augmented_arg__read_str(&augmented_args->arg, oldpath_arg, sizeof(augmented_args->arg.value)); + len += oldpath_len + augmented_arg__read_str((void *)(&augmented_args->arg) + oldpath_len, newpath_arg, sizeof(augmented_args->arg.value)); - /* If perf_event_output fails, return non-zero so that it gets recorded unaugmented */ - return perf_event_output(args, &__augmented_syscalls__, BPF_F_CURRENT_CPU, augmented_args, len); + return augmented__output(args, augmented_args, len); } SEC("raw_syscalls:sys_enter") @@ -250,15 +249,14 @@ int sys_enter(struct syscall_enter_args *args) */ unsigned int len = sizeof(augmented_args->args); struct syscall *syscall; - int key = 0; - - augmented_args = bpf_map_lookup_elem(&augmented_args_tmp, &key); - if (augmented_args == NULL) - return 1; if (pid_filter__has(&pids_filtered, getpid())) return 0; + augmented_args = augmented_args_payload(); + if (augmented_args == NULL) + return 1; + probe_read(&augmented_args->args, sizeof(augmented_args->args), args); /* diff --git a/tools/perf/lib/include/perf/event.h b/tools/perf/lib/include/perf/event.h new file mode 100644 index 000000000000..36ad3a4a79e6 --- /dev/null +++ b/tools/perf/lib/include/perf/event.h @@ -0,0 +1,112 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __LIBPERF_EVENT_H +#define __LIBPERF_EVENT_H + +#include <linux/perf_event.h> +#include <linux/types.h> +#include <linux/limits.h> +#include <linux/bpf.h> + +struct perf_record_mmap { + struct perf_event_header header; + __u32 pid, tid; + __u64 start; + __u64 len; + __u64 pgoff; + char filename[PATH_MAX]; +}; + +struct perf_record_mmap2 { + struct perf_event_header header; + __u32 pid, tid; + __u64 start; + __u64 len; + __u64 pgoff; + __u32 maj; + __u32 min; + __u64 ino; + __u64 ino_generation; + __u32 prot; + __u32 flags; + char filename[PATH_MAX]; +}; + +struct perf_record_comm { + struct perf_event_header header; + __u32 pid, tid; + char comm[16]; +}; + +struct perf_record_namespaces { + struct perf_event_header header; + __u32 pid, tid; + __u64 nr_namespaces; + struct perf_ns_link_info link_info[]; +}; + +struct perf_record_fork { + struct perf_event_header header; + __u32 pid, ppid; + __u32 tid, ptid; + __u64 time; +}; + +struct perf_record_lost { + struct perf_event_header header; + __u64 id; + __u64 lost; +}; + +struct perf_record_lost_samples { + struct perf_event_header header; + __u64 lost; +}; + +/* + * PERF_FORMAT_ENABLED | PERF_FORMAT_RUNNING | PERF_FORMAT_ID + */ +struct perf_record_read { + struct perf_event_header header; + __u32 pid, tid; + __u64 value; + __u64 time_enabled; + __u64 time_running; + __u64 id; +}; + +struct perf_record_throttle { + struct perf_event_header header; + __u64 time; + __u64 id; + __u64 stream_id; +}; + +#ifndef KSYM_NAME_LEN +#define KSYM_NAME_LEN 256 +#endif + +struct perf_record_ksymbol { + struct perf_event_header header; + __u64 addr; + __u32 len; + __u16 ksym_type; + __u16 flags; + char name[KSYM_NAME_LEN]; +}; + +struct perf_record_bpf_event { + struct perf_event_header header; + __u16 type; + __u16 flags; + __u32 id; + + /* for bpf_prog types */ + __u8 tag[BPF_TAG_SIZE]; // prog tag +}; + +struct perf_record_sample { + struct perf_event_header header; + __u64 array[]; +}; + +#endif /* __LIBPERF_EVENT_H */ diff --git a/tools/perf/perf.h b/tools/perf/perf.h index dc0a7a237887..d9e6b8b957b6 100644 --- a/tools/perf/perf.h +++ b/tools/perf/perf.h @@ -35,63 +35,6 @@ extern const char perf_version_string[]; void pthread__unblock_sigwinch(void); -#include "util/target.h" - -struct record_opts { - struct target target; - bool group; - bool inherit_stat; - bool no_buffering; - bool no_inherit; - bool no_inherit_set; - bool no_samples; - bool raw_samples; - bool sample_address; - bool sample_phys_addr; - bool sample_weight; - bool sample_time; - bool sample_time_set; - bool sample_cpu; - bool period; - bool period_set; - bool running_time; - bool full_auxtrace; - bool auxtrace_snapshot_mode; - bool auxtrace_snapshot_on_exit; - bool record_namespaces; - bool record_switch_events; - bool all_kernel; - bool all_user; - bool kernel_callchains; - bool user_callchains; - bool tail_synthesize; - bool overwrite; - bool ignore_missing_thread; - bool strict_freq; - bool sample_id; - bool no_bpf_event; - unsigned int freq; - unsigned int mmap_pages; - unsigned int auxtrace_mmap_pages; - unsigned int user_freq; - u64 branch_stack; - u64 sample_intr_regs; - u64 sample_user_regs; - u64 default_interval; - u64 user_interval; - size_t auxtrace_snapshot_size; - const char *auxtrace_snapshot_opts; - bool sample_transaction; - unsigned initial_delay; - bool use_clockid; - clockid_t clockid; - u64 clockid_res_ns; - int nr_cblocks; - int affinity; - int mmap_flush; - unsigned int comp_level; -}; - enum perf_affinity { PERF_AFFINITY_SYS = 0, PERF_AFFINITY_NODE, @@ -99,10 +42,5 @@ enum perf_affinity { PERF_AFFINITY_MAX }; -struct option; -extern const char * const *record_usage; -extern struct option *record_options; extern int version_verbose; - -int record__parse_freq(const struct option *opt, const char *str, int unset); #endif diff --git a/tools/perf/tests/backward-ring-buffer.c b/tools/perf/tests/backward-ring-buffer.c index 9bdf66139099..b6f27ef9fb02 100644 --- a/tools/perf/tests/backward-ring-buffer.c +++ b/tools/perf/tests/backward-ring-buffer.c @@ -4,9 +4,9 @@ * beginning */ -#include <perf.h> #include <evlist.h> #include <sys/prctl.h> +#include "record.h" #include "tests.h" #include "debug.h" #include <errno.h> diff --git a/tools/perf/tests/bpf.c b/tools/perf/tests/bpf.c index e16f927f38b6..98642961fc63 100644 --- a/tools/perf/tests/bpf.c +++ b/tools/perf/tests/bpf.c @@ -5,6 +5,7 @@ #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> +#include <util/record.h> #include <util/util.h> #include <util/bpf-loader.h> #include <util/evlist.h> diff --git a/tools/perf/tests/code-reading.c b/tools/perf/tests/code-reading.c index e45df0736261..fe671b860086 100644 --- a/tools/perf/tests/code-reading.c +++ b/tools/perf/tests/code-reading.c @@ -20,6 +20,7 @@ #include "map.h" #include "symbol.h" #include "event.h" +#include "record.h" #include "thread.h" #include "tests.h" diff --git a/tools/perf/tests/keep-tracking.c b/tools/perf/tests/keep-tracking.c index 0ce5ce33bac4..2af6faf1bbd6 100644 --- a/tools/perf/tests/keep-tracking.c +++ b/tools/perf/tests/keep-tracking.c @@ -8,6 +8,7 @@ #include "parse-events.h" #include "evlist.h" #include "evsel.h" +#include "record.h" #include "thread_map.h" #include "cpumap.h" #include "tests.h" diff --git a/tools/perf/tests/openat-syscall-tp-fields.c b/tools/perf/tests/openat-syscall-tp-fields.c index 9c06130d37be..62492106fb5e 100644 --- a/tools/perf/tests/openat-syscall-tp-fields.c +++ b/tools/perf/tests/openat-syscall-tp-fields.c @@ -1,12 +1,13 @@ // SPDX-License-Identifier: GPL-2.0 +#include <stdbool.h> #include <linux/err.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> -#include "perf.h" #include "evlist.h" #include "evsel.h" #include "thread_map.h" +#include "record.h" #include "tests.h" #include "debug.h" #include <errno.h> diff --git a/tools/perf/tests/parse-no-sample-id-all.c b/tools/perf/tests/parse-no-sample-id-all.c index 396e40d68922..8284752a60c8 100644 --- a/tools/perf/tests/parse-no-sample-id-all.c +++ b/tools/perf/tests/parse-no-sample-id-all.c @@ -87,10 +87,10 @@ int test__parse_no_sample_id_all(struct test *test __maybe_unused, int subtest _ }, .id = 2, }; - struct mmap_event event3 = { + struct perf_record_mmap event3 = { .header = { .type = PERF_RECORD_MMAP, - .size = sizeof(struct mmap_event), + .size = sizeof(struct perf_record_mmap), }, }; union perf_event *events[] = { diff --git a/tools/perf/tests/perf-record.c b/tools/perf/tests/perf-record.c index 67b388e92cba..3a205f6f9363 100644 --- a/tools/perf/tests/perf-record.c +++ b/tools/perf/tests/perf-record.c @@ -7,8 +7,8 @@ #include <sched.h> #include "evlist.h" #include "evsel.h" -#include "perf.h" #include "debug.h" +#include "record.h" #include "tests.h" static int sched__get_first_possible_cpu(pid_t pid, cpu_set_t *maskp) diff --git a/tools/perf/tests/shell/record+zstd_comp_decomp.sh b/tools/perf/tests/shell/record+zstd_comp_decomp.sh index 899604d17b85..63a91ec473bb 100755 --- a/tools/perf/tests/shell/record+zstd_comp_decomp.sh +++ b/tools/perf/tests/shell/record+zstd_comp_decomp.sh @@ -13,7 +13,7 @@ skip_if_no_z_record() { collect_z_record() { echo "Collecting compressed record file:" $perf_tool record -o $trace_file -g -z -F 5000 -- \ - dd count=500 if=/dev/random of=/dev/null + dd count=500 if=/dev/urandom of=/dev/null } check_compressed_stats() { diff --git a/tools/perf/tests/switch-tracking.c b/tools/perf/tests/switch-tracking.c index e3cee69f6ea2..b63f02768724 100644 --- a/tools/perf/tests/switch-tracking.c +++ b/tools/perf/tests/switch-tracking.c @@ -13,6 +13,7 @@ #include "evsel.h" #include "thread_map.h" #include "cpumap.h" +#include "record.h" #include "tests.h" static int spin_sleep(void) diff --git a/tools/perf/tests/task-exit.c b/tools/perf/tests/task-exit.c index 4ca38fd0379a..d79a22e2d8be 100644 --- a/tools/perf/tests/task-exit.c +++ b/tools/perf/tests/task-exit.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 #include "evlist.h" #include "evsel.h" +#include "target.h" #include "thread_map.h" #include "cpumap.h" #include "tests.h" diff --git a/tools/perf/trace/beauty/ioctl.c b/tools/perf/trace/beauty/ioctl.c index 52242fa4072b..e19eb6ea361d 100644 --- a/tools/perf/trace/beauty/ioctl.c +++ b/tools/perf/trace/beauty/ioctl.c @@ -21,7 +21,7 @@ static size_t ioctl__scnprintf_tty_cmd(int nr, int dir, char *bf, size_t size) { static const char *ioctl_tty_cmd[] = { - "TCGETS", "TCSETS", "TCSETSW", "TCSETSF", "TCGETA", "TCSETA", "TCSETAW", + [_IOC_NR(TCGETS)] = "TCGETS", "TCSETS", "TCSETSW", "TCSETSF", "TCGETA", "TCSETA", "TCSETAW", "TCSETAF", "TCSBRK", "TCXONC", "TCFLSH", "TIOCEXCL", "TIOCNXCL", "TIOCSCTTY", "TIOCGPGRP", "TIOCSPGRP", "TIOCOUTQ", "TIOCSTI", "TIOCGWINSZ", "TIOCSWINSZ", "TIOCMGET", "TIOCMBIS", "TIOCMBIC", "TIOCMSET", "TIOCGSOFTCAR", "TIOCSSOFTCAR", diff --git a/tools/perf/ui/browsers/res_sample.c b/tools/perf/ui/browsers/res_sample.c index 08897bd5eb0f..41a9d8923ec4 100644 --- a/tools/perf/ui/browsers/res_sample.c +++ b/tools/perf/ui/browsers/res_sample.c @@ -6,6 +6,8 @@ #include "sort.h" #include "config.h" #include "time-utils.h" +#include "../util.h" +#include "../../util/util.h" #include <linux/time64.h> #include <linux/zalloc.h> diff --git a/tools/perf/ui/browsers/scripts.c b/tools/perf/ui/browsers/scripts.c index 04f9aff5621e..50e0c03171f2 100644 --- a/tools/perf/ui/browsers/scripts.c +++ b/tools/perf/ui/browsers/scripts.c @@ -1,5 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 +#include "../../builtin.h" #include "../../util/sort.h" +#include "../../util/util.h" #include "../../util/hist.h" #include "../../util/debug.h" #include "../../util/symbol.h" @@ -131,8 +133,10 @@ static int list_scripts(char *script_name, bool *custom, int key = ui_browser__input_window("perf script command", "Enter perf script command line (without perf script prefix)", script_args, "", 0); - if (key != K_ENTER) - return -1; + if (key != K_ENTER) { + ret = -1; + goto out; + } sprintf(script_name, "%s script %s", perf, script_args); } else if (choice < num + max_std) { strcpy(script_name, paths[choice]); diff --git a/tools/perf/ui/stdio/hist.c b/tools/perf/ui/stdio/hist.c index ee7ea6deed21..51ed67548b83 100644 --- a/tools/perf/ui/stdio/hist.c +++ b/tools/perf/ui/stdio/hist.c @@ -3,6 +3,7 @@ #include <linux/string.h> #include "../../util/callchain.h" +#include "../../util/debug.h" #include "../../util/hist.h" #include "../../util/map.h" #include "../../util/map_groups.h" 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 @@ perf-y += annotate.o perf-y += block-range.o perf-y += build-id.o +perf-y += cacheline.o perf-y += config.o perf-y += ctype.o perf-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 @@ #include "cache.h" #include "map.h" #include "symbol.h" +#include "srcline.h" #include "units.h" #include "debug.h" #include "annotate.h" @@ -37,6 +38,7 @@ #include <linux/kernel.h> #include <linux/string.h> #include <bpf/libbpf.h> +#include <subcmd/parse-options.h> /* FIXME: For the HE_COLORSET */ #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 @@ #include <linux/list.h> #include <linux/zalloc.h> -#include "../perf.h" #include "evlist.h" #include "dso.h" #include "map.h" @@ -41,6 +40,7 @@ #include <linux/hash.h> #include "event.h" +#include "record.h" #include "session.h" #include "debug.h" #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 @@ #include "session.h" #include "map.h" #include "evlist.h" +#include "record.h" #define ptr_to_u64(ptr) ((__u64)(unsigned long)(ptr)) @@ -34,7 +35,7 @@ static int machine__process_bpf_event_load(struct machine *machine, struct bpf_prog_info_linear *info_linear; struct bpf_prog_info_node *info_node; struct perf_env *env = machine->env; - int id = event->bpf_event.id; + int id = event->bpf.id; unsigned int i; /* perf-record, no need to handle bpf-event */ @@ -63,14 +64,13 @@ static int machine__process_bpf_event_load(struct machine *machine, return 0; } -int machine__process_bpf_event(struct machine *machine __maybe_unused, - union perf_event *event, - struct perf_sample *sample __maybe_unused) +int machine__process_bpf(struct machine *machine, union perf_event *event, + struct perf_sample *sample) { if (dump_trace) - perf_event__fprintf_bpf_event(event, stdout); + perf_event__fprintf_bpf(event, stdout); - switch (event->bpf_event.type) { + switch (event->bpf.type) { case PERF_BPF_EVENT_PROG_LOAD: return machine__process_bpf_event_load(machine, event, sample); @@ -82,8 +82,7 @@ int machine__process_bpf_event(struct machine *machine __maybe_unused, */ break; default: - pr_debug("unexpected bpf_event type of %d\n", - event->bpf_event.type); + pr_debug("unexpected bpf event type of %d\n", event->bpf.type); break; } return 0; @@ -160,8 +159,8 @@ static int perf_event__synthesize_one_bpf_prog(struct perf_session *session, union perf_event *event, struct record_opts *opts) { - struct ksymbol_event *ksymbol_event = &event->ksymbol_event; - struct bpf_event *bpf_event = &event->bpf_event; + struct perf_record_ksymbol *ksymbol_event = &event->ksymbol; + struct perf_record_bpf_event *bpf_event = &event->bpf; struct bpf_prog_info_linear *info_linear; struct perf_tool *tool = session->tool; struct bpf_prog_info_node *info_node; @@ -229,10 +228,10 @@ static int perf_event__synthesize_one_bpf_prog(struct perf_session *session, __u64 *prog_addrs = (__u64 *)(uintptr_t)(info->jited_ksyms); int name_len; - *ksymbol_event = (struct ksymbol_event){ + *ksymbol_event = (struct perf_record_ksymbol) { .header = { .type = PERF_RECORD_KSYMBOL, - .size = offsetof(struct ksymbol_event, name), + .size = offsetof(struct perf_record_ksymbol, name), }, .addr = prog_addrs[i], .len = prog_lens[i], @@ -253,10 +252,10 @@ static int perf_event__synthesize_one_bpf_prog(struct perf_session *session, if (!opts->no_bpf_event) { /* Synthesize PERF_RECORD_BPF_EVENT */ - *bpf_event = (struct bpf_event){ + *bpf_event = (struct perf_record_bpf_event) { .header = { .type = PERF_RECORD_BPF_EVENT, - .size = sizeof(struct bpf_event), + .size = sizeof(struct perf_record_bpf_event), }, .type = PERF_BPF_EVENT_PROG_LOAD, .flags = 0, @@ -301,7 +300,7 @@ int perf_event__synthesize_bpf_events(struct perf_session *session, int err; int fd; - event = malloc(sizeof(event->bpf_event) + KSYM_NAME_LEN + machine->id_hdr_size); + event = malloc(sizeof(event->bpf) + KSYM_NAME_LEN + machine->id_hdr_size); if (!event) return -1; while (true) { @@ -398,9 +397,9 @@ static int bpf_event__sb_cb(union perf_event *event, void *data) if (event->header.type != PERF_RECORD_BPF_EVENT) return -1; - switch (event->bpf_event.type) { + switch (event->bpf.type) { case PERF_BPF_EVENT_PROG_LOAD: - perf_env__add_bpf_info(env, event->bpf_event.id); + perf_env__add_bpf_info(env, event->bpf.id); case PERF_BPF_EVENT_PROG_UNLOAD: /* @@ -410,8 +409,7 @@ static int bpf_event__sb_cb(union perf_event *event, void *data) */ break; default: - pr_debug("unexpected bpf_event type of %d\n", - event->bpf_event.type); + pr_debug("unexpected bpf event type of %d\n", event->bpf.type); break; } 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 { }; #ifdef HAVE_LIBBPF_SUPPORT -int machine__process_bpf_event(struct machine *machine, union perf_event *event, - struct perf_sample *sample); +int machine__process_bpf(struct machine *machine, union perf_event *event, + struct perf_sample *sample); int perf_event__synthesize_bpf_events(struct perf_session *session, perf_event__handler_t process, @@ -43,9 +43,9 @@ void bpf_event__print_bpf_prog_info(struct bpf_prog_info *info, struct perf_env *env, FILE *fp); #else -static inline int machine__process_bpf_event(struct machine *machine __maybe_unused, - union perf_event *event __maybe_unused, - struct perf_sample *sample __maybe_unused) +static inline int machine__process_bpf(struct machine *machine __maybe_unused, + union perf_event *event __maybe_unused, + struct perf_sample *sample __maybe_unused) { return 0; } 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 @@ +// SPDX-License-Identifier: GPL-2.0 +#include "cacheline.h" +#include "../perf.h" +#include <unistd.h> + +#ifdef _SC_LEVEL1_DCACHE_LINESIZE +#define cache_line_size(cacheline_sizep) *cacheline_sizep = sysconf(_SC_LEVEL1_DCACHE_LINESIZE) +#else +#include <api/fs/fs.h> +#include "debug.h" +static void cache_line_size(int *cacheline_sizep) +{ + if (sysfs__read_int("devices/system/cpu/cpu0/cache/index0/coherency_line_size", cacheline_sizep)) + pr_debug("cannot determine cache line size"); +} +#endif + +int cacheline_size(void) +{ + static int size; + + if (!size) + cache_line_size(&size); + + return size; +} 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 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef PERF_CACHELINE_H +#define PERF_CACHELINE_H + +#include <linux/compiler.h> + +int __pure cacheline_size(void); + +static inline u64 cl_address(u64 address) +{ + /* return the cacheline of the address */ + return (address & ~(cacheline_size() - 1)); +} + +static inline u64 cl_offset(u64 address) +{ + /* return the cacheline of the address */ + return (address & (cacheline_size() - 1)); +} + +#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 @@ #include "asm/bug.h" +#include "debug.h" #include "hist.h" #include "sort.h" #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 @@ #include <internal/cpumap.h> #include <perf/cpumap.h> -#include "perf.h" - struct cpu_map_data; struct 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 @@ #include <unistd.h> #include <string.h> #include <asm/bug.h> -#include <sys/types.h> #include <dirent.h> #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, strcpy(execname, ""); /* 00400000-0040c000 r-xp 00000000 fd:01 41038 /bin/cat */ - n = sscanf(bf, "%"PRIx64"-%"PRIx64" %s %"PRIx64" %x:%x %u %[^\n]\n", + n = sscanf(bf, "%"PRI_lx64"-%"PRI_lx64" %s %"PRI_lx64" %x:%x %u %[^\n]\n", &event->mmap2.start, &event->mmap2.len, prot, &event->mmap2.pgoff, &event->mmap2.maj, &event->mmap2.min, @@ -1343,17 +1343,17 @@ int perf_event__process_ksymbol(struct perf_tool *tool __maybe_unused, return machine__process_ksymbol(machine, event, sample); } -int perf_event__process_bpf_event(struct perf_tool *tool __maybe_unused, - union perf_event *event, - struct perf_sample *sample __maybe_unused, - struct machine *machine) +int perf_event__process_bpf(struct perf_tool *tool __maybe_unused, + union perf_event *event, + struct perf_sample *sample, + struct machine *machine) { - return machine__process_bpf_event(machine, event, sample); + return machine__process_bpf(machine, event, sample); } size_t perf_event__fprintf_mmap(union perf_event *event, FILE *fp) { - return fprintf(fp, " %d/%d: [%#" PRIx64 "(%#" PRIx64 ") @ %#" PRIx64 "]: %c %s\n", + return fprintf(fp, " %d/%d: [%#" PRI_lx64 "(%#" PRI_lx64 ") @ %#" PRI_lx64 "]: %c %s\n", event->mmap.pid, event->mmap.tid, event->mmap.start, event->mmap.len, event->mmap.pgoff, (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) size_t perf_event__fprintf_mmap2(union perf_event *event, FILE *fp) { - return fprintf(fp, " %d/%d: [%#" PRIx64 "(%#" PRIx64 ") @ %#" PRIx64 - " %02x:%02x %"PRIu64" %"PRIu64"]: %c%c%c%c %s\n", + return fprintf(fp, " %d/%d: [%#" PRI_lx64 "(%#" PRI_lx64 ") @ %#" PRI_lx64 + " %02x:%02x %"PRI_lu64" %"PRI_lu64"]: %c%c%c%c %s\n", event->mmap2.pid, event->mmap2.tid, event->mmap2.start, event->mmap2.len, event->mmap2.pgoff, event->mmap2.maj, event->mmap2.min, event->mmap2.ino, @@ -1480,22 +1480,21 @@ size_t perf_event__fprintf_switch(union perf_event *event, FILE *fp) static size_t perf_event__fprintf_lost(union perf_event *event, FILE *fp) { - return fprintf(fp, " lost %" PRIu64 "\n", event->lost.lost); + return fprintf(fp, " lost %" PRI_lu64 "\n", event->lost.lost); } size_t perf_event__fprintf_ksymbol(union perf_event *event, FILE *fp) { - return fprintf(fp, " addr %" PRIx64 " len %u type %u flags 0x%x name %s\n", - event->ksymbol_event.addr, event->ksymbol_event.len, - event->ksymbol_event.ksym_type, - event->ksymbol_event.flags, event->ksymbol_event.name); + return fprintf(fp, " addr %" PRI_lx64 " len %u type %u flags 0x%x name %s\n", + event->ksymbol.addr, event->ksymbol.len, + event->ksymbol.ksym_type, + event->ksymbol.flags, event->ksymbol.name); } -size_t perf_event__fprintf_bpf_event(union perf_event *event, FILE *fp) +size_t perf_event__fprintf_bpf(union perf_event *event, FILE *fp) { return fprintf(fp, " type %u, flags %u, id %u\n", - event->bpf_event.type, event->bpf_event.flags, - event->bpf_event.id); + event->bpf.type, event->bpf.flags, event->bpf.id); } size_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) ret += perf_event__fprintf_ksymbol(event, fp); break; case PERF_RECORD_BPF_EVENT: - ret += perf_event__fprintf_bpf_event(event, fp); + ret += perf_event__fprintf_bpf(event, fp); break; default: 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 @@ #include <linux/kernel.h> #include <linux/bpf.h> #include <linux/perf_event.h> +#include <perf/event.h> #include "../perf.h" #include "build-id.h" #include "perf_regs.h" -struct mmap_event { - struct perf_event_header header; - u32 pid, tid; - u64 start; - u64 len; - u64 pgoff; - char filename[PATH_MAX]; -}; - -struct mmap2_event { - struct perf_event_header header; - u32 pid, tid; - u64 start; - u64 len; - u64 pgoff; - u32 maj; - u32 min; - u64 ino; - u64 ino_generation; - u32 prot; - u32 flags; - char filename[PATH_MAX]; -}; - -struct comm_event { - struct perf_event_header header; - u32 pid, tid; - char comm[16]; -}; - -struct namespaces_event { - struct perf_event_header header; - u32 pid, tid; - u64 nr_namespaces; - struct perf_ns_link_info link_info[]; -}; - -struct fork_event { - struct perf_event_header header; - u32 pid, ppid; - u32 tid, ptid; - u64 time; -}; - -struct lost_event { - struct perf_event_header header; - u64 id; - u64 lost; -}; - -struct lost_samples_event { - struct perf_event_header header; - u64 lost; -}; - +#ifdef __LP64__ /* - * PERF_FORMAT_ENABLED | PERF_FORMAT_RUNNING | PERF_FORMAT_ID + * /usr/include/inttypes.h uses just 'lu' for PRIu64, but we end up defining + * __u64 as long long unsigned int, and then -Werror=format= kicks in and + * complains of the mismatched types, so use these two special extra PRI + * macros to overcome that. */ -struct read_event { - struct perf_event_header header; - u32 pid, tid; - u64 value; - u64 time_enabled; - u64 time_running; - u64 id; -}; - -struct throttle_event { - struct perf_event_header header; - u64 time; - u64 id; - u64 stream_id; -}; - -#ifndef KSYM_NAME_LEN -#define KSYM_NAME_LEN 256 +#define PRI_lu64 "l" PRIu64 +#define PRI_lx64 "l" PRIx64 +#else +#define PRI_lu64 PRIu64 +#define PRI_lx64 PRIx64 #endif -struct ksymbol_event { - struct perf_event_header header; - u64 addr; - u32 len; - u16 ksym_type; - u16 flags; - char name[KSYM_NAME_LEN]; -}; - -struct bpf_event { - struct perf_event_header header; - u16 type; - u16 flags; - u32 id; - - /* for bpf_prog types */ - u8 tag[BPF_TAG_SIZE]; // prog tag -}; - #define PERF_SAMPLE_MASK \ (PERF_SAMPLE_IP | PERF_SAMPLE_TID | \ PERF_SAMPLE_TIME | PERF_SAMPLE_ADDR | \ @@ -119,11 +37,6 @@ struct bpf_event { /* perf sample has 16 bits size limit */ #define PERF_SAMPLE_MAX_SIZE (1 << 16) -struct sample_event { - struct perf_event_header header; - u64 array[]; -}; - struct regs_dump { u64 abi; u64 mask; @@ -392,18 +305,18 @@ static inline void *perf_synth__raw_data(void *p) * when possible sends this number in a PERF_RECORD_LOST event. The number of * such "chunks" of lost events is stored in .nr_events[PERF_EVENT_LOST] while * total_lost tells exactly how many events the kernel in fact lost, i.e. it is - * the sum of all struct lost_event.lost fields reported. + * the sum of all struct perf_record_lost.lost fields reported. * * The kernel discards mixed up samples and sends the number in a * PERF_RECORD_LOST_SAMPLES event. The number of lost-samples events is stored * in .nr_events[PERF_RECORD_LOST_SAMPLES] while total_lost_samples tells * exactly how many samples the kernel in fact dropped, i.e. it is the sum of - * all struct lost_samples_event.lost fields reported. + * all struct perf_record_lost_samples.lost fields reported. * * The total_period is needed because by default auto-freq is used, so * multipling nr_events[PERF_EVENT_SAMPLE] by a frequency isn't possible to get * the total number of low level events, it is necessary to to sum all struct - * sample_event.period and stash the result in total_period. + * perf_record_sample.period and stash the result in total_period. */ struct events_stats { u64 total_period; @@ -637,16 +550,18 @@ struct compressed_event { union perf_event { struct perf_event_header header; - struct mmap_event mmap; - struct mmap2_event mmap2; - struct comm_event comm; - struct namespaces_event namespaces; - struct fork_event fork; - struct lost_event lost; - struct lost_samples_event lost_samples; - struct read_event read; - struct throttle_event throttle; - struct sample_event sample; + struct perf_record_mmap mmap; + struct perf_record_mmap2 mmap2; + struct perf_record_comm comm; + struct perf_record_namespaces namespaces; + struct perf_record_fork fork; + struct perf_record_lost lost; + struct perf_record_lost_samples lost_samples; + struct perf_record_read read; + struct perf_record_throttle throttle; + struct perf_record_sample sample; + struct perf_record_bpf_event bpf; + struct perf_record_ksymbol ksymbol; struct attr_event attr; struct event_update_event event_update; struct event_type_event event_type; @@ -666,8 +581,6 @@ union perf_event { struct stat_round_event stat_round; struct time_conv_event time_conv; struct feature_event feat; - struct ksymbol_event ksymbol_event; - struct bpf_event bpf_event; struct compressed_event pack; }; @@ -770,10 +683,10 @@ int perf_event__process_ksymbol(struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, struct machine *machine); -int perf_event__process_bpf_event(struct perf_tool *tool, - union perf_event *event, - struct perf_sample *sample, - struct machine *machine); +int perf_event__process_bpf(struct perf_tool *tool, + union perf_event *event, + struct perf_sample *sample, + struct machine *machine); int perf_tool__process_synth_event(struct perf_tool *tool, union perf_event *event, struct machine *machine, @@ -838,7 +751,7 @@ size_t perf_event__fprintf_thread_map(union perf_event *event, FILE *fp); size_t perf_event__fprintf_cpu_map(union perf_event *event, FILE *fp); size_t perf_event__fprintf_namespaces(union perf_event *event, FILE *fp); size_t perf_event__fprintf_ksymbol(union perf_event *event, FILE *fp); -size_t perf_event__fprintf_bpf_event(union perf_event *event, FILE *fp); +size_t perf_event__fprintf_bpf(union perf_event *event, FILE *fp); size_t perf_event__fprintf(union perf_event *event, FILE *fp); int 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, static int perf_evlist__event2id(struct evlist *evlist, union perf_event *event, u64 *id) { - const u64 *array = event->sample.array; + const __u64 *array = event->sample.array; ssize_t n; 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 @@ #include "thread_map.h" #include "target.h" #include "perf_regs.h" +#include "record.h" #include "debug.h" #include "trace-event.h" #include "stat.h" @@ -116,7 +117,7 @@ int __perf_evsel__sample_size(u64 sample_type) * * This function returns the position of the event id (PERF_SAMPLE_ID or * PERF_SAMPLE_IDENTIFIER) in a sample event i.e. in the array of struct - * sample_event. + * perf_record_sample. */ static int __perf_evsel__calc_id_pos(u64 sample_type) { @@ -1071,8 +1072,7 @@ void perf_evsel__config(struct evsel *evsel, struct record_opts *opts, attr->mmap2 = track && !perf_missing_features.mmap2; attr->comm = track; attr->ksymbol = track && !perf_missing_features.ksymbol; - attr->bpf_event = track && !opts->no_bpf_event && - !perf_missing_features.bpf_event; + attr->bpf_event = track && !opts->no_bpf_event && !perf_missing_features.bpf; if (opts->record_namespaces) attr->namespaces = track; @@ -1802,7 +1802,7 @@ fallback_missing_features: evsel->core.attr.read_format &= ~(PERF_FORMAT_GROUP|PERF_FORMAT_ID); if (perf_missing_features.ksymbol) evsel->core.attr.ksymbol = 0; - if (perf_missing_features.bpf_event) + if (perf_missing_features.bpf) evsel->core.attr.bpf_event = 0; retry_sample_id: if (perf_missing_features.sample_id_all) @@ -1919,8 +1919,8 @@ try_fallback: perf_missing_features.aux_output = true; pr_debug2("Kernel has no attr.aux_output support, bailing out\n"); goto out_close; - } else if (!perf_missing_features.bpf_event && evsel->core.attr.bpf_event) { - perf_missing_features.bpf_event = true; + } else if (!perf_missing_features.bpf && evsel->core.attr.bpf_event) { + perf_missing_features.bpf = true; pr_debug2("switching off bpf_event\n"); goto fallback_missing_features; } 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, struct perf_sample *sample) { u64 type = evsel->core.attr.sample_type; - const u64 *array = event->sample.array; + const __u64 *array = event->sample.array; bool swapped = evsel->needs_swap; union u64_swap u; @@ -2098,7 +2098,7 @@ int perf_evsel__parse_sample(struct evsel *evsel, union perf_event *event, { u64 type = evsel->core.attr.sample_type; bool swapped = evsel->needs_swap; - const u64 *array; + const __u64 *array; u16 max_size = event->header.size; const void *endp = (void *)event + max_size; u64 sz; @@ -2377,7 +2377,7 @@ int perf_evsel__parse_sample_timestamp(struct evsel *evsel, u64 *timestamp) { u64 type = evsel->core.attr.sample_type; - const u64 *array; + const __u64 *array; if (!(type & PERF_SAMPLE_TIME)) return -1; @@ -2419,7 +2419,7 @@ int perf_evsel__parse_sample_timestamp(struct evsel *evsel, size_t perf_event__sample_event_size(const struct perf_sample *sample, u64 type, u64 read_format) { - size_t sz, result = sizeof(struct sample_event); + size_t sz, result = sizeof(struct perf_record_sample); if (type & PERF_SAMPLE_IDENTIFIER) result += sizeof(u64); @@ -2528,7 +2528,7 @@ int perf_event__synthesize_sample(union perf_event *event, u64 type, u64 read_format, const struct perf_sample *sample) { - u64 *array; + __u64 *array; size_t sz; /* * 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; * show the name used, not some alias. * @id_pos: the position of the event id (PERF_SAMPLE_ID or * PERF_SAMPLE_IDENTIFIER) in a sample event i.e. in the array of - * struct sample_event + * struct perf_record_sample * @is_pos: the position (counting backwards) of the event id (PERF_SAMPLE_ID or * PERF_SAMPLE_IDENTIFIER) in a non-sample event i.e. if sample_id_all * is used there is an id sample appended to non-sample events @@ -194,7 +194,7 @@ struct perf_missing_features { bool write_backward; bool group_read; bool ksymbol; - bool bpf_event; + bool bpf; bool aux_output; }; 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 @@ #include "get_current_dir_name.h" #include <unistd.h> #include <stdlib.h> -#include <stdlib.h> /* Android's 'bionic' library, for one, doesn't have this */ 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) hists__new_col_len(hists, HISTC_MEM_LVL, 21 + 3); hists__new_col_len(hists, HISTC_LOCAL_WEIGHT, 12); hists__new_col_len(hists, HISTC_GLOBAL_WEIGHT, 12); - hists__new_col_len(hists, HISTC_TIME, 12); + if (symbol_conf.nanosecs) + hists__new_col_len(hists, HISTC_TIME, 16); + else + hists__new_col_len(hists, HISTC_TIME, 12); if (h->srcline) { 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, * We only use sample types from PERF_SAMPLE_MASK so we can use * __perf_evsel__sample_size() here. */ - bts->branches_event_size = sizeof(struct sample_event) + + bts->branches_event_size = sizeof(struct perf_record_sample) + __perf_evsel__sample_size(attr.sample_type); } 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 @@ #ifndef __PERF_KVM_STAT_H #define __PERF_KVM_STAT_H -#include "../perf.h" #include "tool.h" #include "stat.h" +#include "record.h" struct evsel; struct 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 @@ #include "hist.h" #include "machine.h" #include "map.h" +#include "srcline.h" #include "symbol.h" #include "sort.h" #include "strlist.h" +#include "target.h" #include "thread.h" +#include "util.h" #include "vdso.h" #include <stdbool.h> #include <sys/types.h> @@ -642,7 +645,7 @@ int machine__process_namespaces_event(struct machine *machine __maybe_unused, int machine__process_lost_event(struct machine *machine __maybe_unused, union perf_event *event, struct perf_sample *sample __maybe_unused) { - dump_printf(": id:%" PRIu64 ": lost:%" PRIu64 "\n", + dump_printf(": id:%" PRI_lu64 ": lost:%" PRI_lu64 "\n", event->lost.id, event->lost.lost); return 0; } @@ -650,7 +653,7 @@ int machine__process_lost_event(struct machine *machine __maybe_unused, int machine__process_lost_samples_event(struct machine *machine __maybe_unused, union perf_event *event, struct perf_sample *sample) { - dump_printf(": id:%" PRIu64 ": lost samples :%" PRIu64 "\n", + dump_printf(": id:%" PRIu64 ": lost samples :%" PRI_lu64 "\n", sample->id, event->lost_samples.lost); return 0; } @@ -710,20 +713,20 @@ static int machine__process_ksymbol_register(struct machine *machine, struct symbol *sym; struct map *map; - map = map_groups__find(&machine->kmaps, event->ksymbol_event.addr); + map = map_groups__find(&machine->kmaps, event->ksymbol.addr); if (!map) { - map = dso__new_map(event->ksymbol_event.name); + map = dso__new_map(event->ksymbol.name); if (!map) return -ENOMEM; - map->start = event->ksymbol_event.addr; - map->end = map->start + event->ksymbol_event.len; + map->start = event->ksymbol.addr; + map->end = map->start + event->ksymbol.len; map_groups__insert(&machine->kmaps, map); } sym = symbol__new(map->map_ip(map, map->start), - event->ksymbol_event.len, - 0, 0, event->ksymbol_event.name); + event->ksymbol.len, + 0, 0, event->ksymbol.name); if (!sym) return -ENOMEM; dso__insert_symbol(map->dso, sym); @@ -736,7 +739,7 @@ static int machine__process_ksymbol_unregister(struct machine *machine, { struct map *map; - map = map_groups__find(&machine->kmaps, event->ksymbol_event.addr); + map = map_groups__find(&machine->kmaps, event->ksymbol.addr); if (map) map_groups__remove(&machine->kmaps, map); @@ -750,7 +753,7 @@ int machine__process_ksymbol(struct machine *machine __maybe_unused, if (dump_trace) perf_event__fprintf_ksymbol(event, stdout); - if (event->ksymbol_event.flags & PERF_RECORD_KSYMBOL_FLAGS_UNREGISTER) + if (event->ksymbol.flags & PERF_RECORD_KSYMBOL_FLAGS_UNREGISTER) return machine__process_ksymbol_unregister(machine, event, sample); return machine__process_ksymbol_register(machine, event, sample); @@ -1919,7 +1922,7 @@ int machine__process_event(struct machine *machine, union perf_event *event, case PERF_RECORD_KSYMBOL: ret = machine__process_ksymbol(machine, event, sample); break; case PERF_RECORD_BPF_EVENT: - ret = machine__process_bpf_event(machine, event, sample); break; + ret = machine__process_bpf(machine, event, sample); break; default: ret = -1; 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; struct evsel; struct perf_sample; struct symbol; +struct target; struct thread; union perf_event; 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 @@ #include <asm/bug.h> #include <linux/zalloc.h> -struct namespaces *namespaces__new(struct namespaces_event *event) +struct namespaces *namespaces__new(struct perf_record_namespaces *event) { struct namespaces *namespaces; 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 @@ int setns(int fd, int nstype); #endif -struct namespaces_event; +struct perf_record_namespaces; struct namespaces { struct list_head list; @@ -25,7 +25,7 @@ struct namespaces { struct perf_ns_link_info link_info[]; }; -struct namespaces *namespaces__new(struct namespaces_event *event); +struct namespaces *namespaces__new(struct perf_record_namespaces *event); void namespaces__free(struct namespaces *namespaces); struct 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[] = { sample_members member_def(perf_event_header, type, T_UINT, "event type"), member_def(perf_event_header, misc, T_UINT, "event misc"), - member_def(mmap_event, pid, T_UINT, "event pid"), - member_def(mmap_event, tid, T_UINT, "event tid"), - member_def(mmap_event, start, T_ULONGLONG, "start of the map"), - member_def(mmap_event, len, T_ULONGLONG, "map length"), - member_def(mmap_event, pgoff, T_ULONGLONG, "page offset"), - member_def(mmap_event, filename, T_STRING_INPLACE, "backing store"), + member_def(perf_record_mmap, pid, T_UINT, "event pid"), + member_def(perf_record_mmap, tid, T_UINT, "event tid"), + member_def(perf_record_mmap, start, T_ULONGLONG, "start of the map"), + member_def(perf_record_mmap, len, T_ULONGLONG, "map length"), + member_def(perf_record_mmap, pgoff, T_ULONGLONG, "page offset"), + member_def(perf_record_mmap, filename, T_STRING_INPLACE, "backing store"), { .name = NULL, }, }; @@ -130,8 +130,8 @@ static PyObject *pyrf_mmap_event__repr(struct pyrf_event *pevent) PyObject *ret; char *s; - if (asprintf(&s, "{ type: mmap, pid: %u, tid: %u, start: %#" PRIx64 ", " - "length: %#" PRIx64 ", offset: %#" PRIx64 ", " + if (asprintf(&s, "{ type: mmap, pid: %u, tid: %u, start: %#" PRI_lx64 ", " + "length: %#" PRI_lx64 ", offset: %#" PRI_lx64 ", " "filename: %s }", pevent->event.mmap.pid, pevent->event.mmap.tid, 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 static PyMemberDef pyrf_task_event__members[] = { sample_members member_def(perf_event_header, type, T_UINT, "event type"), - member_def(fork_event, pid, T_UINT, "event pid"), - member_def(fork_event, ppid, T_UINT, "event ppid"), - member_def(fork_event, tid, T_UINT, "event tid"), - member_def(fork_event, ptid, T_UINT, "event ptid"), - member_def(fork_event, time, T_ULONGLONG, "timestamp"), + member_def(perf_record_fork, pid, T_UINT, "event pid"), + member_def(perf_record_fork, ppid, T_UINT, "event ppid"), + member_def(perf_record_fork, tid, T_UINT, "event tid"), + member_def(perf_record_fork, ptid, T_UINT, "event ptid"), + member_def(perf_record_fork, time, T_ULONGLONG, "timestamp"), { .name = NULL, }, }; static PyObject *pyrf_task_event__repr(struct pyrf_event *pevent) { return _PyUnicode_FromFormat("{ type: %s, pid: %u, ppid: %u, tid: %u, " - "ptid: %u, time: %" PRIu64 "}", + "ptid: %u, time: %" PRI_lu64 "}", pevent->event.header.type == PERF_RECORD_FORK ? "fork" : "exit", pevent->event.fork.pid, pevent->event.fork.ppid, @@ -194,9 +194,9 @@ static char pyrf_comm_event__doc[] = PyDoc_STR("perf comm event object."); static PyMemberDef pyrf_comm_event__members[] = { sample_members member_def(perf_event_header, type, T_UINT, "event type"), - member_def(comm_event, pid, T_UINT, "event pid"), - member_def(comm_event, tid, T_UINT, "event tid"), - member_def(comm_event, comm, T_STRING_INPLACE, "process name"), + member_def(perf_record_comm, pid, T_UINT, "event pid"), + member_def(perf_record_comm, tid, T_UINT, "event tid"), + member_def(perf_record_comm, comm, T_STRING_INPLACE, "process name"), { .name = NULL, }, }; @@ -223,18 +223,18 @@ static char pyrf_throttle_event__doc[] = PyDoc_STR("perf throttle event object." static PyMemberDef pyrf_throttle_event__members[] = { sample_members member_def(perf_event_header, type, T_UINT, "event type"), - member_def(throttle_event, time, T_ULONGLONG, "timestamp"), - member_def(throttle_event, id, T_ULONGLONG, "event id"), - member_def(throttle_event, stream_id, T_ULONGLONG, "event stream id"), + member_def(perf_record_throttle, time, T_ULONGLONG, "timestamp"), + member_def(perf_record_throttle, id, T_ULONGLONG, "event id"), + member_def(perf_record_throttle, stream_id, T_ULONGLONG, "event stream id"), { .name = NULL, }, }; static PyObject *pyrf_throttle_event__repr(struct pyrf_event *pevent) { - struct throttle_event *te = (struct throttle_event *)(&pevent->event.header + 1); + struct perf_record_throttle *te = (struct perf_record_throttle *)(&pevent->event.header + 1); - return _PyUnicode_FromFormat("{ type: %sthrottle, time: %" PRIu64 ", id: %" PRIu64 - ", stream_id: %" PRIu64 " }", + return _PyUnicode_FromFormat("{ type: %sthrottle, time: %" PRI_lu64 ", id: %" PRI_lu64 + ", stream_id: %" PRI_lu64 " }", pevent->event.header.type == PERF_RECORD_THROTTLE ? "" : "un", te->time, te->id, te->stream_id); } @@ -253,8 +253,8 @@ static char pyrf_lost_event__doc[] = PyDoc_STR("perf lost event object."); static PyMemberDef pyrf_lost_event__members[] = { sample_members - member_def(lost_event, id, T_ULONGLONG, "event id"), - member_def(lost_event, lost, T_ULONGLONG, "number of lost events"), + member_def(perf_record_lost, id, T_ULONGLONG, "event id"), + member_def(perf_record_lost, lost, T_ULONGLONG, "number of lost events"), { .name = NULL, }, }; @@ -263,8 +263,8 @@ static PyObject *pyrf_lost_event__repr(struct pyrf_event *pevent) PyObject *ret; char *s; - if (asprintf(&s, "{ type: lost, id: %#" PRIx64 ", " - "lost: %#" PRIx64 " }", + if (asprintf(&s, "{ type: lost, id: %#" PRI_lx64 ", " + "lost: %#" PRI_lx64 " }", pevent->event.lost.id, pevent->event.lost.lost) < 0) { ret = PyErr_NoMemory(); } else { @@ -288,8 +288,8 @@ static char pyrf_read_event__doc[] = PyDoc_STR("perf read event object."); static PyMemberDef pyrf_read_event__members[] = { sample_members - member_def(read_event, pid, T_UINT, "event pid"), - member_def(read_event, tid, T_UINT, "event tid"), + member_def(perf_record_read, pid, T_UINT, "event pid"), + member_def(perf_record_read, tid, T_UINT, "event tid"), { .name = NULL, }, }; 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 @@ #include <perf/cpumap.h> #include "util.h" #include "cloexec.h" +#include "record.h" typedef void (*setup_probe_fn_t)(struct evsel *evsel); 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 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _PERF_RECORD_H +#define _PERF_RECORD_H + +#include <time.h> +#include <stdbool.h> +#include <linux/types.h> +#include <linux/stddef.h> +#include <linux/perf_event.h> +#include "util/target.h" + +struct option; + +struct record_opts { + struct target target; + bool group; + bool inherit_stat; + bool no_buffering; + bool no_inherit; + bool no_inherit_set; + bool no_samples; + bool raw_samples; + bool sample_address; + bool sample_phys_addr; + bool sample_weight; + bool sample_time; + bool sample_time_set; + bool sample_cpu; + bool period; + bool period_set; + bool running_time; + bool full_auxtrace; + bool auxtrace_snapshot_mode; + bool auxtrace_snapshot_on_exit; + bool record_namespaces; + bool record_switch_events; + bool all_kernel; + bool all_user; + bool kernel_callchains; + bool user_callchains; + bool tail_synthesize; + bool overwrite; + bool ignore_missing_thread; + bool strict_freq; + bool sample_id; + bool no_bpf_event; + unsigned int freq; + unsigned int mmap_pages; + unsigned int auxtrace_mmap_pages; + unsigned int user_freq; + u64 branch_stack; + u64 sample_intr_regs; + u64 sample_user_regs; + u64 default_interval; + u64 user_interval; + size_t auxtrace_snapshot_size; + const char *auxtrace_snapshot_opts; + bool sample_transaction; + unsigned initial_delay; + bool use_clockid; + clockid_t clockid; + u64 clockid_res_ns; + int nr_cblocks; + int affinity; + int mmap_flush; + unsigned int comp_level; +}; + +extern const char * const *record_usage; +extern struct option *record_options; + +int record__parse_freq(const struct option *opt, const char *str, int unset); + +#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) tool->context_switch = perf_event__process_switch; if (tool->ksymbol == NULL) tool->ksymbol = perf_event__process_ksymbol; - if (tool->bpf_event == NULL) - tool->bpf_event = perf_event__process_bpf_event; + if (tool->bpf == NULL) + tool->bpf = perf_event__process_bpf; if (tool->read == NULL) tool->read = process_event_sample_stub; if (tool->throttle == NULL) @@ -1254,13 +1254,13 @@ static void dump_sample(struct evsel *evsel, union perf_event *event, static void dump_read(struct evsel *evsel, union perf_event *event) { - struct read_event *read_event = &event->read; + struct perf_record_read *read_event = &event->read; u64 read_format; if (!dump_trace) return; - printf(": %d %d %s %" PRIu64 "\n", event->read.pid, event->read.tid, + printf(": %d %d %s %" PRI_lu64 "\n", event->read.pid, event->read.tid, perf_evsel__name(evsel), event->read.value); @@ -1270,13 +1270,13 @@ static void dump_read(struct evsel *evsel, union perf_event *event) read_format = evsel->core.attr.read_format; if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) - printf("... time enabled : %" PRIu64 "\n", read_event->time_enabled); + printf("... time enabled : %" PRI_lu64 "\n", read_event->time_enabled); if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) - printf("... time running : %" PRIu64 "\n", read_event->time_running); + printf("... time running : %" PRI_lu64 "\n", read_event->time_running); if (read_format & PERF_FORMAT_ID) - printf("... id : %" PRIu64 "\n", read_event->id); + printf("... id : %" PRI_lu64 "\n", read_event->id); } static struct machine *machines__find_for_cpumode(struct machines *machines, @@ -1452,7 +1452,7 @@ static int machines__deliver_event(struct machines *machines, case PERF_RECORD_KSYMBOL: return tool->ksymbol(tool, event, sample, machine); case PERF_RECORD_BPF_EVENT: - return tool->bpf_event(tool, event, sample, machine); + return tool->bpf(tool, event, sample, machine); default: ++evlist->stats.nr_unknown_events; 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 @@ #include <linux/time64.h> #include "sort.h" #include "hist.h" +#include "cacheline.h" #include "comm.h" #include "map.h" #include "symbol.h" #include "thread.h" #include "evsel.h" #include "evlist.h" +#include "srcline.h" #include "strlist.h" #include "strbuf.h" #include <traceevent/event-parse.h> @@ -668,17 +670,11 @@ sort__time_cmp(struct hist_entry *left, struct hist_entry *right) static int hist_entry__time_snprintf(struct hist_entry *he, char *bf, size_t size, unsigned int width) { - unsigned long secs; - unsigned long long nsecs; char he_time[32]; - nsecs = he->time; - secs = nsecs / NSEC_PER_SEC; - nsecs -= secs * NSEC_PER_SEC; - if (symbol_conf.nanosecs) - snprintf(he_time, sizeof he_time, "%5lu.%09llu: ", - secs, nsecs); + timestamp__scnprintf_nsec(he->time, he_time, + sizeof(he_time)); else timestamp__scnprintf_usec(he->time, he_time, 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 @@ /* SPDX-License-Identifier: GPL-2.0 */ #ifndef __PERF_SORT_H #define __PERF_SORT_H -#include "../builtin.h" - #include <regex.h> - -#include "color.h" +#include <stdbool.h> #include <linux/list.h> -#include "cache.h" #include <linux/rbtree.h> #include "map_symbol.h" #include "symbol_conf.h" -#include "string.h" #include "callchain.h" #include "values.h" -#include "../perf.h" -#include "debug.h" -#include "header.h" - -#include <subcmd/parse-options.h> -#include "parse-events.h" #include "hist.h" -#include "srcline.h" +struct option; struct thread; extern regex_t parent_regex; @@ -204,18 +193,6 @@ static inline float hist_entry__get_percent_limit(struct hist_entry *he) return period * 100.0 / total_period; } -static inline u64 cl_address(u64 address) -{ - /* return the cacheline of the address */ - return (address & ~(cacheline_size() - 1)); -} - -static inline u64 cl_offset(u64 address) -{ - /* return the cacheline of the address */ - return (address & (cacheline_size() - 1)); -} - enum sort_mode { SORT_MODE__NORMAL, 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 @@ #include "string2.h" #include <linux/ctype.h> #include "cgroup.h" -#include <math.h> #include <api/fs/fs.h> #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 @@ #include <math.h> #include "counts.h" #include "stat.h" +#include "target.h" #include "evlist.h" #include "evsel.h" #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 @@ #include <linux/types.h> #include <stdio.h> #include <sys/types.h> -#include <sys/time.h> #include <sys/resource.h> -#include <sys/wait.h> #include "rblist.h" -#include "perf.h" #include "event.h" +struct timespec; + struct stats { double n, mean, M2; u64 max, min; @@ -199,6 +198,8 @@ int perf_stat_process_counter(struct perf_stat_config *config, struct perf_tool; union perf_event; struct perf_session; +struct target; + int perf_event__process_stat_event(struct perf_session *session, union perf_event *event); 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) } static int __thread__set_namespaces(struct thread *thread, u64 timestamp, - struct namespaces_event *event) + struct perf_record_namespaces *event) { struct namespaces *new, *curr = __thread__namespaces(thread); @@ -193,7 +193,7 @@ static int __thread__set_namespaces(struct thread *thread, u64 timestamp, } int thread__set_namespaces(struct thread *thread, u64 timestamp, - struct namespaces_event *event) + struct perf_record_namespaces *event) { int ret; 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 @@ struct addr_location; struct map; -struct namespaces_event; +struct perf_record_namespaces; struct thread_stack; struct unwind_libunwind_ops; @@ -74,7 +74,7 @@ static inline void thread__exited(struct thread *thread) struct namespaces *thread__namespaces(struct thread *thread); int thread__set_namespaces(struct thread *thread, u64 timestamp, - struct namespaces_event *event); + struct perf_record_namespaces *event); int __thread__set_comm(struct thread *thread, const char *comm, u64 timestamp, 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 { throttle, unthrottle, ksymbol, - bpf_event; + bpf; event_attr_op attr; 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 @@ #include "tool.h" #include "evswitch.h" #include "annotate.h" +#include "record.h" #include <linux/types.h> #include <stddef.h> #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) unsigned int page_size; -#ifdef _SC_LEVEL1_DCACHE_LINESIZE -#define cache_line_size(cacheline_sizep) *cacheline_sizep = sysconf(_SC_LEVEL1_DCACHE_LINESIZE) -#else -static void cache_line_size(int *cacheline_sizep) -{ - if (sysfs__read_int("devices/system/cpu/cpu0/cache/index0/coherency_line_size", cacheline_sizep)) - pr_debug("cannot determine cache line size"); -} -#endif - -int cacheline_size(void) -{ - static int size; - - if (!size) - cache_line_size(&size); - - return size; -} - int sysctl_perf_event_max_stack = PERF_MAX_STACK_DEPTH; int sysctl_perf_event_max_contexts_per_stack = PERF_MAX_CONTEXTS_PER_STACK; 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); size_t hex_width(u64 v); extern unsigned int page_size; -int __pure cacheline_size(void); int sysctl__max_stack(void); |