Skip to contentSkip to conversation

sched/core: Use do-while instead of for loop in set_nr_if_polling

PATCH Applied Uros Bizjak 2 participants 3 messages Feb 28, 2023 – Sep 15, 2023 Scheduler

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sched/core: Use do-while instead of for loop in set_nr_if_polling

Use equivalent do-while loop instead of infinite for loop.

There are no asm code changes.

Cc Ingo Molnar <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Juri Lelli <[email protected]>
Cc Vincent Guittot <[email protected]>
Cc Dietmar Eggemann <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Ben Segall <[email protected]>
Cc Mel Gorman <[email protected]>
Cc Daniel Bristot de Oliveira <[email protected]>
Cc Christian Brauner <[email protected]>
---
 kernel/sched/core.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
kernel/sched/core.c +3 -4
index af017e038b48..349c018eaf09 100644
@@ -899,14 +899,13 @@ static bool set_nr_if_polling(struct task_struct *p)
 	struct thread_info *ti = task_thread_info(p);
 	typeof(ti->flags) val = READ_ONCE(ti->flags);
 
-	for (;;) {
+	do {
 		if (!(val & _TIF_POLLING_NRFLAG))
 			return false;
 		if (val & _TIF_NEED_RESCHED)
 			return true;
-		if (try_cmpxchg(&ti->flags, &val, val | _TIF_NEED_RESCHED))
-			break;
-	}
+	} while (!try_cmpxchg(&ti->flags, &val, val | _TIF_NEED_RESCHED));
+
 	return true;
 }
 
Signature · 1 line
2.39.2
#1 lore raw

I would like to ping for the patch below. The patch normalizes try_cmpxchg loop to a more readable "while" instead of "for (;;)" loop, otherwise it is a nop.

https://lore.kernel.org/lkml/[email protected]/

Uros.

Quoted 45 lines · Uros Bizjak

Use equivalent do-while loop instead of infinite for loop.

There are no asm code changes.

Cc Ingo Molnar <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Juri Lelli <[email protected]>
Cc Vincent Guittot <[email protected]>
Cc Dietmar Eggemann <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Ben Segall <[email protected]>
Cc Mel Gorman <[email protected]>
Cc Daniel Bristot de Oliveira <[email protected]>
Cc Christian Brauner <[email protected]>
---
 kernel/sched/core.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
kernel/sched/core.c +3 -5
index af017e038b48..349c018eaf09 100644
@@ -899,14 +899,13 @@ static bool set_nr_if_polling(struct task_struct *p)
        struct thread_info *ti = task_thread_info(p);
        typeof(ti->flags) val = READ_ONCE(ti->flags);
 
-       for (;;) {
+       do {
                if (!(val & _TIF_POLLING_NRFLAG))
                        return false;
                if (val & _TIF_NEED_RESCHED)
                        return true;
-               if (try_cmpxchg(&ti->flags, &val, val | _TIF_NEED_RESCHED))
-                       break;
-       }
+       } while (!try_cmpxchg(&ti->flags, &val, val | _TIF_NEED_RESCHED));
+
        return true;
 }
 
--

2.39.2

merge bot Applied
#2 lore raw

[tip: sched/core] sched/core: Use do-while instead of for loop in set_nr_if_polling()

In reply to Uros Bizjak
The following commit has been merged into the sched/core branch of tip:

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

Commit-ID:     4ff34ad3d39377d9f6953f3606ccf611ce636767
Gitweb:        https://git.kernel.org/tip/4ff34ad3d39377d9f6953f3606ccf611ce636767
Author:        Uros Bizjak <[email protected]>
AuthorDate:    Tue, 28 Feb 2023 17:14:26 +01:00
Committer:     Ingo Molnar <[email protected]>
CommitterDate: Fri, 15 Sep 2023 17:18:02 +02:00

sched/core: Use do-while instead of for loop in set_nr_if_polling()

Use equivalent do-while loop instead of infinite for loop.

There are no asm code changes.

---
 kernel/sched/core.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
kernel/sched/core.c +3 -4
index 76662d8..f39482d 100644
@@ -919,14 +919,13 @@ static bool set_nr_if_polling(struct task_struct *p)
 	struct thread_info *ti = task_thread_info(p);
 	typeof(ti->flags) val = READ_ONCE(ti->flags);
 
-	for (;;) {
+	do {
 		if (!(val & _TIF_POLLING_NRFLAG))
 			return false;
 		if (val & _TIF_NEED_RESCHED)
 			return true;
-		if (try_cmpxchg(&ti->flags, &val, val | _TIF_NEED_RESCHED))
-			break;
-	}
+	} while (!try_cmpxchg(&ti->flags, &val, val | _TIF_NEED_RESCHED));
+
 	return true;
 }