* [RFC] [PATCH] [timer] Optimise apply_slack() for size and speed.
@ 2012-01-31 9:37 Chinmay V S
2012-02-02 22:59 ` Sebastian Andrzej Siewior
0 siblings, 1 reply; 3+ messages in thread
From: Chinmay V S @ 2012-01-31 9:37 UTC (permalink / raw)
To: linux-kernel; +Cc: cvs268, tglx, sebastian, arjan, jeff.chua.linux, Chinmay V S
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.
Signed-off-by: Chinmay V S <chinmay.v.s@pathpartnertech.com>
---
kernel/timer.c | 8 ++------
1 files changed, 2 insertions(+), 6 deletions(-)
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);
* 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,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;
return expires_limit;
}
--
1.7.5.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [RFC] [PATCH] [timer] Optimise apply_slack() for size and speed.
2012-01-31 9:37 [RFC] [PATCH] [timer] Optimise apply_slack() for size and speed Chinmay V S
@ 2012-02-02 22:59 ` Sebastian Andrzej Siewior
[not found] ` <CAKZbaaTDcfEVPa2JRSnkv_YCiScoTTqpmzaGQGWT98QJpYzZ8A@mail.gmail.com>
0 siblings, 1 reply; 3+ messages in thread
From: Sebastian Andrzej Siewior @ 2012-02-02 22:59 UTC (permalink / raw)
To: Chinmay V S; +Cc: linux-kernel, cvs268, tglx, sebastian, arjan, jeff.chua.linux
* 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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [RFC] [PATCH] [timer] Optimise apply_slack() for size and speed.
[not found] ` <CAKZbaaTDcfEVPa2JRSnkv_YCiScoTTqpmzaGQGWT98QJpYzZ8A@mail.gmail.com>
@ 2012-02-03 14:52 ` Arjan van de Ven
0 siblings, 0 replies; 3+ messages in thread
From: Arjan van de Ven @ 2012-02-03 14:52 UTC (permalink / raw)
To: Chinmay V S
Cc: Sebastian Andrzej Siewior, linux-kernel, cvs268, tglx, jeff.chua.linux
On 2/2/2012 10:31 PM, Chinmay V S wrote:
> Here is the dis-assembly (build for x86) :
>
> Original code snippet :
> mov %eax,%ecx
> mov $0x1,%edx
> shl %cl,%edx
> sub $0x1,%edx
> mov %edx,-0x10(%ebp)
> not %edx
> and %esi,%edx
> mov %edx,-0x14(%ebp)
>
> Patched code snippet :
> mov %eax,%ecx
> shrl %cl,-0x14(%ebp)
> shll %cl,-0x14(%ebp)
>
> As is evident, we are able to reduce 5 instructions by using a bit-shift
> logic (compared to a masking logic).
>
this code is so not performance critical to this level, that we should
optimize for readability, not for the output of a compiler.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-02-03 14:52 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-31 9:37 [RFC] [PATCH] [timer] Optimise apply_slack() for size and speed Chinmay V S
2012-02-02 22:59 ` Sebastian Andrzej Siewior
[not found] ` <CAKZbaaTDcfEVPa2JRSnkv_YCiScoTTqpmzaGQGWT98QJpYzZ8A@mail.gmail.com>
2012-02-03 14:52 ` Arjan van de Ven
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).