public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Hao Lee <haolee.swjtu@gmail.com>
To: Suren Baghdasaryan <surenb@google.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Zhaoyang Huang <zhaoyang.huang@unisoc.com>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] psi: fix possible missing or delayed pending event
Date: Sat, 17 Sep 2022 07:31:24 +0000	[thread overview]
Message-ID: <20220917073124.GA3483@haolee.io> (raw)
In-Reply-To: <CAJuCfpFVK3ceHy+ipSbLb0jAgE6tJAsu5=kbJEB9X4OWPnsVxA@mail.gmail.com>

On Fri, Sep 16, 2022 at 11:08:34PM -0700, Suren Baghdasaryan wrote:
> On Wed, Sep 14, 2022 at 2:30 AM Hao Lee <haolee.swjtu@gmail.com> wrote:
> >
> > When a pending event exists and growth is less than the threshold, the
> > current logic is to skip this trigger without generating event. However,
> > from e6df4ead85d9 ("psi: fix possible trigger missing in the window"),
> > our purpose is to generate event as long as pending event exists and the
> > rate meets the limit. This patch fixes the possible pending-event
> > missing or delay.
> >
> > Fixes: e6df4ead85d9 ("psi: fix possible trigger missing in the window")
> > Signed-off-by: Hao Lee <haolee.swjtu@gmail.com>
> > ---
> >  kernel/sched/psi.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c
> > index 9711827e3..0bae4ee2b 100644
> > --- a/kernel/sched/psi.c
> > +++ b/kernel/sched/psi.c
> > @@ -539,7 +539,7 @@ static u64 update_triggers(struct psi_group *group, u64 now)
> >
> >                         /* Calculate growth since last update */
> >                         growth = window_update(&t->win, now, total[t->state]);
> > -                       if (growth < t->threshold)
> > +                       if (growth < t->threshold && !t->pending_event)
> 
> I'm not sure how this additional condition changes things. Current
> logic is to set t->pending_event=true whenever growth exceeds the
> t->threshold. This patch will change this logic into setting
> t->pending_event=true also when t->pending_event=true.

This is right.

> But why would
> you want to set t->pending_event=true if it's already true? What am I
> missing?

If I expand this if-else branch and the pending_event statement
to a more detailed snippet, it will be like this:

if (growth < t->threshold && !t->pending_event) // under threshold && no pending event. Skip.
	continue;
else if (growth >= t->threshold) // above threshold. Try to generate event.
	t->pending_event = true;
else // under threshold && have pending events. Try to generate event.
	; // pending_event is already true. do nothing


The original code didn't handle the `else` condition properly. It will
skip the trigger when its growth is under the threshold, even though it
has a pending event. This patch handles this condition correctly.

But I think assigning true to pending_event when it's already true doesn't
have other side effects, so I eliminate the `else if` branch. Maybe we'd
better make it explicit, like the above snippet? Thanks.

> 
> >                                 continue;
> >
> >                         t->pending_event = true;
> > --
> > 2.21.0
> >

  reply	other threads:[~2022-09-17  7:31 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-14  9:29 [PATCH] psi: fix possible missing or delayed pending event Hao Lee
2022-09-17  6:08 ` Suren Baghdasaryan
2022-09-17  7:31   ` Hao Lee [this message]
2022-09-18  4:44     ` Suren Baghdasaryan
2022-09-18 10:55       ` Hao Lee
2022-09-19  5:16         ` Suren Baghdasaryan
2022-09-19  7:10           ` Hao Lee

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=20220917073124.GA3483@haolee.io \
    --to=haolee.swjtu@gmail.com \
    --cc=hannes@cmpxchg.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=surenb@google.com \
    --cc=zhaoyang.huang@unisoc.com \
    /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