From 3f34d024c12e49fbce4009d094ae1d287084e511 Mon Sep 17 00:00:00 2001 From: Dave Young Date: Fri, 18 Apr 2008 13:38:57 -0700 Subject: [PATCH 1/4] jiffies: add time_is_after_jiffies and others which compare with jiffies Most of time_after like macros usages just compare jiffies and another number, so here add some time_is_* macros for convenience. Signed-off-by: Dave Young Cc: Alan Cox Signed-off-by: Andrew Morton Signed-off-by: Thomas Gleixner --- include/linux/jiffies.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h index e0b5b684d83f..e377e34e589e 100644 --- a/include/linux/jiffies.h +++ b/include/linux/jiffies.h @@ -134,6 +134,22 @@ static inline u64 get_jiffies_64(void) ((__s64)(a) - (__s64)(b) >= 0)) #define time_before_eq64(a,b) time_after_eq64(b,a) +/* + * These four macros compare jiffies and 'a' for convenience. + */ + +/* time_is_before_jiffies(a) return true if a is before jiffies */ +#define time_is_before_jiffies(a) time_after(jiffies, a) + +/* time_is_after_jiffies(a) return true if a is after jiffies */ +#define time_is_after_jiffies(a) time_before(jiffies, a) + +/* time_is_before_eq_jiffies(a) return true if a is before or equal to jiffies*/ +#define time_is_before_eq_jiffies(a) time_after_eq(jiffies, a) + +/* time_is_after_eq_jiffies(a) return true if a is after or equal to jiffies*/ +#define time_is_after_eq_jiffies(a) time_before_eq(jiffies, a) + /* * Have the 32 bit jiffies value wrap 5 minutes after boot * so jiffies wrap bugs show up earlier. From 833df317f9ada91488898b005f4641bb674a3bae Mon Sep 17 00:00:00 2001 From: Glauber Costa Date: Fri, 18 Apr 2008 13:38:58 -0700 Subject: [PATCH 2/4] clockevents: fix typo in tick-broadcast.c braodcast -> broadcast Signed-off-by: Glauber Costa Signed-off-by: Andrew Morton Signed-off-by: Thomas Gleixner --- kernel/time/tick-broadcast.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c index fdfa0c745bb6..57a1f02e5ec0 100644 --- a/kernel/time/tick-broadcast.c +++ b/kernel/time/tick-broadcast.c @@ -262,7 +262,7 @@ out: void tick_broadcast_on_off(unsigned long reason, int *oncpu) { if (!cpu_isset(*oncpu, cpu_online_map)) - printk(KERN_ERR "tick-braodcast: ignoring broadcast for " + printk(KERN_ERR "tick-broadcast: ignoring broadcast for " "offline CPU #%d\n", *oncpu); else smp_call_function_single(*oncpu, tick_do_broadcast_on_off, From 833883d9ac4cfb31c1c4419335e68e6895a05b6b Mon Sep 17 00:00:00 2001 From: Dimitri Sivanich Date: Fri, 18 Apr 2008 13:39:00 -0700 Subject: [PATCH 3/4] hrtimer: reduce calls to hrtimer_get_softirq_time() It seems that hrtimer_run_queues() is calling hrtimer_get_softirq_time() more often than it needs to. This can cause frequent contention on systems with large numbers of processors/cores. With this patch, hrtimer_run_queues only calls hrtimer_get_softirq_time() if there is a pending timer in one of the hrtimer bases, and only once. This also combines hrtimer_run_queues() and the inline run_hrtimer_queue() into one function. [ tglx@linutronix.de: coding style ] Signed-off-by: Dimitri Sivanich Cc: Peter Zijlstra Cc: Ingo Molnar Signed-off-by: Andrew Morton Signed-off-by: Thomas Gleixner --- kernel/hrtimer.c | 74 ++++++++++++++++++++++++------------------------ 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c index c642ef75069f..70d4adc74639 100644 --- a/kernel/hrtimer.c +++ b/kernel/hrtimer.c @@ -1238,51 +1238,51 @@ void hrtimer_run_pending(void) /* * Called from hardirq context every jiffy */ -static inline void run_hrtimer_queue(struct hrtimer_cpu_base *cpu_base, - int index) -{ - struct rb_node *node; - struct hrtimer_clock_base *base = &cpu_base->clock_base[index]; - - if (!base->first) - return; - - if (base->get_softirq_time) - base->softirq_time = base->get_softirq_time(); - - spin_lock(&cpu_base->lock); - - while ((node = base->first)) { - struct hrtimer *timer; - - timer = rb_entry(node, struct hrtimer, node); - if (base->softirq_time.tv64 <= timer->expires.tv64) - break; - - if (timer->cb_mode == HRTIMER_CB_SOFTIRQ) { - __remove_hrtimer(timer, base, HRTIMER_STATE_PENDING, 0); - list_add_tail(&timer->cb_entry, - &base->cpu_base->cb_pending); - continue; - } - - __run_hrtimer(timer); - } - spin_unlock(&cpu_base->lock); -} - void hrtimer_run_queues(void) { + struct rb_node *node; struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases); - int i; + struct hrtimer_clock_base *base; + int index, gettime = 1; if (hrtimer_hres_active()) return; - hrtimer_get_softirq_time(cpu_base); + for (index = 0; index < HRTIMER_MAX_CLOCK_BASES; index++) { + base = &cpu_base->clock_base[index]; - for (i = 0; i < HRTIMER_MAX_CLOCK_BASES; i++) - run_hrtimer_queue(cpu_base, i); + if (!base->first) + continue; + + if (gettime) { + hrtimer_get_softirq_time(cpu_base); + gettime = 0; + } + + if (base->get_softirq_time) + base->softirq_time = base->get_softirq_time(); + + spin_lock(&cpu_base->lock); + + while ((node = base->first)) { + struct hrtimer *timer; + + timer = rb_entry(node, struct hrtimer, node); + if (base->softirq_time.tv64 <= timer->expires.tv64) + break; + + if (timer->cb_mode == HRTIMER_CB_SOFTIRQ) { + __remove_hrtimer(timer, base, + HRTIMER_STATE_PENDING, 0); + list_add_tail(&timer->cb_entry, + &base->cpu_base->cb_pending); + continue; + } + + __run_hrtimer(timer); + } + spin_unlock(&cpu_base->lock); + } } /* From 259aae864ceeb2b34e7bafa1ce18d096a357fab2 Mon Sep 17 00:00:00 2001 From: Thomas Gleixner Date: Sat, 19 Apr 2008 21:31:26 +0200 Subject: [PATCH 4/4] hrtimer: optimize the softirq time optimization The previous optimization did not take the case into account where a clock provides its own softirq_get_time() function. Check for the availablitiy of the clock get time function first and then check if we need to retrieve the time for both clocks via hrtimer_softirq_gettime() to avoid a double evaluation of time in that case as well. Signed-off-by: Thomas Gleixner --- kernel/hrtimer.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c index 70d4adc74639..f78777abe769 100644 --- a/kernel/hrtimer.c +++ b/kernel/hrtimer.c @@ -1254,14 +1254,13 @@ void hrtimer_run_queues(void) if (!base->first) continue; - if (gettime) { + if (base->get_softirq_time) + base->softirq_time = base->get_softirq_time(); + else if (gettime) { hrtimer_get_softirq_time(cpu_base); gettime = 0; } - if (base->get_softirq_time) - base->softirq_time = base->get_softirq_time(); - spin_lock(&cpu_base->lock); while ((node = base->first)) {