1 /* SPDX-License-Identifier: GPL-2.0-only */ 1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 2 3 %module raw_pylibcpupower 3 %module raw_pylibcpupower 4 %{ 4 %{ 5 #include "../../lib/cpupower_intern.h" 5 #include "../../lib/cpupower_intern.h" 6 #include "../../lib/acpi_cppc.h" 6 #include "../../lib/acpi_cppc.h" 7 #include "../../lib/cpufreq.h" 7 #include "../../lib/cpufreq.h" 8 #include "../../lib/cpuidle.h" 8 #include "../../lib/cpuidle.h" 9 #include "../../lib/cpupower.h" 9 #include "../../lib/cpupower.h" 10 #include "../../lib/powercap.h" 10 #include "../../lib/powercap.h" 11 %} 11 %} 12 12 13 /* 13 /* 14 * cpupower_intern.h 14 * cpupower_intern.h 15 */ 15 */ 16 16 17 #define PATH_TO_CPU "/sys/devices/system/cpu/" 17 #define PATH_TO_CPU "/sys/devices/system/cpu/" 18 #define MAX_LINE_LEN 4096 18 #define MAX_LINE_LEN 4096 19 #define SYSFS_PATH_MAX 255 19 #define SYSFS_PATH_MAX 255 20 20 21 int is_valid_path(const char *path); 21 int is_valid_path(const char *path); 22 22 23 unsigned int cpupower_read_sysfs(const char *p 23 unsigned int cpupower_read_sysfs(const char *path, char *buf, size_t buflen); 24 24 25 unsigned int cpupower_write_sysfs(const char * 25 unsigned int cpupower_write_sysfs(const char *path, char *buf, size_t buflen); 26 26 27 /* 27 /* 28 * acpi_cppc.h 28 * acpi_cppc.h 29 */ 29 */ 30 30 31 enum acpi_cppc_value { 31 enum acpi_cppc_value { 32 HIGHEST_PERF, 32 HIGHEST_PERF, 33 LOWEST_PERF, 33 LOWEST_PERF, 34 NOMINAL_PERF, 34 NOMINAL_PERF, 35 LOWEST_NONLINEAR_PERF, 35 LOWEST_NONLINEAR_PERF, 36 LOWEST_FREQ, 36 LOWEST_FREQ, 37 NOMINAL_FREQ, 37 NOMINAL_FREQ, 38 REFERENCE_PERF, 38 REFERENCE_PERF, 39 WRAPAROUND_TIME, 39 WRAPAROUND_TIME, 40 MAX_CPPC_VALUE_FILES 40 MAX_CPPC_VALUE_FILES 41 }; 41 }; 42 42 43 unsigned long acpi_cppc_get_data(unsigned int 43 unsigned long acpi_cppc_get_data(unsigned int cpu, 44 enum acpi_cpp 44 enum acpi_cppc_value which); 45 45 46 /* 46 /* 47 * cpufreq.h 47 * cpufreq.h 48 */ 48 */ 49 49 50 struct cpufreq_policy { 50 struct cpufreq_policy { 51 unsigned long min; 51 unsigned long min; 52 unsigned long max; 52 unsigned long max; 53 char *governor; 53 char *governor; 54 }; 54 }; 55 55 56 struct cpufreq_available_governors { 56 struct cpufreq_available_governors { 57 char *governor; 57 char *governor; 58 struct cpufreq_available_governors *ne 58 struct cpufreq_available_governors *next; 59 struct cpufreq_available_governors *fi 59 struct cpufreq_available_governors *first; 60 }; 60 }; 61 61 62 struct cpufreq_available_frequencies { 62 struct cpufreq_available_frequencies { 63 unsigned long frequency; 63 unsigned long frequency; 64 struct cpufreq_available_frequencies * 64 struct cpufreq_available_frequencies *next; 65 struct cpufreq_available_frequencies * 65 struct cpufreq_available_frequencies *first; 66 }; 66 }; 67 67 68 68 69 struct cpufreq_affected_cpus { 69 struct cpufreq_affected_cpus { 70 unsigned int cpu; 70 unsigned int cpu; 71 struct cpufreq_affected_cpus *next; 71 struct cpufreq_affected_cpus *next; 72 struct cpufreq_affected_cpus *first; 72 struct cpufreq_affected_cpus *first; 73 }; 73 }; 74 74 75 struct cpufreq_stats { 75 struct cpufreq_stats { 76 unsigned long frequency; 76 unsigned long frequency; 77 unsigned long long time_in_state; 77 unsigned long long time_in_state; 78 struct cpufreq_stats *next; 78 struct cpufreq_stats *next; 79 struct cpufreq_stats *first; 79 struct cpufreq_stats *first; 80 }; 80 }; 81 81 82 unsigned long cpufreq_get_freq_kernel(unsigned 82 unsigned long cpufreq_get_freq_kernel(unsigned int cpu); 83 83 84 unsigned long cpufreq_get_freq_hardware(unsign 84 unsigned long cpufreq_get_freq_hardware(unsigned int cpu); 85 85 86 #define cpufreq_get(cpu) cpufreq_get_freq_kern 86 #define cpufreq_get(cpu) cpufreq_get_freq_kernel(cpu); 87 87 88 unsigned long cpufreq_get_transition_latency(u 88 unsigned long cpufreq_get_transition_latency(unsigned int cpu); 89 89 90 int cpufreq_get_hardware_limits(unsigned int c 90 int cpufreq_get_hardware_limits(unsigned int cpu, 91 unsigned long 91 unsigned long *min, 92 unsigned long 92 unsigned long *max); 93 93 94 char *cpufreq_get_driver(unsigned int cpu); 94 char *cpufreq_get_driver(unsigned int cpu); 95 95 96 void cpufreq_put_driver(char *ptr); 96 void cpufreq_put_driver(char *ptr); 97 97 98 struct cpufreq_policy *cpufreq_get_policy(unsi 98 struct cpufreq_policy *cpufreq_get_policy(unsigned int cpu); 99 99 100 void cpufreq_put_policy(struct cpufreq_policy 100 void cpufreq_put_policy(struct cpufreq_policy *policy); 101 101 102 struct cpufreq_available_governors 102 struct cpufreq_available_governors 103 *cpufreq_get_available_governors(unsigned int 103 *cpufreq_get_available_governors(unsigned int cpu); 104 104 105 void cpufreq_put_available_governors( 105 void cpufreq_put_available_governors( 106 struct cpufreq_available_governors *fi 106 struct cpufreq_available_governors *first); 107 107 108 struct cpufreq_available_frequencies 108 struct cpufreq_available_frequencies 109 *cpufreq_get_available_frequencies(unsigned in 109 *cpufreq_get_available_frequencies(unsigned int cpu); 110 110 111 void cpufreq_put_available_frequencies( 111 void cpufreq_put_available_frequencies( 112 struct cpufreq_available_frequ 112 struct cpufreq_available_frequencies *first); 113 113 114 struct cpufreq_available_frequencies 114 struct cpufreq_available_frequencies 115 *cpufreq_get_boost_frequencies(unsigned int cp 115 *cpufreq_get_boost_frequencies(unsigned int cpu); 116 116 117 void cpufreq_put_boost_frequencies( 117 void cpufreq_put_boost_frequencies( 118 struct cpufreq_available_frequ 118 struct cpufreq_available_frequencies *first); 119 119 120 struct cpufreq_affected_cpus *cpufreq_get_affe 120 struct cpufreq_affected_cpus *cpufreq_get_affected_cpus(unsigned 121 121 int cpu); 122 122 123 void cpufreq_put_affected_cpus(struct cpufreq_ 123 void cpufreq_put_affected_cpus(struct cpufreq_affected_cpus *first); 124 124 125 struct cpufreq_affected_cpus *cpufreq_get_rela 125 struct cpufreq_affected_cpus *cpufreq_get_related_cpus(unsigned 126 126 int cpu); 127 127 128 void cpufreq_put_related_cpus(struct cpufreq_a 128 void cpufreq_put_related_cpus(struct cpufreq_affected_cpus *first); 129 129 130 struct cpufreq_stats *cpufreq_get_stats(unsign 130 struct cpufreq_stats *cpufreq_get_stats(unsigned int cpu, 131 unsign 131 unsigned long long *total_time); 132 132 133 void cpufreq_put_stats(struct cpufreq_stats *s 133 void cpufreq_put_stats(struct cpufreq_stats *stats); 134 134 135 unsigned long cpufreq_get_transitions(unsigned 135 unsigned long cpufreq_get_transitions(unsigned int cpu); 136 136 137 int cpufreq_set_policy(unsigned int cpu, struc 137 int cpufreq_set_policy(unsigned int cpu, struct cpufreq_policy *policy); 138 138 139 int cpufreq_modify_policy_min(unsigned int cpu 139 int cpufreq_modify_policy_min(unsigned int cpu, unsigned long min_freq); 140 140 141 int cpufreq_modify_policy_max(unsigned int cpu 141 int cpufreq_modify_policy_max(unsigned int cpu, unsigned long max_freq); 142 142 143 int cpufreq_modify_policy_governor(unsigned in 143 int cpufreq_modify_policy_governor(unsigned int cpu, char *governor); 144 144 145 int cpufreq_set_frequency(unsigned int cpu, 145 int cpufreq_set_frequency(unsigned int cpu, 146 unsigned long 146 unsigned long target_frequency); 147 147 148 unsigned long cpufreq_get_sysfs_value_from_tab 148 unsigned long cpufreq_get_sysfs_value_from_table(unsigned int cpu, 149 149 const char **table, 150 150 unsigned int index, 151 151 unsigned int size); 152 152 153 /* 153 /* 154 * cpuidle.h 154 * cpuidle.h 155 */ 155 */ 156 156 157 int cpuidle_is_state_disabled(unsigned int cpu 157 int cpuidle_is_state_disabled(unsigned int cpu, 158 unsigne 158 unsigned int idlestate); 159 int cpuidle_state_disable(unsigned int cpu, un 159 int cpuidle_state_disable(unsigned int cpu, unsigned int idlestate, 160 unsigned in 160 unsigned int disable); 161 unsigned long cpuidle_state_latency(unsigned i 161 unsigned long cpuidle_state_latency(unsigned int cpu, 162 162 unsigned int idlestate); 163 unsigned long cpuidle_state_usage(unsigned int 163 unsigned long cpuidle_state_usage(unsigned int cpu, 164 unsign 164 unsigned int idlestate); 165 unsigned long long cpuidle_state_time(unsigned 165 unsigned long long cpuidle_state_time(unsigned int cpu, 166 166 unsigned int idlestate); 167 char *cpuidle_state_name(unsigned int cpu, 167 char *cpuidle_state_name(unsigned int cpu, 168 unsigned int i 168 unsigned int idlestate); 169 char *cpuidle_state_desc(unsigned int cpu, 169 char *cpuidle_state_desc(unsigned int cpu, 170 unsigned int i 170 unsigned int idlestate); 171 unsigned int cpuidle_state_count(unsigned int 171 unsigned int cpuidle_state_count(unsigned int cpu); 172 172 173 char *cpuidle_get_governor(void); 173 char *cpuidle_get_governor(void); 174 174 175 char *cpuidle_get_driver(void); 175 char *cpuidle_get_driver(void); 176 176 177 /* 177 /* 178 * cpupower.h 178 * cpupower.h 179 */ 179 */ 180 180 181 struct cpupower_topology { 181 struct cpupower_topology { 182 /* Amount of CPU cores, packages and t 182 /* Amount of CPU cores, packages and threads per core in the system */ 183 unsigned int cores; 183 unsigned int cores; 184 unsigned int pkgs; 184 unsigned int pkgs; 185 unsigned int threads; /* per core */ 185 unsigned int threads; /* per core */ 186 186 187 /* Array gets mallocated with cores en 187 /* Array gets mallocated with cores entries, holding per core info */ 188 struct cpuid_core_info *core_info; 188 struct cpuid_core_info *core_info; 189 }; 189 }; 190 190 191 struct cpuid_core_info { 191 struct cpuid_core_info { 192 int pkg; 192 int pkg; 193 int core; 193 int core; 194 int cpu; 194 int cpu; 195 195 196 /* flags */ 196 /* flags */ 197 unsigned int is_online:1; 197 unsigned int is_online:1; 198 }; 198 }; 199 199 200 int get_cpu_topology(struct cpupower_topology 200 int get_cpu_topology(struct cpupower_topology *cpu_top); 201 201 202 void cpu_topology_release(struct cpupower_topo 202 void cpu_topology_release(struct cpupower_topology cpu_top); 203 203 204 int cpupower_is_cpu_online(unsigned int cpu); 204 int cpupower_is_cpu_online(unsigned int cpu); 205 205 206 /* 206 /* 207 * powercap.h 207 * powercap.h 208 */ 208 */ 209 209 210 struct powercap_zone { 210 struct powercap_zone { 211 char name[MAX_LINE_LEN]; 211 char name[MAX_LINE_LEN]; 212 /* 212 /* 213 * sys_name relative to PATH_TO_POWERC 213 * sys_name relative to PATH_TO_POWERCAP, 214 * do not forget the / in between 214 * do not forget the / in between 215 */ 215 */ 216 char sys_name[SYSFS_PATH_MAX]; 216 char sys_name[SYSFS_PATH_MAX]; 217 int tree_depth; 217 int tree_depth; 218 struct powercap_zone *parent; 218 struct powercap_zone *parent; 219 struct powercap_zone *children[POWERCA 219 struct powercap_zone *children[POWERCAP_MAX_CHILD_ZONES]; 220 /* More possible caps or attributes to 220 /* More possible caps or attributes to be added? */ 221 uint32_t has_power_uw:1, 221 uint32_t has_power_uw:1, 222 has_energy_uj:1; 222 has_energy_uj:1; 223 223 224 }; 224 }; 225 225 226 int powercap_walk_zones(struct powercap_zone * 226 int powercap_walk_zones(struct powercap_zone *zone, 227 int (*f)(struct powerc 227 int (*f)(struct powercap_zone *zone)); 228 228 229 struct powercap_zone *powercap_init_zones(void 229 struct powercap_zone *powercap_init_zones(void); 230 230 231 int powercap_get_enabled(int *mode); 231 int powercap_get_enabled(int *mode); 232 232 233 int powercap_set_enabled(int mode); 233 int powercap_set_enabled(int mode); 234 234 235 int powercap_get_driver(char *driver, int bufl 235 int powercap_get_driver(char *driver, int buflen); 236 236 237 int powercap_get_max_energy_range_uj(struct po 237 int powercap_get_max_energy_range_uj(struct powercap_zone *zone, uint64_t *val); 238 238 239 int powercap_get_energy_uj(struct powercap_zon 239 int powercap_get_energy_uj(struct powercap_zone *zone, uint64_t *val); 240 240 241 int powercap_get_max_power_range_uw(struct pow 241 int powercap_get_max_power_range_uw(struct powercap_zone *zone, uint64_t *val); 242 242 243 int powercap_get_power_uw(struct powercap_zone 243 int powercap_get_power_uw(struct powercap_zone *zone, uint64_t *val); 244 244 245 int powercap_zone_get_enabled(struct powercap_ 245 int powercap_zone_get_enabled(struct powercap_zone *zone, int *mode); 246 246 247 int powercap_zone_set_enabled(struct powercap_ 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.