Skip to content

Commit e0253c4

Browse files
kimphillamdgregkh
authored andcommitted
x86/cpu/amd: Enable the fixed Instructions Retired counter IRPERF
commit 21b5ee5 upstream. 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] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 88e4901 commit e0253c4

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
@@ -510,6 +510,8 @@
510510
#define MSR_K7_HWCR 0xc0010015
511511
#define MSR_K7_HWCR_SMMLOCK_BIT 0
512512
#define MSR_K7_HWCR_SMMLOCK BIT_ULL(MSR_K7_HWCR_SMMLOCK_BIT)
513+
#define MSR_K7_HWCR_IRPERF_EN_BIT 30
514+
#define MSR_K7_HWCR_IRPERF_EN BIT_ULL(MSR_K7_HWCR_IRPERF_EN_BIT)
513515
#define MSR_K7_FID_VID_CTL 0xc0010041
514516
#define MSR_K7_FID_VID_STATUS 0xc0010042
515517

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
/*
@@ -978,6 +979,15 @@ static void init_amd(struct cpuinfo_x86 *c)
978979
/* AMD CPUs don't reset SS attributes on SYSRET, Xen does. */
979980
if (!cpu_has(c, X86_FEATURE_XENPV))
980981
set_cpu_bug(c, X86_BUG_SYSRET_SS_ATTRS);
982+
983+
/*
984+
* Turn on the Instructions Retired free counter on machines not
985+
* susceptible to erratum #1054 "Instructions Retired Performance
986+
* Counter May Be Inaccurate".
987+
*/
988+
if (cpu_has(c, X86_FEATURE_IRPERF) &&
989+
!cpu_has_amd_erratum(c, amd_erratum_1054))
990+
msr_set_bit(MSR_K7_HWCR, MSR_K7_HWCR_IRPERF_EN_BIT);
981991
}
982992

983993
#ifdef CONFIG_X86_32
@@ -1105,6 +1115,10 @@ static const int amd_erratum_400[] =
11051115
static const int amd_erratum_383[] =
11061116
AMD_OSVW_ERRATUM(3, AMD_MODEL_RANGE(0x10, 0, 0, 0xff, 0xf));
11071117

1118+
/* #1054: Instructions Retired Performance Counter May Be Inaccurate */
1119+
static const int amd_erratum_1054[] =
1120+
AMD_OSVW_ERRATUM(0, AMD_MODEL_RANGE(0x17, 0, 0, 0x2f, 0xf));
1121+
11081122

11091123
static bool cpu_has_amd_erratum(struct cpuinfo_x86 *cpu, const int *erratum)
11101124
{

0 commit comments

Comments
 (0)