The following commit has been merged into the timers/core branch of tip:

Commit-ID:     3b495b22d04df3220ccae829bf7c5cadb3059ccf
Gitweb:        
https://git.kernel.org/tip/3b495b22d04df3220ccae829bf7c5cadb3059ccf
Author:        Thomas Gleixner <t...@linutronix.de>
AuthorDate:    Wed, 21 Aug 2019 21:09:08 +02:00
Committer:     Thomas Gleixner <t...@linutronix.de>
CommitterDate: Wed, 28 Aug 2019 11:50:36 +02:00

posix-cpu-timers: Simplify timer queueing

Now that the expiry cache can be accessed as an array, the per clock
checking can be reduced to just comparing the corresponding array elements.

Signed-off-by: Thomas Gleixner <t...@linutronix.de>
Reviewed-by: Frederic Weisbecker <frede...@kernel.org>
Link: https://lkml.kernel.org/r/20190821192921.212129...@linutronix.de

---
 kernel/time/posix-cpu-timers.c | 55 ++++++++++++---------------------
 1 file changed, 21 insertions(+), 34 deletions(-)

diff --git a/kernel/time/posix-cpu-timers.c b/kernel/time/posix-cpu-timers.c
index a38b6d0..b132417 100644
--- a/kernel/time/posix-cpu-timers.c
+++ b/kernel/time/posix-cpu-timers.c
@@ -456,20 +456,20 @@ static inline int expires_gt(u64 expires, u64 new_exp)
  */
 static void arm_timer(struct k_itimer *timer)
 {
+       struct cpu_timer_list *const nt = &timer->it.cpu;
+       int clkidx = CPUCLOCK_WHICH(timer->it_clock);
+       u64 *cpuexp, newexp = timer->it.cpu.expires;
        struct task_struct *p = timer->it.cpu.task;
        struct list_head *head, *listpos;
-       struct task_cputime *cputime_expires;
-       struct cpu_timer_list *const nt = &timer->it.cpu;
        struct cpu_timer_list *next;
 
        if (CPUCLOCK_PERTHREAD(timer->it_clock)) {
-               head = p->posix_cputimers.cpu_timers;
-               cputime_expires = &p->posix_cputimers.cputime_expires;
+               head = p->posix_cputimers.cpu_timers + clkidx;
+               cpuexp = p->posix_cputimers.expiries + clkidx;
        } else {
-               head = p->signal->posix_cputimers.cpu_timers;
-               cputime_expires = &p->signal->posix_cputimers.cputime_expires;
+               head = p->signal->posix_cputimers.cpu_timers + clkidx;
+               cpuexp = p->signal->posix_cputimers.expiries + clkidx;
        }
-       head += CPUCLOCK_WHICH(timer->it_clock);
 
        listpos = head;
        list_for_each_entry(next, head, entry) {
@@ -479,35 +479,22 @@ static void arm_timer(struct k_itimer *timer)
        }
        list_add(&nt->entry, listpos);
 
-       if (listpos == head) {
-               u64 exp = nt->expires;
+       if (listpos != head)
+               return;
 
-               /*
-                * We are the new earliest-expiring POSIX 1.b timer, hence
-                * need to update expiration cache. Take into account that
-                * for process timers we share expiration cache with itimers
-                * and RLIMIT_CPU and for thread timers with RLIMIT_RTTIME.
-                */
+       /*
+        * We are the new earliest-expiring POSIX 1.b timer, hence
+        * need to update expiration cache. Take into account that
+        * for process timers we share expiration cache with itimers
+        * and RLIMIT_CPU and for thread timers with RLIMIT_RTTIME.
+        */
+       if (expires_gt(*cpuexp, newexp))
+               *cpuexp = newexp;
 
-               switch (CPUCLOCK_WHICH(timer->it_clock)) {
-               case CPUCLOCK_PROF:
-                       if (expires_gt(cputime_expires->prof_exp, exp))
-                               cputime_expires->prof_exp = exp;
-                       break;
-               case CPUCLOCK_VIRT:
-                       if (expires_gt(cputime_expires->virt_exp, exp))
-                               cputime_expires->virt_exp = exp;
-                       break;
-               case CPUCLOCK_SCHED:
-                       if (expires_gt(cputime_expires->sched_exp, exp))
-                               cputime_expires->sched_exp = exp;
-                       break;
-               }
-               if (CPUCLOCK_PERTHREAD(timer->it_clock))
-                       tick_dep_set_task(p, TICK_DEP_BIT_POSIX_TIMER);
-               else
-                       tick_dep_set_signal(p->signal, 
TICK_DEP_BIT_POSIX_TIMER);
-       }
+       if (CPUCLOCK_PERTHREAD(timer->it_clock))
+               tick_dep_set_task(p, TICK_DEP_BIT_POSIX_TIMER);
+       else
+               tick_dep_set_signal(p->signal, TICK_DEP_BIT_POSIX_TIMER);
 }
 
 /*

Reply via email to