From 4fd5475f2ee94d3766d7a227279add3f3038caa3 Mon Sep 17 00:00:00 2001 From: Ruchi Kandoi Date: Fri, 26 Jun 2015 19:02:08 -0700 Subject: [PATCH] cpu_power: Avoids race condition when the task exits. When the task is terminated, the cpu_power for that particular task is added to the terminated tasks. cpu_power is set to ULLONG_MAX at this point to avoid double accounting of the power. It is possible that before the task releases all the resources, cpu reschedules the task or a timer interrupt is fired. At this point we will try to add the additional time to the process, which will cause the accounting to be skewed. This avoids the case where we change the cpu_power when it is already set to ULLONG_MAX. Bug: 22064385 Change-Id: I405733725d535b0a864088516bf52fa3638ee6aa Signed-off-by: Jin Qian Signed-off-by: Ruchi Kandoi (cherry picked from commit fd72341df7e6e8b834f5d4ec86a30f248eb96385) --- drivers/cpufreq/cpufreq_stats.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c index 2433e404721a..4f09f740da06 100644 --- a/drivers/cpufreq/cpufreq_stats.c +++ b/drivers/cpufreq/cpufreq_stats.c @@ -151,7 +151,8 @@ void acct_update_power(struct task_struct *task, cputime_t cputime) { return; curr = powerstats->curr[stats->last_index]; - task->cpu_power += curr * cputime_to_usecs(cputime); + if (task->cpu_power != ULLONG_MAX) + task->cpu_power += curr * cputime_to_usecs(cputime); } EXPORT_SYMBOL_GPL(acct_update_power); -- 2.34.1