diff options
author | viresh kumar <viresh.kumar@linaro.org> | 2012-10-22 19:28:05 -0400 |
---|---|---|
committer | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2012-11-14 18:33:06 -0500 |
commit | 2aacdfff9c6958723aa5076003247933cefc32ea (patch) | |
tree | a9ce276509ea2bf7b880920af0431a3d8fe86245 /drivers/cpufreq/cpufreq_governor.c | |
parent | 4b972f0b04eaae645b22d99479b9aea43c3d64e7 (diff) |
cpufreq: Move common part from governors to separate file, v2
Multiple cpufreq governers have defined similar get_cpu_idle_time_***()
routines. These routines must be moved to some common place, so that all
governors can use them.
So moving them to cpufreq_governor.c, which seems to be a better place for
keeping these routines.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Diffstat (limited to 'drivers/cpufreq/cpufreq_governor.c')
-rw-r--r-- | drivers/cpufreq/cpufreq_governor.c | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c new file mode 100644 index 000000000000..0001071cdcdb --- /dev/null +++ b/drivers/cpufreq/cpufreq_governor.c | |||
@@ -0,0 +1,52 @@ | |||
1 | /* | ||
2 | * drivers/cpufreq/cpufreq_governor.c | ||
3 | * | ||
4 | * CPUFREQ governors common code | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License version 2 as | ||
8 | * published by the Free Software Foundation. | ||
9 | */ | ||
10 | |||
11 | #include <asm/cputime.h> | ||
12 | #include <linux/export.h> | ||
13 | #include <linux/kernel_stat.h> | ||
14 | #include <linux/tick.h> | ||
15 | #include <linux/types.h> | ||
16 | /* | ||
17 | * Code picked from earlier governer implementations | ||
18 | */ | ||
19 | static inline u64 get_cpu_idle_time_jiffy(unsigned int cpu, u64 *wall) | ||
20 | { | ||
21 | u64 idle_time; | ||
22 | u64 cur_wall_time; | ||
23 | u64 busy_time; | ||
24 | |||
25 | cur_wall_time = jiffies64_to_cputime64(get_jiffies_64()); | ||
26 | |||
27 | busy_time = kcpustat_cpu(cpu).cpustat[CPUTIME_USER]; | ||
28 | busy_time += kcpustat_cpu(cpu).cpustat[CPUTIME_SYSTEM]; | ||
29 | busy_time += kcpustat_cpu(cpu).cpustat[CPUTIME_IRQ]; | ||
30 | busy_time += kcpustat_cpu(cpu).cpustat[CPUTIME_SOFTIRQ]; | ||
31 | busy_time += kcpustat_cpu(cpu).cpustat[CPUTIME_STEAL]; | ||
32 | busy_time += kcpustat_cpu(cpu).cpustat[CPUTIME_NICE]; | ||
33 | |||
34 | idle_time = cur_wall_time - busy_time; | ||
35 | if (wall) | ||
36 | *wall = jiffies_to_usecs(cur_wall_time); | ||
37 | |||
38 | return jiffies_to_usecs(idle_time); | ||
39 | } | ||
40 | |||
41 | cputime64_t get_cpu_idle_time(unsigned int cpu, cputime64_t *wall) | ||
42 | { | ||
43 | u64 idle_time = get_cpu_idle_time_us(cpu, NULL); | ||
44 | |||
45 | if (idle_time == -1ULL) | ||
46 | return get_cpu_idle_time_jiffy(cpu, wall); | ||
47 | else | ||
48 | idle_time += get_cpu_iowait_time_us(cpu, wall); | ||
49 | |||
50 | return idle_time; | ||
51 | } | ||
52 | EXPORT_SYMBOL_GPL(get_cpu_idle_time); | ||