This source file includes following definitions.
- dprint
- decode_pstates
- read_msr
- write_msr
- msr_intel_set_perf_bias
- msr_intel_get_perf_bias
- msr_intel_get_turbo_ratio
- cpufreq_has_boost_support
- cpuid_eax
- cpuid_ebx
- cpuid_ecx
- cpuid_edx
1
2
3
4
5
6
7
8
9 #ifndef __CPUPOWERUTILS_HELPERS__
10 #define __CPUPOWERUTILS_HELPERS__
11
12 #include <libintl.h>
13 #include <locale.h>
14
15 #include "helpers/bitmask.h"
16 #include <cpupower.h>
17
18
19 #ifdef NLS
20
21 #define _(String) gettext(String)
22 #ifndef gettext_noop
23 #define gettext_noop(String) String
24 #endif
25 #define N_(String) gettext_noop(String)
26
27 #else
28
29 #define _(String) String
30 #define N_(String) String
31
32 #endif
33
34
35 extern int run_as_root;
36 extern int base_cpu;
37 extern struct bitmask *cpus_chosen;
38
39
40
41
42
43
44
45
46 #ifdef DEBUG
47 extern int be_verbose;
48
49 #define dprint(fmt, ...) { \
50 if (be_verbose) { \
51 fprintf(stderr, "%s: " fmt, \
52 __func__, ##__VA_ARGS__); \
53 } \
54 }
55 #else
56 static inline void dprint(const char *fmt, ...) { }
57 #endif
58 extern int be_verbose;
59
60
61
62 enum cpupower_cpu_vendor {X86_VENDOR_UNKNOWN = 0, X86_VENDOR_INTEL,
63 X86_VENDOR_AMD, X86_VENDOR_HYGON, X86_VENDOR_MAX};
64
65 #define CPUPOWER_CAP_INV_TSC 0x00000001
66 #define CPUPOWER_CAP_APERF 0x00000002
67 #define CPUPOWER_CAP_AMD_CBP 0x00000004
68 #define CPUPOWER_CAP_PERF_BIAS 0x00000008
69 #define CPUPOWER_CAP_HAS_TURBO_RATIO 0x00000010
70 #define CPUPOWER_CAP_IS_SNB 0x00000020
71 #define CPUPOWER_CAP_INTEL_IDA 0x00000040
72
73 #define CPUPOWER_AMD_CPBDIS 0x02000000
74
75 #define MAX_HW_PSTATES 10
76
77 struct cpupower_cpu_info {
78 enum cpupower_cpu_vendor vendor;
79 unsigned int family;
80 unsigned int model;
81 unsigned int stepping;
82
83 unsigned long long caps;
84 };
85
86
87
88
89
90
91
92
93
94 extern int get_cpu_info(struct cpupower_cpu_info *cpu_info);
95 extern struct cpupower_cpu_info cpupower_cpu_info;
96
97
98
99 #if defined(__i386__) || defined(__x86_64__)
100
101 #include <pci/pci.h>
102
103
104 extern int read_msr(int cpu, unsigned int idx, unsigned long long *val);
105 extern int write_msr(int cpu, unsigned int idx, unsigned long long val);
106
107 extern int msr_intel_set_perf_bias(unsigned int cpu, unsigned int val);
108 extern int msr_intel_get_perf_bias(unsigned int cpu);
109 extern unsigned long long msr_intel_get_turbo_ratio(unsigned int cpu);
110
111
112
113
114 extern int amd_pci_get_num_boost_states(int *active, int *states);
115 extern struct pci_dev *pci_acc_init(struct pci_access **pacc, int domain,
116 int bus, int slot, int func, int vendor,
117 int dev);
118 extern struct pci_dev *pci_slot_func_init(struct pci_access **pacc,
119 int slot, int func);
120
121
122
123
124
125 extern int decode_pstates(unsigned int cpu, unsigned int cpu_family,
126 int boost_states, unsigned long *pstates, int *no);
127
128
129
130 extern int cpufreq_has_boost_support(unsigned int cpu, int *support,
131 int *active, int * states);
132
133
134
135 unsigned int cpuid_eax(unsigned int op);
136 unsigned int cpuid_ebx(unsigned int op);
137 unsigned int cpuid_ecx(unsigned int op);
138 unsigned int cpuid_edx(unsigned int op);
139
140
141
142 #else
143 static inline int decode_pstates(unsigned int cpu, unsigned int cpu_family,
144 int boost_states, unsigned long *pstates,
145 int *no)
146 { return -1; };
147
148 static inline int read_msr(int cpu, unsigned int idx, unsigned long long *val)
149 { return -1; };
150 static inline int write_msr(int cpu, unsigned int idx, unsigned long long val)
151 { return -1; };
152 static inline int msr_intel_set_perf_bias(unsigned int cpu, unsigned int val)
153 { return -1; };
154 static inline int msr_intel_get_perf_bias(unsigned int cpu)
155 { return -1; };
156 static inline unsigned long long msr_intel_get_turbo_ratio(unsigned int cpu)
157 { return 0; };
158
159
160
161 static inline int cpufreq_has_boost_support(unsigned int cpu, int *support,
162 int *active, int * states)
163 { return -1; }
164
165
166
167 static inline unsigned int cpuid_eax(unsigned int op) { return 0; };
168 static inline unsigned int cpuid_ebx(unsigned int op) { return 0; };
169 static inline unsigned int cpuid_ecx(unsigned int op) { return 0; };
170 static inline unsigned int cpuid_edx(unsigned int op) { return 0; };
171 #endif
172
173 #endif