Skip to content

Commit 7ef0343

Browse files
sandip4nPeter Zijlstra
authored and
Peter Zijlstra
committed
perf/x86/amd/uncore: Use rdmsr if rdpmc is unavailable
Not all uncore PMUs may support the use of the RDPMC instruction for reading counters. In such cases, read the count from the corresponding PERF_CTR register using the RDMSR instruction. Signed-off-by: Sandipan Das <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lore.kernel.org/r/e9d994e32a3fcb39fa59fcf43ab4260d11aba097.1696425185.git.sandipan.das@amd.com
1 parent 07888da commit 7ef0343

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

arch/x86/events/amd/uncore.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,16 @@ static void amd_uncore_read(struct perf_event *event)
9696
*/
9797

9898
prev = local64_read(&hwc->prev_count);
99-
rdpmcl(hwc->event_base_rdpmc, new);
99+
100+
/*
101+
* Some uncore PMUs do not have RDPMC assignments. In such cases,
102+
* read counts directly from the corresponding PERF_CTR.
103+
*/
104+
if (hwc->event_base_rdpmc < 0)
105+
rdmsrl(hwc->event_base, new);
106+
else
107+
rdpmcl(hwc->event_base_rdpmc, new);
108+
100109
local64_set(&hwc->prev_count, new);
101110
delta = (new << COUNTER_SHIFT) - (prev << COUNTER_SHIFT);
102111
delta >>= COUNTER_SHIFT;
@@ -164,6 +173,9 @@ static int amd_uncore_add(struct perf_event *event, int flags)
164173
hwc->event_base_rdpmc = pmu->rdpmc_base + hwc->idx;
165174
hwc->state = PERF_HES_UPTODATE | PERF_HES_STOPPED;
166175

176+
if (pmu->rdpmc_base < 0)
177+
hwc->event_base_rdpmc = -1;
178+
167179
if (flags & PERF_EF_START)
168180
event->pmu->start(event, PERF_EF_RELOAD);
169181

0 commit comments

Comments
 (0)