Skip to contentSkip to conversation

reduce false TIMER_SOFTIRQ calls

PATCH New Oleg Nesterov 1 participant 1 message Nov 16, 2004 High-resolution timers, timer wheel, clockevents

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 reduce false TIMER_SOFTIRQ calls

Hello.

smp_local_timer_interrupt() calls run_local_timers() which triggers TIMER_SOFTIRQ unconditionally.

The handler, run_timer_softirq(), does:

	if (time_after_eq(jiffies, base->timer_jiffies))
		__run_timers(base);

This time_after_eq() is useless, base->timer_jiffies == jifiies almost allways.

So every local timer interrupt implies do_softirq()->__run_timers().

This patch adds tvec_base_t->timer_expires, which is used as estimation for the "nearest" pending timer. It is calculated in __run_timers(), by scanning next 64 entries in tvec_base_t->tv1.

So, if we have single pending timer which constantly readds itself after invocation with expires = jiffies + 1, we lost up to 64 (average 56) loop iterations (scanning tvec_base_t->tv1) per jiffie. But if expires = jiffies + 2, we have 28 iterations per jiffie, and only 50% of interrupts trigger TIMER_SOFTIRQ.

I have collected some stat during kernel compilation:

0.0282  TIMER_SOFTIRQ's per jiffie
1.0880  loop iterations (timer_expires calculation) per jiffie
0.0570  do_softirq() calls from smp_apic_timer_interrupt()

but there is no noticeable time difference.

Simple benchmark, counts gettimeofday() per second, 3 runs.

Clean kernel:
2810548.9333 // gettimeofday()s per second
1m0.002s 0m8.761s 0m51.243s // real, user, sys
2811569.0833
1m0.003s 0m8.875s 0m51.130s
2810842.0333
1m0.002s 0m9.073s 0m50.931s

Patched:
2812897.6667 // gettimeofday()s per second
1m0.002s 0m10.920s 0m49.090s // real, user, sys
2812929.4667
1m0.002s 0m11.074s 0m48.938s
2812905.9000
1m0.002s 0m11.092s 0m48.919s

Again, slightly faster, but far below 1%.

Code bloat: 68 bytes (gcc 2.95.3).

Oleg.

include/linux/timer.h renamed from include/linux/timer.h~ +0 -1
@@ -96,7 +96,6 @@ static inline void add_timer(struct time
 #endif
 
 extern void init_timers(void);
-extern void run_local_timers(void);
 extern void it_real_fn(unsigned long);
 
 #endif
kernel/timer.c renamed from kernel/timer.c~ +41 -24

131 lines not on this page · raw message