From: Leo Yan <leo.yan@linux.dev>
To: Ian Rogers <irogers@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Namhyung Kim <namhyung@kernel.org>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Jiri Olsa <jolsa@kernel.org>,
Adrian Hunter <adrian.hunter@intel.com>,
James Clark <james.clark@linaro.org>,
John Garry <john.g.garry@oracle.com>,
Will Deacon <will@kernel.org>, Mike Leach <mike.leach@linaro.org>,
Paul Walmsley <pjw@kernel.org>,
Palmer Dabbelt <palmer@dabbelt.com>,
Albert Ou <aou@eecs.berkeley.edu>,
Alexandre Ghiti <alex@ghiti.fr>,
Shimin Guo <shimin.guo@skydio.com>,
Yunseong Kim <ysk@kzalloc.com>,
Athira Rajeev <atrajeev@linux.ibm.com>,
Quan Zhou <zhouquan@iscas.ac.cn>,
Andrew Jones <ajones@ventanamicro.com>,
Anup Patel <anup@brainfault.org>,
Dapeng Mi <dapeng1.mi@linux.intel.com>,
Thomas Falcon <thomas.falcon@intel.com>,
Blake Jones <blakejones@google.com>,
Swapnil Sapkal <swapnil.sapkal@amd.com>,
Kan Liang <kan.liang@linux.intel.com>,
Howard Chu <howardchu95@gmail.com>,
Anubhav Shelat <ashelat@redhat.com>,
Aditya Bodkhe <aditya.b1@linux.ibm.com>,
Chun-Tse Shao <ctshao@google.com>,
Andi Kleen <ak@linux.intel.com>,
Dmitry Vyukov <dvyukov@google.com>,
linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-riscv@lists.infradead.org
Subject: Re: [PATCH v2 2/6] perf kvm stat: Remove use of the arch directory
Date: Mon, 2 Feb 2026 01:04:59 +0800 [thread overview]
Message-ID: <20260201170459.GA584@debian-dev> (raw)
In-Reply-To: <20260131200224.1296136-3-irogers@google.com>
On Sat, Jan 31, 2026 at 12:02:20PM -0800, Ian Rogers wrote:
[...]
> @@ -1666,7 +1661,7 @@ kvm_events_record(struct perf_kvm_stat *kvm, int argc, const char **argv)
> return ret;
> }
>
> - for (events_tp = kvm_events_tp; *events_tp; events_tp++)
> + for (events_tp = kvm_events_tp(); *events_tp; events_tp++)
> events_tp_size++;
>
> rec_argc = ARRAY_SIZE(record_args) + argc + 2 +
> @@ -1681,7 +1676,7 @@ kvm_events_record(struct perf_kvm_stat *kvm, int argc, const char **argv)
>
> for (j = 0; j < events_tp_size; j++) {
> rec_argv[i++] = STRDUP_FAIL_EXIT("-e");
> - rec_argv[i++] = STRDUP_FAIL_EXIT(kvm_events_tp[j]);
> + rec_argv[i++] = STRDUP_FAIL_EXIT(kvm_events_tp()[j]);
> }
Nitpick: we can assign reuse events_tp throughout the
kvm_events_record(). Something like:
events_tp = kvm_events_tp();
for (j = 0; events_tp[j]; j++)
events_tp_size++;
...
for (j = 0; j < events_tp_size; j++) {
rec_argv[i++] = STRDUP_FAIL_EXIT("-e");
rec_argv[i++] = STRDUP_FAIL_EXIT(events_tp[j]);
}
[...]
> +int setup_kvm_events_tp(struct perf_kvm_stat *kvm)
> +{
> + switch (EM_HOST) {
> + case EM_PPC:
> + case EM_PPC64:
> + return __setup_kvm_events_tp_powerpc(kvm);
> + default:
> + return 0;
> + }
> +}
> +
> +int cpu_isa_init(struct perf_kvm_stat *kvm, const char *cpuid)
> +{
> + switch (EM_HOST) {
> + case EM_AARCH64:
> + return __cpu_isa_init_arm64(kvm);
> + case EM_LOONGARCH:
> + return __cpu_isa_init_loongarch(kvm);
> + case EM_PPC:
> + case EM_PPC64:
> + return __cpu_isa_init_powerpc(kvm);
> + case EM_RISCV:
> + return __cpu_isa_init_riscv(kvm);
> + case EM_S390:
> + return __cpu_isa_init_s390(kvm, cpuid);
> + case EM_X86_64:
> + case EM_386:
> + return __cpu_isa_init_x86(kvm, cpuid);
> + default:
> + pr_err("Unsupported kvm-stat host %d\n", EM_HOST);
> + return -1;
> + }
> +}
For a general solution, I'd prefer to use "install" + callback methods
rather than the opened code. E.g., each arch installs a structure
with callbacks:
struct kvm_stat_arch kvm_stat_aarch64 {
.setup_events_tp = NULL;
.cpu_isa_init = __cpu_isa_init_arm64;
...
};
Then at the init phase, we can install arch's structure:
switch (EM_HOST) {
case EM_AARCH64:
kvm_stat_arch_init(&kvm_stat_aarch64);
break;
...
}
Afterwards, it is no need to check EM_HOST anymore, it can simply
invoke the arch's callback:
int cpu_isa_init(struct perf_kvm_stat *kvm, const char *cpuid)
{
if (!arch_kvm_stat || !arch_kvm_stat->cpu_isa_init)
return -1;
return arch_kvm_stat->cpu_isa_init(kvm, cpuid);
}
As a result, we can avoid spreading "switch (EM_HOST)" everywhere.
Thanks,
Leo
next prev parent reply other threads:[~2026-02-01 17:05 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-31 20:02 [PATCH v2 0/6] perf Cross platform KVM support Ian Rogers
2026-01-31 20:02 ` [PATCH v2 1/6] perf test kvm: Add stat live testing Ian Rogers
2026-01-31 20:02 ` [PATCH v2 2/6] perf kvm stat: Remove use of the arch directory Ian Rogers
2026-02-01 17:04 ` Leo Yan [this message]
2026-02-02 1:55 ` Ian Rogers
2026-01-31 20:02 ` [PATCH v2 3/6] perf kvm: Wire up e_machine Ian Rogers
2026-01-31 20:02 ` [PATCH v2 4/6] perf session: Add e_flags to the e_machine helper Ian Rogers
2026-01-31 20:02 ` [PATCH v2 5/6] perf header: Add e_machine/e_flags to the header Ian Rogers
2026-01-31 20:02 ` [PATCH v2 6/6] perf thread: Don't require machine to compute the e_machine Ian Rogers
2026-02-03 14:42 ` [PATCH v2 0/6] perf Cross platform KVM support Arnaldo Carvalho de Melo
2026-02-03 14:57 ` Arnaldo Carvalho de Melo
2026-02-03 15:03 ` Arnaldo Carvalho de Melo
2026-02-03 18:26 ` [PATCH v3 0/5] " Ian Rogers
2026-02-03 18:26 ` [PATCH v3 1/5] perf kvm stat: Remove use of the arch directory Ian Rogers
2026-03-24 6:07 ` patchwork-bot+linux-riscv
2026-02-03 18:26 ` [PATCH v3 2/5] perf kvm: Wire up e_machine Ian Rogers
2026-02-03 18:26 ` [PATCH v3 3/5] perf session: Add e_flags to the e_machine helper Ian Rogers
2026-02-03 18:26 ` [PATCH v3 4/5] perf header: Add e_machine/e_flags to the header Ian Rogers
2026-02-03 18:26 ` [PATCH v3 5/5] perf thread: Don't require machine to compute the e_machine Ian Rogers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260201170459.GA584@debian-dev \
--to=leo.yan@linux.dev \
--cc=acme@kernel.org \
--cc=aditya.b1@linux.ibm.com \
--cc=adrian.hunter@intel.com \
--cc=ajones@ventanamicro.com \
--cc=ak@linux.intel.com \
--cc=alex@ghiti.fr \
--cc=alexander.shishkin@linux.intel.com \
--cc=anup@brainfault.org \
--cc=aou@eecs.berkeley.edu \
--cc=ashelat@redhat.com \
--cc=atrajeev@linux.ibm.com \
--cc=blakejones@google.com \
--cc=ctshao@google.com \
--cc=dapeng1.mi@linux.intel.com \
--cc=dvyukov@google.com \
--cc=howardchu95@gmail.com \
--cc=irogers@google.com \
--cc=james.clark@linaro.org \
--cc=john.g.garry@oracle.com \
--cc=jolsa@kernel.org \
--cc=kan.liang@linux.intel.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=mike.leach@linaro.org \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=palmer@dabbelt.com \
--cc=peterz@infradead.org \
--cc=pjw@kernel.org \
--cc=shimin.guo@skydio.com \
--cc=swapnil.sapkal@amd.com \
--cc=thomas.falcon@intel.com \
--cc=will@kernel.org \
--cc=ysk@kzalloc.com \
--cc=zhouquan@iscas.ac.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox