Skip to contentSkip to conversation

kernel: time: timer.c: use __fls in apply_slack()

PATCH New Rasmus Villemoes 2 participants 3 messages Oct 2, 2015 – Oct 11, 2015 High-resolution timers, timer wheel, clockevents

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kernel: time: timer.c: use __fls in apply_slack()

In apply_slack(), find_last_bit() is applied to a bitmask consisting of precisely BITS_PER_LONG bits. Since mask is non-zero, we might as well eliminate the function call and use __fls() directly. On x86_64, this shaves 23 bytes of the only caller, mod_timer().

This also gets rid of Coverity CID 1192106, but that is a false
positive: Coverity is not aware that mask != 0 implies that find_last_bit will not return BITS_PER_LONG.

---
 kernel/time/timer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/time/timer.c +1 -1
index 84190f02b521..71eb089d1030 100644
@@ -867,7 +867,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 = (1UL << bit) - 1;
 
Signature · 1 line
2.1.3
#1 lore raw

[tip:timers/core] timers: Use __fls in apply_slack()

timers: Use __fls in apply_slack()
Commit-ID:  3e17510cbc3e75cae0c96fa38ca469ffe754aedf
Gitweb:     http://git.kernel.org/tip/3e17510cbc3e75cae0c96fa38ca469ffe754aedf
Author:     Rasmus Villemoes <[email protected]>
AuthorDate: Fri, 2 Oct 2015 09:45:30 +0200
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Sun, 11 Oct 2015 22:07:23 +0200

timers: Use __fls in apply_slack()

In apply_slack(), find_last_bit() is applied to a bitmask consisting of precisely BITS_PER_LONG bits. Since mask is non-zero, we might as well eliminate the function call and use __fls() directly. On x86_64, this shaves 23 bytes of the only caller, mod_timer().

This also gets rid of Coverity CID 1192106, but that is a false
positive: Coverity is not aware that mask != 0 implies that find_last_bit will not return BITS_PER_LONG.

---
 kernel/time/timer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/time/timer.c +1 -1
index d3f5e92..74591ba 100644
@@ -874,7 +874,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 = (1UL << bit) - 1;
 
#2 lore raw

[tip:timers/core] timers: Use __fls in apply_slack()

In reply to Rasmus Villemoes
timers: Use __fls in apply_slack()
Commit-ID:  9fc4468d546b6eb55b0aa5b04b0c36238ebf57e7
Gitweb:     http://git.kernel.org/tip/9fc4468d546b6eb55b0aa5b04b0c36238ebf57e7
Author:     Rasmus Villemoes <[email protected]>
AuthorDate: Fri, 2 Oct 2015 09:45:30 +0200
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Sun, 11 Oct 2015 22:13:46 +0200

timers: Use __fls in apply_slack()

In apply_slack(), find_last_bit() is applied to a bitmask consisting of precisely BITS_PER_LONG bits. Since mask is non-zero, we might as well eliminate the function call and use __fls() directly. On x86_64, this shaves 23 bytes of the only caller, mod_timer().

This also gets rid of Coverity CID 1192106, but that is a false
positive: Coverity is not aware that mask != 0 implies that find_last_bit will not return BITS_PER_LONG.

---
 kernel/time/timer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/time/timer.c +1 -1
index d3f5e92..74591ba 100644
@@ -874,7 +874,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 = (1UL << bit) - 1;