diff options
| author | Ruchi Kandoi <kandoiruchi@google.com> | 2015-04-17 16:33:29 -0700 |
|---|---|---|
| committer | Arvin Quilao <arquilao@gmail.com> | 2017-04-21 02:05:15 +0000 |
| commit | 923e61f4db764a7a25369a5dcecdd8ce2eb141fa (patch) | |
| tree | d78ae8178d467bb6d0e5b5aaa95330b2455ca802 | |
| parent | f65c3c9134ffd4cb87afcc8874b14a4fa8264aad (diff) | |
sched: cpufreq: Adds a field cpu_power in the task_struct
cpu_power has been added to keep track of amount of power each task is
consuming. cpu_power is updated whenever stime and utime are updated for
a task. power is computed by taking into account the frequency at which
the current core was running and the current for cpu actively
running at hat frequency.
Bug: 21498425
Change-Id: Ic535941e7b339aab5cae9081a34049daeb44b248
Signed-off-by: Ruchi Kandoi <kandoiruchi@google.com>
Git-commit: 94877641f6b6ea17aa335729f548eb5647db3e3e
Git-repo: https://android.googlesource.com/kernel/msm/
Signed-off-by: Nirmal Abraham <nabrah@codeaurora.org>
| -rw-r--r-- | drivers/cpufreq/cpufreq_stats.c | 19 | ||||
| -rw-r--r-- | include/linux/cpufreq.h | 1 | ||||
| -rw-r--r-- | kernel/sched/cputime.c | 4 |
3 files changed, 19 insertions, 5 deletions
diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c index c35e82f8dd2..5eb1df1bc0e 100644 --- a/drivers/cpufreq/cpufreq_stats.c +++ b/drivers/cpufreq/cpufreq_stats.c @@ -18,6 +18,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; @@ -128,6 +129,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 2d04ab36b60..d3c1819dc0d 100644 --- a/include/linux/cpufreq.h +++ b/include/linux/cpufreq.h @@ -484,7 +484,6 @@ static inline int cpufreq_generic_exit(struct cpufreq_policy *policy) return 0; } - /********************************************************************* * CPUFREQ STATS * *********************************************************************/ diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c index 997bacfed82..199dda8db9a 100644 --- a/kernel/sched/cputime.c +++ b/kernel/sched/cputime.c @@ -157,10 +157,8 @@ void account_user_time(struct task_struct *p, cputime_t cputime, /* Account for user time used */ acct_account_cputime(p); -#ifdef CONFIG_CPU_FREQ_STAT /* Account power usage for user time */ acct_update_power(p, cputime); -#endif } /* @@ -212,10 +210,8 @@ void __account_system_time(struct task_struct *p, cputime_t cputime, /* Account for system time used */ acct_account_cputime(p); -#ifdef CONFIG_CPU_FREQ_STAT /* Account power usage for system time */ acct_update_power(p, cputime); -#endif } /* |
