1 /* SPDX-License-Identifier: GPL-2.0-only */
3 %module raw_pylibcpupower
5 #include "../../lib/cpupower_intern.h"
6 #include "../../lib/acpi_cppc.h"
7 #include "../../lib/cpufreq.h"
8 #include "../../lib/cpuidle.h"
9 #include "../../lib/cpupower.h"
10 #include "../../lib/powercap.h"
17 #define PATH_TO_CPU "/sys/devices/system/cpu/"
18 #define MAX_LINE_LEN 4096
19 #define SYSFS_PATH_MAX 255
21 int is_valid_path(const char *path);
23 unsigned int cpupower_read_sysfs(const char *path, char *buf, size_t buflen);
25 unsigned int cpupower_write_sysfs(const char *path, char *buf, size_t buflen);
31 enum acpi_cppc_value {
35 LOWEST_NONLINEAR_PERF,
43 unsigned long acpi_cppc_get_data(unsigned int cpu,
44 enum acpi_cppc_value which);
50 struct cpufreq_policy {
56 struct cpufreq_available_governors {
58 struct cpufreq_available_governors *next;
59 struct cpufreq_available_governors *first;
62 struct cpufreq_available_frequencies {
63 unsigned long frequency;
64 struct cpufreq_available_frequencies *next;
65 struct cpufreq_available_frequencies *first;
69 struct cpufreq_affected_cpus {
71 struct cpufreq_affected_cpus *next;
72 struct cpufreq_affected_cpus *first;
75 struct cpufreq_stats {
76 unsigned long frequency;
77 unsigned long long time_in_state;
78 struct cpufreq_stats *next;
79 struct cpufreq_stats *first;
82 unsigned long cpufreq_get_freq_kernel(unsigned int cpu);
84 unsigned long cpufreq_get_freq_hardware(unsigned int cpu);
86 #define cpufreq_get(cpu) cpufreq_get_freq_kernel(cpu);
88 unsigned long cpufreq_get_transition_latency(unsigned int cpu);
90 int cpufreq_get_hardware_limits(unsigned int cpu,
94 char *cpufreq_get_driver(unsigned int cpu);
96 void cpufreq_put_driver(char *ptr);
98 struct cpufreq_policy *cpufreq_get_policy(unsigned int cpu);
100 void cpufreq_put_policy(struct cpufreq_policy *policy);
102 struct cpufreq_available_governors
103 *cpufreq_get_available_governors(unsigned int cpu);
105 void cpufreq_put_available_governors(
106 struct cpufreq_available_governors *first);
108 struct cpufreq_available_frequencies
109 *cpufreq_get_available_frequencies(unsigned int cpu);
111 void cpufreq_put_available_frequencies(
112 struct cpufreq_available_frequencies *first);
114 struct cpufreq_available_frequencies
115 *cpufreq_get_boost_frequencies(unsigned int cpu);
117 void cpufreq_put_boost_frequencies(
118 struct cpufreq_available_frequencies *first);
120 struct cpufreq_affected_cpus *cpufreq_get_affected_cpus(unsigned
123 void cpufreq_put_affected_cpus(struct cpufreq_affected_cpus *first);
125 struct cpufreq_affected_cpus *cpufreq_get_related_cpus(unsigned
128 void cpufreq_put_related_cpus(struct cpufreq_affected_cpus *first);
130 struct cpufreq_stats *cpufreq_get_stats(unsigned int cpu,
131 unsigned long long *total_time);
133 void cpufreq_put_stats(struct cpufreq_stats *stats);
135 unsigned long cpufreq_get_transitions(unsigned int cpu);
137 int cpufreq_set_policy(unsigned int cpu, struct cpufreq_policy *policy);
139 int cpufreq_modify_policy_min(unsigned int cpu, unsigned long min_freq);
141 int cpufreq_modify_policy_max(unsigned int cpu, unsigned long max_freq);
143 int cpufreq_modify_policy_governor(unsigned int cpu, char *governor);
145 int cpufreq_set_frequency(unsigned int cpu,
146 unsigned long target_frequency);
148 unsigned long cpufreq_get_sysfs_value_from_table(unsigned int cpu,
157 int cpuidle_is_state_disabled(unsigned int cpu,
158 unsigned int idlestate);
159 int cpuidle_state_disable(unsigned int cpu, unsigned int idlestate,
160 unsigned int disable);
161 unsigned long cpuidle_state_latency(unsigned int cpu,
162 unsigned int idlestate);
163 unsigned long cpuidle_state_usage(unsigned int cpu,
164 unsigned int idlestate);
165 unsigned long long cpuidle_state_time(unsigned int cpu,
166 unsigned int idlestate);
167 char *cpuidle_state_name(unsigned int cpu,
168 unsigned int idlestate);
169 char *cpuidle_state_desc(unsigned int cpu,
170 unsigned int idlestate);
171 unsigned int cpuidle_state_count(unsigned int cpu);
173 char *cpuidle_get_governor(void);
175 char *cpuidle_get_driver(void);
181 struct cpupower_topology {
182 /* Amount of CPU cores, packages and threads per core in the system */
185 unsigned int threads; /* per core */
187 /* Array gets mallocated with cores entries, holding per core info */
188 struct cpuid_core_info *core_info;
191 struct cpuid_core_info {
197 unsigned int is_online:1;
200 int get_cpu_topology(struct cpupower_topology *cpu_top);
202 void cpu_topology_release(struct cpupower_topology cpu_top);
204 int cpupower_is_cpu_online(unsigned int cpu);
210 struct powercap_zone {
211 char name[MAX_LINE_LEN];
213 * sys_name relative to PATH_TO_POWERCAP,
214 * do not forget the / in between
216 char sys_name[SYSFS_PATH_MAX];
218 struct powercap_zone *parent;
219 struct powercap_zone *children[POWERCAP_MAX_CHILD_ZONES];
220 /* More possible caps or attributes to be added? */
221 uint32_t has_power_uw:1,
226 int powercap_walk_zones(struct powercap_zone *zone,
227 int (*f)(struct powercap_zone *zone));
229 struct powercap_zone *powercap_init_zones(void);
231 int powercap_get_enabled(int *mode);
233 int powercap_set_enabled(int mode);
235 int powercap_get_driver(char *driver, int buflen);
237 int powercap_get_max_energy_range_uj(struct powercap_zone *zone, uint64_t *val);
239 int powercap_get_energy_uj(struct powercap_zone *zone, uint64_t *val);
241 int powercap_get_max_power_range_uw(struct powercap_zone *zone, uint64_t *val);
243 int powercap_get_power_uw(struct powercap_zone *zone, uint64_t *val);
245 int powercap_zone_get_enabled(struct powercap_zone *zone, int *mode);
247 int powercap_zone_set_enabled(struct powercap_zone *zone, int mode);