Skip to content

Commit 21b5ee5

Browse files
kimphillamdsuryasaimadhu
authored andcommitted
x86/cpu/amd: Enable the fixed Instructions Retired counter IRPERF
Commit aaf2488 ("perf/x86/msr: Add AMD IRPERF (Instructions Retired) performance counter") added support for access to the free-running counter via 'perf -e msr/irperf/', but when exercised, it always returns a 0 count: BEFORE: $ perf stat -e instructions,msr/irperf/ true Performance counter stats for 'true': 624,833 instructions 0 msr/irperf/ Simply set its enable bit - HWCR bit 30 - to make it start counting. Enablement is restricted to all machines advertising IRPERF capability, except those susceptible to an erratum that makes the IRPERF return bad values. That erratum occurs in Family 17h models 00-1fh [1], but not in F17h models 20h and above [2]. AFTER (on a family 17h model 31h machine): $ perf stat -e instructions,msr/irperf/ true Performance counter stats for 'true': 621,690 instructions 622,490 msr/irperf/ [1] Revision Guide for AMD Family 17h Models 00h-0Fh Processors [2] Revision Guide for AMD Family 17h Models 30h-3Fh Processors The revision guides are available from the bugzilla Link below. [ bp: Massage commit message. ] Fixes: aaf2488 ("perf/x86/msr: Add AMD IRPERF (Instructions Retired) performance counter") Signed-off-by: Kim Phillips <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: [email protected] Link: https://bugzilla.kernel.org/show_bug.cgi?id=206537 Link: http://lkml.kernel.org/r/[email protected]
1 parent df6d4f9 commit 21b5ee5

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

arch/x86/include/asm/msr-index.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,8 @@
512512
#define MSR_K7_HWCR 0xc0010015
513513
#define MSR_K7_HWCR_SMMLOCK_BIT 0
514514
#define MSR_K7_HWCR_SMMLOCK BIT_ULL(MSR_K7_HWCR_SMMLOCK_BIT)
515+
#define MSR_K7_HWCR_IRPERF_EN_BIT 30
516+
#define MSR_K7_HWCR_IRPERF_EN BIT_ULL(MSR_K7_HWCR_IRPERF_EN_BIT)
515517
#define MSR_K7_FID_VID_CTL 0xc0010041
516518
#define MSR_K7_FID_VID_STATUS 0xc0010042
517519

arch/x86/kernel/cpu/amd.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
static const int amd_erratum_383[];
3030
static const int amd_erratum_400[];
31+
static const int amd_erratum_1054[];
3132
static bool cpu_has_amd_erratum(struct cpuinfo_x86 *cpu, const int *erratum);
3233

3334
/*
@@ -972,6 +973,15 @@ static void init_amd(struct cpuinfo_x86 *c)
972973
/* AMD CPUs don't reset SS attributes on SYSRET, Xen does. */
973974
if (!cpu_has(c, X86_FEATURE_XENPV))
974975
set_cpu_bug(c, X86_BUG_SYSRET_SS_ATTRS);
976+
977+
/*
978+
* Turn on the Instructions Retired free counter on machines not
979+
* susceptible to erratum #1054 "Instructions Retired Performance
980+
* Counter May Be Inaccurate".
981+
*/
982+
if (cpu_has(c, X86_FEATURE_IRPERF) &&
983+
!cpu_has_amd_erratum(c, amd_erratum_1054))
984+
msr_set_bit(MSR_K7_HWCR, MSR_K7_HWCR_IRPERF_EN_BIT);
975985
}
976986

977987
#ifdef CONFIG_X86_32
@@ -1099,6 +1109,10 @@ static const int amd_erratum_400[] =
10991109
static const int amd_erratum_383[] =
11001110
AMD_OSVW_ERRATUM(3, AMD_MODEL_RANGE(0x10, 0, 0, 0xff, 0xf));
11011111

1112+
/* #1054: Instructions Retired Performance Counter May Be Inaccurate */
1113+
static const int amd_erratum_1054[] =
1114+
AMD_OSVW_ERRATUM(0, AMD_MODEL_RANGE(0x17, 0, 0, 0x2f, 0xf));
1115+
11021116

11031117
static bool cpu_has_amd_erratum(struct cpuinfo_x86 *cpu, const int *erratum)
11041118
{

0 commit comments

Comments
 (0)