diff options
author | Dominik Brodowski <linux@dominikbrodowski.net> | 2011-03-30 18:30:11 +0400 |
---|---|---|
committer | Dominik Brodowski <linux@dominikbrodowski.net> | 2011-07-29 20:35:36 +0400 |
commit | 7fe2f6399a84760a9af8896ac152728250f82adb (patch) | |
tree | fa4bf236359b8d6d9f8d6ff823ddd3e839da5768 /tools/power/cpupower/lib/cpufreq.c | |
parent | 02f8c6aee8df3cdc935e9bdd4f2d020306035dbe (diff) | |
download | linux-7fe2f6399a84760a9af8896ac152728250f82adb.tar.xz |
cpupowerutils - cpufrequtils extended with quite some features
CPU power consumption vs performance tuning is no longer
limited to CPU frequency switching anymore: deep sleep states,
traditional dynamic frequency scaling and hidden turbo/boost
frequencies are tied close together and depend on each other.
The first two exist on different architectures like PPC, Itanium and
ARM, the latter (so far) only on X86. On X86 the APU (CPU+GPU) will
only run most efficiently if CPU and GPU has proper power management
in place.
Users and Developers want to have *one* tool to get an overview what
their system supports and to monitor and debug CPU power management
in detail. The tool should compile and work on as many architectures
as possible.
Once this tool stabilizes a bit, it is intended to replace the
Intel-specific tools in tools/power/x86
Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net>
Diffstat (limited to 'tools/power/cpupower/lib/cpufreq.c')
-rw-r--r-- | tools/power/cpupower/lib/cpufreq.c | 190 |
1 files changed, 190 insertions, 0 deletions
diff --git a/tools/power/cpupower/lib/cpufreq.c b/tools/power/cpupower/lib/cpufreq.c new file mode 100644 index 000000000000..ae7d8c57b447 --- /dev/null +++ b/tools/power/cpupower/lib/cpufreq.c @@ -0,0 +1,190 @@ +/* + * (C) 2004-2009 Dominik Brodowski <linux@dominikbrodowski.de> + * + * Licensed under the terms of the GNU GPL License version 2. + */ + + +#include <stdio.h> +#include <errno.h> +#include <stdlib.h> +#include <string.h> + +#include "cpufreq.h" +#include "sysfs.h" + +int cpufreq_cpu_exists(unsigned int cpu) +{ + return sysfs_cpu_exists(cpu); +} + +unsigned long cpufreq_get_freq_kernel(unsigned int cpu) +{ + return sysfs_get_freq_kernel(cpu); +} + +unsigned long cpufreq_get_freq_hardware(unsigned int cpu) +{ + return sysfs_get_freq_hardware(cpu); +} + +unsigned long cpufreq_get_transition_latency(unsigned int cpu) +{ + return sysfs_get_freq_transition_latency(cpu); +} + +int cpufreq_get_hardware_limits(unsigned int cpu, + unsigned long *min, + unsigned long *max) +{ + if ((!min) || (!max)) + return -EINVAL; + return sysfs_get_freq_hardware_limits(cpu, min, max); +} + +char * cpufreq_get_driver(unsigned int cpu) { + return sysfs_get_freq_driver(cpu); +} + +void cpufreq_put_driver(char * ptr) { + if (!ptr) + return; + free(ptr); +} + +struct cpufreq_policy * cpufreq_get_policy(unsigned int cpu) { + return sysfs_get_freq_policy(cpu); +} + +void cpufreq_put_policy(struct cpufreq_policy *policy) { + if ((!policy) || (!policy->governor)) + return; + + free(policy->governor); + policy->governor = NULL; + free(policy); +} + +struct cpufreq_available_governors * cpufreq_get_available_governors(unsigned int cpu) { + return sysfs_get_freq_available_governors(cpu); +} + +void cpufreq_put_available_governors(struct cpufreq_available_governors *any) { + struct cpufreq_available_governors *tmp, *next; + + if (!any) + return; + + tmp = any->first; + while (tmp) { + next = tmp->next; + if (tmp->governor) + free(tmp->governor); + free(tmp); + tmp = next; + } +} + + +struct cpufreq_available_frequencies * cpufreq_get_available_frequencies(unsigned int cpu) { + return sysfs_get_available_frequencies(cpu); +} + +void cpufreq_put_available_frequencies(struct cpufreq_available_frequencies *any) { + struct cpufreq_available_frequencies *tmp, *next; + + if (!any) + return; + + tmp = any->first; + while (tmp) { + next = tmp->next; + free(tmp); + tmp = next; + } +} + + +struct cpufreq_affected_cpus * cpufreq_get_affected_cpus(unsigned int cpu) { + return sysfs_get_freq_affected_cpus(cpu); +} + +void cpufreq_put_affected_cpus(struct cpufreq_affected_cpus *any) { + struct cpufreq_affected_cpus *tmp, *next; + + if (!any) + return; + + tmp = any->first; + while (tmp) { + next = tmp->next; + free(tmp); + tmp = next; + } +} + + +struct cpufreq_affected_cpus * cpufreq_get_related_cpus(unsigned int cpu) { + return sysfs_get_freq_related_cpus(cpu); +} + +void cpufreq_put_related_cpus(struct cpufreq_affected_cpus *any) { + cpufreq_put_affected_cpus(any); +} + + +int cpufreq_set_policy(unsigned int cpu, struct cpufreq_policy *policy) { + if (!policy || !(policy->governor)) + return -EINVAL; + + return sysfs_set_freq_policy(cpu, policy); +} + + +int cpufreq_modify_policy_min(unsigned int cpu, unsigned long min_freq) { + return sysfs_modify_freq_policy_min(cpu, min_freq); +} + + +int cpufreq_modify_policy_max(unsigned int cpu, unsigned long max_freq) { + return sysfs_modify_freq_policy_max(cpu, max_freq); +} + + +int cpufreq_modify_policy_governor(unsigned int cpu, char *governor) { + if ((!governor) || (strlen(governor) > 19)) + return -EINVAL; + + return sysfs_modify_freq_policy_governor(cpu, governor); +} + +int cpufreq_set_frequency(unsigned int cpu, unsigned long target_frequency) { + return sysfs_set_frequency(cpu, target_frequency); +} + +struct cpufreq_stats * cpufreq_get_stats(unsigned int cpu, unsigned long long *total_time) { + struct cpufreq_stats *ret; + + ret = sysfs_get_freq_stats(cpu, total_time); + return (ret); +} + +void cpufreq_put_stats(struct cpufreq_stats *any) { + struct cpufreq_stats *tmp, *next; + + if (!any) + return; + + tmp = any->first; + while (tmp) { + next = tmp->next; + free(tmp); + tmp = next; + } +} + +unsigned long cpufreq_get_transitions(unsigned int cpu) { + unsigned long ret = sysfs_get_freq_transitions(cpu); + + return (ret); +} |