From: "Mi, Dapeng" <dapeng1.mi@linux.intel.com>
To: Petr Tesarik <ptesarik@suse.com>
Cc: Sandipan Das <sandipan.das@amd.com>,
linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org,
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>,
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: Fri, 14 Aug 2026 08:20:35 +0800 [thread overview]
Message-ID: <8dc153c7-b21b-4fe3-8d14-3bd13c1ee6b5@linux.intel.com> (raw)
In-Reply-To: <20260813145725.22f21719@mordecai>
On 8/13/2026 8:57 PM, Petr Tesarik wrote:
> On Wed, 12 Aug 2026 10:37:20 +0800
> "Mi, Dapeng" <dapeng1.mi@linux.intel.com> wrote:
>
>> 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.
> Is it worth the extra complexity for code that is used only by SysRq
> debugging?
perf_event_print_debug() is not just called in sysrq debugging, it's also
called by intel_pmu_handle_irq() which is a NMI handler. Any code in NMI
handler should be as simple as possible. Thanks.
>
> Of course, if it's trivial, let's do it anyway.
>
> Petr T
next prev parent reply other threads:[~2026-08-14 0:20 UTC|newest]
Thread overview: 8+ 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-12 2:37 ` Mi, Dapeng
2026-08-13 12:57 ` Petr Tesarik
2026-08-14 0:20 ` 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=8dc153c7-b21b-4fe3-8d14-3bd13c1ee6b5@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
all inboxes | Powered by JetHome®