Skip to content

Commit 9c63a65

Browse files
committed
tools/power/x86/turbostat: share kernel MSR #defines
Now that turbostat is built in the kernel tree, it can share MSR #defines with the kernel. Signed-off-by: Len Brown <len.brown@intel.com> Cc: x86@kernel.org
1 parent d91bb17 commit 9c63a65

File tree

3 files changed

+22
-19
lines changed

3 files changed

+22
-19
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,14 @@
3535
#define MSR_IA32_PERFCTR0 0x000000c1
3636
#define MSR_IA32_PERFCTR1 0x000000c2
3737
#define MSR_FSB_FREQ 0x000000cd
38+
#define MSR_NHM_PLATFORM_INFO 0x000000ce
3839

3940
#define MSR_NHM_SNB_PKG_CST_CFG_CTL 0x000000e2
4041
#define NHM_C3_AUTO_DEMOTE (1UL << 25)
4142
#define NHM_C1_AUTO_DEMOTE (1UL << 26)
4243
#define ATM_LNC_C6_AUTO_DEMOTE (1UL << 25)
44+
#define SNB_C1_AUTO_UNDEMOTE (1UL << 27)
45+
#define SNB_C3_AUTO_UNDEMOTE (1UL << 28)
4346

4447
#define MSR_MTRRcap 0x000000fe
4548
#define MSR_IA32_BBL_CR_CTL 0x00000119
@@ -55,6 +58,8 @@
5558

5659
#define MSR_OFFCORE_RSP_0 0x000001a6
5760
#define MSR_OFFCORE_RSP_1 0x000001a7
61+
#define MSR_NHM_TURBO_RATIO_LIMIT 0x000001ad
62+
#define MSR_IVT_TURBO_RATIO_LIMIT 0x000001ae
5863

5964
#define MSR_LBR_SELECT 0x000001c8
6065
#define MSR_LBR_TOS 0x000001c9
@@ -103,6 +108,15 @@
103108
#define MSR_IA32_MC0_ADDR 0x00000402
104109
#define MSR_IA32_MC0_MISC 0x00000403
105110

111+
/* C-state Residency Counters */
112+
#define MSR_PKG_C3_RESIDENCY 0x000003f8
113+
#define MSR_PKG_C6_RESIDENCY 0x000003f9
114+
#define MSR_PKG_C7_RESIDENCY 0x000003fa
115+
#define MSR_CORE_C3_RESIDENCY 0x000003fc
116+
#define MSR_CORE_C6_RESIDENCY 0x000003fd
117+
#define MSR_CORE_C7_RESIDENCY 0x000003fe
118+
#define MSR_PKG_C2_RESIDENCY 0x0000060d
119+
106120
#define MSR_AMD64_MC0_MASK 0xc0010044
107121

108122
#define MSR_IA32_MCx_CTL(x) (MSR_IA32_MC0_CTL + 4*(x))

tools/power/x86/turbostat/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
turbostat : turbostat.c
22
CFLAGS += -Wall
3+
CFLAGS += -I../../../../arch/x86/include/
34

45
clean :
56
rm -f turbostat

tools/power/x86/turbostat/turbostat.c

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
*/
2121

2222
#define _GNU_SOURCE
23+
#include <asm/msr.h>
2324
#include <stdio.h>
2425
#include <unistd.h>
2526
#include <sys/types.h>
@@ -35,19 +36,6 @@
3536
#include <ctype.h>
3637
#include <sched.h>
3738

38-
#define MSR_NEHALEM_PLATFORM_INFO 0xCE
39-
#define MSR_NEHALEM_TURBO_RATIO_LIMIT 0x1AD
40-
#define MSR_IVT_TURBO_RATIO_LIMIT 0x1AE
41-
#define MSR_APERF 0xE8
42-
#define MSR_MPERF 0xE7
43-
#define MSR_PKG_C2_RESIDENCY 0x60D /* SNB only */
44-
#define MSR_PKG_C3_RESIDENCY 0x3F8
45-
#define MSR_PKG_C6_RESIDENCY 0x3F9
46-
#define MSR_PKG_C7_RESIDENCY 0x3FA /* SNB only */
47-
#define MSR_CORE_C3_RESIDENCY 0x3FC
48-
#define MSR_CORE_C6_RESIDENCY 0x3FD
49-
#define MSR_CORE_C7_RESIDENCY 0x3FE /* SNB only */
50-
5139
char *proc_stat = "/proc/stat";
5240
unsigned int interval_sec = 5; /* set with -i interval_sec */
5341
unsigned int verbose; /* set with -v */
@@ -674,9 +662,9 @@ int get_counters(struct thread_data *t, struct core_data *c, struct pkg_data *p)
674662
t->tsc = rdtsc(); /* we are running on local CPU of interest */
675663

676664
if (has_aperf) {
677-
if (get_msr(cpu, MSR_APERF, &t->aperf))
665+
if (get_msr(cpu, MSR_IA32_APERF, &t->aperf))
678666
return -3;
679-
if (get_msr(cpu, MSR_MPERF, &t->mperf))
667+
if (get_msr(cpu, MSR_IA32_MPERF, &t->mperf))
680668
return -4;
681669
}
682670

@@ -742,10 +730,10 @@ void print_verbose_header(void)
742730
if (!do_nehalem_platform_info)
743731
return;
744732

745-
get_msr(0, MSR_NEHALEM_PLATFORM_INFO, &msr);
733+
get_msr(0, MSR_NHM_PLATFORM_INFO, &msr);
746734

747735
if (verbose > 1)
748-
fprintf(stderr, "MSR_NEHALEM_PLATFORM_INFO: 0x%llx\n", msr);
736+
fprintf(stderr, "MSR_NHM_PLATFORM_INFO: 0x%llx\n", msr);
749737

750738
ratio = (msr >> 40) & 0xFF;
751739
fprintf(stderr, "%d * %.0f = %.0f MHz max efficiency\n",
@@ -808,10 +796,10 @@ void print_verbose_header(void)
808796
if (!do_nehalem_turbo_ratio_limit)
809797
return;
810798

811-
get_msr(0, MSR_NEHALEM_TURBO_RATIO_LIMIT, &msr);
799+
get_msr(0, MSR_NHM_TURBO_RATIO_LIMIT, &msr);
812800

813801
if (verbose > 1)
814-
fprintf(stderr, "MSR_NEHALEM_TURBO_RATIO_LIMIT: 0x%llx\n", msr);
802+
fprintf(stderr, "MSR_NHM_TURBO_RATIO_LIMIT: 0x%llx\n", msr);
815803

816804
ratio = (msr >> 56) & 0xFF;
817805
if (ratio)

0 commit comments

Comments
 (0)