cpufreq: support for "target frequency governors"
PATCH 1/1 cpufreq: support for "target frequency governors"
This patch adds support for "cpufreq governors".
Most cpufreq drivers (in fact, all except one, longrun) or even most cpu frequency scaling algorithms only allow the CPU to be set to one frequency. In order to offer dynamic frequency scaling, the cpufreq core must be able to tell these drivers a "target frequency". So these specific processor drivers will be transformed to offer a "->target" call instead of the existing "->setpolicy" call. For "longrun", all stays the same, though.
How to decide what _frequency_ within the CPUfreq _policy_ should be used? That's done using "cpufreq governors". Two are already in this patch -- they're the already existing "powersave" and "performance" which set the frequency statically to the lowest or highest frequency, respectively. At least two more such governors will be ready for addition in the near future, but likely many more as there exist many different theories and models about dynamic frequency scaling. Using such a generic interface as cpufreq offers for scaling governors, these can be tested extensively, and the best one can be selected for each specific use.
Basically, it's the following flow graph:
CPU can be set to switch independetly | CPU can only be set
within specific "limits" | to specific frequencies
"CPUfreq policy"
consists of frequency limits (policy->{min,max})
and CPUfreq governor to be used
/ \
/ \
/ the cpufreq governor decides
/ (dynamically or statically)
/ what target_freq to set within
/ the limits of policy->{min,max}
/ \
/ \
Using the ->setpolicy call, Using the ->target call,
the limits and the the frequency closest
"policy" is set. to target_freq is set.
It is assured that it
is within policy->{min,max}kernel/cpufreq.c | 357 ++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 378 insertions(+), 51 deletions(-)
include/linux/cpufreq.h +61 -11
@@ -2,10 +2,10 @@* linux/include/linux/cpufreq.h * * Copyright (C) 2001 Russell King -* (C) 2002 Dominik Brodowski <[email protected]> +* (C) 2002 - 2003 Dominik Brodowski <[email protected]> * * -* $Id: cpufreq.h,v 1.29 2002/11/11 15:35:47 db Exp $ +* $Id: cpufreq.h,v 1.36 2003/01/20 17:31:48 db Exp $ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as
@@ -20,6 +20,9 @@#include <linux/device.h> +#define CPUFREQ_NAME_LEN 16 + +/********************************************************************* * CPUFREQ NOTIFIER INTERFACE * *********************************************************************/
@@ -37,14 +40,17 @@#define CPUFREQ_POLICY_POWERSAVE (1)#define CPUFREQ_POLICY_PERFORMANCE (2) +#define CPUFREQ_POLICY_GOVERNOR (3)/* Frequency values here are CPU kHz so that hardware which doesn't run * with some frequencies can complain without having to guess what per * cent / per mille means. -* Maximum transition latency is in nanoseconds - if it's unknown, +* Maximum transition latency is in microseconds - if it's unknown, * CPUFREQ_ETERNAL shall be used. */ +struct cpufreq_governor ; +#define CPUFREQ_ETERNAL (-1)struct cpufreq_cpuinfo {unsigned int max_freq;
@@ -57,6 +63,7 @@unsigned int min;/* in kHz */ unsigned int max;/* in kHz */ unsigned int policy;/* see above */ +struct cpufreq_governor *governor;/* see below */ struct cpufreq_cpuinfo cpuinfo;/* see above */ struct intf_data intf;/* interface data */ };
@@ -104,25 +111,62 @@return carry + val; }; +/********************************************************************* +* CPUFREQ GOVERNORS * +*********************************************************************/ + +#define CPUFREQ_GOV_START 1 +#define CPUFREQ_GOV_STOP 2 +#define CPUFREQ_GOV_LIMITS 3 + +struct cpufreq_governor { +char name[CPUFREQ_NAME_LEN ]; +int (*governor) (struct cpufreq_policy *policy, +unsigned int event); +struct list_head governor_list; +struct module *owner; +}; + +/* pass a target to the cpufreq driver +* _l : (cpufreq_driver_sem is not held) +*/ +inline int cpufreq_driver_target (struct cpufreq_policy *policy, +unsigned int target_freq, +unsigned int relation); + +inline int cpufreq_driver_target_l (struct cpufreq_policy *policy, +unsigned int target_freq, +unsigned int relation); + +/* pass an event to the cpufreq governor */ +int cpufreq_governor_l (unsigned int cpu,unsigned int event); + +int cpufreq_register_governor (struct cpufreq_governor *governor); +void cpufreq_unregister_governor (struct cpufreq_governor *governor);/********************************************************************* * CPUFREQ DRIVER INTERFACE * *********************************************************************/ -#define CPUFREQ_NAME_LEN 16 +#define CPUFREQ_RELATION_L 0/* lowest frequency at or above target */ +#define CPUFREQ_RELATION_H 1/* highest frequency below or at target */ struct cpufreq_driver {/* needed by all drivers */ -int (*verify) (struct cpufreq_policy *policy); -int (*setpolicy) (struct cpufreq_policy *policy); -struct cpufreq_policy *policy; -char name[CPUFREQ_NAME_LEN ]; +int (*verify) (struct cpufreq_policy *policy); +struct cpufreq_policy *policy; +char name[CPUFREQ_NAME_LEN ]; +/* define one out of two */ +int (*setpolicy) (struct cpufreq_policy *policy); +int (*target) (struct cpufreq_policy *policy, +unsigned int target_freq, +unsigned int relation);/* optional, for the moment */ -int (*init) (struct cpufreq_policy *policy); -int (*exit) (struct cpufreq_policy *policy); +int (*init) (struct cpufreq_policy *policy); +int (*exit) (struct cpufreq_policy *policy);/* 2.4. compatible API */ #ifdef CONFIG_CPU_FREQ_24_API -unsigned int cpu_cur_freq[NR_CPUS ]; +unsigned int cpu_cur_freq[NR_CPUS ];#endif };
@@ -276,4 +320,10 @@struct cpufreq_frequency_table *table, unsigned int *index); +int cpufreq_frequency_table_target (struct cpufreq_policy *policy, +struct cpufreq_frequency_table *table, +unsigned int target_freq, +unsigned int relation, +unsigned int *index); +#endif /* _LINUX_CPUFREQ_H */
kernel/cpufreq.c +317 -40
523 lines not on this page · raw message
Quoted 2 lines · Dominik Brodowski
This patch adds support for "cpufreq governors".
<snip excellent description of governors>
Could you add your descriptions to Documentation/cpufreq/ too? The cpufreq interface has come quite a way since the original version and is getting quite complex. Keeping documentation around for it can only be a good thing, and as you've already written it.. 8-)
Dave
Signature · 2 lines
| Dave Jones. http://www.codemonkey.org.uk | SuSE Labs
Quoted 8 lines · Dave Jones
Quoted 2 lines · Dominik Brodowski
This patch adds support for "cpufreq governors".
<snip excellent description of governors>Could you add your descriptions to
Documentation/cpufreq/too? The cpufreq interface has come quite a way since the original version and is getting quite complex. Keeping documentation around for it can only be a good thing, and as you've already written it.. 8-)
A very large documentation-update patch (37K) is in my queue, but as long as the corresponding code isn't in the kernel completely, it makes no sense in update the documentation :)
Dominik