From: Jeremy Fitzhardinge <jeremy@goop.org>
To: Andi Kleen <ak@suse.de>
Cc: Andrew Morton <akpm@linux-foundation.org>,
virtualization@lists.osdl.org,
lkml <linux-kernel@vger.kernel.org>,
john stultz <johnstul@us.ibm.com>
Subject: [PATCH 09/25] xen: Account for time stolen by Xen
Date: Mon, 23 Apr 2007 14:56:47 -0700 [thread overview]
Message-ID: <20070423215710.867690403@goop.org> (raw)
In-Reply-To: 20070423215638.563901986@goop.org
[-- Attachment #1: xen-stolen-time.patch --]
[-- Type: text/plain, Size: 4589 bytes --]
This accounts for the time Xen steals from our VCPUs. This accounting
gets run on each timer interrupt, just as a way to get it run
relatively often, and when interesting things are going on.
Stolen time is not really used by much in the kernel; it is reported
in /proc/stats, and that's about it.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Cc: john stultz <johnstul@us.ibm.com>
---
arch/i386/xen/time.c | 101 +++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 100 insertions(+), 1 deletion(-)
===================================================================
--- a/arch/i386/xen/time.c
+++ b/arch/i386/xen/time.c
@@ -2,6 +2,7 @@
#include <linux/interrupt.h>
#include <linux/clocksource.h>
#include <linux/clockchips.h>
+#include <linux/kernel_stat.h>
#include <asm/xen/hypervisor.h>
#include <asm/xen/hypercall.h>
@@ -14,6 +15,7 @@
#define XEN_SHIFT 22
#define TIMER_SLOP 100000 /* Xen may fire a timer up to this many ns early */
+#define NS_PER_TICK (1000000000ll / HZ)
/* These are perodically updated in shared_info, and then copied here. */
struct shadow_time_info {
@@ -26,6 +28,99 @@ struct shadow_time_info {
static DEFINE_PER_CPU(struct shadow_time_info, shadow_time);
+/* runstate info updated by Xen */
+static DEFINE_PER_CPU(struct vcpu_runstate_info, runstate);
+
+/* snapshots of runstate info */
+static DEFINE_PER_CPU(struct vcpu_runstate_info, runstate_snapshot);
+
+/* unused ns of stolen and blocked time */
+static DEFINE_PER_CPU(u64, residual_stolen);
+static DEFINE_PER_CPU(u64, residual_blocked);
+
+/*
+ * Runstate accounting
+ */
+static void get_runstate_snapshot(struct vcpu_runstate_info *res)
+{
+ u64 state_time;
+ struct vcpu_runstate_info *state;
+
+ preempt_disable();
+
+ state = &__get_cpu_var(runstate);
+
+ do {
+ state_time = state->state_entry_time;
+ barrier();
+ *res = *state;
+ barrier();
+ } while(state->state_entry_time != state_time);
+
+ preempt_enable();
+}
+
+static void setup_runstate_info(void)
+{
+ struct vcpu_register_runstate_memory_area area;
+
+ area.addr.v = &__get_cpu_var(runstate);
+
+ if (HYPERVISOR_vcpu_op(VCPUOP_register_runstate_memory_area,
+ smp_processor_id(), &area))
+ BUG();
+
+ get_runstate_snapshot(&__get_cpu_var(runstate_snapshot));
+}
+
+static void do_stolen_accounting(void)
+{
+ struct vcpu_runstate_info state;
+ struct vcpu_runstate_info *snap;
+ u64 blocked, runnable, offline, stolen;
+ cputime_t ticks;
+
+ get_runstate_snapshot(&state);
+
+ WARN_ON(state.state != RUNSTATE_running);
+
+ snap = &__get_cpu_var(runstate_snapshot);
+
+ /* work out how much time the VCPU has not been runn*ing* */
+ blocked = state.time[RUNSTATE_blocked] - snap->time[RUNSTATE_blocked];
+ runnable = state.time[RUNSTATE_runnable] - snap->time[RUNSTATE_runnable];
+ offline = state.time[RUNSTATE_offline] - snap->time[RUNSTATE_offline];
+
+ *snap = state;
+
+ /* Add the appropriate number of ticks of stolen time,
+ including any left-overs from last time. Passing NULL to
+ account_steal_time accounts the time as stolen. */
+ stolen = runnable + offline + __get_cpu_var(residual_stolen);
+ ticks = 0;
+ while(stolen >= NS_PER_TICK) {
+ ticks++;
+ stolen -= NS_PER_TICK;
+ }
+ __get_cpu_var(residual_stolen) = stolen;
+ account_steal_time(NULL, ticks);
+
+ /* Add the appropriate number of ticks of blocked time,
+ including any left-overs from last time. Passing idle to
+ account_steal_time accounts the time as idle/wait. */
+ blocked += __get_cpu_var(residual_blocked);
+ ticks = 0;
+ while(blocked >= NS_PER_TICK) {
+ ticks++;
+ blocked -= NS_PER_TICK;
+ }
+ __get_cpu_var(residual_blocked) = blocked;
+ account_steal_time(idle_task(smp_processor_id()), ticks);
+}
+
+
+
+/* Get the CPU speed from Xen */
unsigned long xen_cpu_khz(void)
{
u64 cpu_khz = 1000000ULL << 32;
@@ -338,6 +433,8 @@ static irqreturn_t xen_timer_interrupt(i
ret = IRQ_HANDLED;
}
+ do_stolen_accounting();
+
return ret;
}
@@ -363,6 +460,8 @@ static void xen_setup_timer(int cpu)
evt->irq = irq;
clockevents_register_device(evt);
+ setup_runstate_info();
+
put_cpu_var(xen_clock_events);
}
@@ -375,7 +474,7 @@ __init void xen_time_init(void)
clocksource_register(&xen_clocksource);
if (HYPERVISOR_vcpu_op(VCPUOP_stop_periodic_timer, cpu, NULL) == 0) {
- /* Successfully turned off 100hz tick, so we have the
+ /* Successfully turned off 100Hz tick, so we have the
vcpuop-based timer interface */
printk(KERN_DEBUG "Xen: using vcpuop timer interface\n");
xen_clockevent = &xen_vcpuop_clockevent;
--
next prev parent reply other threads:[~2007-04-23 23:16 UTC|newest]
Thread overview: 66+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-04-23 21:56 [PATCH 00/25] xen: Xen implementation for paravirt_ops Jeremy Fitzhardinge
2007-04-23 21:56 ` [PATCH 01/25] xen: Add apply_to_page_range() which applies a function to a pte range Jeremy Fitzhardinge
2007-04-23 21:56 ` [PATCH 02/25] xen: Allocate and free vmalloc areas Jeremy Fitzhardinge
2007-04-23 21:56 ` [PATCH 03/25] xen: Add nosegneg capability to the vsyscall page notes Jeremy Fitzhardinge
2007-04-23 23:29 ` Roland McGrath
2007-04-24 1:24 ` Jeremy Fitzhardinge
2007-04-24 4:26 ` Roland McGrath
2007-04-24 6:19 ` Jeremy Fitzhardinge
2007-04-23 21:56 ` [PATCH 04/25] xen: Add XEN config options Jeremy Fitzhardinge
2007-04-23 23:00 ` Andi Kleen
2007-04-23 23:11 ` Jeremy Fitzhardinge
2007-04-24 19:45 ` Andi Kleen
2007-04-23 21:56 ` [PATCH 06/25] xen: Core Xen implementation Jeremy Fitzhardinge
2007-04-24 21:25 ` Andi Kleen
2007-04-25 2:02 ` Jeremy Fitzhardinge
2007-04-25 9:12 ` Andi Kleen
2007-04-25 19:41 ` Jeremy Fitzhardinge
2007-04-25 19:43 ` Andi Kleen
2007-04-25 19:44 ` [PATCH 06/25] xen: Core Xen implementation II Andi Kleen
2007-04-25 20:03 ` [PATCH 06/25] xen: Core Xen implementation Jeremy Fitzhardinge
2007-04-25 20:17 ` Andi Kleen
2007-04-25 20:20 ` Jeremy Fitzhardinge
2007-04-27 7:08 ` Jeremy Fitzhardinge
2007-04-27 7:31 ` Keir Fraser
2007-04-23 21:56 ` [PATCH 07/25] xen: Complete pagetable pinning for Xen Jeremy Fitzhardinge
2007-04-23 21:56 ` [PATCH 08/25] xen: xen: fix multicall batching Jeremy Fitzhardinge
2007-04-23 21:56 ` Jeremy Fitzhardinge [this message]
2007-04-25 9:15 ` [PATCH 09/25] xen: Account for time stolen by Xen Andi Kleen
2007-04-25 18:13 ` Jeremy Fitzhardinge
2007-04-25 18:15 ` Andi Kleen
2007-04-25 18:40 ` Jeremy Fitzhardinge
2007-04-23 21:56 ` [PATCH 10/25] xen: Implement xen_sched_clock Jeremy Fitzhardinge
2007-04-23 21:56 ` [PATCH 11/25] xen: Xen SMP guest support Jeremy Fitzhardinge
2007-04-25 9:24 ` Andi Kleen
2007-04-25 18:45 ` Jeremy Fitzhardinge
2007-04-27 6:46 ` Jeremy Fitzhardinge
2007-04-27 9:10 ` Andi Kleen
2007-04-23 21:56 ` [PATCH 12/25] xen: Add support for preemption Jeremy Fitzhardinge
2007-04-23 21:56 ` [PATCH 13/25] xen: xen: lazy-mmu operations Jeremy Fitzhardinge
2007-04-23 21:56 ` [PATCH 14/25] xen: xen: deal with negative stolen time Jeremy Fitzhardinge
2007-04-23 21:56 ` [PATCH 15/25] xen: xen time fixups Jeremy Fitzhardinge
2007-04-23 21:56 ` [PATCH 16/25] xen: Use the hvc console infrastructure for Xen console Jeremy Fitzhardinge
2007-04-24 1:21 ` Olof Johansson
2007-04-24 20:01 ` Jeremy Fitzhardinge
2007-04-23 21:56 ` [PATCH 17/25] xen: Add early printk support via hvc console Jeremy Fitzhardinge
2007-04-23 21:56 ` [PATCH 18/25] xen: Add Xen grant table support Jeremy Fitzhardinge
2007-04-23 21:56 ` [PATCH 19/25] xen: Add the Xenbus sysfs and virtual device hotplug driver Jeremy Fitzhardinge
2007-04-23 21:56 ` [PATCH 20/25] xen: Add Xen virtual block device driver Jeremy Fitzhardinge
2007-04-23 21:56 ` [PATCH 21/25] xen: Add the Xen virtual network " Jeremy Fitzhardinge
2007-04-23 21:57 ` [PATCH 22/25] xen: xen-netfront: use skb.cb for storing private data Jeremy Fitzhardinge
2007-04-24 1:45 ` Herbert Xu
2007-04-24 4:34 ` Jeremy Fitzhardinge
2007-04-24 5:57 ` Herbert Xu
2007-04-27 22:19 ` Jeremy Fitzhardinge
2007-04-27 22:37 ` Herbert Xu
2007-04-27 23:27 ` Jeremy Fitzhardinge
2007-04-28 6:28 ` Herbert Xu
2007-04-29 7:43 ` Jeremy Fitzhardinge
2007-04-29 8:05 ` Herbert Xu
2007-04-23 21:57 ` [PATCH 23/25] xen: Lockdep fixes for xen-netfront Jeremy Fitzhardinge
2007-04-24 3:22 ` Herbert Xu
2007-04-24 4:36 ` Jeremy Fitzhardinge
2007-04-23 21:57 ` [PATCH 24/25] xen: xen: diddle netfront Jeremy Fitzhardinge
2007-04-23 21:57 ` [PATCH 25/25] xen: Xen machine operations Jeremy Fitzhardinge
2007-04-23 22:50 ` [PATCH 00/25] xen: Xen implementation for paravirt_ops Andi Kleen
2007-04-23 23:09 ` Jeremy Fitzhardinge
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=20070423215710.867690403@goop.org \
--to=jeremy@goop.org \
--cc=ak@suse.de \
--cc=akpm@linux-foundation.org \
--cc=johnstul@us.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=virtualization@lists.osdl.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).