223 lines · c
1/* SPDX-License-Identifier: GPL-2.0-only */2/*3 * cpufreq.h - definitions for libcpufreq4 *5 * Copyright (C) 2004-2009 Dominik Brodowski <linux@dominikbrodowski.de>6 */7 8#ifndef __CPUPOWER_CPUFREQ_H__9#define __CPUPOWER_CPUFREQ_H__10 11struct cpufreq_policy {12 unsigned long min;13 unsigned long max;14 char *governor;15};16 17struct cpufreq_available_governors {18 char *governor;19 struct cpufreq_available_governors *next;20 struct cpufreq_available_governors *first;21};22 23struct cpufreq_available_frequencies {24 unsigned long frequency;25 struct cpufreq_available_frequencies *next;26 struct cpufreq_available_frequencies *first;27};28 29 30struct cpufreq_affected_cpus {31 unsigned int cpu;32 struct cpufreq_affected_cpus *next;33 struct cpufreq_affected_cpus *first;34};35 36struct cpufreq_stats {37 unsigned long frequency;38 unsigned long long time_in_state;39 struct cpufreq_stats *next;40 struct cpufreq_stats *first;41};42 43 44 45#ifdef __cplusplus46extern "C" {47#endif48 49/* determine current CPU frequency50 * - _kernel variant means kernel's opinion of CPU frequency51 * - _hardware variant means actual hardware CPU frequency,52 * which is only available to root.53 *54 * returns 0 on failure, else frequency in kHz.55 */56 57unsigned long cpufreq_get_freq_kernel(unsigned int cpu);58 59unsigned long cpufreq_get_freq_hardware(unsigned int cpu);60 61#define cpufreq_get(cpu) cpufreq_get_freq_kernel(cpu);62 63 64/* determine CPU transition latency65 *66 * returns 0 on failure, else transition latency in 10^(-9) s = nanoseconds67 */68unsigned long cpufreq_get_transition_latency(unsigned int cpu);69 70 71/* determine hardware CPU frequency limits72 *73 * These may be limited further by thermal, energy or other74 * considerations by cpufreq policy notifiers in the kernel.75 */76 77int cpufreq_get_hardware_limits(unsigned int cpu,78 unsigned long *min,79 unsigned long *max);80 81 82/* determine CPUfreq driver used83 *84 * Remember to call cpufreq_put_driver when no longer needed85 * to avoid memory leakage, please.86 */87 88char *cpufreq_get_driver(unsigned int cpu);89 90void cpufreq_put_driver(char *ptr);91 92 93/* determine CPUfreq policy currently used94 *95 * Remember to call cpufreq_put_policy when no longer needed96 * to avoid memory leakage, please.97 */98 99 100struct cpufreq_policy *cpufreq_get_policy(unsigned int cpu);101 102void cpufreq_put_policy(struct cpufreq_policy *policy);103 104 105/* determine CPUfreq governors currently available106 *107 * may be modified by modprobe'ing or rmmod'ing other governors. Please108 * free allocated memory by calling cpufreq_put_available_governors109 * after use.110 */111 112 113struct cpufreq_available_governors114*cpufreq_get_available_governors(unsigned int cpu);115 116void cpufreq_put_available_governors(117 struct cpufreq_available_governors *first);118 119 120/* determine CPU frequency states available121 *122 * Only present on _some_ ->target() cpufreq drivers. For information purposes123 * only. Please free allocated memory by calling124 * cpufreq_put_frequencies after use.125 */126 127struct cpufreq_available_frequencies128*cpufreq_get_available_frequencies(unsigned int cpu);129 130void cpufreq_put_available_frequencies(131 struct cpufreq_available_frequencies *first);132 133struct cpufreq_available_frequencies134*cpufreq_get_boost_frequencies(unsigned int cpu);135 136void cpufreq_put_boost_frequencies(137 struct cpufreq_available_frequencies *first);138 139 140/* determine affected CPUs141 *142 * Remember to call cpufreq_put_affected_cpus when no longer needed143 * to avoid memory leakage, please.144 */145 146struct cpufreq_affected_cpus *cpufreq_get_affected_cpus(unsigned147 int cpu);148 149void cpufreq_put_affected_cpus(struct cpufreq_affected_cpus *first);150 151 152/* determine related CPUs153 *154 * Remember to call cpufreq_put_related_cpus when no longer needed155 * to avoid memory leakage, please.156 */157 158struct cpufreq_affected_cpus *cpufreq_get_related_cpus(unsigned159 int cpu);160 161void cpufreq_put_related_cpus(struct cpufreq_affected_cpus *first);162 163 164/* determine stats for cpufreq subsystem165 *166 * This is not available in all kernel versions or configurations.167 */168 169struct cpufreq_stats *cpufreq_get_stats(unsigned int cpu,170 unsigned long long *total_time);171 172void cpufreq_put_stats(struct cpufreq_stats *stats);173 174unsigned long cpufreq_get_transitions(unsigned int cpu);175 176 177/* set new cpufreq policy178 *179 * Tries to set the passed policy as new policy as close as possible,180 * but results may differ depending e.g. on governors being available.181 */182 183int cpufreq_set_policy(unsigned int cpu, struct cpufreq_policy *policy);184 185 186/* modify a policy by only changing min/max freq or governor187 *188 * Does not check whether result is what was intended.189 */190 191int cpufreq_modify_policy_min(unsigned int cpu, unsigned long min_freq);192int cpufreq_modify_policy_max(unsigned int cpu, unsigned long max_freq);193int cpufreq_modify_policy_governor(unsigned int cpu, char *governor);194 195 196/* set a specific frequency197 *198 * Does only work if userspace governor can be used and no external199 * interference (other calls to this function or to set/modify_policy)200 * occurs. Also does not work on ->range() cpufreq drivers.201 */202 203int cpufreq_set_frequency(unsigned int cpu,204 unsigned long target_frequency);205 206/*207 * get the sysfs value from specific table208 *209 * Read the value with the sysfs file name from specific table. Does210 * only work if the cpufreq driver has the specific sysfs interfaces.211 */212 213unsigned long cpufreq_get_sysfs_value_from_table(unsigned int cpu,214 const char **table,215 unsigned int index,216 unsigned int size);217 218#ifdef __cplusplus219}220#endif221 222#endif /* _CPUFREQ_H */223