diff options
| -rw-r--r-- | drivers/cpufreq/cpufreq_stats.c | 19 | ||||
| -rw-r--r-- | include/linux/cpufreq.h | 10 | ||||
| -rw-r--r-- | include/linux/sched.h | 1 | ||||
| -rw-r--r-- | kernel/fork.c | 1 | ||||
| -rw-r--r-- | kernel/sched/cputime.c | 7 |
5 files changed, 37 insertions, 1 deletions
diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c index 824e4d529..5efb22fdc 100644 --- a/drivers/cpufreq/cpufreq_stats.c +++ b/drivers/cpufreq/cpufreq_stats.c @@ -23,6 +23,7 @@ #include <linux/sort.h> #include <linux/err.h> #include <linux/of.h> +#include <linux/sched.h> #include <asm/cputime.h> static spinlock_t cpufreq_stats_lock; @@ -133,6 +134,24 @@ static int get_index_all_cpufreq_stat(struct all_cpufreq_stats *all_stat, return -1; } +void acct_update_power(struct task_struct *task, cputime_t cputime) { + struct cpufreq_power_stats *powerstats; + struct cpufreq_stats *stats; + unsigned int cpu_num, curr; + + if (!task) + return; + cpu_num = task_cpu(task); + powerstats = per_cpu(cpufreq_power_stats, cpu_num); + stats = per_cpu(cpufreq_stats_table, cpu_num); + if (!powerstats || !stats) + return; + + curr = powerstats->curr[stats->last_index]; + task->cpu_power += curr * cputime_to_usecs(cputime); +} +EXPORT_SYMBOL_GPL(acct_update_power); + static ssize_t show_current_in_state(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h index 0ef97797b..0391ce43d 100644 --- a/include/linux/cpufreq.h +++ b/include/linux/cpufreq.h @@ -17,6 +17,8 @@ #include <linux/threads.h> #include <linux/kobject.h> #include <linux/sysfs.h> +#include <asm/cputime.h> + #include <linux/completion.h> #include <linux/workqueue.h> #include <linux/cpumask.h> @@ -26,7 +28,6 @@ /* Print length for names. Extra 1 space for accomodating '\n' in prints */ #define CPUFREQ_NAME_PLEN (CPUFREQ_NAME_LEN + 1) - /********************************************************************* * CPUFREQ NOTIFIER INTERFACE * *********************************************************************/ @@ -448,4 +449,11 @@ void cpufreq_frequency_table_get_attr(struct cpufreq_frequency_table *table, void cpufreq_frequency_table_update_policy_cpu(struct cpufreq_policy *policy); void cpufreq_frequency_table_put_attr(unsigned int cpu); + +/********************************************************************* + * CPUFREQ STATS * + *********************************************************************/ + +void acct_update_power(struct task_struct *p, cputime_t cputime); + #endif /* _LINUX_CPUFREQ_H */ diff --git a/include/linux/sched.h b/include/linux/sched.h index 9e5800231..0217ec155 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1282,6 +1282,7 @@ struct task_struct { cputime_t utime, stime, utimescaled, stimescaled; cputime_t gtime; + unsigned long long cpu_power; #ifndef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE struct cputime prev_cputime; #endif diff --git a/kernel/fork.c b/kernel/fork.c index 486303367..01650a5dd 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -1345,6 +1345,7 @@ static struct task_struct *copy_process(unsigned long clone_flags, p->utime = p->stime = p->gtime = 0; p->utimescaled = p->stimescaled = 0; + p->cpu_power = 0; #ifndef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE p->prev_cputime.utime = p->prev_cputime.stime = 0; #endif diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c index c23a8fd36..ee65c82af 100644 --- a/kernel/sched/cputime.c +++ b/kernel/sched/cputime.c @@ -1,3 +1,4 @@ +#include <linux/cpufreq.h> #include <linux/export.h> #include <linux/sched.h> #include <linux/tsacct_kern.h> @@ -149,6 +150,9 @@ void account_user_time(struct task_struct *p, cputime_t cputime, /* Account for user time used */ acct_account_cputime(p); + + /* Account power usage for user time */ + acct_update_power(p, cputime); } /* @@ -199,6 +203,9 @@ void __account_system_time(struct task_struct *p, cputime_t cputime, /* Account for system time used */ acct_account_cputime(p); + + /* Account power usage for system time */ + acct_update_power(p, cputime); } /* |
