Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 39641
b: refs/heads/master
c: e08f5f5
h: refs/heads/master
i:
  39639: d09208f
v: v3
  • Loading branch information
Gautham R Shenoy authored and Dave Jones committed Nov 7, 2006
1 parent e3efdaf commit 837a082
Show file tree
Hide file tree
Showing 8 changed files with 151 additions and 79 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 95625b8f19e1e030c7fe3c010407d90fa248c68f
refs/heads/master: e08f5f5bb5dfaaa28d69ffe37eb774533297657f
136 changes: 91 additions & 45 deletions trunk/drivers/cpufreq/cpufreq.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
#include <linux/completion.h>
#include <linux/mutex.h>

#define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_CORE, "cpufreq-core", msg)
#define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_CORE, \
"cpufreq-core", msg)

/**
* The "cpufreq driver" - the arch- or hardware-dependent low
Expand All @@ -41,7 +42,8 @@ static struct cpufreq_policy *cpufreq_cpu_data[NR_CPUS];
static DEFINE_SPINLOCK(cpufreq_driver_lock);

/* internal prototypes */
static int __cpufreq_governor(struct cpufreq_policy *policy, unsigned int event);
static int __cpufreq_governor(struct cpufreq_policy *policy,
unsigned int event);
static void handle_update(void *data);

/**
Expand Down Expand Up @@ -151,7 +153,8 @@ static void cpufreq_debug_disable_ratelimit(void)
spin_unlock_irqrestore(&disable_ratelimit_lock, flags);
}

void cpufreq_debug_printk(unsigned int type, const char *prefix, const char *fmt, ...)
void cpufreq_debug_printk(unsigned int type, const char *prefix,
const char *fmt, ...)
{
char s[256];
va_list args;
Expand All @@ -161,7 +164,8 @@ void cpufreq_debug_printk(unsigned int type, const char *prefix, const char *fmt
WARN_ON(!prefix);
if (type & debug) {
spin_lock_irqsave(&disable_ratelimit_lock, flags);
if (!disable_ratelimit && debug_ratelimit && !printk_ratelimit()) {
if (!disable_ratelimit && debug_ratelimit
&& !printk_ratelimit()) {
spin_unlock_irqrestore(&disable_ratelimit_lock, flags);
return;
}
Expand All @@ -182,10 +186,12 @@ EXPORT_SYMBOL(cpufreq_debug_printk);


module_param(debug, uint, 0644);
MODULE_PARM_DESC(debug, "CPUfreq debugging: add 1 to debug core, 2 to debug drivers, and 4 to debug governors.");
MODULE_PARM_DESC(debug, "CPUfreq debugging: add 1 to debug core,"
" 2 to debug drivers, and 4 to debug governors.");

module_param(debug_ratelimit, uint, 0644);
MODULE_PARM_DESC(debug_ratelimit, "CPUfreq debugging: set to 0 to disable ratelimiting.");
MODULE_PARM_DESC(debug_ratelimit, "CPUfreq debugging:"
" set to 0 to disable ratelimiting.");

#else /* !CONFIG_CPU_FREQ_DEBUG */

Expand Down Expand Up @@ -219,17 +225,23 @@ static void adjust_jiffies(unsigned long val, struct cpufreq_freqs *ci)
if (!l_p_j_ref_freq) {
l_p_j_ref = loops_per_jiffy;
l_p_j_ref_freq = ci->old;
dprintk("saving %lu as reference value for loops_per_jiffy; freq is %u kHz\n", l_p_j_ref, l_p_j_ref_freq);
dprintk("saving %lu as reference value for loops_per_jiffy;"
"freq is %u kHz\n", l_p_j_ref, l_p_j_ref_freq);
}
if ((val == CPUFREQ_PRECHANGE && ci->old < ci->new) ||
(val == CPUFREQ_POSTCHANGE && ci->old > ci->new) ||
(val == CPUFREQ_RESUMECHANGE || val == CPUFREQ_SUSPENDCHANGE)) {
loops_per_jiffy = cpufreq_scale(l_p_j_ref, l_p_j_ref_freq, ci->new);
dprintk("scaling loops_per_jiffy to %lu for frequency %u kHz\n", loops_per_jiffy, ci->new);
loops_per_jiffy = cpufreq_scale(l_p_j_ref, l_p_j_ref_freq,
ci->new);
dprintk("scaling loops_per_jiffy to %lu"
"for frequency %u kHz\n", loops_per_jiffy, ci->new);
}
}
#else
static inline void adjust_jiffies(unsigned long val, struct cpufreq_freqs *ci) { return; }
static inline void adjust_jiffies(unsigned long val, struct cpufreq_freqs *ci)
{
return;
}
#endif


Expand Down Expand Up @@ -316,7 +328,8 @@ static int cpufreq_parse_governor (char *str_governor, unsigned int *policy,
if (!strnicmp(str_governor, "performance", CPUFREQ_NAME_LEN)) {
*policy = CPUFREQ_POLICY_PERFORMANCE;
err = 0;
} else if (!strnicmp(str_governor, "powersave", CPUFREQ_NAME_LEN)) {
} else if (!strnicmp(str_governor, "powersave",
CPUFREQ_NAME_LEN)) {
*policy = CPUFREQ_POLICY_POWERSAVE;
err = 0;
}
Expand All @@ -328,7 +341,8 @@ static int cpufreq_parse_governor (char *str_governor, unsigned int *policy,
t = __find_governor(str_governor);

if (t == NULL) {
char *name = kasprintf(GFP_KERNEL, "cpufreq_%s", str_governor);
char *name = kasprintf(GFP_KERNEL, "cpufreq_%s",
str_governor);

if (name) {
int ret;
Expand Down Expand Up @@ -361,7 +375,8 @@ extern struct sysdev_class cpu_sysdev_class;


/**
* cpufreq_per_cpu_attr_read() / show_##file_name() - print out cpufreq information
* cpufreq_per_cpu_attr_read() / show_##file_name() -
* print out cpufreq information
*
* Write out information from cpufreq_driver->policy[cpu]; object must be
* "unsigned int".
Expand All @@ -380,7 +395,8 @@ show_one(scaling_min_freq, min);
show_one(scaling_max_freq, max);
show_one(scaling_cur_freq, cur);

static int __cpufreq_set_policy(struct cpufreq_policy *data, struct cpufreq_policy *policy);
static int __cpufreq_set_policy(struct cpufreq_policy *data,
struct cpufreq_policy *policy);

/**
* cpufreq_per_cpu_attr_write() / store_##file_name() - sysfs write access
Expand Down Expand Up @@ -416,7 +432,8 @@ store_one(scaling_max_freq,max);
/**
* show_cpuinfo_cur_freq - current CPU frequency as detected by hardware
*/
static ssize_t show_cpuinfo_cur_freq (struct cpufreq_policy * policy, char *buf)
static ssize_t show_cpuinfo_cur_freq (struct cpufreq_policy * policy,
char *buf)
{
unsigned int cur_freq = cpufreq_get(policy->cpu);
if (!cur_freq)
Expand All @@ -428,7 +445,8 @@ static ssize_t show_cpuinfo_cur_freq (struct cpufreq_policy * policy, char *buf)
/**
* show_scaling_governor - show the current policy for the specified CPU
*/
static ssize_t show_scaling_governor (struct cpufreq_policy * policy, char *buf)
static ssize_t show_scaling_governor (struct cpufreq_policy * policy,
char *buf)
{
if(policy->policy == CPUFREQ_POLICY_POWERSAVE)
return sprintf(buf, "powersave\n");
Expand Down Expand Up @@ -458,7 +476,8 @@ static ssize_t store_scaling_governor (struct cpufreq_policy * policy,
if (ret != 1)
return -EINVAL;

if (cpufreq_parse_governor(str_governor, &new_policy.policy, &new_policy.governor))
if (cpufreq_parse_governor(str_governor, &new_policy.policy,
&new_policy.governor))
return -EINVAL;

lock_cpu_hotplug();
Expand All @@ -474,7 +493,10 @@ static ssize_t store_scaling_governor (struct cpufreq_policy * policy,

unlock_cpu_hotplug();

return ret ? ret : count;
if (ret)
return ret;
else
return count;
}

/**
Expand All @@ -488,7 +510,7 @@ static ssize_t show_scaling_driver (struct cpufreq_policy * policy, char *buf)
/**
* show_scaling_available_governors - show the available CPUfreq governors
*/
static ssize_t show_scaling_available_governors (struct cpufreq_policy * policy,
static ssize_t show_scaling_available_governors (struct cpufreq_policy *policy,
char *buf)
{
ssize_t i = 0;
Expand Down Expand Up @@ -574,7 +596,11 @@ static ssize_t show(struct kobject * kobj, struct attribute * attr ,char * buf)
policy = cpufreq_cpu_get(policy->cpu);
if (!policy)
return -EINVAL;
ret = fattr->show ? fattr->show(policy,buf) : -EIO;
if (fattr->show)
ret = fattr->show(policy, buf);
else
ret = -EIO;

cpufreq_cpu_put(policy);
return ret;
}
Expand All @@ -588,7 +614,11 @@ static ssize_t store(struct kobject * kobj, struct attribute * attr,
policy = cpufreq_cpu_get(policy->cpu);
if (!policy)
return -EINVAL;
ret = fattr->store ? fattr->store(policy,buf,count) : -EIO;
if (fattr->store)
ret = fattr->store(policy, buf, count);
else
ret = -EIO;

cpufreq_cpu_put(policy);
return ret;
}
Expand Down Expand Up @@ -911,7 +941,8 @@ static void handle_update(void *data)
* We adjust to current frequency first, and need to clean up later. So either call
* to cpufreq_update_policy() or schedule handle_update()).
*/
static void cpufreq_out_of_sync(unsigned int cpu, unsigned int old_freq, unsigned int new_freq)
static void cpufreq_out_of_sync(unsigned int cpu, unsigned int old_freq,
unsigned int new_freq)
{
struct cpufreq_freqs freqs;

Expand All @@ -936,16 +967,16 @@ static void cpufreq_out_of_sync(unsigned int cpu, unsigned int old_freq, unsigne
unsigned int cpufreq_quick_get(unsigned int cpu)
{
struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
unsigned int ret = 0;
unsigned int ret_freq = 0;

if (policy) {
mutex_lock(&policy->lock);
ret = policy->cur;
ret_freq = policy->cur;
mutex_unlock(&policy->lock);
cpufreq_cpu_put(policy);
}

return (ret);
return (ret_freq);
}
EXPORT_SYMBOL(cpufreq_quick_get);

Expand All @@ -959,7 +990,7 @@ EXPORT_SYMBOL(cpufreq_quick_get);
unsigned int cpufreq_get(unsigned int cpu)
{
struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
unsigned int ret = 0;
unsigned int ret_freq = 0;

if (!policy)
return 0;
Expand All @@ -969,12 +1000,14 @@ unsigned int cpufreq_get(unsigned int cpu)

mutex_lock(&policy->lock);

ret = cpufreq_driver->get(cpu);
ret_freq = cpufreq_driver->get(cpu);

if (ret && policy->cur && !(cpufreq_driver->flags & CPUFREQ_CONST_LOOPS)) {
/* verify no discrepancy between actual and saved value exists */
if (unlikely(ret != policy->cur)) {
cpufreq_out_of_sync(cpu, policy->cur, ret);
if (ret_freq && policy->cur &&
!(cpufreq_driver->flags & CPUFREQ_CONST_LOOPS)) {
/* verify no discrepancy between actual and
saved value exists */
if (unlikely(ret_freq != policy->cur)) {
cpufreq_out_of_sync(cpu, policy->cur, ret_freq);
schedule_work(&policy->update);
}
}
Expand All @@ -984,7 +1017,7 @@ unsigned int cpufreq_get(unsigned int cpu)
out:
cpufreq_cpu_put(policy);

return (ret);
return (ret_freq);
}
EXPORT_SYMBOL(cpufreq_get);

Expand All @@ -996,7 +1029,7 @@ EXPORT_SYMBOL(cpufreq_get);
static int cpufreq_suspend(struct sys_device * sysdev, pm_message_t pmsg)
{
int cpu = sysdev->id;
unsigned int ret = 0;
int ret = 0;
unsigned int cur_freq = 0;
struct cpufreq_policy *cpu_policy;

Expand Down Expand Up @@ -1078,7 +1111,7 @@ static int cpufreq_suspend(struct sys_device * sysdev, pm_message_t pmsg)
static int cpufreq_resume(struct sys_device * sysdev)
{
int cpu = sysdev->id;
unsigned int ret = 0;
int ret = 0;
struct cpufreq_policy *cpu_policy;

dprintk("resuming cpu %u\n", cpu);
Expand Down Expand Up @@ -1299,17 +1332,20 @@ EXPORT_SYMBOL_GPL(cpufreq_driver_getavg);
* when "event" is CPUFREQ_GOV_LIMITS
*/

static int __cpufreq_governor(struct cpufreq_policy *policy, unsigned int event)
static int __cpufreq_governor(struct cpufreq_policy *policy,
unsigned int event)
{
int ret;

if (!try_module_get(policy->governor->owner))
return -EINVAL;

dprintk("__cpufreq_governor for CPU %u, event %u\n", policy->cpu, event);
dprintk("__cpufreq_governor for CPU %u, event %u\n",
policy->cpu, event);
ret = policy->governor->governor(policy, event);

/* we keep one module reference alive for each CPU governed by this CPU */
/* we keep one module reference alive for
each CPU governed by this CPU */
if ((event != CPUFREQ_GOV_START) || ret)
module_put(policy->governor->owner);
if ((event == CPUFREQ_GOV_STOP) && !ret)
Expand Down Expand Up @@ -1385,17 +1421,21 @@ EXPORT_SYMBOL(cpufreq_get_policy);


/*
* data : current policy.
* policy : policy to be set.
* Locking: Must be called with the lock_cpu_hotplug() lock held
*/
static int __cpufreq_set_policy(struct cpufreq_policy *data, struct cpufreq_policy *policy)
static int __cpufreq_set_policy(struct cpufreq_policy *data,
struct cpufreq_policy *policy)
{
int ret = 0;

cpufreq_debug_disable_ratelimit();
dprintk("setting new policy for CPU %u: %u - %u kHz\n", policy->cpu,
policy->min, policy->max);

memcpy(&policy->cpuinfo, &data->cpuinfo, sizeof(struct cpufreq_cpuinfo));
memcpy(&policy->cpuinfo, &data->cpuinfo,
sizeof(struct cpufreq_cpuinfo));

if (policy->min > data->min && policy->min > policy->max) {
ret = -EINVAL;
Expand Down Expand Up @@ -1428,7 +1468,8 @@ static int __cpufreq_set_policy(struct cpufreq_policy *data, struct cpufreq_poli
data->min = policy->min;
data->max = policy->max;

dprintk("new min and max freqs are %u - %u kHz\n", data->min, data->max);
dprintk("new min and max freqs are %u - %u kHz\n",
data->min, data->max);

if (cpufreq_driver->setpolicy) {
data->policy = policy->policy;
Expand All @@ -1449,10 +1490,12 @@ static int __cpufreq_set_policy(struct cpufreq_policy *data, struct cpufreq_poli
data->governor = policy->governor;
if (__cpufreq_governor(data, CPUFREQ_GOV_START)) {
/* new governor failed, so re-start old one */
dprintk("starting governor %s failed\n", data->governor->name);
dprintk("starting governor %s failed\n",
data->governor->name);
if (old_gov) {
data->governor = old_gov;
__cpufreq_governor(data, CPUFREQ_GOV_START);
__cpufreq_governor(data,
CPUFREQ_GOV_START);
}
ret = -EINVAL;
goto error_out;
Expand Down Expand Up @@ -1542,7 +1585,8 @@ int cpufreq_update_policy(unsigned int cpu)
data->cur = policy.cur;
} else {
if (data->cur != policy.cur)
cpufreq_out_of_sync(cpu, data->cur, policy.cur);
cpufreq_out_of_sync(cpu, data->cur,
policy.cur);
}
}

Expand Down Expand Up @@ -1646,8 +1690,10 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)

/* if all ->init() calls failed, unregister */
if (ret) {
dprintk("no CPU initialized for driver %s\n", driver_data->name);
sysdev_driver_unregister(&cpu_sysdev_class, &cpufreq_sysdev_driver);
dprintk("no CPU initialized for driver %s\n",
driver_data->name);
sysdev_driver_unregister(&cpu_sysdev_class,
&cpufreq_sysdev_driver);

spin_lock_irqsave(&cpufreq_driver_lock, flags);
cpufreq_driver = NULL;
Expand Down
Loading

0 comments on commit 837a082

Please sign in to comment.