From: Jeremy Fitzhardinge <jeremy@goop.org>
To: Glauber Costa <glommer@redhat.com>
Cc: "kvm@vger.kernel.org" <kvm@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"aliguori@us.ibm.com" <aliguori@us.ibm.com>,
Rik van Riel <riel@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
Avi Kivity <avi@redhat.com>
Subject: Re: [PATCH v2 3/6] KVM-GST: KVM Steal time accounting
Date: Fri, 28 Jan 2011 17:16:24 -0800 [thread overview]
Message-ID: <4D436A68.2000100@goop.org> (raw)
In-Reply-To: <1296244340-15173-4-git-send-email-glommer@redhat.com>
On 01/28/2011 11:52 AM, Glauber Costa wrote:
> This patch accounts steal time time in kernel/sched.
> I kept it from last proposal, because I still see advantages
> in it: Doing it here will give us easier access from scheduler
> variables such as the cpu rq. The next patch shows an example of
> usage for it.
Is this used on the host or guest side?
J
> Since functions like account_idle_time() can be called from
> multiple places, not only account_process_tick(), steal time
> grabbing is repeated in each account function separatedely.
>
> Signed-off-by: Glauber Costa <glommer@redhat.com>
> CC: Rik van Riel <riel@redhat.com>
> CC: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
> CC: Peter Zijlstra <peterz@infradead.org>
> CC: Avi Kivity <avi@redhat.com>
> ---
> include/linux/sched.h | 1 +
> kernel/sched.c | 41 +++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 42 insertions(+), 0 deletions(-)
>
> diff --git a/include/linux/sched.h b/include/linux/sched.h
> index d747f94..77e9297 100644
> --- a/include/linux/sched.h
> +++ b/include/linux/sched.h
> @@ -302,6 +302,7 @@ long io_schedule_timeout(long timeout);
> extern void cpu_init (void);
> extern void trap_init(void);
> extern void update_process_times(int user);
> +extern u64 (*hypervisor_steal_time)(void);
> extern void scheduler_tick(void);
>
> extern void sched_show_task(struct task_struct *p);
> diff --git a/kernel/sched.c b/kernel/sched.c
> index ea3e5ef..7765e9d 100644
> --- a/kernel/sched.c
> +++ b/kernel/sched.c
> @@ -3508,6 +3508,39 @@ unsigned long long thread_group_sched_runtime(struct task_struct *p)
> return ns;
> }
>
> +u64 (*hypervisor_steal_time)(void) = NULL;
> +
> +/*
> + * We have to at flush steal time information every time something else
> + * is accounted. Since the accounting functions are all visible to the rest
> + * of the kernel, it gets tricky to do them in one place. This helper function
> + * helps us.
> + *
> + * When the system is idle, the concept of steal time does not apply. We just
> + * tell the underlying hypervisor that we grabbed the data, but skip steal time
> + * accounting
> + */
> +static int touch_steal_time(int is_idle)
> +{
> + u64 steal, st;
> +
> + if (!hypervisor_steal_time)
> + return 0;
> +
> + steal = hypervisor_steal_time();
> +
> + st = usecs_to_cputime(steal / 1000);
> +
> + if (is_idle)
> + return 0;
> +
> + if (st) {
> + account_steal_time(st);
> + return 1;
> + }
> + return 0;
> +}
> +
> /*
> * Account user cpu time to a process.
> * @p: the process that the cpu time gets accounted to
> @@ -3520,6 +3553,9 @@ void account_user_time(struct task_struct *p, cputime_t cputime,
> struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
> cputime64_t tmp;
>
> + if (touch_steal_time(0))
> + return;
> +
> /* Add user time to process. */
> p->utime = cputime_add(p->utime, cputime);
> p->utimescaled = cputime_add(p->utimescaled, cputime_scaled);
> @@ -3580,6 +3616,9 @@ void account_system_time(struct task_struct *p, int hardirq_offset,
> struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
> cputime64_t tmp;
>
> + if (touch_steal_time(0))
> + return;
> +
> if ((p->flags & PF_VCPU) && (irq_count() - hardirq_offset == 0)) {
> account_guest_time(p, cputime, cputime_scaled);
> return;
> @@ -3627,6 +3666,8 @@ void account_idle_time(cputime_t cputime)
> cputime64_t cputime64 = cputime_to_cputime64(cputime);
> struct rq *rq = this_rq();
>
> + touch_steal_time(1);
> +
> if (atomic_read(&rq->nr_iowait) > 0)
> cpustat->iowait = cputime64_add(cpustat->iowait, cputime64);
> else
next prev parent reply other threads:[~2011-01-29 1:16 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-01-28 19:52 [PATCH v2 0/6] KVM Steal time, new submission Glauber Costa
2011-01-28 19:52 ` [PATCH v2 1/6] KVM-HDR: KVM Steal time implementation Glauber Costa
2011-01-29 1:28 ` Rik van Riel
2011-01-28 19:52 ` [PATCH v2 2/6] KVM-HV: " Glauber Costa
2011-01-29 1:46 ` Rik van Riel
2011-01-30 13:13 ` Avi Kivity
2011-02-01 15:48 ` Glauber Costa
2011-02-01 17:09 ` Avi Kivity
2011-02-01 19:58 ` Glauber Costa
2011-02-02 10:09 ` Avi Kivity
2011-01-31 11:07 ` Peter Zijlstra
2011-01-28 19:52 ` [PATCH v2 3/6] KVM-GST: KVM Steal time accounting Glauber Costa
2011-01-29 1:16 ` Jeremy Fitzhardinge [this message]
2011-01-29 1:27 ` Glauber Costa
2011-01-29 1:53 ` Rik van Riel
2011-01-30 14:04 ` Avi Kivity
2011-01-30 16:45 ` lidong chen
2011-02-01 15:58 ` Glauber Costa
2011-02-01 15:57 ` Glauber Costa
2011-02-02 10:11 ` Avi Kivity
2011-02-02 10:51 ` Avi Kivity
2011-02-02 11:57 ` Glauber Costa
2011-01-28 19:52 ` [PATCH v2 4/6] KVM-GST: KVM Steal time registration Glauber Costa
2011-01-29 2:16 ` Rik van Riel
2011-01-30 13:16 ` Avi Kivity
2011-02-01 15:53 ` Glauber Costa
2011-02-01 16:17 ` Peter Zijlstra
2011-02-01 17:00 ` Glauber Costa
2011-02-01 17:44 ` Peter Zijlstra
2011-02-01 20:20 ` Venkatesh Pallipadi
2011-01-31 11:11 ` Peter Zijlstra
2011-01-28 19:52 ` [PATCH v2 5/6] KVM-GST: adjust scheduler cpu power Glauber Costa
2011-01-31 11:25 ` Peter Zijlstra
2011-01-31 11:27 ` Peter Zijlstra
2011-02-01 15:59 ` Glauber Costa
2011-02-01 16:19 ` Peter Zijlstra
2011-02-01 16:22 ` Glauber Costa
2011-02-01 18:59 ` Peter Zijlstra
2011-02-01 19:55 ` Glauber Costa
2011-02-01 20:04 ` Peter Zijlstra
2011-01-28 19:52 ` [PATCH v2 6/6] Describe KVM_MSR_STEAL_TIME Glauber Costa
2011-01-30 13:19 ` Avi Kivity
2011-02-01 15:54 ` Glauber Costa
2011-02-02 10:14 ` Avi Kivity
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=4D436A68.2000100@goop.org \
--to=jeremy@goop.org \
--cc=aliguori@us.ibm.com \
--cc=avi@redhat.com \
--cc=glommer@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=peterz@infradead.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.