From: "Ville Syrjälä" <ville.syrjala@linux.intel.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
bigeasy@linutronix.de, rjw@rjwysocki.net, oleg@redhat.com,
rostedt@goodmis.org, mingo@kernel.org, mgorman@suse.de,
intel-gfx@lists.freedesktop.org, tj@kernel.org,
Will Deacon <will@kernel.org>,
dietmar.eggemann@arm.com, ebiederm@xmission.com
Subject: Re: [Intel-gfx] [PATCH v3 6/6] freezer, sched: Rewrite core freezer logic
Date: Mon, 7 Nov 2022 13:47:23 +0200 [thread overview]
Message-ID: <Y2jwSwfRC3Q5x7Rm@intel.com> (raw)
In-Reply-To: <Y2LsUIfbUiy2Ar0r@hirez.programming.kicks-ass.net>
On Wed, Nov 02, 2022 at 11:16:48PM +0100, Peter Zijlstra wrote:
> On Wed, Nov 02, 2022 at 06:57:51PM +0200, Ville Syrjälä wrote:
> > On Thu, Oct 27, 2022 at 06:53:23PM +0200, Peter Zijlstra wrote:
> > > On Thu, Oct 27, 2022 at 04:09:01PM +0300, Ville Syrjälä wrote:
> > > > On Wed, Oct 26, 2022 at 01:43:00PM +0200, Peter Zijlstra wrote:
> > >
> > > > > Could you please give the below a spin?
> > > >
> > > > Thanks. I've added this to our CI branch. I'll try to keep and eye
> > > > on it in the coming days and let you know if anything still trips.
> > > > And I'll report back maybe ~middle of next week if we haven't caught
> > > > anything by then.
> > >
> > > Thanks!
> >
> > Looks like we haven't caught anything since I put the patch in.
> > So the fix seems good.
>
> While writing up the Changelog, it occured to me it might be possible to
> fix another way, could I bother you to also run the below patch for a
> bit?
I swapped in the new patch to the CI branch. I'll check back
after a few days.
>
> ---
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index cb2aa2b54c7a..daff72f00385 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -4200,6 +4200,40 @@ try_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags)
> return success;
> }
>
> +static bool __task_needs_rq_lock(struct task_struct *p)
> +{
> + unsigned int state = READ_ONCE(p->__state);
> +
> + /*
> + * Since pi->lock blocks try_to_wake_up(), we don't need rq->lock when
> + * the task is blocked. Make sure to check @state since ttwu() can drop
> + * locks at the end, see ttwu_queue_wakelist().
> + */
> + if (state == TASK_RUNNING || state == TASK_WAKING)
> + return true;
> +
> + /*
> + * Ensure we load p->on_rq after p->__state, otherwise it would be
> + * possible to, falsely, observe p->on_rq == 0.
> + *
> + * See try_to_wake_up() for a longer comment.
> + */
> + smp_rmb();
> + if (p->on_rq)
> + return true;
> +
> +#ifdef CONFIG_SMP
> + /*
> + * Ensure the task has finished __schedule() and will not be referenced
> + * anymore. Again, see try_to_wake_up() for a longer comment.
> + */
> + smp_rmb();
> + smp_cond_load_acquire(&p->on_cpu, !VAL);
> +#endif
> +
> + return false;
> +}
> +
> /**
> * task_call_func - Invoke a function on task in fixed state
> * @p: Process for which the function is to be invoked, can be @current.
> @@ -4217,28 +4251,12 @@ try_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags)
> int task_call_func(struct task_struct *p, task_call_f func, void *arg)
> {
> struct rq *rq = NULL;
> - unsigned int state;
> struct rq_flags rf;
> int ret;
>
> raw_spin_lock_irqsave(&p->pi_lock, rf.flags);
>
> - state = READ_ONCE(p->__state);
> -
> - /*
> - * Ensure we load p->on_rq after p->__state, otherwise it would be
> - * possible to, falsely, observe p->on_rq == 0.
> - *
> - * See try_to_wake_up() for a longer comment.
> - */
> - smp_rmb();
> -
> - /*
> - * Since pi->lock blocks try_to_wake_up(), we don't need rq->lock when
> - * the task is blocked. Make sure to check @state since ttwu() can drop
> - * locks at the end, see ttwu_queue_wakelist().
> - */
> - if (state == TASK_RUNNING || state == TASK_WAKING || p->on_rq)
> + if (__task_needs_rq_lock(p))
> rq = __task_rq_lock(p, &rf);
>
> /*
--
Ville Syrjälä
Intel
next prev parent reply other threads:[~2022-11-07 11:47 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20220822111816.760285417@infradead.org>
[not found] ` <20220822114649.055452969@infradead.org>
2022-10-21 17:22 ` [Intel-gfx] [PATCH v3 6/6] freezer, sched: Rewrite core freezer logic Ville Syrjälä
2022-10-25 4:52 ` Ville Syrjälä
2022-10-25 10:49 ` Peter Zijlstra
2022-10-26 10:32 ` Ville Syrjälä
2022-10-26 11:43 ` Peter Zijlstra
2022-10-26 12:12 ` Peter Zijlstra
2022-10-26 12:14 ` Peter Zijlstra
2022-10-27 5:58 ` Chen Yu
2022-10-27 7:39 ` Peter Zijlstra
2022-10-27 13:09 ` Ville Syrjälä
2022-10-27 16:53 ` Peter Zijlstra
2022-11-02 16:57 ` Ville Syrjälä
2022-11-02 22:16 ` Peter Zijlstra
2022-11-07 11:47 ` Ville Syrjälä [this message]
2022-11-10 20:27 ` Ville Syrjälä
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=Y2jwSwfRC3Q5x7Rm@intel.com \
--to=ville.syrjala@linux.intel.com \
--cc=bigeasy@linutronix.de \
--cc=dietmar.eggemann@arm.com \
--cc=ebiederm@xmission.com \
--cc=intel-gfx@lists.freedesktop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=mingo@kernel.org \
--cc=oleg@redhat.com \
--cc=peterz@infradead.org \
--cc=rjw@rjwysocki.net \
--cc=rostedt@goodmis.org \
--cc=tj@kernel.org \
--cc=will@kernel.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