cpu_power: Avoids race condition when the task exits.
authorRuchi Kandoi <kandoiruchi@google.com>
Sat, 27 Jun 2015 02:02:08 +0000 (19:02 -0700)
committerHuang, Tao <huangtao@rock-chips.com>
Tue, 27 Oct 2015 08:28:04 +0000 (16:28 +0800)
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 <jinqian@google.com>
Signed-off-by: Ruchi Kandoi <kandoiruchi@google.com>
(cherry picked from commit fd72341df7e6e8b834f5d4ec86a30f248eb96385)

drivers/cpufreq/cpufreq_stats.c

index 2433e404721aa48d7094e03a30526096e79de8bf..4f09f740da06242f8754375d3efcdc3fabe8a7db 100644 (file)
@@ -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);