From: Peter Zijlstra <peterz@infradead.org>
To: Ankur Arora <ankur.a.arora@oracle.com>
Cc: linux-kernel@vger.kernel.org, tglx@linutronix.de,
torvalds@linux-foundation.org, paulmck@kernel.org,
rostedt@goodmis.org, mark.rutland@arm.com, juri.lelli@redhat.com,
joel@joelfernandes.org, raghavendra.kt@amd.com,
sshegde@linux.ibm.com, boris.ostrovsky@oracle.com,
konrad.wilk@oracle.com, Ingo Molnar <mingo@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>
Subject: Re: [PATCH v2 07/35] sched: define *_tsk_need_resched_lazy() helpers
Date: Tue, 28 May 2024 18:09:05 +0200 [thread overview]
Message-ID: <20240528160905.GC26599@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <20240528003521.979836-8-ankur.a.arora@oracle.com>
On Mon, May 27, 2024 at 05:34:53PM -0700, Ankur Arora wrote:
> Define __{set,test}_tsk_need_resched() to test for the immediacy of the
> need-resched.
>
> The current helpers, {set,test}_tsk_need_resched(...) stay the same.
>
> In scheduler code, switch to the more explicit variants,
> __set_tsk_need_resched(...), __test_tsk_need_resched(...).
>
> Note that clear_tsk_need_resched() is only used from __schedule()
> to clear the flags before switching context. Now it clears all the
> need-resched flags.
>
> Cc: Peter Ziljstra <peterz@infradead.org>
> Cc: Ingo Molnar <mingo@redhat.com>
> Cc: Juri Lelli <juri.lelli@redhat.com>
> Cc: Vincent Guittot <vincent.guittot@linaro.org>
> Cc: Paul E. McKenney <paulmck@kernel.org>
> Originally-by: Thomas Gleixner <tglx@linutronix.de>
> Link: https://lore.kernel.org/lkml/87jzshhexi.ffs@tglx/
> Signed-off-by: Ankur Arora <ankur.a.arora@oracle.com>
> ---
> include/linux/sched.h | 45 +++++++++++++++++++++++++++++++++++++----
> kernel/sched/core.c | 9 +++++----
> kernel/sched/deadline.c | 4 ++--
> kernel/sched/fair.c | 2 +-
> kernel/sched/rt.c | 4 ++--
> 5 files changed, 51 insertions(+), 13 deletions(-)
>
> diff --git a/include/linux/sched.h b/include/linux/sched.h
> index 37a51115b691..804a76e6f3c5 100644
> --- a/include/linux/sched.h
> +++ b/include/linux/sched.h
> @@ -1952,19 +1952,56 @@ static inline bool test_tsk_thread_flag(struct task_struct *tsk, int flag)
> return test_ti_thread_flag(task_thread_info(tsk), flag);
> }
>
> -static inline void set_tsk_need_resched(struct task_struct *tsk)
> +/*
> + * With !CONFIG_PREEMPT_AUTO, tif_resched(RESCHED_LAZY) reduces to
> + * tif_resched(RESCHED_NOW). Add a check in the helpers below to ensure
> + * we don't touch the tif_reshed(RESCHED_NOW) bit unnecessarily.
> + */
> +static inline void __set_tsk_need_resched(struct task_struct *tsk, resched_t rs)
> {
> - set_tsk_thread_flag(tsk,TIF_NEED_RESCHED);
> + if (IS_ENABLED(CONFIG_PREEMPT_AUTO) || rs == RESCHED_NOW)
> + set_tsk_thread_flag(tsk, tif_resched(rs));
> + else
> + /*
> + * RESCHED_LAZY is only touched under CONFIG_PREEMPT_AUTO.
> + */
> + BUG();
> }
This straight up violates coding style and would require a dose of {}.
if (!IS_ENABLED(CONFIG_PREEMPT_AUTO && rs == RESCHED_LAZY)
BUG();
set_tsk_thread_flag(tsk, tif_resched(rs));
seems much saner to me.
> static inline void clear_tsk_need_resched(struct task_struct *tsk)
> {
> - clear_tsk_thread_flag(tsk,TIF_NEED_RESCHED);
> + clear_tsk_thread_flag(tsk, tif_resched(RESCHED_NOW));
> +
> + if (IS_ENABLED(CONFIG_PREEMPT_AUTO))
> + clear_tsk_thread_flag(tsk, tif_resched(RESCHED_LAZY));
> +}
> +
> +static inline bool __test_tsk_need_resched(struct task_struct *tsk, resched_t rs)
> +{
> + if (IS_ENABLED(CONFIG_PREEMPT_AUTO) || rs == RESCHED_NOW)
> + return unlikely(test_tsk_thread_flag(tsk, tif_resched(rs)));
> + else
> + return false;
> }
if (!IS_ENABLED(CONFIG_PREEMPT_AUTO) && rs == RESCHED_LAZY)
return false;
return unlikely(test_tsk_thread_flag(tsk, tif_resched(rs)));
>
> static inline bool test_tsk_need_resched(struct task_struct *tsk)
> {
> - return unlikely(test_tsk_thread_flag(tsk,TIF_NEED_RESCHED));
> + return __test_tsk_need_resched(tsk, RESCHED_NOW);
> +}
> +
> +static inline bool test_tsk_need_resched_lazy(struct task_struct *tsk)
> +{
> + return __test_tsk_need_resched(tsk, RESCHED_LAZY);
> +}
> +
> +static inline void set_tsk_need_resched(struct task_struct *tsk)
> +{
> + return __set_tsk_need_resched(tsk, RESCHED_NOW);
> +}
> +
> +static inline void set_tsk_need_resched_lazy(struct task_struct *tsk)
> +{
> + return __set_tsk_need_resched(tsk, RESCHED_LAZY);
> }
>
> /*
So far so good, however:
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index 7019a40457a6..d00d7b45303e 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -933,7 +933,7 @@ static bool set_nr_if_polling(struct task_struct *p)
> #else
> static inline bool set_nr_and_not_polling(struct task_struct *p)
> {
> - set_tsk_need_resched(p);
> + __set_tsk_need_resched(p, RESCHED_NOW);
> return true;
> }
>
> @@ -1045,13 +1045,13 @@ void resched_curr(struct rq *rq)
>
> lockdep_assert_rq_held(rq);
>
> - if (test_tsk_need_resched(curr))
> + if (__test_tsk_need_resched(curr, RESCHED_NOW))
> return;
>
> cpu = cpu_of(rq);
>
> if (cpu == smp_processor_id()) {
> - set_tsk_need_resched(curr);
> + __set_tsk_need_resched(curr, RESCHED_NOW);
> set_preempt_need_resched();
> return;
> }
> @@ -2245,7 +2245,8 @@ void wakeup_preempt(struct rq *rq, struct task_struct *p, int flags)
> * A queue event has occurred, and we're going to schedule. In
> * this case, we can save a useless back to back clock update.
> */
> - if (task_on_rq_queued(rq->curr) && test_tsk_need_resched(rq->curr))
> + if (task_on_rq_queued(rq->curr) &&
> + __test_tsk_need_resched(rq->curr, RESCHED_NOW))
> rq_clock_skip_update(rq);
> }
>
> diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
> index a04a436af8cc..d24d6bfee293 100644
> --- a/kernel/sched/deadline.c
> +++ b/kernel/sched/deadline.c
> @@ -2035,7 +2035,7 @@ static void wakeup_preempt_dl(struct rq *rq, struct task_struct *p,
> * let us try to decide what's the best thing to do...
> */
> if ((p->dl.deadline == rq->curr->dl.deadline) &&
> - !test_tsk_need_resched(rq->curr))
> + !__test_tsk_need_resched(rq->curr, RESCHED_NOW))
> check_preempt_equal_dl(rq, p);
> #endif /* CONFIG_SMP */
> }
> @@ -2564,7 +2564,7 @@ static void pull_dl_task(struct rq *this_rq)
> static void task_woken_dl(struct rq *rq, struct task_struct *p)
> {
> if (!task_on_cpu(rq, p) &&
> - !test_tsk_need_resched(rq->curr) &&
> + !__test_tsk_need_resched(rq->curr, RESCHED_NOW) &&
> p->nr_cpus_allowed > 1 &&
> dl_task(rq->curr) &&
> (rq->curr->nr_cpus_allowed < 2 ||
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index c62805dbd608..c5171c247466 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -8316,7 +8316,7 @@ static void check_preempt_wakeup_fair(struct rq *rq, struct task_struct *p, int
> * prevents us from potentially nominating it as a false LAST_BUDDY
> * below.
> */
> - if (test_tsk_need_resched(curr))
> + if (__test_tsk_need_resched(curr, RESCHED_NOW))
> return;
>
> /* Idle tasks are by definition preempted by non-idle tasks. */
> diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c
> index 3261b067b67e..f0a6c9bb890b 100644
> --- a/kernel/sched/rt.c
> +++ b/kernel/sched/rt.c
> @@ -1680,7 +1680,7 @@ static void wakeup_preempt_rt(struct rq *rq, struct task_struct *p, int flags)
> * to move current somewhere else, making room for our non-migratable
> * task.
> */
> - if (p->prio == rq->curr->prio && !test_tsk_need_resched(rq->curr))
> + if (p->prio == rq->curr->prio && !__test_tsk_need_resched(rq->curr, RESCHED_NOW))
> check_preempt_equal_prio(rq, p);
> #endif
> }
> @@ -2415,7 +2415,7 @@ static void pull_rt_task(struct rq *this_rq)
> static void task_woken_rt(struct rq *rq, struct task_struct *p)
> {
> bool need_to_push = !task_on_cpu(rq, p) &&
> - !test_tsk_need_resched(rq->curr) &&
> + !__test_tsk_need_resched(rq->curr, RESCHED_NOW) &&
> p->nr_cpus_allowed > 1 &&
> (dl_task(rq->curr) || rt_task(rq->curr)) &&
> (rq->curr->nr_cpus_allowed < 2 ||
These are all NO-OPs.... Changelog says:
> In scheduler code, switch to the more explicit variants,
> __set_tsk_need_resched(...), __test_tsk_need_resched(...).
But leaves me wondering *WHY* ?!?
I can't help but feel this patch attempts to do 2 things and fails to
justify at least one of them.
next prev parent reply other threads:[~2024-05-28 16:09 UTC|newest]
Thread overview: 95+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-28 0:34 [PATCH v2 00/35] PREEMPT_AUTO: support lazy rescheduling Ankur Arora
2024-05-28 0:34 ` [PATCH v2 01/35] sched/core: Move preempt_model_*() helpers from sched.h to preempt.h Ankur Arora
2024-06-06 17:45 ` [tip: sched/core] " tip-bot2 for Sean Christopherson
2024-05-28 0:34 ` [PATCH v2 02/35] sched/core: Drop spinlocks on contention iff kernel is preemptible Ankur Arora
2024-05-28 0:34 ` [PATCH v2 03/35] sched: make test_*_tsk_thread_flag() return bool Ankur Arora
2024-05-28 0:34 ` [PATCH v2 04/35] preempt: introduce CONFIG_PREEMPT_AUTO Ankur Arora
2024-06-03 15:04 ` Shrikanth Hegde
2024-06-04 17:52 ` Ankur Arora
2024-05-28 0:34 ` [PATCH v2 05/35] thread_info: selector for TIF_NEED_RESCHED[_LAZY] Ankur Arora
2024-05-28 15:55 ` Peter Zijlstra
2024-05-30 9:07 ` Ankur Arora
2024-05-28 0:34 ` [PATCH v2 06/35] thread_info: define __tif_need_resched(resched_t) Ankur Arora
2024-05-28 16:03 ` Peter Zijlstra
2024-05-28 0:34 ` [PATCH v2 07/35] sched: define *_tsk_need_resched_lazy() helpers Ankur Arora
2024-05-28 16:09 ` Peter Zijlstra [this message]
2024-05-30 9:02 ` Ankur Arora
2024-05-29 8:25 ` Peter Zijlstra
2024-05-30 9:08 ` Ankur Arora
2024-05-28 0:34 ` [PATCH v2 08/35] entry: handle lazy rescheduling at user-exit Ankur Arora
2024-05-28 16:12 ` Peter Zijlstra
2024-05-28 0:34 ` [PATCH v2 09/35] entry/kvm: handle lazy rescheduling at guest-entry Ankur Arora
2024-05-28 16:13 ` Peter Zijlstra
2024-05-30 9:04 ` Ankur Arora
2024-05-28 0:34 ` [PATCH v2 10/35] entry: irqentry_exit only preempts for TIF_NEED_RESCHED Ankur Arora
2024-05-28 16:18 ` Peter Zijlstra
2024-05-30 9:03 ` Ankur Arora
2024-05-28 0:34 ` [PATCH v2 11/35] sched: __schedule_loop() doesn't need to check for need_resched_lazy() Ankur Arora
2024-05-28 0:34 ` [PATCH v2 12/35] sched: separate PREEMPT_DYNAMIC config logic Ankur Arora
2024-05-28 16:25 ` Peter Zijlstra
2024-05-30 9:30 ` Ankur Arora
2024-05-28 0:34 ` [PATCH v2 13/35] sched: allow runtime config for PREEMPT_AUTO Ankur Arora
2024-05-28 16:27 ` Peter Zijlstra
2024-05-30 9:29 ` Ankur Arora
2024-06-06 11:51 ` Peter Zijlstra
2024-06-06 15:11 ` Ankur Arora
2024-06-06 17:32 ` Peter Zijlstra
2024-06-09 0:46 ` Ankur Arora
2024-06-12 18:10 ` Paul E. McKenney
2024-05-28 0:35 ` [PATCH v2 14/35] rcu: limit PREEMPT_RCU to full preemption under PREEMPT_AUTO Ankur Arora
2024-05-28 0:35 ` [PATCH v2 15/35] rcu: fix header guard for rcu_all_qs() Ankur Arora
2024-05-28 0:35 ` [PATCH v2 16/35] preempt,rcu: warn on PREEMPT_RCU=n, preempt=full Ankur Arora
2024-05-29 8:14 ` Peter Zijlstra
2024-05-30 18:32 ` Paul E. McKenney
2024-05-30 23:05 ` Ankur Arora
2024-05-30 23:15 ` Paul E. McKenney
2024-05-30 23:04 ` Ankur Arora
2024-05-30 23:20 ` Paul E. McKenney
2024-06-06 11:53 ` Peter Zijlstra
2024-06-06 13:38 ` Paul E. McKenney
2024-06-17 15:54 ` Paul E. McKenney
2024-06-18 16:29 ` Paul E. McKenney
2024-05-28 0:35 ` [PATCH v2 17/35] rcu: handle quiescent states for PREEMPT_RCU=n, PREEMPT_COUNT=y Ankur Arora
2024-05-28 0:35 ` [PATCH v2 18/35] rcu: force context-switch " Ankur Arora
2024-05-28 0:35 ` [PATCH v2 19/35] x86/thread_info: define TIF_NEED_RESCHED_LAZY Ankur Arora
2024-05-28 0:35 ` [PATCH v2 20/35] powerpc: add support for PREEMPT_AUTO Ankur Arora
2024-05-28 0:35 ` [PATCH v2 21/35] sched: prepare for lazy rescheduling in resched_curr() Ankur Arora
2024-05-29 9:32 ` Peter Zijlstra
2024-05-28 0:35 ` [PATCH v2 22/35] sched: default preemption policy for PREEMPT_AUTO Ankur Arora
2024-05-28 0:35 ` [PATCH v2 23/35] sched: handle idle preemption " Ankur Arora
2024-05-28 0:35 ` [PATCH v2 24/35] sched: schedule eagerly in resched_cpu() Ankur Arora
2024-05-28 0:35 ` [PATCH v2 25/35] sched/fair: refactor update_curr(), entity_tick() Ankur Arora
2024-05-28 0:35 ` [PATCH v2 26/35] sched/fair: handle tick expiry under lazy preemption Ankur Arora
2024-05-28 0:35 ` [PATCH v2 27/35] sched: support preempt=none under PREEMPT_AUTO Ankur Arora
2024-05-28 0:35 ` [PATCH v2 28/35] sched: support preempt=full " Ankur Arora
2024-05-28 0:35 ` [PATCH v2 29/35] sched: handle preempt=voluntary " Ankur Arora
2024-06-17 3:20 ` Tianchen Ding
2024-06-21 18:58 ` Ankur Arora
2024-06-24 2:35 ` Tianchen Ding
2024-06-25 1:12 ` Ankur Arora
2024-06-26 2:43 ` Tianchen Ding
2024-05-28 0:35 ` [PATCH v2 30/35] sched: latency warn for TIF_NEED_RESCHED_LAZY Ankur Arora
2024-05-28 0:35 ` [PATCH v2 31/35] tracing: support lazy resched Ankur Arora
2024-05-28 0:35 ` [PATCH v2 32/35] Documentation: tracing: add TIF_NEED_RESCHED_LAZY Ankur Arora
2024-05-28 0:35 ` [PATCH v2 33/35] osnoise: handle quiescent states for PREEMPT_RCU=n, PREEMPTION=y Ankur Arora
2024-05-28 13:12 ` Daniel Bristot de Oliveira
2024-05-28 0:35 ` [PATCH v2 34/35] kconfig: decompose ARCH_NO_PREEMPT Ankur Arora
2024-05-28 0:35 ` [PATCH v2 35/35] arch: " Ankur Arora
2024-05-29 6:16 ` [PATCH v2 00/35] PREEMPT_AUTO: support lazy rescheduling Shrikanth Hegde
2024-06-01 11:47 ` Ankur Arora
2024-06-04 7:32 ` Shrikanth Hegde
2024-06-07 16:48 ` Shrikanth Hegde
2024-06-10 7:23 ` Ankur Arora
2024-06-15 15:04 ` Shrikanth Hegde
2024-06-18 18:27 ` Shrikanth Hegde
2024-06-19 2:40 ` Ankur Arora
2024-06-24 18:37 ` Shrikanth Hegde
2024-06-27 2:50 ` Ankur Arora
2024-06-27 5:56 ` Michael Ellerman
2024-06-27 15:44 ` Shrikanth Hegde
2024-07-03 5:27 ` Ankur Arora
2024-08-12 17:32 ` Shrikanth Hegde
2024-08-12 21:07 ` Linus Torvalds
2024-08-13 5:40 ` Ankur Arora
2024-06-05 15:44 ` Sean Christopherson
2024-06-05 17:45 ` Peter Zijlstra
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240528160905.GC26599@noisy.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=ankur.a.arora@oracle.com \
--cc=boris.ostrovsky@oracle.com \
--cc=joel@joelfernandes.org \
--cc=juri.lelli@redhat.com \
--cc=konrad.wilk@oracle.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=paulmck@kernel.org \
--cc=raghavendra.kt@amd.com \
--cc=rostedt@goodmis.org \
--cc=sshegde@linux.ibm.com \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
--cc=vincent.guittot@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox