From a5b89db9ee090f3ef5109a746224eeabfb1e6e24 Mon Sep 17 00:00:00 2001 From: Ruchi Kandoi Date: Fri, 26 Jun 2015 14:19:21 -0700 Subject: [PATCH] uid_cputime: Avoids double accounting of process stime, utime and cpu_power in task exit. This avoids the race where a particular process is terminating and we read the show_uid_stats. At this time since the task_struct still exists and we will account for the terminating process as one of the active task, where as the stats would have been added in the task exit callback. When the task is terminated, the cpu_power for that particular task is added to the terminated tasks. 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 that race condition. Bug: 22064385 Change-Id: Id2ae04b33fcd230eda9683a41b6019d4dd8f5d85 Signed-off-by: Jin Qian Signed-off-by: Ruchi Kandoi Git-commit: 344377047daa5832ef798af697adee388e367d57 Git-repo: https://android.googlesource.com/kernel/msm/ Signed-off-by: Nirmal Abraham --- drivers/misc/uid_cputime.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/misc/uid_cputime.c b/drivers/misc/uid_cputime.c index 89bfba6c5b6..9a87640b478 100644 --- a/drivers/misc/uid_cputime.c +++ b/drivers/misc/uid_cputime.c @@ -100,6 +100,7 @@ static int uid_stat_show(struct seq_file *m, void *v) task_uid(task))); return -ENOMEM; } + task_cputime_adjusted(task, &utime, &stime); uid_entry->active_utime += utime; uid_entry->active_stime += stime; @@ -211,6 +212,7 @@ static int process_notifier(struct notifier_block *self, uid_entry->utime += utime; uid_entry->stime += stime; uid_entry->power += task->cpu_power; + task->cpu_power = ULLONG_MAX; exit: mutex_unlock(&uid_lock); -- 2.20.1