Skip to content

Commit 8a22426

Browse files
huangruiIngo Molnar
authored andcommitted
perf/x86/msr: Add AMD PTSC (Performance Time-Stamp Counter) support
AMD Carrizo (Family 15h, Model 60h) introduces a time-stamp counter which is indicated by CPUID.8000_0001H:ECX[27]. It increments at a 100 MHz rate in all P-states, and C states, S0, or S1. The frequency is about 100MHz. This counter will be used to calculate processor power and other parts. So add an interface into the MSR PMU to get the PTSC counter value. Signed-off-by: Huang Rui <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Andy Lutomirski <[email protected]> Cc: Aravind Gopalakrishnan <[email protected]> Cc: Arnaldo Carvalho de Melo <[email protected]> Cc: Arnaldo Carvalho de Melo <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: Fengguang Wu <[email protected]> Cc: Jacob Shin <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Kan Liang <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Robert Richter <[email protected]> Cc: Stephane Eranian <[email protected]> Cc: Suravee Suthikulpanit <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Vince Weaver <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent c7afba3 commit 8a22426

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

arch/x86/events/msr.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ enum perf_msr_id {
66
PERF_MSR_MPERF = 2,
77
PERF_MSR_PPERF = 3,
88
PERF_MSR_SMI = 4,
9+
PERF_MSR_PTSC = 5,
910

1011
PERF_MSR_EVENT_MAX,
1112
};
@@ -15,6 +16,11 @@ static bool test_aperfmperf(int idx)
1516
return boot_cpu_has(X86_FEATURE_APERFMPERF);
1617
}
1718

19+
static bool test_ptsc(int idx)
20+
{
21+
return boot_cpu_has(X86_FEATURE_PTSC);
22+
}
23+
1824
static bool test_intel(int idx)
1925
{
2026
if (boot_cpu_data.x86_vendor != X86_VENDOR_INTEL ||
@@ -74,13 +80,15 @@ PMU_EVENT_ATTR_STRING(aperf, evattr_aperf, "event=0x01");
7480
PMU_EVENT_ATTR_STRING(mperf, evattr_mperf, "event=0x02");
7581
PMU_EVENT_ATTR_STRING(pperf, evattr_pperf, "event=0x03");
7682
PMU_EVENT_ATTR_STRING(smi, evattr_smi, "event=0x04");
83+
PMU_EVENT_ATTR_STRING(ptsc, evattr_ptsc, "event=0x05");
7784

7885
static struct perf_msr msr[] = {
7986
[PERF_MSR_TSC] = { 0, &evattr_tsc, NULL, },
8087
[PERF_MSR_APERF] = { MSR_IA32_APERF, &evattr_aperf, test_aperfmperf, },
8188
[PERF_MSR_MPERF] = { MSR_IA32_MPERF, &evattr_mperf, test_aperfmperf, },
8289
[PERF_MSR_PPERF] = { MSR_PPERF, &evattr_pperf, test_intel, },
8390
[PERF_MSR_SMI] = { MSR_SMI_COUNT, &evattr_smi, test_intel, },
91+
[PERF_MSR_PTSC] = { MSR_F15H_PTSC, &evattr_ptsc, test_ptsc, },
8492
};
8593

8694
static struct attribute *events_attrs[PERF_MSR_EVENT_MAX + 1] = {

arch/x86/include/asm/cpufeatures.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@
177177
#define X86_FEATURE_PERFCTR_CORE ( 6*32+23) /* core performance counter extensions */
178178
#define X86_FEATURE_PERFCTR_NB ( 6*32+24) /* NB performance counter extensions */
179179
#define X86_FEATURE_BPEXT (6*32+26) /* data breakpoint extension */
180+
#define X86_FEATURE_PTSC ( 6*32+27) /* performance time-stamp counter */
180181
#define X86_FEATURE_PERFCTR_L2 ( 6*32+28) /* L2 performance counter extensions */
181182
#define X86_FEATURE_MWAITX ( 6*32+29) /* MWAIT extension (MONITORX/MWAITX) */
182183

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@
326326
#define MSR_F15H_PERF_CTR 0xc0010201
327327
#define MSR_F15H_NB_PERF_CTL 0xc0010240
328328
#define MSR_F15H_NB_PERF_CTR 0xc0010241
329+
#define MSR_F15H_PTSC 0xc0010280
329330
#define MSR_F15H_IC_CFG 0xc0011021
330331

331332
/* Fam 10h MSRs */

0 commit comments

Comments
 (0)