]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
sh: cpufreq: percpu struct clk accounting.
authorPaul Mundt <lethal@linux-sh.org>
Fri, 27 Jan 2012 08:49:16 +0000 (17:49 +0900)
committerPaul Mundt <lethal@linux-sh.org>
Fri, 27 Jan 2012 08:49:16 +0000 (17:49 +0900)
At the moment there is simply a global struct clk pointer for the CPU
frequency, which is fundamentally broken in the SMP case. This moves to
fix it up by switching to a percpu case.

Signed-off-by: Paul Mundt <lethal@linux-sh.org>
arch/sh/kernel/cpufreq.c

index 0fffacea6ed96aebda4c692ace9b1185468d74b5..8203865e16b70801f9217a7c89997d90d03c53f8 100644 (file)
@@ -3,7 +3,7 @@
  *
  * cpufreq driver for the SuperH processors.
  *
- * Copyright (C) 2002 - 2007 Paul Mundt
+ * Copyright (C) 2002 - 2012 Paul Mundt
  * Copyright (C) 2002 M. R. Brown
  *
  * Clock framework bits from arch/avr32/mach-at32ap/cpufreq.c
 #include <linux/smp.h>
 #include <linux/sched.h>       /* set_cpus_allowed() */
 #include <linux/clk.h>
+#include <linux/percpu.h>
+#include <linux/sh_clk.h>
 
-static struct clk *cpuclk;
+static DEFINE_PER_CPU(struct clk, sh_cpuclk);
 
 static unsigned int sh_cpufreq_get(unsigned int cpu)
 {
-       return (clk_get_rate(cpuclk) + 500) / 1000;
+       return (clk_get_rate(&per_cpu(sh_cpuclk, cpu)) + 500) / 1000;
 }
 
 /*
@@ -40,6 +42,7 @@ static int sh_cpufreq_target(struct cpufreq_policy *policy,
                             unsigned int relation)
 {
        unsigned int cpu = policy->cpu;
+       struct clk *cpuclk = &per_cpu(sh_cpuclk, cpu);
        cpumask_t cpus_allowed;
        struct cpufreq_freqs freqs;
        long freq;
@@ -77,13 +80,15 @@ static int sh_cpufreq_target(struct cpufreq_policy *policy,
 
 static int sh_cpufreq_cpu_init(struct cpufreq_policy *policy)
 {
-       if (!cpu_online(policy->cpu))
+       unsigned int cpu = policy->cpu;
+       struct clk *cpuclk = &per_cpu(sh_cpuclk, cpu);
+
+       if (!cpu_online(cpu))
                return -ENODEV;
 
        cpuclk = clk_get(NULL, "cpu_clk");
        if (IS_ERR(cpuclk)) {
-               printk(KERN_ERR "cpufreq: couldn't get CPU#%d clk\n",
-                      policy->cpu);
+               printk(KERN_ERR "cpufreq: couldn't get CPU#%d clk\n", cpu);
                return PTR_ERR(cpuclk);
        }
 
@@ -92,7 +97,7 @@ static int sh_cpufreq_cpu_init(struct cpufreq_policy *policy)
        policy->cpuinfo.max_freq = (clk_round_rate(cpuclk, ~0UL) + 500) / 1000;
        policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL;
 
-       policy->cur             = sh_cpufreq_get(policy->cpu);
+       policy->cur             = sh_cpufreq_get(cpu);
        policy->min             = policy->cpuinfo.min_freq;
        policy->max             = policy->cpuinfo.max_freq;
 
@@ -102,7 +107,7 @@ static int sh_cpufreq_cpu_init(struct cpufreq_policy *policy)
         */
        if (unlikely(policy->min == policy->max)) {
                printk(KERN_ERR "cpufreq: clock framework rate rounding "
-                      "not supported on CPU#%d.\n", policy->cpu);
+                      "not supported on CPU#%d.\n", cpu);
 
                clk_put(cpuclk);
                return -EINVAL;
@@ -110,7 +115,7 @@ static int sh_cpufreq_cpu_init(struct cpufreq_policy *policy)
 
        printk(KERN_INFO "cpufreq: CPU#%d Frequencies - Minimum %u.%03u MHz, "
               "Maximum %u.%03u MHz.\n",
-              policy->cpu, policy->min / 1000, policy->min % 1000,
+              cpu, policy->min / 1000, policy->min % 1000,
               policy->max / 1000, policy->max % 1000);
 
        return 0;
@@ -125,6 +130,7 @@ static int sh_cpufreq_verify(struct cpufreq_policy *policy)
 
 static int sh_cpufreq_exit(struct cpufreq_policy *policy)
 {
+       struct clk *cpuclk = &per_cpu(sh_cpuclk, policy->cpu);
        clk_put(cpuclk);
        return 0;
 }