]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
posix_cpu_timers: consolidate timer list cleanups
authorFrederic Weisbecker <fweisbec@gmail.com>
Tue, 26 Mar 2013 23:24:10 +0000 (10:24 +1100)
committerStephen Rothwell <sfr@canb.auug.org.au>
Thu, 4 Apr 2013 06:04:10 +0000 (17:04 +1100)
Cleaning up the posix cpu timers on task exit shares some common code
among timer list types, most notably the list traversal and expiry time
update.

Unify this in a common helper.

Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Stanislaw Gruszka <sgruszka@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
kernel/posix-cpu-timers.c

index e5286b5492820d84a4c34d1fea0725a4cf7afbd7..b30775f88a4e2534e3300a92147a647ab88333fd 100644 (file)
@@ -382,6 +382,21 @@ static int posix_cpu_timer_del(struct k_itimer *timer)
        return ret;
 }
 
+static void cleanup_timers_list(struct list_head *head,
+                               unsigned long long curr)
+{
+       struct cpu_timer_list *timer, *next;
+
+       list_for_each_entry_safe(timer, next, head, entry) {
+               list_del_init(&timer->entry);
+               if (timer->expires < curr) {
+                       timer->expires = 0;
+               } else {
+                       timer->expires -= curr;
+               }
+       }
+}
+
 /*
  * Clean out CPU timers still ticking when a thread exited.  The task
  * pointer is cleared, and the expiry time is replaced with the residual
@@ -392,37 +407,12 @@ static void cleanup_timers(struct list_head *head,
                           cputime_t utime, cputime_t stime,
                           unsigned long long sum_exec_runtime)
 {
-       struct cpu_timer_list *timer, *next;
-       cputime_t ptime = utime + stime;
 
-       list_for_each_entry_safe(timer, next, head, entry) {
-               list_del_init(&timer->entry);
-               if (timer->expires < cputime_to_expires(ptime)) {
-                       timer->expires = 0;
-               } else {
-                       timer->expires -= cputime_to_expires(ptime);
-               }
-       }
-
-       ++head;
-       list_for_each_entry_safe(timer, next, head, entry) {
-               list_del_init(&timer->entry);
-               if (timer->expires < cputime_to_expires(utime)) {
-                       timer->expires = 0;
-               } else {
-                       timer->expires -= cputime_to_expires(utime);
-               }
-       }
+       cputime_t ptime = utime + stime;
 
-       ++head;
-       list_for_each_entry_safe(timer, next, head, entry) {
-               list_del_init(&timer->entry);
-               if (timer->expires < sum_exec_runtime) {
-                       timer->expires = 0;
-               } else {
-                       timer->expires -= sum_exec_runtime;
-               }
-       }
+       cleanup_timers_list(head, cputime_to_expires(ptime));
+       cleanup_timers_list(++head, cputime_to_expires(utime));
+       cleanup_timers_list(++head, sum_exec_runtime);
 }
 
 /*