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 ****************************/
19 #define _(String) gettext(String)
21 #define gettext_noop(String) String
23 #define N_(String) gettext_noop (String)
24 /* Internationalization ****************************/
26 extern int run_as_root;
27 extern struct bitmask *cpus_chosen;
29 /* Global verbose (-d) stuff *********************************/
31 * define DEBUG via global Makefile variable
32 * Debug output is sent to stderr, do:
33 * cpupower monitor 2>/tmp/debug
34 * to split debug output away from normal output
37 extern int be_verbose;
39 #define dprint(fmt, ...) { \
41 fprintf(stderr, "%s: " fmt, \
42 __FUNCTION__, ##__VA_ARGS__); \
46 static inline void dprint(const char *fmt, ...) { }
48 extern int be_verbose;
49 /* Global verbose (-v) stuff *********************************/
51 /* cpuid and cpuinfo helpers **************************/
52 enum cpupower_cpu_vendor {X86_VENDOR_UNKNOWN = 0, X86_VENDOR_INTEL,
53 X86_VENDOR_AMD, X86_VENDOR_MAX};
55 #define CPUPOWER_CAP_INV_TSC 0x00000001
56 #define CPUPOWER_CAP_APERF 0x00000002
57 #define CPUPOWER_CAP_AMD_CBP 0x00000004
58 #define CPUPOWER_CAP_PERF_BIAS 0x00000008
60 #define MAX_HW_PSTATES 10
62 struct cpupower_cpu_info {
63 enum cpupower_cpu_vendor vendor;
66 unsigned int stepping;
67 /* CPU capabilities read out from cpuid */
68 unsigned long long caps;
73 * Extract CPU vendor, family, model, stepping info from /proc/cpuinfo
75 * Returns 0 on success or a negativ error code
76 * Only used on x86, below global's struct values are zero/unknown on
79 extern int get_cpu_info(unsigned int cpu, struct cpupower_cpu_info *cpu_info);
80 extern struct cpupower_cpu_info cpupower_cpu_info;
81 /* cpuid and cpuinfo helpers **************************/
84 /* CPU topology/hierarchy parsing ******************/
85 struct cpupower_topology {
86 /* Amount of CPU cores, packages and threads per core in the system */
89 unsigned int threads; /* per core */
91 /* Array gets mallocated with cores entries, holding per core info */
99 extern int get_cpu_topology(struct cpupower_topology *cpu_top);
100 extern void cpu_topology_release(struct cpupower_topology cpu_top);
101 /* CPU topology/hierarchy parsing ******************/
103 /* X86 ONLY ****************************************/
104 #if defined(__i386__) || defined(__x86_64__)
108 /* Read/Write msr ****************************/
109 extern int read_msr(int cpu, unsigned int idx, unsigned long long *val);
110 extern int write_msr(int cpu, unsigned int idx, unsigned long long val);
112 extern int msr_intel_set_perf_bias(unsigned int cpu, unsigned int val);
113 extern int msr_intel_get_perf_bias(unsigned int cpu);
115 extern int msr_intel_has_boost_support(unsigned int cpu);
116 extern int msr_intel_boost_is_active(unsigned int cpu);
118 /* Read/Write msr ****************************/
120 /* PCI stuff ****************************/
121 extern int amd_pci_get_num_boost_states(int *active, int *states);
122 extern struct pci_dev *pci_acc_init(struct pci_access **pacc, int vendor_id,
125 /* PCI stuff ****************************/
127 /* AMD HW pstate decoding **************************/
129 extern int decode_pstates(unsigned int cpu, unsigned int cpu_family,
130 int boost_states, unsigned long *pstates, int *no);
132 /* AMD HW pstate decoding **************************/
134 extern int cpufreq_has_boost_support(unsigned int cpu, int *support,
135 int *active, int * states);
137 * CPUID functions returning a single datum
139 unsigned int cpuid_eax(unsigned int op);
140 unsigned int cpuid_ebx(unsigned int op);
141 unsigned int cpuid_ecx(unsigned int op);
142 unsigned int cpuid_edx(unsigned int op);
144 /* cpuid and cpuinfo helpers **************************/
145 /* X86 ONLY ********************************************/
147 static inline int decode_pstates(unsigned int cpu, unsigned int cpu_family,
148 int boost_states, unsigned long *pstates,
152 static inline int read_msr(int cpu, unsigned int idx, unsigned long long *val)
154 static inline int write_msr(int cpu, unsigned int idx, unsigned long long val)
156 static inline int msr_intel_set_perf_bias(unsigned int cpu, unsigned int val)
158 static inline int msr_intel_get_perf_bias(unsigned int cpu)
161 static inline int msr_intel_has_boost_support(unsigned int cpu)
163 static inline int msr_intel_boost_is_active(unsigned int cpu)
166 /* Read/Write msr ****************************/
168 static inline int cpufreq_has_boost_support(unsigned int cpu, int *support,
169 int *active, int * states)
172 /* cpuid and cpuinfo helpers **************************/
174 static inline unsigned int cpuid_eax(unsigned int op) { return 0; };
175 static inline unsigned int cpuid_ebx(unsigned int op) { return 0; };
176 static inline unsigned int cpuid_ecx(unsigned int op) { return 0; };
177 static inline unsigned int cpuid_edx(unsigned int op) { return 0; };
178 #endif /* defined(__i386__) || defined(__x86_64__) */
180 #endif /* __CPUPOWERUTILS_HELPERS__ */