public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Glauber Costa <glommer@redhat.com>
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
	Rik van Riel <riel@redhat.com>,
	Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>,
	Avi Kivity <avi@redhat.com>,
	Anthony Liguori <aliguori@us.ibm.com>,
	Eric B Munson <emunson@mgebm.net>, Jeff Law <law@redhat.com>
Subject: Re: [PATCH v4 8/9] KVM-GST: adjust scheduler cpu power
Date: Sat, 02 Jul 2011 12:24:51 +0200	[thread overview]
Message-ID: <1309602291.10073.22.camel@twins> (raw)
In-Reply-To: <1309555369-16867-9-git-send-email-glommer@redhat.com>

On Fri, 2011-07-01 at 17:22 -0400, Glauber Costa wrote:
> @@ -1971,8 +1974,14 @@ static inline u64 steal_ticks(u64 steal)
>  
>  static void update_rq_clock_task(struct rq *rq, s64 delta)
>  {
> -       s64 irq_delta;
> -
> +/*
> + * In theory, the compile should just see 0 here, and optimize out the call
> + * to sched_rt_avg_update. But I don't trust it...
> + */
> +#if defined(CONFIG_IRQ_TIME_ACCOUNTING) || defined(CONFIG_PARAVIRT_TIME_ACCOUNTING)
> +       s64 steal = 0, irq_delta = 0;
> +#endif

So I wanted to ask a GCC person (Hi Jeff) about this.

> +#ifdef CONFIG_IRQ_TIME_ACCOUNTING
>         irq_delta = irq_time_read(cpu_of(rq)) - rq->prev_irq_time;
>  
>         /*
> @@ -1995,12 +2004,35 @@ static void update_rq_clock_task(struct rq *rq, s64 delta)
>  
>         rq->prev_irq_time += irq_delta;
>         delta -= irq_delta;
> +#endif
> +#ifdef CONFIG_PARAVIRT_TIME_ACCOUNTING
> +       if (static_branch((&paravirt_steal_rq_enabled))) {
> +               u64 st;
> +
> +               steal = paravirt_steal_clock(cpu_of(rq));
> +               steal -= rq->prev_steal_time_rq;
> +
> +               if (unlikely(steal > delta))
> +                       steal = delta;
> +
> +               st = steal_ticks(steal);
> +               steal = st * TICK_NSEC;
> +
> +               rq->prev_steal_time_rq += steal;
> +
> +               delta -= steal;
> +       }
> +#endif
> +
>         rq->clock_task += delta;
>  
> -       if (irq_delta && sched_feat(NONIRQ_POWER))
> -               sched_rt_avg_update(rq, irq_delta);
> +#if defined(CONFIG_IRQ_TIME_ACCOUNTING) || defined(CONFIG_PARAVIRT_TIME_ACCOUNTING)
> +       if ((irq_delta + steal) && sched_feat(NONTASK_POWER))
> +               sched_rt_avg_update(rq, irq_delta + steal);
> +#endif
>  } 

In case of !CONFIG_IRQ_TIME_ACCOUNTING && !
CONFIG_PARAVIRT_TIME_ACCOUNTING, irq_delta and steal will both always be
0.

The function will basically look like:

static void update_rq_clock_task(struct rq *rq, s64 delta)
{
	s64 irq_delta = 0, steal = 0;

	rq->clock_task += delta;

	if ((irq_delta + steal) && sched_feat(NONTASK_POWER))
		sched_rt_avg_update(rq, irq_delta + steal);
}

And we want it to emit the equivalent of:

static void update_rq_clock_task(struct rq *rq, s64 delta)
{
	rq->clock_task += delta;
}

Now Glauber is properly paranoid and doesn't trust his compiler (this is
very hot code in the kernel so any extra code emitted here is sad) and
chose the heavy handed CPP solution.

Now without checking a all relevant gcc versions on all relevant
architectures (see you in a few weeks etc..) can we actually rely on gcc
doing such relatively simple things correct, or should we stick with CPP
just to make sure?

  reply	other threads:[~2011-07-02 10:26 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-01 21:22 [PATCH v4 0/9] Steal time series again Glauber Costa
2011-07-01 21:22 ` [PATCH v4 1/9] introduce kvm_read_guest_cached Glauber Costa
2011-07-01 21:22 ` [PATCH v4 2/9] KVM-HDR Add constant to represent KVM MSRs enabled bit Glauber Costa
2011-07-01 21:22 ` [PATCH v4 3/9] KVM-HDR: KVM Steal time implementation Glauber Costa
2011-07-01 21:22 ` [PATCH v4 4/9] KVM-HV: " Glauber Costa
2011-07-01 21:22 ` [PATCH v4 5/9] KVM-GST: Add a pv_ops stub for steal time Glauber Costa
2011-07-01 21:22 ` [PATCH v4 6/9] add jump labels for ia64 paravirt Glauber Costa
2011-07-01 21:22 ` [PATCH v4 7/9] KVM-GST: KVM Steal time accounting Glauber Costa
2011-07-02 10:30   ` Peter Zijlstra
2011-07-01 21:22 ` [PATCH v4 8/9] KVM-GST: adjust scheduler cpu power Glauber Costa
2011-07-02 10:24   ` Peter Zijlstra [this message]
2011-07-03 13:20     ` Avi Kivity
2011-07-02 10:31   ` Peter Zijlstra
2011-07-01 21:22 ` [PATCH v4 9/9] KVM-GST: KVM Steal time registration Glauber Costa

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=1309602291.10073.22.camel@twins \
    --to=peterz@infradead.org \
    --cc=aliguori@us.ibm.com \
    --cc=avi@redhat.com \
    --cc=emunson@mgebm.net \
    --cc=glommer@redhat.com \
    --cc=jeremy.fitzhardinge@citrix.com \
    --cc=kvm@vger.kernel.org \
    --cc=law@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=riel@redhat.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