Skip to contentSkip to conversation

timer: optimize apply_slack()

PATCH In review Felix Fietkau 2 participants 2 messages Mar 17, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 timer: optimize apply_slack()

__fls(mask) is equivalent to find_last_bit(&mask, BITS_PER_LONG), but cheaper. find_last_bit was showing up high on the list when I was profiling for stalls on icache misses on a system with very small cache size (MIPS).

---
 kernel/timer.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
kernel/timer.c +1 -1
index a297ffc..659371e 100644
@@ -809,7 +809,7 @@ unsigned long apply_slack(struct timer_list *timer, unsigned long expires)
 	if (mask == 0)
 		return expires;
 
-	bit = find_last_bit(&mask, BITS_PER_LONG);
+	bit = __fls(mask);
 
 	mask = (1 << bit) - 1;
 
Signature · 1 line
1.7.3.2
#1 lore raw
Quoted 14 lines · Felix Fietkau

__fls(mask) is equivalent to find_last_bit(&mask, BITS_PER_LONG), but cheaper. find_last_bit was showing up high on the list when I was profiling for stalls on icache misses on a system with very small cache size (MIPS).

---
 kernel/timer.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
kernel/timer.c +0 -0
index a297ffc..659371e 100644

kernel/timer.c unsigned long apply_slack(struct timer_list *timer, unsigned long expires) · line 815

Quoted 8 lines
kernel/timer.c +1 -1
@@ -809,7 +809,7 @@ unsigned long apply_slack(struct timer_list *timer, unsigned long expires)
 	if (mask == 0)
 		return expires;
 
-	bit = find_last_bit(&mask, BITS_PER_LONG);
+	bit = __fls(mask);
 
 	mask = (1 << bit) - 1;
 

Not a comment on your patch, but this code seems not correct.

This probably should be :

	mask = (1UL << bit) - 1;