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 | |
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')
-rw-r--r-- | drivers/cpufreq/Makefile | 4 | ||||
-rw-r--r-- | drivers/cpufreq/cpufreq_conservative.c | 34 | ||||
-rw-r--r-- | drivers/cpufreq/cpufreq_governor.c | 52 | ||||
-rw-r--r-- | drivers/cpufreq/cpufreq_ondemand.c | 34 |
4 files changed, 54 insertions, 70 deletions
diff --git a/drivers/cpufreq/Makefile b/drivers/cpufreq/Makefile index 1bc90e1306d8..5b1413e47216 100644 --- a/drivers/cpufreq/Makefile +++ b/drivers/cpufreq/Makefile | |||
@@ -7,8 +7,8 @@ obj-$(CONFIG_CPU_FREQ_STAT) += cpufreq_stats.o | |||
7 | obj-$(CONFIG_CPU_FREQ_GOV_PERFORMANCE) += cpufreq_performance.o | 7 | obj-$(CONFIG_CPU_FREQ_GOV_PERFORMANCE) += cpufreq_performance.o |
8 | obj-$(CONFIG_CPU_FREQ_GOV_POWERSAVE) += cpufreq_powersave.o | 8 | obj-$(CONFIG_CPU_FREQ_GOV_POWERSAVE) += cpufreq_powersave.o |
9 | obj-$(CONFIG_CPU_FREQ_GOV_USERSPACE) += cpufreq_userspace.o | 9 | obj-$(CONFIG_CPU_FREQ_GOV_USERSPACE) += cpufreq_userspace.o |
10 | obj-$(CONFIG_CPU_FREQ_GOV_ONDEMAND) += cpufreq_ondemand.o | 10 | obj-$(CONFIG_CPU_FREQ_GOV_ONDEMAND) += cpufreq_ondemand.o cpufreq_governor.o |
11 | obj-$(CONFIG_CPU_FREQ_GOV_CONSERVATIVE) += cpufreq_conservative.o | 11 | obj-$(CONFIG_CPU_FREQ_GOV_CONSERVATIVE) += cpufreq_conservative.o cpufreq_governor.o |
12 | 12 | ||
13 | # CPUfreq cross-arch helpers | 13 | # CPUfreq cross-arch helpers |
14 | obj-$(CONFIG_CPU_FREQ_TABLE) += freq_table.o | 14 | obj-$(CONFIG_CPU_FREQ_TABLE) += freq_table.o |
diff --git a/drivers/cpufreq/cpufreq_conservative.c b/drivers/cpufreq/cpufreq_conservative.c index a152af7e1991..181abad07266 100644 --- a/drivers/cpufreq/cpufreq_conservative.c +++ b/drivers/cpufreq/cpufreq_conservative.c | |||
@@ -95,40 +95,6 @@ static struct dbs_tuners { | |||
95 | .freq_step = 5, | 95 | .freq_step = 5, |
96 | }; | 96 | }; |
97 | 97 | ||
98 | static inline u64 get_cpu_idle_time_jiffy(unsigned int cpu, u64 *wall) | ||
99 | { | ||
100 | u64 idle_time; | ||
101 | u64 cur_wall_time; | ||
102 | u64 busy_time; | ||
103 | |||
104 | cur_wall_time = jiffies64_to_cputime64(get_jiffies_64()); | ||
105 | |||
106 | busy_time = kcpustat_cpu(cpu).cpustat[CPUTIME_USER]; | ||
107 | busy_time += kcpustat_cpu(cpu).cpustat[CPUTIME_SYSTEM]; | ||
108 | busy_time += kcpustat_cpu(cpu).cpustat[CPUTIME_IRQ]; | ||
109 | busy_time += kcpustat_cpu(cpu).cpustat[CPUTIME_SOFTIRQ]; | ||
110 | busy_time += kcpustat_cpu(cpu).cpustat[CPUTIME_STEAL]; | ||
111 | busy_time += kcpustat_cpu(cpu).cpustat[CPUTIME_NICE]; | ||
112 | |||
113 | idle_time = cur_wall_time - busy_time; | ||
114 | if (wall) | ||
115 | *wall = jiffies_to_usecs(cur_wall_time); | ||
116 | |||
117 | return jiffies_to_usecs(idle_time); | ||
118 | } | ||
119 | |||
120 | static inline cputime64_t get_cpu_idle_time(unsigned int cpu, cputime64_t *wall) | ||
121 | { | ||
122 | u64 idle_time = get_cpu_idle_time_us(cpu, NULL); | ||
123 | |||
124 | if (idle_time == -1ULL) | ||
125 | return get_cpu_idle_time_jiffy(cpu, wall); | ||
126 | else | ||
127 | idle_time += get_cpu_iowait_time_us(cpu, wall); | ||
128 | |||
129 | return idle_time; | ||
130 | } | ||
131 | |||
132 | /* keep track of frequency transitions */ | 98 | /* keep track of frequency transitions */ |
133 | static int | 99 | static int |
134 | dbs_cpufreq_notifier(struct notifier_block *nb, unsigned long val, | 100 | dbs_cpufreq_notifier(struct notifier_block *nb, unsigned long val, |
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); | ||
diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c index 396322f2a83f..d7f774bb49dd 100644 --- a/drivers/cpufreq/cpufreq_ondemand.c +++ b/drivers/cpufreq/cpufreq_ondemand.c | |||
@@ -119,40 +119,6 @@ static struct dbs_tuners { | |||
119 | .powersave_bias = 0, | 119 | .powersave_bias = 0, |
120 | }; | 120 | }; |
121 | 121 | ||
122 | static inline u64 get_cpu_idle_time_jiffy(unsigned int cpu, u64 *wall) | ||
123 | { | ||
124 | u64 idle_time; | ||
125 | u64 cur_wall_time; | ||
126 | u64 busy_time; | ||
127 | |||
128 | cur_wall_time = jiffies64_to_cputime64(get_jiffies_64()); | ||
129 | |||
130 | busy_time = kcpustat_cpu(cpu).cpustat[CPUTIME_USER]; | ||
131 | busy_time += kcpustat_cpu(cpu).cpustat[CPUTIME_SYSTEM]; | ||
132 | busy_time += kcpustat_cpu(cpu).cpustat[CPUTIME_IRQ]; | ||
133 | busy_time += kcpustat_cpu(cpu).cpustat[CPUTIME_SOFTIRQ]; | ||
134 | busy_time += kcpustat_cpu(cpu).cpustat[CPUTIME_STEAL]; | ||
135 | busy_time += kcpustat_cpu(cpu).cpustat[CPUTIME_NICE]; | ||
136 | |||
137 | idle_time = cur_wall_time - busy_time; | ||
138 | if (wall) | ||
139 | *wall = jiffies_to_usecs(cur_wall_time); | ||
140 | |||
141 | return jiffies_to_usecs(idle_time); | ||
142 | } | ||
143 | |||
144 | static inline cputime64_t get_cpu_idle_time(unsigned int cpu, cputime64_t *wall) | ||
145 | { | ||
146 | u64 idle_time = get_cpu_idle_time_us(cpu, NULL); | ||
147 | |||
148 | if (idle_time == -1ULL) | ||
149 | return get_cpu_idle_time_jiffy(cpu, wall); | ||
150 | else | ||
151 | idle_time += get_cpu_iowait_time_us(cpu, wall); | ||
152 | |||
153 | return idle_time; | ||
154 | } | ||
155 | |||
156 | static inline cputime64_t get_cpu_iowait_time(unsigned int cpu, cputime64_t *wall) | 122 | static inline cputime64_t get_cpu_iowait_time(unsigned int cpu, cputime64_t *wall) |
157 | { | 123 | { |
158 | u64 iowait_time = get_cpu_iowait_time_us(cpu, wall); | 124 | u64 iowait_time = get_cpu_iowait_time_us(cpu, wall); |