Skip to contentSkip to conversation

timers/migration: Clean up the loop in tmigr_quick_check()

PATCH Applied Petr Tesarik 3 participants 3 messages Jun 6, 2025 – Jun 12, 2025 High-resolution timers, timer wheel, clockevents

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 timers/migration: Clean up the loop in tmigr_quick_check()

Make the logic easier to follow:

- Remove the final return statement, which is never reached, and move the actual walk-terminating return statement out of the do-while loop.

- Remove the else-clause to reduce indentation. If a non-lonely group is encountered during the walk, the loop is immediately terminated with a return statement anyway; no need for an else.

---
 kernel/time/timer_migration.c | 23 ++++++++++-------------
 1 file changed, 10 insertions(+), 13 deletions(-)
kernel/time/timer_migration.c +10 -13
index 2f6330831f084..c0c54dc5314c3 100644
@@ -1405,23 +1405,20 @@ u64 tmigr_quick_check(u64 nextevt)
 		return KTIME_MAX;
 
 	do {
-		if (!tmigr_check_lonely(group)) {
+		if (!tmigr_check_lonely(group))
 			return KTIME_MAX;
-		} else {
-			/*
-			 * Since current CPU is active, events may not be sorted
-			 * from bottom to the top because the CPU's event is ignored
-			 * up to the top and its sibling's events not propagated upwards.
-			 * Thus keep track of the lowest observed expiry.
-			 */
-			nextevt = min_t(u64, nextevt, READ_ONCE(group->next_expiry));
-			if (!group->parent)
-				return nextevt;
-		}
+
+		/*
+		 * Since current CPU is active, events may not be sorted
+		 * from bottom to the top because the CPU's event is ignored
+		 * up to the top and its sibling's events not propagated upwards.
+		 * Thus keep track of the lowest observed expiry.
+		 */
+		nextevt = min_t(u64, nextevt, READ_ONCE(group->next_expiry));
 		group = group->parent;
 	} while (group);
 
-	return KTIME_MAX;
+	return nextevt;
 }
 
 /*
Signature · 1 line
2.49.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Petr Tesarik

Make the logic easier to follow:

- Remove the final return statement, which is never reached, and move the actual walk-terminating return statement out of the do-while loop.

- Remove the else-clause to reduce indentation. If a non-lonely group is encountered during the walk, the loop is immediately terminated with a return statement anyway; no need for an else.

Signature · 2 lines
Frederic Weisbecker
SUSE Labs
merge bot Applied
#2 lore raw
In reply to Petr Tesarik
The following commit has been merged into the timers/core branch of tip:

The following commit has been merged into the timers/core branch of tip:

Commit-ID:     ff56a3e2a8613e8524f40ef2efa2c0169659e99e
Gitweb:        https://git.kernel.org/tip/ff56a3e2a8613e8524f40ef2efa2c0169659e99e
Author:        Petr Tesarik <[email protected]>
AuthorDate:    Fri, 06 Jun 2025 14:48:18 +02:00
Committer:     Thomas Gleixner <[email protected]>
CommitterDate: Thu, 12 Jun 2025 21:03:45 +02:00

timers/migration: Clean up the loop in tmigr_quick_check()

Make the logic easier to follow:

- Remove the final return statement, which is never reached, and move the actual walk-terminating return statement out of the do-while loop.

- Remove the else-clause to reduce indentation. If a non-lonely group is encountered during the walk, the loop is immediately terminated with a return statement anyway; no need for an else.

---
 kernel/time/timer_migration.c | 23 ++++++++++-------------
 1 file changed, 10 insertions(+), 13 deletions(-)
kernel/time/timer_migration.c +10 -13
index 2f63308..c0c54dc 100644
@@ -1405,23 +1405,20 @@ u64 tmigr_quick_check(u64 nextevt)
 		return KTIME_MAX;
 
 	do {
-		if (!tmigr_check_lonely(group)) {
+		if (!tmigr_check_lonely(group))
 			return KTIME_MAX;
-		} else {
-			/*
-			 * Since current CPU is active, events may not be sorted
-			 * from bottom to the top because the CPU's event is ignored
-			 * up to the top and its sibling's events not propagated upwards.
-			 * Thus keep track of the lowest observed expiry.
-			 */
-			nextevt = min_t(u64, nextevt, READ_ONCE(group->next_expiry));
-			if (!group->parent)
-				return nextevt;
-		}
+
+		/*
+		 * Since current CPU is active, events may not be sorted
+		 * from bottom to the top because the CPU's event is ignored
+		 * up to the top and its sibling's events not propagated upwards.
+		 * Thus keep track of the lowest observed expiry.
+		 */
+		nextevt = min_t(u64, nextevt, READ_ONCE(group->next_expiry));
 		group = group->parent;
 	} while (group);
 
-	return KTIME_MAX;
+	return nextevt;
 }
 
 /*