blob: 0001071cdcdb992167023151a270a874abb80bce [file] [log] [blame]
viresh kumar2aacdff2012-10-23 01:28:05 +02001/*
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 */
19static 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
41cputime64_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}
52EXPORT_SYMBOL_GPL(get_cpu_idle_time);