From: Frederic Weisbecker <fweisbec@gmail.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
Ingo Molnar <mingo@kernel.org>, Mike Galbraith <efault@gmx.de>,
Thomas Gleixner <tglx@linutronix.de>
Subject: Re: [PATCH 2/3] sched: Unloop sched avg decaying
Date: Thu, 30 Jun 2016 14:52:26 +0200 [thread overview]
Message-ID: <20160630125225.GA32568@lerouge> (raw)
In-Reply-To: <20160614155842.GJ30921@twins.programming.kicks-ass.net>
On Tue, Jun 14, 2016 at 05:58:42PM +0200, Peter Zijlstra wrote:
> On Tue, Jun 14, 2016 at 05:28:01PM +0200, Frederic Weisbecker wrote:
> > diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> > index 385c947..0c0578a 100644
> > --- a/kernel/sched/core.c
> > +++ b/kernel/sched/core.c
> > @@ -666,17 +666,17 @@ bool sched_can_stop_tick(struct rq *rq)
> > void sched_avg_update(struct rq *rq)
> > {
> > s64 period = sched_avg_period();
> > + s64 delta;
> > + u64 rem;
> > + int pending;
> >
> > + delta = (s64)(rq_clock(rq) - rq->age_stamp);
> > + if (delta <= period)
> > + return;
> > +
> > + pending = div64_u64_rem(delta, period, &rem);
> > + rq->age_stamp += delta - rem;
> > + rq->rt_avg >>= pending;
> > }
>
> Blergh, and now do the profile on machine that doesn't have major
> transistor count dedicated to divisions.
Indeed I was afraid of something like that. That said I'm not sure which
is worse between iteration or division out of native asm.
Would it be worth testing?
>
> Why not add the division to the nohz exit path only?
It would be worse I think because we may exit much more often from nohz
than we reach a sched_avg_period().
So the only safe optimization I can do for now is:
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 8b489fc..4632d31 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -626,8 +626,9 @@ bool sched_can_stop_tick(struct rq *rq)
void sched_avg_update(struct rq *rq)
{
s64 period = sched_avg_period();
+ int i;
- while ((s64)(rq_clock(rq) - rq->age_stamp) > period) {
+ for (i = 0; (s64)(rq_clock(rq) - rq->age_stamp) > period); i++) {
/*
* Inline assembly required to prevent the compiler
* optimising this loop into a divmod call.
@@ -635,8 +636,8 @@ void sched_avg_update(struct rq *rq)
*/
asm("" : "+rm" (rq->age_stamp));
rq->age_stamp += period;
- rq->rt_avg /= 2;
}
+ rq->rt_avg >>= i;
}
#endif /* CONFIG_SMP */
next prev parent reply other threads:[~2016-06-30 12:52 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-14 15:27 [PATCH 0/3] sched: Enhance/fix sched_avg_update() Frederic Weisbecker
2016-06-14 15:28 ` [PATCH 1/3] sched: Introduce sched_time_avg_ns minimal value Frederic Weisbecker
2016-06-14 15:28 ` [PATCH 2/3] sched: Unloop sched avg decaying Frederic Weisbecker
2016-06-14 15:58 ` Peter Zijlstra
2016-06-30 12:52 ` Frederic Weisbecker [this message]
2016-06-30 13:20 ` Peter Zijlstra
2016-07-06 11:53 ` Frederic Weisbecker
2016-06-14 15:28 ` [NOT-FOR-MERGE-PATCH 3/3] Debug: Alternate old/new version of sched_avg_update calls for profiling Frederic Weisbecker
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=20160630125225.GA32568@lerouge \
--to=fweisbec@gmail.com \
--cc=efault@gmx.de \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
/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
all inboxes | Powered by JetHome®