Re: [RFC] [PATCH] [timer] Optimise apply_slack() for size and speed.

From: Sebastian Andrzej Siewior
Date: Thu Feb 02 2012 - 18:25:18 EST


* Chinmay V S | 2012-01-31 15:07:32 [+0530]:

>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.
>diff --git a/kernel/timer.c b/kernel/timer.c
>index a297ffc..0379658 100644
>--- a/kernel/timer.c
>+++ b/kernel/timer.c
>@@ -785,9 +785,7 @@ EXPORT_SYMBOL(mod_timer_pending);
>@@ -811,9 +809,7 @@ 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);
>+ expires_limit = (expires_limit >> bit) << bit;

The question is whether a shift left is more efficient compared to an
and operation. Besides that you save atleast one operation because you
don't need to load -1 into a register for creating a mask. So it looks
like less code.

Sebastian
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/