1 // SPDX-License-Identifier: GPL-2.0-only
3 * (C) 2003 - 2004 Dominik Brodowski <linux@dominikbrodowski.de>
5 * Based on code found in
6 * linux/arch/i386/kernel/cpu/cpufreq/speedstep-centrino.c
7 * and originally developed by Jeremy Fitzhardinge.
9 * USAGE: simply run it to decode the current settings on CPU 0,
10 * or pass the CPU number as argument, or pass the MSR content
21 #include <sys/types.h>
26 #define MSR_IA32_PERF_STATUS 0x198
28 static int rdmsr(unsigned int cpu, unsigned int msr,
29 unsigned int *lo, unsigned int *hi)
33 unsigned long long val;
41 sprintf(file, "/dev/cpu/%d/msr", cpu);
42 fd = open(file, O_RDONLY);
47 if (lseek(fd, msr, SEEK_CUR) == -1)
50 if (read(fd, &val, 8) != 8)
53 *lo = (uint32_t )(val & 0xffffffffull);
54 *hi = (uint32_t )(val>>32 & 0xffffffffull);
63 static void decode (unsigned int msr)
65 unsigned int multiplier;
68 multiplier = ((msr >> 8) & 0xFF);
70 mv = (((msr & 0xFF) * 16) + 700);
72 printf("0x%x means multiplier %d @ %d mV\n", msr, multiplier, mv);
75 static int decode_live(unsigned int cpu)
80 err = rdmsr(cpu, MSR_IA32_PERF_STATUS, &lo, &hi);
83 printf("can't get MSR_IA32_PERF_STATUS for cpu %d\n", cpu);
84 printf("Possible trouble: you don't run an Enhanced SpeedStep capable cpu\n");
85 printf("or you are not root, or the msr driver is not present\n");
94 int main (int argc, char **argv)
96 unsigned int cpu, mode = 0;
101 cpu = strtoul(argv[1], NULL, 0);