* [PATCH] Optimise apply_slack() for faster execution
@ 2011-12-25 21:05 Chinmay V S
[not found] ` <CAK-9PRBFuVQG8cvmry5wtw7d2AM0v+D1eV+YTckox1mS7K6NGw@mail.gmail.com>
0 siblings, 1 reply; 2+ messages in thread
From: Chinmay V S @ 2011-12-25 21:05 UTC (permalink / raw)
To: tglx; +Cc: linux-kernel, Chinmay V S
This patch simplifies the apply_slack() function in the kernel timer
subsystem. This is frequently called in mod_timer()/add_timer() and will
thus improve the performance of both the functions.
The existing logic used an intermediate-mask and a set of bitwise
operations using the mask to round-off the expires_limit variable. This
patch discards the intermediate-mask in favour of direct
shift-operations.
Signed-off-by: Chinmay V S <cvs268@gmail.com>
---
kernel/timer.c | 22 +++++++++-------------
1 files changed, 9 insertions(+), 13 deletions(-)
diff --git a/kernel/timer.c b/kernel/timer.c
index 9c3c62b..3fc1f48 100644
--- a/kernel/timer.c
+++ b/kernel/timer.c
@@ -739,37 +739,33 @@ 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) use this bit to round down maximum time, so that all last bits are 0
*/
static inline
unsigned long apply_slack(struct timer_list *timer, unsigned long expires)
{
- unsigned long expires_limit, mask;
+ unsigned long slack = 0;
int bit;
if (timer->slack >= 0) {
- expires_limit = expires + timer->slack;
+ slack = timer->slack;
} else {
long delta = expires - jiffies;
if (delta < 256)
return expires;
- expires_limit = expires + delta / 256;
+ slack = delta/256;
}
- mask = expires ^ expires_limit;
- if (mask == 0)
- return expires;
- bit = find_last_bit(&mask, BITS_PER_LONG);
+ if (slack == 0)
+ return expires;
- mask = (1 << bit) - 1;
+ bit = find_last_bit(&slack, BITS_PER_LONG);
- expires_limit = expires_limit & ~(mask);
+ expires = (expires >> bit) << bit;
- return expires_limit;
+ return expires;
}
/**
--
1.7.0.4
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] Optimise apply_slack() for faster execution
[not found] ` <CAK-9PRBFuVQG8cvmry5wtw7d2AM0v+D1eV+YTckox1mS7K6NGw@mail.gmail.com>
@ 2011-12-27 11:36 ` Chinmay V S
0 siblings, 0 replies; 2+ messages in thread
From: Chinmay V S @ 2011-12-27 11:36 UTC (permalink / raw)
To: linux-kernel
The patch reduces code complexity by:
- Eliminating the need for intermediate expires_limit and mask variables.
- Simplifying the timer-coalescing logic of discarding lesser significant bits.
This leads to smaller mod_timer() and add_timer() subroutines in which
apply_slack() is inlined. For example, on a typical x86-build, the
patch reduces the size of mod_timer() by 16 instructions.The total
mod_timer() function is 173 instructions i.e. the patch makes the
function 9% smaller. A typical ARM-build also shows similar savings.
original masking-logic:
shl %cl,%edx
sub $0x1,%edx
mov %edx,-0x10(%ebp)
not %edx
and %esi,%edx
mov %edx,-0x14(%ebp)
patched bitwise logic:
shrl %cl,-0x14(%ebp)
shll %cl,-0x14(%ebp)
Enabling function-traces shows us that the mod_timer() and add_timer()
functions are called ~1300 times every minute. Hence optimising these
functions gives us some significant improvement.
regards
ChinmayVS
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2011-12-27 11:37 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-12-25 21:05 [PATCH] Optimise apply_slack() for faster execution Chinmay V S
[not found] ` <CAK-9PRBFuVQG8cvmry5wtw7d2AM0v+D1eV+YTckox1mS7K6NGw@mail.gmail.com>
2011-12-27 11:36 ` Chinmay V S
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome