From nobody Mon Feb 9 05:58:29 2026 Received: from mail-dl1-f73.google.com (mail-dl1-f73.google.com [74.125.82.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C413736656F for ; Tue, 3 Feb 2026 18:27:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770143239; cv=none; b=bNppmf+jDJ59Y822FiXQfWNnGsGC6Acvrzqs0AcUXWpdk0rozDjptHrS/pB/Z4T7v1ztrWPrfetP74X9sd3Bid7d+21mA4AZAGHwU7Fjt2iyPzPXmDvS2ayA9nk93gJkb6q3mk/5F2Xe0zPHJMxLykEsgxRCUfPNV8MMv7GeUNo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770143239; c=relaxed/simple; bh=a+Y4py5jBynuEDeCwPw/Te+ijF9HqtSNvPZC2XbL9xw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=tMWzV5xtwmlxNlj50nGkrZBr9MYEfpIZBFITtFAZLZY1Et3FoalgAnWrKY1BtEzmyYIMlkgs2QWXLlBe/sqIm2OdTSwr9NF5XnMMldmwXL4L9vfzHL1Gk+ssobi2JIFPUuLPiJ1bSfw2QOAfZI+HapyFtb5duUU0OqGsheTBPDQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=DI3/zVfm; arc=none smtp.client-ip=74.125.82.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="DI3/zVfm" Received: by mail-dl1-f73.google.com with SMTP id a92af1059eb24-124a978ba9bso7055496c88.0 for ; Tue, 03 Feb 2026 10:27:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1770143237; x=1770748037; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=IQ/mKH6xXSRuds8KmNTYjhBcMp07hv028GEXnHNtdUs=; b=DI3/zVfmSbviv6mPwto5aYGO+TVEVKLY/hhMwI83tqTwiZ2giTvLOOyVn3vz6rQmDn YgV7qNRlFNuHux4aKI/f6XS6OOZFEO+j+DJpGlksTUuFGOMGgHz0fQYWuwEjeKoF47fS hQN5GjJvzbEpVVQPs3e0i3rk1ljbQmQ5xFhdFV9HukEOC1XiRilcLnJIfVV/x6/9fvUg WIwNrnrFIAndlpjm46u3JFu9fqISNKLYvNVcTYGIEGbmjXl54BtCG1l3aTWf8sfOJfBh /W/qNJLivv2zEjjZQBoHtfrDPmmGiF7FKFm1QANElJ2YkxCX72TpecoswQgrJk7Zns8v zN0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770143237; x=1770748037; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=IQ/mKH6xXSRuds8KmNTYjhBcMp07hv028GEXnHNtdUs=; b=cmS1weLpsgpstg9AfeeVLyM5PiJDsQ6o8Ou17bOkR1X6OqMJ7/sbl8l8gGHrJ5uEGL oiM2tU4ckIURD724/y0CX/3Y9rqrDuxYXN2+nXWZ2h6BJFZtZHl0as4m7hQoy/R/9Qdf CzPRT7bed6Wqy7BzIvwRUNMc98+DjI9gjz92dxN5ytgaJpfzXOE5IMnqUuqckR3zL5j0 Wvn/JP5V0WAMdB6PJbZfrXBghiy50k52ozKctJcRoQE2hoqq+u/rqoQmZZLP10lQjSzr s+r1/2xE6qZEA4620tBjzQppHd1IbrXzrVzeXguzGl4ubOsJr5SHNarWhCKADKDcyxjv Vtkw== X-Forwarded-Encrypted: i=1; AJvYcCUYkgTKG7lcuMPamdmAy1CrJmbq4hNDVvp6EDZjpULn6Hl0EXIfbw4p5b97N/dAzRznTrOI/17rGSthBkA=@vger.kernel.org X-Gm-Message-State: AOJu0YwHuw0t6T4VFECXJmrkrHxthluMzh5htaSi9D5D4ZSCWd+3YuRH 6q7E+091j+TPyD4vJ7fwtPRUAs27w7K/BogvlzRARj8EJ1yFs8DuOEfhTp/yburFrYYqe06AKlh D6BBLILKQyQ== X-Received: from dlboy9.prod.google.com ([2002:a05:7022:1289:b0:124:9d31:3581]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:b81:b0:119:e56b:989b with SMTP id a92af1059eb24-126f4780cc5mr128964c88.2.1770143236840; Tue, 03 Feb 2026 10:27:16 -0800 (PST) Date: Tue, 3 Feb 2026 10:26:38 -0800 In-Reply-To: <20260203182640.3911987-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260203182640.3911987-1-irogers@google.com> X-Mailer: git-send-email 2.53.0.rc2.204.g2597b5adb4-goog Message-ID: <20260203182640.3911987-4-irogers@google.com> Subject: [PATCH v3 3/5] perf session: Add e_flags to the e_machine helper From: Ian Rogers To: acme@kernel.org Cc: aditya.b1@linux.ibm.com, adrian.hunter@intel.com, ajones@ventanamicro.com, ak@linux.intel.com, alex@ghiti.fr, alexander.shishkin@linux.intel.com, anup@brainfault.org, aou@eecs.berkeley.edu, ashelat@redhat.com, atrajeev@linux.ibm.com, blakejones@google.com, ctshao@google.com, dapeng1.mi@linux.intel.com, dvyukov@google.com, howardchu95@gmail.com, irogers@google.com, james.clark@linaro.org, john.g.garry@oracle.com, jolsa@kernel.org, leo.yan@linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-riscv@lists.infradead.org, mingo@redhat.com, namhyung@kernel.org, palmer@dabbelt.com, peterz@infradead.org, pjw@kernel.org, shimin.guo@skydio.com, swapnil.sapkal@amd.com, thomas.falcon@intel.com, will@kernel.org, ysk@kzalloc.com, zhouquan@iscas.ac.cn Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 --- tools/perf/builtin-kvm.c | 9 +++++---- tools/perf/builtin-report.c | 4 ++-- tools/perf/builtin-script.c | 6 ++++-- tools/perf/util/evsel.c | 6 +++--- tools/perf/util/evsel.h | 2 +- tools/perf/util/kvm-stat.c | 12 ++++++++--- tools/perf/util/session.c | 40 +++++++++++++++++++++++++++---------- tools/perf/util/session.h | 2 +- 8 files changed, 55 insertions(+), 26 deletions(-) diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index 93ba07c58290..0c5e6b3aac74 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -902,7 +902,7 @@ static bool handle_end_event(struct perf_kvm_stat *kvm, =20 if (kvm->duration && time_diff > kvm->duration) { char decode[KVM_EVENT_NAME_LEN]; - uint16_t e_machine =3D perf_session__e_machine(kvm->session); + uint16_t e_machine =3D perf_session__e_machine(kvm->session, /*e_flags= =3D*/NULL); =20 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; } =20 - e_machine =3D perf_session__e_machine(kvm->session); + e_machine =3D perf_session__e_machine(kvm->session, /*e_flags=3D*/NULL); err =3D cpu_isa_init(kvm, e_machine, cpuid); if (err =3D=3D -ENOTSUP) pr_err("CPU %s is not supported.\n", cpuid); @@ -1549,7 +1549,7 @@ static int kvm_live_open_events(struct perf_kvm_stat = *kvm) static int read_events(struct perf_kvm_stat *kvm) { int ret; - + uint16_t e_machine; struct perf_data file =3D { .path =3D kvm->file_name, .mode =3D PERF_DATA_MODE_READ, @@ -1574,7 +1574,8 @@ static int read_events(struct perf_kvm_stat *kvm) goto out_delete; } =20 - if (!register_kvm_events_ops(kvm, perf_session__e_machine(kvm->session)))= { + e_machine =3D perf_session__e_machine(kvm->session, /*e_flags=3D*/NULL); + if (!register_kvm_events_ops(kvm, e_machine)) { ret =3D -EINVAL; goto out_delete; } diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index 810ffd66b11c..3b81f4b3dc49 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c @@ -448,7 +448,7 @@ static int report__setup_sample_type(struct report *rep) } } =20 - callchain_param_setup(sample_type, perf_session__e_machine(session)); + callchain_param_setup(sample_type, perf_session__e_machine(session, /*e_f= lags=3D*/NULL)); =20 if (rep->stitch_lbr && (callchain_param.record_mode !=3D 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 =3D evlist__combined_sample_type(*pevlist); session =3D (*pevlist)->session; - callchain_param_setup(sample_type, perf_session__e_machine(session)); + callchain_param_setup(sample_type, perf_session__e_machine(session, /*e_f= lags=3D*/NULL)); return 0; } =20 diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index c7d5a325b5cb..14c6f6c3c4f2 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -2818,6 +2818,7 @@ static int process_attr(const struct perf_tool *tool,= union perf_event *event, struct perf_script *scr =3D container_of(tool, struct perf_script, tool); struct evlist *evlist; struct evsel *evsel, *pos; + uint16_t e_machine; u64 sample_type; int err; =20 @@ -2859,7 +2860,8 @@ static int process_attr(const struct perf_tool *tool,= union perf_event *event, * on events sample_type. */ sample_type =3D evlist__combined_sample_type(evlist); - callchain_param_setup(sample_type, perf_session__e_machine(evsel__session= (evsel))); + e_machine =3D perf_session__e_machine(evsel__session(evsel), /*e_flags=3D= */NULL); + callchain_param_setup(sample_type, e_machine); =20 /* Enable fields for callchain entries */ if (symbol_conf.use_callchain && @@ -3834,7 +3836,7 @@ static void script__setup_sample_type(struct perf_scr= ipt *script) struct perf_session *session =3D script->session; u64 sample_type =3D evlist__combined_sample_type(session->evlist); =20 - callchain_param_setup(sample_type, perf_session__e_machine(session)); + callchain_param_setup(sample_type, perf_session__e_machine(session, /*e_f= lags=3D*/NULL)); =20 if (script->stitch_lbr && (callchain_param.record_mode !=3D CALLCHAIN_LBR= )) { pr_warning("Can't find LBR callchain. Switch off --stitch-lbr.\n" diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 848d0faf6698..aff44ffd3ff1 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1008,11 +1008,11 @@ int evsel__group_desc(struct evsel *evsel, char *bu= f, size_t size) return ret; } =20 -uint16_t evsel__e_machine(struct evsel *evsel) +uint16_t evsel__e_machine(struct evsel *evsel, uint32_t *e_flags) { struct perf_session *session =3D evsel__session(evsel); =20 - return session ? perf_session__e_machine(session) : EM_HOST; + return perf_session__e_machine(session, e_flags); } =20 static void __evsel__config_callchain(struct evsel *evsel, struct record_o= pts *opts, @@ -1050,7 +1050,7 @@ static void __evsel__config_callchain(struct evsel *e= vsel, struct record_opts *o =20 if (param->record_mode =3D=3D CALLCHAIN_DWARF) { if (!function) { - uint16_t e_machine =3D evsel__e_machine(evsel); + uint16_t e_machine =3D evsel__e_machine(evsel, /*e_flags=3D*/NULL); =20 evsel__set_sample_bit(evsel, REGS_USER); evsel__set_sample_bit(evsel, STACK_USER); diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index eefb5d569971..a3d754c029a0 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -546,7 +546,7 @@ static inline bool evsel__is_dummy_event(struct evsel *= evsel) =20 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); =20 int evsel__store_ids(struct evsel *evsel, struct evlist *evlist); =20 diff --git a/tools/perf/util/kvm-stat.c b/tools/perf/util/kvm-stat.c index 858b5dbd39f6..27f16810498c 100644 --- a/tools/perf/util/kvm-stat.c +++ b/tools/perf/util/kvm-stat.c @@ -6,15 +6,19 @@ =20 bool kvm_exit_event(struct evsel *evsel) { - return evsel__name_is(evsel, kvm_exit_trace(evsel__e_machine(evsel))); + uint16_t e_machine =3D evsel__e_machine(evsel, /*e_flags=3D*/NULL); + + return evsel__name_is(evsel, kvm_exit_trace(e_machine)); } =20 void exit_event_get_key(struct evsel *evsel, struct perf_sample *sample, struct event_key *key) { + uint16_t e_machine =3D evsel__e_machine(evsel, /*e_flags=3D*/NULL); + key->info =3D 0; - key->key =3D evsel__intval(evsel, sample, kvm_exit_reason(evsel__e_machi= ne(evsel))); + key->key =3D evsel__intval(evsel, sample, kvm_exit_reason(e_machine)); } =20 =20 @@ -31,7 +35,9 @@ bool exit_event_begin(struct evsel *evsel, =20 bool kvm_entry_event(struct evsel *evsel) { - return evsel__name_is(evsel, kvm_entry_trace(evsel__e_machine(evsel))); + uint16_t e_machine =3D evsel__e_machine(evsel, /*e_flags=3D*/NULL); + + return evsel__name_is(evsel, kvm_entry_trace(e_machine)); } =20 bool exit_event_end(struct evsel *evsel, diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index d0053618f540..72e8bb67d740 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -2964,27 +2964,47 @@ struct perf_env *perf_session__env(struct perf_sess= ion *session) return &session->header.env; } =20 -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 =3D arg; + struct perf_session__e_machine_cb_args *args =3D _args; struct machine *machine =3D maps__machine(thread__maps(thread)); =20 - *result =3D thread__e_machine(thread, machine, /*e_flags=3D*/NULL); - return *result !=3D EM_NONE ? 1 : 0; + args->e_machine =3D thread__e_machine(thread, machine, + args->need_e_flags ? &args->e_flags : NULL); + return args->e_machine !=3D EM_NONE ? 1 : 0; } =20 /* * 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 =3D EM_NONE; + struct perf_session__e_machine_cb_args args =3D { + .e_machine =3D EM_NONE, + .need_e_flags =3D e_flags !=3D NULL, + }; + + if (!session) { + /* Default to assuming a host machine. */ + if (e_flags) + *e_flags =3D EF_HOST; + + return EM_HOST; + } =20 machines__for_each_thread(&session->machines, - perf_session__e_machine_cb, - &e_machine); + perf_session__e_machine_cb, + &args); + + if (e_flags) + *e_flags =3D args.e_flags; =20 - return e_machine =3D=3D EM_NONE ? EM_HOST : e_machine; + return args.e_machine =3D=3D EM_NONE ? EM_HOST : args.e_machine; } diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h index eddc4c630b33..f05f0d4a6c23 100644 --- a/tools/perf/util/session.h +++ b/tools/perf/util/session.h @@ -211,6 +211,6 @@ int perf_event__process_finished_round(const struct per= f_tool *tool, struct ordered_events *oe); =20 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); =20 #endif /* __PERF_SESSION_H */ --=20 2.53.0.rc2.204.g2597b5adb4-goog