Skip to contentSkip to conversation

Optimise apply_slack() for size and speed.

PATCH In review Chinmay V S 2 participants 2 messages Feb 3, 2012 – Feb 5, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Optimise apply_slack() for size and speed.

Updated the patch for improved readability.
How about the following patch?

To apply proper slack, the original algorithm used to prepare a mask and then apply the mask to obtain the appropriately rounded-off absolute time the timer expires.

This patch modifies the masking logic to a bit-shift logic, therby reducing the complexity and number of operations. Thus obtaining a minor speed-up.

---
 kernel/timer.c |    9 +++------
 1 files changed, 3 insertions(+), 6 deletions(-)
kernel/timer.c +3 -6
index a297ffc..eb4b708 100644
@@ -785,9 +785,7 @@ EXPORT_SYMBOL(mod_timer_pending);
  * Algorithm:
  *   1) calculate the maximum (absolute) time
  *   2) calculate the highest bit where the expires and new max are different
- *   3) use this bit to make a mask
- *   4) use the bitmask to round down the maximum time, so that all last
- *      bits are zeros
+ *   3) round down the maximum time, so that all the lower bits are zeros
  */
 static inline
 unsigned long apply_slack(struct timer_list *timer, unsigned long expires)
@@ -811,9 +809,8 @@ unsigned long apply_slack(struct timer_list *timer, unsigned long expires)
 
 	bit = find_last_bit(&mask, BITS_PER_LONG);
 
-	mask = (1 << bit) - 1;
-
-	expires_limit = expires_limit & ~(mask);
+	/* Round down by zero-ing the lower bits */
+	expires_limit = (expires_limit >> bit) << bit;
 
 	return expires_limit;
 }
Signature · 1 line
1.7.5.4
#1 lore raw
Quoted 1 line · * Chinmay V S | 2012-02-03 21:30:50 [+0530]:

Updated the patch for improved readability.

Arjan's point was that this is not critical for performance and as such it does not need an improvement.

Quoted 1 line

How about the following patch?

I guess this will be left as is.

Sebastian