]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
perf session: Add e_flags to the e_machine helper
authorIan Rogers <irogers@google.com>
Tue, 3 Feb 2026 18:26:38 +0000 (10:26 -0800)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 3 Feb 2026 21:01:27 +0000 (18:01 -0300)
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>
tools/perf/builtin-kvm.c
tools/perf/builtin-report.c
tools/perf/builtin-script.c
tools/perf/util/evsel.c
tools/perf/util/evsel.h
tools/perf/util/kvm-stat.c
tools/perf/util/session.c
tools/perf/util/session.h

index 93ba07c58290656eefdcd3507ef52aeff50fcc23..0c5e6b3aac74dec5d3eee7789cb46890da8d338d 100644 (file)
@@ -902,7 +902,7 @@ static bool handle_end_event(struct perf_kvm_stat *kvm,
 
        if (kvm->duration && time_diff > kvm->duration) {
                char decode[KVM_EVENT_NAME_LEN];
-               uint16_t e_machine = perf_session__e_machine(kvm->session);
+               uint16_t e_machine = perf_session__e_machine(kvm->session, /*e_flags=*/NULL);
 
                kvm->events_ops->decode_key(kvm, &event->key, decode);
                if (!skip_event(e_machine, decode)) {
@@ -1187,7 +1187,7 @@ static int cpu_isa_config(struct perf_kvm_stat *kvm)
                return -EINVAL;
        }
 
-       e_machine = perf_session__e_machine(kvm->session);
+       e_machine = perf_session__e_machine(kvm->session, /*e_flags=*/NULL);
        err = cpu_isa_init(kvm, e_machine, cpuid);
        if (err == -ENOTSUP)
                pr_err("CPU %s is not supported.\n", cpuid);
@@ -1549,7 +1549,7 @@ out:
 static int read_events(struct perf_kvm_stat *kvm)
 {
        int ret;
-
+       uint16_t e_machine;
        struct perf_data file = {
                .path  = kvm->file_name,
                .mode  = PERF_DATA_MODE_READ,
@@ -1574,7 +1574,8 @@ static int read_events(struct perf_kvm_stat *kvm)
                goto out_delete;
        }
 
-       if (!register_kvm_events_ops(kvm, perf_session__e_machine(kvm->session))) {
+       e_machine = perf_session__e_machine(kvm->session, /*e_flags=*/NULL);
+       if (!register_kvm_events_ops(kvm, e_machine)) {
                ret = -EINVAL;
                goto out_delete;
        }
index 810ffd66b11c34cddba041d4b3ac2954e0ae7935..3b81f4b3dc4903d5759466c331d657c22a7ef8f4 100644 (file)
@@ -448,7 +448,7 @@ static int report__setup_sample_type(struct report *rep)
                }
        }
 
-       callchain_param_setup(sample_type, perf_session__e_machine(session));
+       callchain_param_setup(sample_type, perf_session__e_machine(session, /*e_flags=*/NULL));
 
        if (rep->stitch_lbr && (callchain_param.record_mode != CALLCHAIN_LBR)) {
                ui__warning("Can't find LBR callchain. Switch off --stitch-lbr.\n"
@@ -1296,7 +1296,7 @@ static int process_attr(const struct perf_tool *tool __maybe_unused,
         */
        sample_type = evlist__combined_sample_type(*pevlist);
        session = (*pevlist)->session;
-       callchain_param_setup(sample_type, perf_session__e_machine(session));
+       callchain_param_setup(sample_type, perf_session__e_machine(session, /*e_flags=*/NULL));
        return 0;
 }
 
index c7d5a325b5cb48cfde2fa264c05296e75f2d676f..14c6f6c3c4f2f79a44b393be8e32ec9b17d44848 100644 (file)
@@ -2818,6 +2818,7 @@ static int process_attr(const struct perf_tool *tool, union perf_event *event,
        struct perf_script *scr = container_of(tool, struct perf_script, tool);
        struct evlist *evlist;
        struct evsel *evsel, *pos;
+       uint16_t e_machine;
        u64 sample_type;
        int err;
 
@@ -2859,7 +2860,8 @@ static int process_attr(const struct perf_tool *tool, union perf_event *event,
         * on events sample_type.
         */
        sample_type = evlist__combined_sample_type(evlist);
-       callchain_param_setup(sample_type, perf_session__e_machine(evsel__session(evsel)));
+       e_machine = perf_session__e_machine(evsel__session(evsel), /*e_flags=*/NULL);
+       callchain_param_setup(sample_type, e_machine);
 
        /* Enable fields for callchain entries */
        if (symbol_conf.use_callchain &&
@@ -3834,7 +3836,7 @@ static void script__setup_sample_type(struct perf_script *script)
        struct perf_session *session = script->session;
        u64 sample_type = evlist__combined_sample_type(session->evlist);
 
-       callchain_param_setup(sample_type, perf_session__e_machine(session));
+       callchain_param_setup(sample_type, perf_session__e_machine(session, /*e_flags=*/NULL));
 
        if (script->stitch_lbr && (callchain_param.record_mode != CALLCHAIN_LBR)) {
                pr_warning("Can't find LBR callchain. Switch off --stitch-lbr.\n"
index 848d0faf66983979798032ce6f7d69be49b3fe04..aff44ffd3ff12382faf48d840e8696f79cec2c13 100644 (file)
@@ -1008,11 +1008,11 @@ int evsel__group_desc(struct evsel *evsel, char *buf, size_t size)
        return ret;
 }
 
-uint16_t evsel__e_machine(struct evsel *evsel)
+uint16_t evsel__e_machine(struct evsel *evsel, uint32_t *e_flags)
 {
        struct perf_session *session = evsel__session(evsel);
 
-       return session ? perf_session__e_machine(session) : EM_HOST;
+       return perf_session__e_machine(session, e_flags);
 }
 
 static void __evsel__config_callchain(struct evsel *evsel, struct record_opts *opts,
@@ -1050,7 +1050,7 @@ static void __evsel__config_callchain(struct evsel *evsel, struct record_opts *o
 
        if (param->record_mode == CALLCHAIN_DWARF) {
                if (!function) {
-                       uint16_t e_machine = evsel__e_machine(evsel);
+                       uint16_t e_machine = evsel__e_machine(evsel, /*e_flags=*/NULL);
 
                        evsel__set_sample_bit(evsel, REGS_USER);
                        evsel__set_sample_bit(evsel, STACK_USER);
index eefb5d56997145dbb5f4a519ccaf8eec176b156b..a3d754c029a0243078db94ec8494eb49d563db1b 100644 (file)
@@ -546,7 +546,7 @@ static inline bool evsel__is_dummy_event(struct evsel *evsel)
 
 struct perf_session *evsel__session(struct evsel *evsel);
 struct perf_env *evsel__env(struct evsel *evsel);
-uint16_t evsel__e_machine(struct evsel *evsel);
+uint16_t evsel__e_machine(struct evsel *evsel, uint32_t *e_flags);
 
 int evsel__store_ids(struct evsel *evsel, struct evlist *evlist);
 
index 858b5dbd39f6690b4b76dc77b4459b9bf1e7acb1..27f16810498ca245cbcb76ccf241e1e0dff0a858 100644 (file)
@@ -6,15 +6,19 @@
 
 bool kvm_exit_event(struct evsel *evsel)
 {
-       return evsel__name_is(evsel, kvm_exit_trace(evsel__e_machine(evsel)));
+       uint16_t e_machine = evsel__e_machine(evsel, /*e_flags=*/NULL);
+
+       return evsel__name_is(evsel, kvm_exit_trace(e_machine));
 }
 
 void exit_event_get_key(struct evsel *evsel,
                        struct perf_sample *sample,
                        struct event_key *key)
 {
+       uint16_t e_machine = evsel__e_machine(evsel, /*e_flags=*/NULL);
+
        key->info = 0;
-       key->key  = evsel__intval(evsel, sample, kvm_exit_reason(evsel__e_machine(evsel)));
+       key->key  = evsel__intval(evsel, sample, kvm_exit_reason(e_machine));
 }
 
 
@@ -31,7 +35,9 @@ bool exit_event_begin(struct evsel *evsel,
 
 bool kvm_entry_event(struct evsel *evsel)
 {
-       return evsel__name_is(evsel, kvm_entry_trace(evsel__e_machine(evsel)));
+       uint16_t e_machine = evsel__e_machine(evsel, /*e_flags=*/NULL);
+
+       return evsel__name_is(evsel, kvm_entry_trace(e_machine));
 }
 
 bool exit_event_end(struct evsel *evsel,
index d0053618f54042459f495290c6eb2635515a05b7..72e8bb67d7407d9c8af00cf5b66fc540f167e26a 100644 (file)
@@ -2964,27 +2964,47 @@ struct perf_env *perf_session__env(struct perf_session *session)
        return &session->header.env;
 }
 
-static int perf_session__e_machine_cb(struct thread *thread,
-                                     void *arg __maybe_unused)
+struct perf_session__e_machine_cb_args {
+       uint32_t e_flags;
+       uint16_t e_machine;
+       bool need_e_flags;
+};
+
+static int perf_session__e_machine_cb(struct thread *thread, void *_args)
 {
-       uint16_t *result = arg;
+       struct perf_session__e_machine_cb_args *args = _args;
        struct machine *machine = maps__machine(thread__maps(thread));
 
-       *result = thread__e_machine(thread, machine, /*e_flags=*/NULL);
-       return *result != EM_NONE ? 1 : 0;
+       args->e_machine = thread__e_machine(thread, machine,
+                                           args->need_e_flags ? &args->e_flags : NULL);
+       return args->e_machine != EM_NONE ? 1 : 0;
 }
 
 /*
  * Note, a machine may have mixed 32-bit and 64-bit processes and so mixed
  * e_machines. Use thread__e_machine when this matters.
  */
-uint16_t perf_session__e_machine(struct perf_session *session)
+uint16_t perf_session__e_machine(struct perf_session *session, uint32_t *e_flags)
 {
-       uint16_t e_machine = EM_NONE;
+       struct perf_session__e_machine_cb_args args = {
+               .e_machine = EM_NONE,
+               .need_e_flags = e_flags != NULL,
+       };
+
+       if (!session) {
+               /* Default to assuming a host machine. */
+               if (e_flags)
+                       *e_flags = EF_HOST;
+
+               return EM_HOST;
+       }
 
        machines__for_each_thread(&session->machines,
-                                        perf_session__e_machine_cb,
-                                        &e_machine);
+                                 perf_session__e_machine_cb,
+                                 &args);
+
+       if (e_flags)
+               *e_flags = args.e_flags;
 
-       return e_machine == EM_NONE ? EM_HOST : e_machine;
+       return args.e_machine == EM_NONE ? EM_HOST : args.e_machine;
 }
index eddc4c630b33390c4bcbc6b82edbf0f30625114c..f05f0d4a6c238dc8ead192cdf8176d2aaa5de301 100644 (file)
@@ -211,6 +211,6 @@ int perf_event__process_finished_round(const struct perf_tool *tool,
                                       struct ordered_events *oe);
 
 struct perf_env *perf_session__env(struct perf_session *session);
-uint16_t perf_session__e_machine(struct perf_session *session);
+uint16_t perf_session__e_machine(struct perf_session *session, uint32_t *e_flags);
 
 #endif /* __PERF_SESSION_H */