From: "Mi, Dapeng" <dapeng1.mi@linux.intel.com>
To: Sandipan Das <sandipan.das@amd.com>,
linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Namhyung Kim <namhyung@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Jiri Olsa <jolsa@kernel.org>, Ian Rogers <irogers@google.com>,
Adrian Hunter <adrian.hunter@intel.com>,
James Clark <james.clark@linaro.org>,
Thomas Gleixner <tglx@kernel.org>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
x86@kernel.org, "H . Peter Anvin" <hpa@zytor.com>,
Petr Tesarik <ptesarik@suse.com>,
Ravi Bangoria <ravi.bangoria@amd.com>,
Ananth Narayan <ananth.narayan@amd.com>
Subject: Re: [PATCH 1/3] perf/x86: Add x86_pmu::print_debug
Date: Wed, 12 Aug 2026 10:37:20 +0800 [thread overview]
Message-ID: <7078a9e7-6493-42b0-b297-ce174effdfb3@linux.intel.com> (raw)
In-Reply-To: <fc6ff612d26c2f5b0f015d9fac309cc58e913c1f.1786010408.git.sandipan.das@amd.com>
On 8/6/2026 6:03 PM, Sandipan Das wrote:
> perf_event_print_debug() dumps the global control and status MSRs
> whenever x86_pmu.version >= 2, reading registers that exist only on
> Intel-compatible PMUs. This is not safe since x86_pmu.version is not
> Intel-specific and is now set by other vendors whose global registers
> use different addresses.
>
> As a first step, split perf_event_print_debug() in two. The register
> dump moves into a new common helper, x86_pmu_print_debug(), leaving
> perf_event_print_debug() to handle the preamble and dispatch to an
> optional x86_pmu::print_debug method. This lets each vendor-specific
> PMU dump its own global state before chaining into the common helper.
> PMUs that do not implement the method, such as those with
> x86_pmu.version < 2, get the common helper alone.
>
> No functional change intended.
>
> Signed-off-by: Sandipan Das <sandipan.das@amd.com>
> ---
> arch/x86/events/core.c | 29 ++++++++++++++++++++++-------
> arch/x86/events/perf_event.h | 4 ++++
> 2 files changed, 26 insertions(+), 7 deletions(-)
>
> diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c
> index af0b67ffb43d..17dc53a62378 100644
> --- a/arch/x86/events/core.c
> +++ b/arch/x86/events/core.c
> @@ -1557,7 +1557,7 @@ static void x86_pmu_start(struct perf_event *event, int flags)
> perf_event_update_userpage(event);
> }
>
> -void perf_event_print_debug(void)
> +void x86_pmu_print_debug(int cpu)
> {
> u64 ctrl, status, overflow, pmc_ctrl, pmc_count, prev_left, fixed;
> unsigned long *cntr_mask, *fixed_cntr_mask;
> @@ -1566,17 +1566,11 @@ void perf_event_print_debug(void)
> u64 pebs, debugctl;
> int cpu, idx;
>
> - guard(irqsave)();
> -
> - cpu = smp_processor_id();
> cpuc = &per_cpu(cpu_hw_events, cpu);
> cntr_mask = hybrid(cpuc->pmu, cntr_mask);
> fixed_cntr_mask = hybrid(cpuc->pmu, fixed_cntr_mask);
> pebs_constraints = hybrid(cpuc->pmu, pebs_constraints);
>
> - if (!*(u64 *)cntr_mask)
> - return;
> -
> if (x86_pmu.version >= 2) {
> rdmsrq(MSR_CORE_PERF_GLOBAL_CTRL, ctrl);
> rdmsrq(MSR_CORE_PERF_GLOBAL_STATUS, status);
> @@ -1622,6 +1616,27 @@ void perf_event_print_debug(void)
> }
> }
>
> +void perf_event_print_debug(void)
> +{
> + struct cpu_hw_events *cpuc;
> + unsigned long *cntr_mask;
> + int cpu;
> +
> + guard(irqsave)();
> +
> + cpu = smp_processor_id();
> + cpuc = &per_cpu(cpu_hw_events, cpu);
> + cntr_mask = hybrid(cpuc->pmu, cntr_mask);
> +
> + if (!*(u64 *)cntr_mask)
> + return;
> +
> + if (x86_pmu.print_debug)
> + x86_pmu.print_debug(cpu);
> + else
> + x86_pmu_print_debug(cpu);
The logic looks good, but better change this to the static_call() just like
other x86_pmu callbacks. It eliminates the branch prediction cost. Thanks.
> +}
> +
> void x86_pmu_stop(struct perf_event *event, int flags)
> {
> struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
> diff --git a/arch/x86/events/perf_event.h b/arch/x86/events/perf_event.h
> index a8afea8d38f0..465bf513bb82 100644
> --- a/arch/x86/events/perf_event.h
> +++ b/arch/x86/events/perf_event.h
> @@ -1052,6 +1052,8 @@ struct x86_pmu {
> int num_hybrid_pmus;
> struct x86_hybrid_pmu *hybrid_pmu;
> enum intel_cpu_type (*get_hybrid_cpu_type) (void);
> +
> + void (*print_debug)(int cpu);
> };
>
> struct x86_perf_task_context_opt {
> @@ -1316,6 +1318,8 @@ int x86_pmu_handle_irq(struct pt_regs *regs);
>
> void x86_pmu_show_pmu_cap(struct pmu *pmu);
>
> +void x86_pmu_print_debug(int cpu);
> +
> static inline int x86_pmu_num_counters(struct pmu *pmu)
> {
> return hweight64(hybrid(pmu, cntr_mask64));
next prev parent reply other threads:[~2026-08-12 2:37 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-06 10:03 [PATCH 0/3] perf/x86: Fix perf_event_print_debug() on non-Intel PMUs Sandipan Das
2026-08-06 10:03 ` [PATCH 1/3] perf/x86: Add x86_pmu::print_debug Sandipan Das
2026-08-06 10:24 ` sashiko-bot
2026-08-12 2:37 ` Mi, Dapeng [this message]
2026-08-06 10:03 ` [PATCH 2/3] perf/x86: Move MSR_CORE_PERF_GLOBAL_* dump to vendor code Sandipan Das
2026-08-06 10:03 ` [PATCH 3/3] perf/x86/amd: Implement x86_pmu::print_debug Sandipan Das
2026-08-06 15:44 ` Petr Tesarik
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=7078a9e7-6493-42b0-b297-ce174effdfb3@linux.intel.com \
--to=dapeng1.mi@linux.intel.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=ananth.narayan@amd.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=irogers@google.com \
--cc=james.clark@linaro.org \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=ptesarik@suse.com \
--cc=ravi.bangoria@amd.com \
--cc=sandipan.das@amd.com \
--cc=tglx@kernel.org \
--cc=x86@kernel.org \
/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