1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 3 %module raw_pylibcpupower 4 %{ 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" 11 %} 12 13 /* 14 * cpupower_intern.h 15 */ 16 17 #define PATH_TO_CPU "/sys/devices/system/cpu/" 18 #define MAX_LINE_LEN 4096 19 #define SYSFS_PATH_MAX 255 20 21 int is_valid_path(const char *path); 22 23 unsigned int cpupower_read_sysfs(const char *path, char *buf, size_t buflen); 24 25 unsigned int cpupower_write_sysfs(const char *path, char *buf, size_t buflen); 26 27 /* 28 * acpi_cppc.h 29 */ 30 31 enum acpi_cppc_value { 32 HIGHEST_PERF, 33 LOWEST_PERF, 34 NOMINAL_PERF, 35 LOWEST_NONLINEAR_PERF, 36 LOWEST_FREQ, 37 NOMINAL_FREQ, 38 REFERENCE_PERF, 39 WRAPAROUND_TIME, 40 MAX_CPPC_VALUE_FILES 41 }; 42 43 unsigned long acpi_cppc_get_data(unsigned int cpu, 44 enum acpi_cppc_value which); 45 46 /* 47 * cpufreq.h 48 */ 49 50 struct cpufreq_policy { 51 unsigned long min; 52 unsigned long max; 53 char *governor; 54 }; 55 56 struct cpufreq_available_governors { 57 char *governor; 58 struct cpufreq_available_governors *next; 59 struct cpufreq_available_governors *first; 60 }; 61 62 struct cpufreq_available_frequencies { 63 unsigned long frequency; 64 struct cpufreq_available_frequencies *next; 65 struct cpufreq_available_frequencies *first; 66 }; 67 68 69 struct cpufreq_affected_cpus { 70 unsigned int cpu; 71 struct cpufreq_affected_cpus *next; 72 struct cpufreq_affected_cpus *first; 73 }; 74 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; 80 }; 81 82 unsigned long cpufreq_get_freq_kernel(unsigned int cpu); 83 84 unsigned long cpufreq_get_freq_hardware(unsigned int cpu); 85 86 #define cpufreq_get(cpu) cpufreq_get_freq_kernel(cpu); 87 88 unsigned long cpufreq_get_transition_latency(unsigned int cpu); 89 90 int cpufreq_get_hardware_limits(unsigned int cpu, 91 unsigned long *min, 92 unsigned long *max); 93 94 char *cpufreq_get_driver(unsigned int cpu); 95 96 void cpufreq_put_driver(char *ptr); 97 98 struct cpufreq_policy *cpufreq_get_policy(unsigned int cpu); 99 100 void cpufreq_put_policy(struct cpufreq_policy *policy); 101 102 struct cpufreq_available_governors 103 *cpufreq_get_available_governors(unsigned int cpu); 104 105 void cpufreq_put_available_governors( 106 struct cpufreq_available_governors *first); 107 108 struct cpufreq_available_frequencies 109 *cpufreq_get_available_frequencies(unsigned int cpu); 110 111 void cpufreq_put_available_frequencies( 112 struct cpufreq_available_frequencies *first); 113 114 struct cpufreq_available_frequencies 115 *cpufreq_get_boost_frequencies(unsigned int cpu); 116 117 void cpufreq_put_boost_frequencies( 118 struct cpufreq_available_frequencies *first); 119 120 struct cpufreq_affected_cpus *cpufreq_get_affected_cpus(unsigned 121 int cpu); 122 123 void cpufreq_put_affected_cpus(struct cpufreq_affected_cpus *first); 124 125 struct cpufreq_affected_cpus *cpufreq_get_related_cpus(unsigned 126 int cpu); 127 128 void cpufreq_put_related_cpus(struct cpufreq_affected_cpus *first); 129 130 struct cpufreq_stats *cpufreq_get_stats(unsigned int cpu, 131 unsigned long long *total_time); 132 133 void cpufreq_put_stats(struct cpufreq_stats *stats); 134 135 unsigned long cpufreq_get_transitions(unsigned int cpu); 136 137 int cpufreq_set_policy(unsigned int cpu, struct cpufreq_policy *policy); 138 139 int cpufreq_modify_policy_min(unsigned int cpu, unsigned long min_freq); 140 141 int cpufreq_modify_policy_max(unsigned int cpu, unsigned long max_freq); 142 143 int cpufreq_modify_policy_governor(unsigned int cpu, char *governor); 144 145 int cpufreq_set_frequency(unsigned int cpu, 146 unsigned long target_frequency); 147 148 unsigned long cpufreq_get_sysfs_value_from_table(unsigned int cpu, 149 const char **table, 150 unsigned int index, 151 unsigned int size); 152 153 /* 154 * cpuidle.h 155 */ 156 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); 172 173 char *cpuidle_get_governor(void); 174 175 char *cpuidle_get_driver(void); 176 177 /* 178 * cpupower.h 179 */ 180 181 struct cpupower_topology { 182 /* Amount of CPU cores, packages and threads per core in the system */ 183 unsigned int cores; 184 unsigned int pkgs; 185 unsigned int threads; /* per core */ 186 187 /* Array gets mallocated with cores entries, holding per core info */ 188 struct cpuid_core_info *core_info; 189 }; 190 191 struct cpuid_core_info { 192 int pkg; 193 int core; 194 int cpu; 195 196 /* flags */ 197 unsigned int is_online:1; 198 }; 199 200 int get_cpu_topology(struct cpupower_topology *cpu_top); 201 202 void cpu_topology_release(struct cpupower_topology cpu_top); 203 204 int cpupower_is_cpu_online(unsigned int cpu); 205 206 /* 207 * powercap.h 208 */ 209 210 struct powercap_zone { 211 char name[MAX_LINE_LEN]; 212 /* 213 * sys_name relative to PATH_TO_POWERCAP, 214 * do not forget the / in between 215 */ 216 char sys_name[SYSFS_PATH_MAX]; 217 int tree_depth; 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, 222 has_energy_uj:1; 223 224 }; 225 226 int powercap_walk_zones(struct powercap_zone *zone, 227 int (*f)(struct powercap_zone *zone)); 228 229 struct powercap_zone *powercap_init_zones(void); 230 231 int powercap_get_enabled(int *mode); 232 233 int powercap_set_enabled(int mode); 234 235 int powercap_get_driver(char *driver, int buflen); 236 237 int powercap_get_max_energy_range_uj(struct powercap_zone *zone, uint64_t *val); 238 239 int powercap_get_energy_uj(struct powercap_zone *zone, uint64_t *val); 240 241 int powercap_get_max_power_range_uw(struct powercap_zone *zone, uint64_t *val); 242 243 int powercap_get_power_uw(struct powercap_zone *zone, uint64_t *val); 244 245 int powercap_zone_get_enabled(struct powercap_zone *zone, int *mode); 246 247 int powercap_zone_set_enabled(struct powercap_zone *zone, int mode);
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.