Commit 72a4ce340a7ebf39e1c6fdc8f5feb4f974d6c635

Authored by Viresh Kumar
Committed by Rafael J. Wysocki
1 parent 944e9a0316

cpufreq: Move get_cpu_idle_time() to cpufreq.c

Governors other than ondemand and conservative can also use
get_cpu_idle_time() and they aren't required to compile
cpufreq_governor.c. So, move these independent routines to
cpufreq.c instead.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Showing 4 changed files with 39 additions and 37 deletions Side-by-side Diff

drivers/cpufreq/cpufreq.c
... ... @@ -17,7 +17,9 @@
17 17  
18 18 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
19 19  
  20 +#include <asm/cputime.h>
20 21 #include <linux/kernel.h>
  22 +#include <linux/kernel_stat.h>
21 23 #include <linux/module.h>
22 24 #include <linux/init.h>
23 25 #include <linux/notifier.h>
... ... @@ -25,6 +27,7 @@
25 27 #include <linux/delay.h>
26 28 #include <linux/interrupt.h>
27 29 #include <linux/spinlock.h>
  30 +#include <linux/tick.h>
28 31 #include <linux/device.h>
29 32 #include <linux/slab.h>
30 33 #include <linux/cpu.h>
... ... @@ -142,6 +145,41 @@
142 145 return cpufreq_global_kobject;
143 146 }
144 147 EXPORT_SYMBOL_GPL(get_governor_parent_kobj);
  148 +
  149 +static inline u64 get_cpu_idle_time_jiffy(unsigned int cpu, u64 *wall)
  150 +{
  151 + u64 idle_time;
  152 + u64 cur_wall_time;
  153 + u64 busy_time;
  154 +
  155 + cur_wall_time = jiffies64_to_cputime64(get_jiffies_64());
  156 +
  157 + busy_time = kcpustat_cpu(cpu).cpustat[CPUTIME_USER];
  158 + busy_time += kcpustat_cpu(cpu).cpustat[CPUTIME_SYSTEM];
  159 + busy_time += kcpustat_cpu(cpu).cpustat[CPUTIME_IRQ];
  160 + busy_time += kcpustat_cpu(cpu).cpustat[CPUTIME_SOFTIRQ];
  161 + busy_time += kcpustat_cpu(cpu).cpustat[CPUTIME_STEAL];
  162 + busy_time += kcpustat_cpu(cpu).cpustat[CPUTIME_NICE];
  163 +
  164 + idle_time = cur_wall_time - busy_time;
  165 + if (wall)
  166 + *wall = cputime_to_usecs(cur_wall_time);
  167 +
  168 + return cputime_to_usecs(idle_time);
  169 +}
  170 +
  171 +u64 get_cpu_idle_time(unsigned int cpu, u64 *wall, int io_busy)
  172 +{
  173 + u64 idle_time = get_cpu_idle_time_us(cpu, io_busy ? wall : NULL);
  174 +
  175 + if (idle_time == -1ULL)
  176 + return get_cpu_idle_time_jiffy(cpu, wall);
  177 + else if (!io_busy)
  178 + idle_time += get_cpu_iowait_time_us(cpu, wall);
  179 +
  180 + return idle_time;
  181 +}
  182 +EXPORT_SYMBOL_GPL(get_cpu_idle_time);
145 183  
146 184 static struct cpufreq_policy *__cpufreq_cpu_get(unsigned int cpu, bool sysfs)
147 185 {
drivers/cpufreq/cpufreq_governor.c
... ... @@ -23,7 +23,6 @@
23 23 #include <linux/kernel_stat.h>
24 24 #include <linux/mutex.h>
25 25 #include <linux/slab.h>
26   -#include <linux/tick.h>
27 26 #include <linux/types.h>
28 27 #include <linux/workqueue.h>
29 28  
... ... @@ -36,41 +35,6 @@
36 35 else
37 36 return dbs_data->cdata->attr_group_gov_sys;
38 37 }
39   -
40   -static inline u64 get_cpu_idle_time_jiffy(unsigned int cpu, u64 *wall)
41   -{
42   - u64 idle_time;
43   - u64 cur_wall_time;
44   - u64 busy_time;
45   -
46   - cur_wall_time = jiffies64_to_cputime64(get_jiffies_64());
47   -
48   - busy_time = kcpustat_cpu(cpu).cpustat[CPUTIME_USER];
49   - busy_time += kcpustat_cpu(cpu).cpustat[CPUTIME_SYSTEM];
50   - busy_time += kcpustat_cpu(cpu).cpustat[CPUTIME_IRQ];
51   - busy_time += kcpustat_cpu(cpu).cpustat[CPUTIME_SOFTIRQ];
52   - busy_time += kcpustat_cpu(cpu).cpustat[CPUTIME_STEAL];
53   - busy_time += kcpustat_cpu(cpu).cpustat[CPUTIME_NICE];
54   -
55   - idle_time = cur_wall_time - busy_time;
56   - if (wall)
57   - *wall = cputime_to_usecs(cur_wall_time);
58   -
59   - return cputime_to_usecs(idle_time);
60   -}
61   -
62   -u64 get_cpu_idle_time(unsigned int cpu, u64 *wall, int io_busy)
63   -{
64   - u64 idle_time = get_cpu_idle_time_us(cpu, io_busy ? wall : NULL);
65   -
66   - if (idle_time == -1ULL)
67   - return get_cpu_idle_time_jiffy(cpu, wall);
68   - else if (!io_busy)
69   - idle_time += get_cpu_iowait_time_us(cpu, wall);
70   -
71   - return idle_time;
72   -}
73   -EXPORT_SYMBOL_GPL(get_cpu_idle_time);
74 38  
75 39 void dbs_check_cpu(struct dbs_data *dbs_data, int cpu)
76 40 {
drivers/cpufreq/cpufreq_governor.h
... ... @@ -256,7 +256,6 @@
256 256 return sprintf(buf, "%u\n", dbs_data->min_sampling_rate); \
257 257 }
258 258  
259   -u64 get_cpu_idle_time(unsigned int cpu, u64 *wall, int io_busy);
260 259 void dbs_check_cpu(struct dbs_data *dbs_data, int cpu);
261 260 bool need_load_eval(struct cpu_dbs_common_info *cdbs,
262 261 unsigned int sampling_rate);
include/linux/cpufreq.h
... ... @@ -337,6 +337,7 @@
337 337 /*********************************************************************
338 338 * CPUFREQ 2.6. INTERFACE *
339 339 *********************************************************************/
  340 +u64 get_cpu_idle_time(unsigned int cpu, u64 *wall, int io_busy);
340 341 int cpufreq_get_policy(struct cpufreq_policy *policy, unsigned int cpu);
341 342 int cpufreq_update_policy(unsigned int cpu);
342 343 bool have_governor_per_policy(void);