1 #if defined(__i386__) || defined(__x86_64__)
8 #include "helpers/helpers.h"
10 /* Intel specific MSRs */
11 #define MSR_IA32_PERF_STATUS 0x198
12 #define MSR_IA32_MISC_ENABLES 0x1a0
13 #define MSR_IA32_ENERGY_PERF_BIAS 0x1b0
18 * Will return 0 on success and -1 on failure.
19 * Possible errno values could be:
20 * EFAULT -If the read/write did not fully complete
21 * EIO -If the CPU does not support MSRs
22 * ENXIO -If the CPU does not exist
25 int read_msr(int cpu, unsigned int idx, unsigned long long *val)
28 char msr_file_name[64];
30 sprintf(msr_file_name, "/dev/cpu/%d/msr", cpu);
31 fd = open(msr_file_name, O_RDONLY);
34 if (lseek(fd, idx, SEEK_CUR) == -1)
36 if (read(fd, val, sizeof *val) != sizeof *val)
48 * Will return 0 on success and -1 on failure.
49 * Possible errno values could be:
50 * EFAULT -If the read/write did not fully complete
51 * EIO -If the CPU does not support MSRs
52 * ENXIO -If the CPU does not exist
54 int write_msr(int cpu, unsigned int idx, unsigned long long val)
57 char msr_file_name[64];
59 sprintf(msr_file_name, "/dev/cpu/%d/msr", cpu);
60 fd = open(msr_file_name, O_WRONLY);
63 if (lseek(fd, idx, SEEK_CUR) == -1)
65 if (write(fd, &val, sizeof val) != sizeof val)
74 int msr_intel_has_boost_support(unsigned int cpu)
76 unsigned long long misc_enables;
79 ret = read_msr(cpu, MSR_IA32_MISC_ENABLES, &misc_enables);
82 return (misc_enables >> 38) & 0x1;
85 int msr_intel_boost_is_active(unsigned int cpu)
87 unsigned long long perf_status;
90 ret = read_msr(cpu, MSR_IA32_PERF_STATUS, &perf_status);
93 return (perf_status >> 32) & 0x1;
96 int msr_intel_get_perf_bias(unsigned int cpu)
98 unsigned long long val;
101 if (!(cpupower_cpu_info.caps & CPUPOWER_CAP_PERF_BIAS))
104 ret = read_msr(cpu, MSR_IA32_ENERGY_PERF_BIAS, &val);
110 int msr_intel_set_perf_bias(unsigned int cpu, unsigned int val)
114 if (!(cpupower_cpu_info.caps & CPUPOWER_CAP_PERF_BIAS))
117 ret = write_msr(cpu, MSR_IA32_ENERGY_PERF_BIAS, val);