]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
perf/x86: Fix non-sampling (counting) events on certain x86 platforms
authorLuo Gengkun <luogengkun@huaweicloud.com>
Wed, 23 Apr 2025 06:47:24 +0000 (06:47 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 2 May 2025 05:50:45 +0000 (07:50 +0200)
[ Upstream commit 1a97fea9db9e9b9c4839d4232dde9f505ff5b4cc ]

Perf doesn't work at perf stat for hardware events on certain x86 platforms:

 $perf stat -- sleep 1
 Performance counter stats for 'sleep 1':
             16.44 msec task-clock                       #    0.016 CPUs utilized
                 2      context-switches                 #  121.691 /sec
                 0      cpu-migrations                   #    0.000 /sec
                54      page-faults                      #    3.286 K/sec
   <not supported> cycles
   <not supported> instructions
   <not supported> branches
   <not supported> branch-misses

The reason is that the check in x86_pmu_hw_config() for sampling events is
unexpectedly applied to counting events as well.

It should only impact x86 platforms with limit_period used for non-PEBS
events. For Intel platforms, it should only impact some older platforms,
e.g., HSW, BDW and NHM.

Fixes: 88ec7eedbbd2 ("perf/x86: Fix low freqency setting issue")
Signed-off-by: Luo Gengkun <luogengkun@huaweicloud.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Reviewed-by: Kan Liang <kan.liang@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Link: https://lore.kernel.org/r/20250423064724.3716211-1-luogengkun@huaweicloud.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
arch/x86/events/core.c

index 1458ccaa6a05792addb8662e0bb6256c9c7ddfb9..ad63bd408cd9003ab4a45fe56cab6690b815987f 100644 (file)
@@ -623,7 +623,7 @@ int x86_pmu_hw_config(struct perf_event *event)
        if (event->attr.type == event->pmu->type)
                event->hw.config |= event->attr.config & X86_RAW_EVENT_MASK;
 
-       if (!event->attr.freq && x86_pmu.limit_period) {
+       if (is_sampling_event(event) && !event->attr.freq && x86_pmu.limit_period) {
                s64 left = event->attr.sample_period;
                x86_pmu.limit_period(event, &left);
                if (left > event->attr.sample_period)