Skip to contentSkip to conversation

timers/migration: remove an unneeded call to find_first_bit()

PATCH In review Petr Tesarik 1 participant 2 messages May 30, 2025 – Jun 6, 2025 High-resolution timers, timer wheel, clockevents

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 timers/migration: remove an unneeded call to find_first_bit()

Use simple bit arithmetic to extract the least significant bit from the active bitmask, because the bit position is not needed, only the bit itself.

No functional change.

---
 kernel/time/timer_migration.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
kernel/time/timer_migration.c +4 -4
index 2f6330831f08..0f40727b6cac 100644
@@ -1277,12 +1277,12 @@ static bool tmigr_inactive_up(struct tmigr_group *group,
 			 * group is idle!
 			 */
 			if (!childstate.active) {
-				unsigned long new_migr_bit, active = newstate.active;
+				u8 active = newstate.active;
 
-				new_migr_bit = find_first_bit(&active, BIT_CNT);
+				if (active) {
+					u8 lsbit = active & -active;
 
-				if (new_migr_bit != BIT_CNT) {
-					newstate.migrator = BIT(new_migr_bit);
+					newstate.migrator = lsbit;
 				} else {
 					newstate.migrator = TMIGR_NONE;
 
Signature · 1 line
2.49.0
#1 lore raw
Quoted 3 lines · On Fri, 30 May 2025 15:25:39 +0200 Petr Tesarik <[email protected]> wrote:

Use simple bit arithmetic to extract the least significant bit from the active bitmask, because the bit position is not needed, only the bit itself.

There has been no reply here, but I received an out-of-band recommendation to wrap this bit-twiddling trick in a macro.

So, you can ignore this patch for now and wait for a respin after I add the macro and convert pre-existing uses in the kernel.

Petr T

Quoted 28 lines

No functional change.

---
 kernel/time/timer_migration.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
kernel/time/timer_migration.c +4 -4
index 2f6330831f08..0f40727b6cac 100644
@@ -1277,12 +1277,12 @@ static bool tmigr_inactive_up(struct tmigr_group *group,
 			 * group is idle!
 			 */
 			if (!childstate.active) {
-				unsigned long new_migr_bit, active = newstate.active;
+				u8 active = newstate.active;
 
-				new_migr_bit = find_first_bit(&active, BIT_CNT);
+				if (active) {
+					u8 lsbit = active & -active;
 
-				if (new_migr_bit != BIT_CNT) {
-					newstate.migrator = BIT(new_migr_bit);
+					newstate.migrator = lsbit;
 				} else {
 					newstate.migrator = TMIGR_NONE;