Skip to content

Commit

Permalink
perf/x86/amd/uncore: Use rdmsr if rdpmc is unavailable
Browse files Browse the repository at this point in the history
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 <sandipan.das@amd.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lore.kernel.org/r/e9d994e32a3fcb39fa59fcf43ab4260d11aba097.1696425185.git.sandipan.das@amd.com
  • Loading branch information
sandip4n authored and Peter Zijlstra committed Oct 9, 2023
1 parent 07888da commit 7ef0343
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion arch/x86/events/amd/uncore.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,16 @@ static void amd_uncore_read(struct perf_event *event)
*/

prev = local64_read(&hwc->prev_count);
rdpmcl(hwc->event_base_rdpmc, new);

/*
* Some uncore PMUs do not have RDPMC assignments. In such cases,
* read counts directly from the corresponding PERF_CTR.
*/
if (hwc->event_base_rdpmc < 0)
rdmsrl(hwc->event_base, new);
else
rdpmcl(hwc->event_base_rdpmc, new);

local64_set(&hwc->prev_count, new);
delta = (new << COUNTER_SHIFT) - (prev << COUNTER_SHIFT);
delta >>= COUNTER_SHIFT;
Expand Down Expand Up @@ -164,6 +173,9 @@ static int amd_uncore_add(struct perf_event *event, int flags)
hwc->event_base_rdpmc = pmu->rdpmc_base + hwc->idx;
hwc->state = PERF_HES_UPTODATE | PERF_HES_STOPPED;

if (pmu->rdpmc_base < 0)
hwc->event_base_rdpmc = -1;

if (flags & PERF_EF_START)
event->pmu->start(event, PERF_EF_RELOAD);

Expand Down

0 comments on commit 7ef0343

Please sign in to comment.