Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 141aa174 authored by Ruchi Kandoi's avatar Ruchi Kandoi
Browse files

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.

Change-Id: Ic535941e7b339aab5cae9081a34049daeb44b248
Signed-off-by: default avatarRuchi Kandoi <kandoiruchi@google.com>
parent 7f53705d
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
#include <linux/slab.h>
#include <linux/sort.h>
#include <linux/of.h>
#include <linux/sched.h>
#include <linux/cputime.h>

static spinlock_t cpufreq_stats_lock;
@@ -125,6 +126,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)
{
+9 −0
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@
#include <linux/notifier.h>
#include <linux/spinlock.h>
#include <linux/sysfs.h>
#include <asm/cputime.h>


/*********************************************************************
 *                        CPUFREQ INTERFACE                          *
@@ -600,4 +602,11 @@ unsigned int cpufreq_generic_get(unsigned int cpu);
int cpufreq_generic_init(struct cpufreq_policy *policy,
		struct cpufreq_frequency_table *table,
		unsigned int transition_latency);

/*********************************************************************
 *                         CPUFREQ STATS                             *
 *********************************************************************/

void acct_update_power(struct task_struct *p, cputime_t cputime);

#endif /* _LINUX_CPUFREQ_H */
+1 −0
Original line number Diff line number Diff line
@@ -1367,6 +1367,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
+1 −0
Original line number Diff line number Diff line
@@ -1304,6 +1304,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
+7 −0
Original line number Diff line number Diff line
#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);
}

/*