From: Juri Lelli <juri.lelli@arm.com>
To: luca abeni <luca.abeni@unitn.it>
Cc: linux-kernel@vger.kernel.org,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Claudio Scordino <claudio@evidence.eu.com>,
Steven Rostedt <rostedt@goodmis.org>
Subject: Re: [RFC v3 2/6] Improve the tracking of active utilisation
Date: Thu, 10 Nov 2016 12:34:15 +0000 [thread overview]
Message-ID: <20161110123415.GJ16920@e106622-lin> (raw)
In-Reply-To: <20161110131558.7a9480b2@sweethome>
On 10/11/16 13:15, Luca Abeni wrote:
> On Thu, 10 Nov 2016 11:56:10 +0000
> Juri Lelli <juri.lelli@arm.com> wrote:
>
> > On 10/11/16 10:04, Juri Lelli wrote:
> > > On 02/11/16 03:35, Luca Abeni wrote:
> > > > On Tue, 1 Nov 2016 22:46:33 +0100
> > > > luca abeni <luca.abeni@unitn.it> wrote:
> > > > [...]
> > > > > > > @@ -1074,6 +1161,14 @@ select_task_rq_dl(struct task_struct
> > > > > > > *p, int cpu, int sd_flag, int flags) }
> > > > > > > rcu_read_unlock();
> > > > > > >
> > > > > > > + rq = task_rq(p);
> > > > > > > + raw_spin_lock(&rq->lock);
> > > > > > > + if (hrtimer_active(&p->dl.inactive_timer)) {
> > > > > > > + sub_running_bw(&p->dl, &rq->dl);
> > > > > > > +
> > > > > > > hrtimer_try_to_cancel(&p->dl.inactive_timer);
> > > > > >
> > > > > > Can't we subtract twice if it happens that after we grabbed
> > > > > > rq_lock the timer fired, so it's now waiting for that lock
> > > > > > and it goes ahead and sub_running_bw again after we release
> > > > > > the lock?
> > > > > Uhm... I somehow convinced myself that this could not happen,
> > > > > but I do not remember the details, sorry :(
> > > > I think I remember the answer now: pi_lock is acquired before
> > > > invoking select_task_rq and is released after invoking
> > > > enqueue_task... So, if there is a pending inactive timer, its
> > > > handler will be executed after the task is enqueued... It will
> > > > see the task as RUNNING, and will not decrease the active
> > > > utilisation.
> > >
> > > Oh, because we do task_rq_lock() inactive_task_timer(). So, that
> > > should save us from the double subtract. Would you mind adding
> > > something along the line of what you said above as a comment for
> > > next version?
> >
> > Mmm, wait again.
> >
> > Cannot the following happen?
> >
> > - inactive_timer fires and does sub_running_bw (as the task is not
> > RUNNING)
> > - another cpu does try_to_wake_up and blocks on pi_lock
> > - inactive timer releases both pi and rq locks (but is still
> > executing, let's say it is doing put_task_struct())
> > - try_to_wake_up goes ahead and calls select_task_rq_dl
> > + it finds inactive_timer active
> > + sub_running_bw again :(
> Uhm... Right; this can happen :(
>
:(
> Ok; I'll think about some possible solution for this race... If I do
> not find any simple way to solve it, I'll add a "contending" flag,
> which allows to know if the inactive timer handler already executed or
> not.
>
Right, this might help.
Another thing that I was thinking of is whether we can use the return
value of hrtimer_try_to_cancel() to decide what to do:
- if it returns 0 it means that the callback exectuted or the timer was
never set, so nothing to do (as in nothing to sub_running_bw from)
- if it returns 1 we succedeed, so we need to actively sub_running_bw
- if -1 we can assume that it will eventually do sub_running_bw() so we
don't need to care explicitly
Now I guess the problem is that the task can be migrated while his
inactive_timer is set (by select_task_rq_dl or by other classes load
balacing if setscheduled to a different class). Can't we store a back
reference to the rq from which the inactive_timer was queued and use
that to sub_running_bw() from? It seems that we might end up with some
"shadow" bandwidth, say when we do a wakeup migration, but maybe this is
something we can tolerate? Just thinking aloud. :)
> BTW, talking about sched_dl_entity flags: I see there are three
> different int fields "dl_throttled, "dl_boosted" and "dl_yielded"; any
> reason for doing this instead of having a "dl_flags" field and setting
> its different bits when the entity is throttled, boosted or yielded? In
> other words: if I need this "contending" flag, should I add a new
> "dl_contending" field?
>
I think you might want to add a clean-up patch to your series (or a
separate one) fixing the current situation, and the build on to adding
the new flag if needed.
Thanks,
- Juri
next prev parent reply other threads:[~2016-11-10 12:34 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-24 14:06 [RFC v3 0/6] CPU reclaiming for SCHED_DEADLINE Luca Abeni
2016-10-24 14:06 ` [RFC v3 1/6] Track the active utilisation Luca Abeni
2016-10-25 9:09 ` Daniel Bristot de Oliveira
2016-10-25 9:29 ` luca abeni
2016-10-25 13:58 ` Steven Rostedt
2016-10-25 18:04 ` Luca Abeni
2016-11-18 14:23 ` Peter Zijlstra
2016-11-18 15:10 ` luca abeni
2016-11-18 15:28 ` Peter Zijlstra
2016-11-18 16:42 ` Steven Rostedt
2016-12-05 22:30 ` luca abeni
2016-12-06 8:35 ` Peter Zijlstra
2016-12-06 8:57 ` luca abeni
2016-12-06 13:47 ` luca abeni
2016-11-01 16:45 ` Juri Lelli
2016-11-01 21:10 ` luca abeni
2016-11-08 17:56 ` Juri Lelli
2016-11-08 18:17 ` Luca Abeni
2016-11-08 18:53 ` Juri Lelli
2016-11-08 19:09 ` Luca Abeni
2016-11-08 20:02 ` Juri Lelli
2016-11-09 15:25 ` luca abeni
2016-11-09 16:29 ` luca abeni
2016-11-18 14:55 ` Peter Zijlstra
2016-11-18 13:55 ` Peter Zijlstra
2016-11-18 15:06 ` luca abeni
2016-10-24 14:06 ` [RFC v3 2/6] Improve the tracking of " Luca Abeni
2016-11-01 16:46 ` Juri Lelli
2016-11-01 21:46 ` luca abeni
2016-11-02 2:35 ` luca abeni
2016-11-10 10:04 ` Juri Lelli
2016-11-10 11:56 ` Juri Lelli
2016-11-10 12:15 ` luca abeni
2016-11-10 12:34 ` Juri Lelli [this message]
2016-11-10 12:45 ` luca abeni
2016-11-02 2:41 ` luca abeni
2016-11-18 15:36 ` Peter Zijlstra
2016-11-18 15:56 ` luca abeni
2016-11-18 15:47 ` Peter Zijlstra
2016-11-18 16:06 ` luca abeni
2016-11-18 18:49 ` Peter Zijlstra
2016-10-24 14:06 ` [RFC v3 3/6] Fix the update of the total -deadline utilization Luca Abeni
2016-10-24 14:06 ` [RFC v3 4/6] GRUB accounting Luca Abeni
2016-10-24 14:06 ` [RFC v3 5/6] Do not reclaim the whole CPU bandwidth Luca Abeni
2016-10-24 14:06 ` [RFC v3 6/6] Make GRUB a task's flag Luca Abeni
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=20161110123415.GJ16920@e106622-lin \
--to=juri.lelli@arm.com \
--cc=claudio@evidence.eu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luca.abeni@unitn.it \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.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;
as well as URLs for NNTP newsgroup(s).