2 * (C) 2010,2011 Thomas Renninger <trenn@suse.de>, Novell Inc.
4 * Licensed under the terms of the GNU GPL License version 2.
6 * Miscellaneous helpers which do not fit or are worth
7 * to put into separate headers
10 #ifndef __CPUPOWERUTILS_HELPERS__
11 #define __CPUPOWERUTILS_HELPERS__
16 #include "helpers/bitmask.h"
18 /* Internationalization ****************************/
21 #define _(String) gettext(String)
23 #define gettext_noop(String) String
25 #define N_(String) gettext_noop(String)
29 #define _(String) String
30 #define N_(String) String
33 /* Internationalization ****************************/
35 extern int run_as_root
;
36 extern struct bitmask
*cpus_chosen
;
38 /* Global verbose (-d) stuff *********************************/
40 * define DEBUG via global Makefile variable
41 * Debug output is sent to stderr, do:
42 * cpupower monitor 2>/tmp/debug
43 * to split debug output away from normal output
46 extern int be_verbose
;
48 #define dprint(fmt, ...) { \
50 fprintf(stderr, "%s: " fmt, \
51 __func__, ##__VA_ARGS__); \
55 static inline void dprint(const char *fmt
, ...) { }
57 extern int be_verbose
;
58 /* Global verbose (-v) stuff *********************************/
60 /* cpuid and cpuinfo helpers **************************/
61 enum cpupower_cpu_vendor
{X86_VENDOR_UNKNOWN
= 0, X86_VENDOR_INTEL
,
62 X86_VENDOR_AMD
, X86_VENDOR_MAX
};
64 #define CPUPOWER_CAP_INV_TSC 0x00000001
65 #define CPUPOWER_CAP_APERF 0x00000002
66 #define CPUPOWER_CAP_AMD_CBP 0x00000004
67 #define CPUPOWER_CAP_PERF_BIAS 0x00000008
68 #define CPUPOWER_CAP_HAS_TURBO_RATIO 0x00000010
69 #define CPUPOWER_CAP_IS_SNB 0x00000011
70 #define CPUPOWER_CAP_INTEL_IDA 0x00000012
72 #define MAX_HW_PSTATES 10
74 struct cpupower_cpu_info
{
75 enum cpupower_cpu_vendor vendor
;
78 unsigned int stepping
;
79 /* CPU capabilities read out from cpuid */
80 unsigned long long caps
;
85 * Extract CPU vendor, family, model, stepping info from /proc/cpuinfo
87 * Returns 0 on success or a negativ error code
88 * Only used on x86, below global's struct values are zero/unknown on
91 extern int get_cpu_info(unsigned int cpu
, struct cpupower_cpu_info
*cpu_info
);
92 extern struct cpupower_cpu_info cpupower_cpu_info
;
93 /* cpuid and cpuinfo helpers **************************/
96 /* CPU topology/hierarchy parsing ******************/
97 struct cpupower_topology
{
98 /* Amount of CPU cores, packages and threads per core in the system */
101 unsigned int threads
; /* per core */
103 /* Array gets mallocated with cores entries, holding per core info */
110 unsigned int is_online
:1;
114 extern int get_cpu_topology(struct cpupower_topology
*cpu_top
);
115 extern void cpu_topology_release(struct cpupower_topology cpu_top
);
116 /* CPU topology/hierarchy parsing ******************/
118 /* X86 ONLY ****************************************/
119 #if defined(__i386__) || defined(__x86_64__)
123 /* Read/Write msr ****************************/
124 extern int read_msr(int cpu
, unsigned int idx
, unsigned long long *val
);
125 extern int write_msr(int cpu
, unsigned int idx
, unsigned long long val
);
127 extern int msr_intel_set_perf_bias(unsigned int cpu
, unsigned int val
);
128 extern int msr_intel_get_perf_bias(unsigned int cpu
);
129 extern unsigned long long msr_intel_get_turbo_ratio(unsigned int cpu
);
131 /* Read/Write msr ****************************/
133 /* PCI stuff ****************************/
134 extern int amd_pci_get_num_boost_states(int *active
, int *states
);
135 extern struct pci_dev
*pci_acc_init(struct pci_access
**pacc
, int vendor_id
,
138 /* PCI stuff ****************************/
140 /* AMD HW pstate decoding **************************/
142 extern int decode_pstates(unsigned int cpu
, unsigned int cpu_family
,
143 int boost_states
, unsigned long *pstates
, int *no
);
145 /* AMD HW pstate decoding **************************/
147 extern int cpufreq_has_boost_support(unsigned int cpu
, int *support
,
148 int *active
, int * states
);
150 * CPUID functions returning a single datum
152 unsigned int cpuid_eax(unsigned int op
);
153 unsigned int cpuid_ebx(unsigned int op
);
154 unsigned int cpuid_ecx(unsigned int op
);
155 unsigned int cpuid_edx(unsigned int op
);
157 /* cpuid and cpuinfo helpers **************************/
158 /* X86 ONLY ********************************************/
160 static inline int decode_pstates(unsigned int cpu
, unsigned int cpu_family
,
161 int boost_states
, unsigned long *pstates
,
165 static inline int read_msr(int cpu
, unsigned int idx
, unsigned long long *val
)
167 static inline int write_msr(int cpu
, unsigned int idx
, unsigned long long val
)
169 static inline int msr_intel_set_perf_bias(unsigned int cpu
, unsigned int val
)
171 static inline int msr_intel_get_perf_bias(unsigned int cpu
)
173 static inline unsigned long long msr_intel_get_turbo_ratio(unsigned int cpu
)
176 /* Read/Write msr ****************************/
178 static inline int cpufreq_has_boost_support(unsigned int cpu
, int *support
,
179 int *active
, int * states
)
182 /* cpuid and cpuinfo helpers **************************/
184 static inline unsigned int cpuid_eax(unsigned int op
) { return 0; };
185 static inline unsigned int cpuid_ebx(unsigned int op
) { return 0; };
186 static inline unsigned int cpuid_ecx(unsigned int op
) { return 0; };
187 static inline unsigned int cpuid_edx(unsigned int op
) { return 0; };
188 #endif /* defined(__i386__) || defined(__x86_64__) */
190 #endif /* __CPUPOWERUTILS_HELPERS__ */