Re: [PATCH] sched/core: Use do-while instead of for loop in set_nr_if_polling
From: Uros Bizjak
Date: Tue Apr 04 2023 - 02:04:27 EST
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/20230228161426.4508-1-ubizjak@xxxxxxxxx/
Uros.
On Tue, Feb 28, 2023 at 5:14 PM Uros Bizjak <ubizjak@xxxxxxxxx> wrote:
>
> Use equivalent do-while loop instead of infinite for loop.
>
> There are no asm code changes.
>
> Signed-off-by: Uros Bizjak <ubizjak@xxxxxxxxx>
> Cc: Ingo Molnar <mingo@xxxxxxxxxx>
> Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
> Cc: Juri Lelli <juri.lelli@xxxxxxxxxx>
> Cc: Vincent Guittot <vincent.guittot@xxxxxxxxxx>
> Cc: Dietmar Eggemann <dietmar.eggemann@xxxxxxx>
> Cc: Steven Rostedt <rostedt@xxxxxxxxxxx>
> Cc: Ben Segall <bsegall@xxxxxxxxxx>
> Cc: Mel Gorman <mgorman@xxxxxxx>
> Cc: Daniel Bristot de Oliveira <bristot@xxxxxxxxxx>
> Cc: Christian Brauner <brauner@xxxxxxxxxx>
> ---
> kernel/sched/core.c | 7 +++----
> 1 file changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index af017e038b48..349c018eaf09 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -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
>