Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf session: Add e_flags to the e_machine helper

Allow e_flags as well as e_machine to be computed using the e_machine
helper.

This isn't currently used, the argument is always NULL, but it will be
used for a new header feature.

Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Aditya Bodkhe <aditya.b1@linux.ibm.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Albert Ou <aou@eecs.berkeley.edu>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexandre Ghiti <alex@ghiti.fr>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Andrew Jones <ajones@ventanamicro.com>
Cc: Anubhav Shelat <ashelat@redhat.com>
Cc: Anup Patel <anup@brainfault.org>
Cc: Athira Rajeev <atrajeev@linux.ibm.com>
Cc: Blake Jones <blakejones@google.com>
Cc: Chun-Tse Shao <ctshao@google.com>
Cc: Dapeng Mi <dapeng1.mi@linux.intel.com>
Cc: Dmitriy Vyukov <dvyukov@google.com>
Cc: Howard Chu <howardchu95@gmail.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@linaro.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: John Garry <john.g.garry@oracle.com>
Cc: Leo Yan <leo.yan@linux.dev>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Palmer Dabbelt <palmer@dabbelt.com>
Cc: Paul Walmsley <pjw@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Quan Zhou <zhouquan@iscas.ac.cn>
Cc: Shimin Guo <shimin.guo@skydio.com>
Cc: Swapnil Sapkal <swapnil.sapkal@amd.com>
Cc: Thomas Falcon <thomas.falcon@intel.com>
Cc: Will Deacon <will@kernel.org>
Cc: Yunseong Kim <ysk@kzalloc.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Ian Rogers and committed by
Arnaldo Carvalho de Melo
07ad6f31 43af5484

+55 -26
+5 -4
tools/perf/builtin-kvm.c
··· 902 902 903 903 if (kvm->duration && time_diff > kvm->duration) { 904 904 char decode[KVM_EVENT_NAME_LEN]; 905 - uint16_t e_machine = perf_session__e_machine(kvm->session); 905 + uint16_t e_machine = perf_session__e_machine(kvm->session, /*e_flags=*/NULL); 906 906 907 907 kvm->events_ops->decode_key(kvm, &event->key, decode); 908 908 if (!skip_event(e_machine, decode)) { ··· 1187 1187 return -EINVAL; 1188 1188 } 1189 1189 1190 - e_machine = perf_session__e_machine(kvm->session); 1190 + e_machine = perf_session__e_machine(kvm->session, /*e_flags=*/NULL); 1191 1191 err = cpu_isa_init(kvm, e_machine, cpuid); 1192 1192 if (err == -ENOTSUP) 1193 1193 pr_err("CPU %s is not supported.\n", cpuid); ··· 1549 1549 static int read_events(struct perf_kvm_stat *kvm) 1550 1550 { 1551 1551 int ret; 1552 - 1552 + uint16_t e_machine; 1553 1553 struct perf_data file = { 1554 1554 .path = kvm->file_name, 1555 1555 .mode = PERF_DATA_MODE_READ, ··· 1574 1574 goto out_delete; 1575 1575 } 1576 1576 1577 - if (!register_kvm_events_ops(kvm, perf_session__e_machine(kvm->session))) { 1577 + e_machine = perf_session__e_machine(kvm->session, /*e_flags=*/NULL); 1578 + if (!register_kvm_events_ops(kvm, e_machine)) { 1578 1579 ret = -EINVAL; 1579 1580 goto out_delete; 1580 1581 }
+2 -2
tools/perf/builtin-report.c
··· 448 448 } 449 449 } 450 450 451 - callchain_param_setup(sample_type, perf_session__e_machine(session)); 451 + callchain_param_setup(sample_type, perf_session__e_machine(session, /*e_flags=*/NULL)); 452 452 453 453 if (rep->stitch_lbr && (callchain_param.record_mode != CALLCHAIN_LBR)) { 454 454 ui__warning("Can't find LBR callchain. Switch off --stitch-lbr.\n" ··· 1296 1296 */ 1297 1297 sample_type = evlist__combined_sample_type(*pevlist); 1298 1298 session = (*pevlist)->session; 1299 - callchain_param_setup(sample_type, perf_session__e_machine(session)); 1299 + callchain_param_setup(sample_type, perf_session__e_machine(session, /*e_flags=*/NULL)); 1300 1300 return 0; 1301 1301 } 1302 1302
+4 -2
tools/perf/builtin-script.c
··· 2818 2818 struct perf_script *scr = container_of(tool, struct perf_script, tool); 2819 2819 struct evlist *evlist; 2820 2820 struct evsel *evsel, *pos; 2821 + uint16_t e_machine; 2821 2822 u64 sample_type; 2822 2823 int err; 2823 2824 ··· 2860 2859 * on events sample_type. 2861 2860 */ 2862 2861 sample_type = evlist__combined_sample_type(evlist); 2863 - callchain_param_setup(sample_type, perf_session__e_machine(evsel__session(evsel))); 2862 + e_machine = perf_session__e_machine(evsel__session(evsel), /*e_flags=*/NULL); 2863 + callchain_param_setup(sample_type, e_machine); 2864 2864 2865 2865 /* Enable fields for callchain entries */ 2866 2866 if (symbol_conf.use_callchain && ··· 3836 3834 struct perf_session *session = script->session; 3837 3835 u64 sample_type = evlist__combined_sample_type(session->evlist); 3838 3836 3839 - callchain_param_setup(sample_type, perf_session__e_machine(session)); 3837 + callchain_param_setup(sample_type, perf_session__e_machine(session, /*e_flags=*/NULL)); 3840 3838 3841 3839 if (script->stitch_lbr && (callchain_param.record_mode != CALLCHAIN_LBR)) { 3842 3840 pr_warning("Can't find LBR callchain. Switch off --stitch-lbr.\n"
+3 -3
tools/perf/util/evsel.c
··· 1008 1008 return ret; 1009 1009 } 1010 1010 1011 - uint16_t evsel__e_machine(struct evsel *evsel) 1011 + uint16_t evsel__e_machine(struct evsel *evsel, uint32_t *e_flags) 1012 1012 { 1013 1013 struct perf_session *session = evsel__session(evsel); 1014 1014 1015 - return session ? perf_session__e_machine(session) : EM_HOST; 1015 + return perf_session__e_machine(session, e_flags); 1016 1016 } 1017 1017 1018 1018 static void __evsel__config_callchain(struct evsel *evsel, struct record_opts *opts, ··· 1050 1050 1051 1051 if (param->record_mode == CALLCHAIN_DWARF) { 1052 1052 if (!function) { 1053 - uint16_t e_machine = evsel__e_machine(evsel); 1053 + uint16_t e_machine = evsel__e_machine(evsel, /*e_flags=*/NULL); 1054 1054 1055 1055 evsel__set_sample_bit(evsel, REGS_USER); 1056 1056 evsel__set_sample_bit(evsel, STACK_USER);
+1 -1
tools/perf/util/evsel.h
··· 546 546 547 547 struct perf_session *evsel__session(struct evsel *evsel); 548 548 struct perf_env *evsel__env(struct evsel *evsel); 549 - uint16_t evsel__e_machine(struct evsel *evsel); 549 + uint16_t evsel__e_machine(struct evsel *evsel, uint32_t *e_flags); 550 550 551 551 int evsel__store_ids(struct evsel *evsel, struct evlist *evlist); 552 552
+9 -3
tools/perf/util/kvm-stat.c
··· 6 6 7 7 bool kvm_exit_event(struct evsel *evsel) 8 8 { 9 - return evsel__name_is(evsel, kvm_exit_trace(evsel__e_machine(evsel))); 9 + uint16_t e_machine = evsel__e_machine(evsel, /*e_flags=*/NULL); 10 + 11 + return evsel__name_is(evsel, kvm_exit_trace(e_machine)); 10 12 } 11 13 12 14 void exit_event_get_key(struct evsel *evsel, 13 15 struct perf_sample *sample, 14 16 struct event_key *key) 15 17 { 18 + uint16_t e_machine = evsel__e_machine(evsel, /*e_flags=*/NULL); 19 + 16 20 key->info = 0; 17 - key->key = evsel__intval(evsel, sample, kvm_exit_reason(evsel__e_machine(evsel))); 21 + key->key = evsel__intval(evsel, sample, kvm_exit_reason(e_machine)); 18 22 } 19 23 20 24 ··· 35 31 36 32 bool kvm_entry_event(struct evsel *evsel) 37 33 { 38 - return evsel__name_is(evsel, kvm_entry_trace(evsel__e_machine(evsel))); 34 + uint16_t e_machine = evsel__e_machine(evsel, /*e_flags=*/NULL); 35 + 36 + return evsel__name_is(evsel, kvm_entry_trace(e_machine)); 39 37 } 40 38 41 39 bool exit_event_end(struct evsel *evsel,
+30 -10
tools/perf/util/session.c
··· 2964 2964 return &session->header.env; 2965 2965 } 2966 2966 2967 - static int perf_session__e_machine_cb(struct thread *thread, 2968 - void *arg __maybe_unused) 2967 + struct perf_session__e_machine_cb_args { 2968 + uint32_t e_flags; 2969 + uint16_t e_machine; 2970 + bool need_e_flags; 2971 + }; 2972 + 2973 + static int perf_session__e_machine_cb(struct thread *thread, void *_args) 2969 2974 { 2970 - uint16_t *result = arg; 2975 + struct perf_session__e_machine_cb_args *args = _args; 2971 2976 struct machine *machine = maps__machine(thread__maps(thread)); 2972 2977 2973 - *result = thread__e_machine(thread, machine, /*e_flags=*/NULL); 2974 - return *result != EM_NONE ? 1 : 0; 2978 + args->e_machine = thread__e_machine(thread, machine, 2979 + args->need_e_flags ? &args->e_flags : NULL); 2980 + return args->e_machine != EM_NONE ? 1 : 0; 2975 2981 } 2976 2982 2977 2983 /* 2978 2984 * Note, a machine may have mixed 32-bit and 64-bit processes and so mixed 2979 2985 * e_machines. Use thread__e_machine when this matters. 2980 2986 */ 2981 - uint16_t perf_session__e_machine(struct perf_session *session) 2987 + uint16_t perf_session__e_machine(struct perf_session *session, uint32_t *e_flags) 2982 2988 { 2983 - uint16_t e_machine = EM_NONE; 2989 + struct perf_session__e_machine_cb_args args = { 2990 + .e_machine = EM_NONE, 2991 + .need_e_flags = e_flags != NULL, 2992 + }; 2993 + 2994 + if (!session) { 2995 + /* Default to assuming a host machine. */ 2996 + if (e_flags) 2997 + *e_flags = EF_HOST; 2998 + 2999 + return EM_HOST; 3000 + } 2984 3001 2985 3002 machines__for_each_thread(&session->machines, 2986 - perf_session__e_machine_cb, 2987 - &e_machine); 3003 + perf_session__e_machine_cb, 3004 + &args); 2988 3005 2989 - return e_machine == EM_NONE ? EM_HOST : e_machine; 3006 + if (e_flags) 3007 + *e_flags = args.e_flags; 3008 + 3009 + return args.e_machine == EM_NONE ? EM_HOST : args.e_machine; 2990 3010 }
+1 -1
tools/perf/util/session.h
··· 211 211 struct ordered_events *oe); 212 212 213 213 struct perf_env *perf_session__env(struct perf_session *session); 214 - uint16_t perf_session__e_machine(struct perf_session *session); 214 + uint16_t perf_session__e_machine(struct perf_session *session, uint32_t *e_flags); 215 215 216 216 #endif /* __PERF_SESSION_H */