WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH 6/7] xen: Enable PV clocksource for HVM

To: Jeremy Fitzhardinge <jeremy.fitzhardinge@xxxxxxxxxx>, Keir Fraser <keir.fraser@xxxxxxxxxxxxx>, Ingo Molnar <mingo@xxxxxxx>, Ian Pratt <Ian.Pratt@xxxxxxxxxxxxx>
Subject: [Xen-devel] [PATCH 6/7] xen: Enable PV clocksource for HVM
From: Sheng Yang <sheng@xxxxxxxxxxxxxxx>
Date: Mon, 8 Mar 2010 15:18:51 +0800
Cc: xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxx>, Ian Campbell <Ian.Campbell@xxxxxxxxxx>, Sheng Yang <sheng@xxxxxxxxxxxxxxx>, linux-kernel@xxxxxxxxxxxxxxx
Delivery-date: Sun, 07 Mar 2010 23:23:05 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <1268032732-8025-1-git-send-email-sheng@xxxxxxxxxxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
References: <1268032732-8025-1-git-send-email-sheng@xxxxxxxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
PV clocksource can provide a reliable clocksource for HVM running on Xen.

To enable it, put following line to the HVM configure file:

cpuid = [ '0x40000002:edx=0x3' ]

It would set bit 0 and bit 1 in 0x40000002:edx, which enable PV extension
framework and PV clocksource.

Signed-off-by: Sheng Yang <sheng@xxxxxxxxxxxxxxx>
---
 arch/x86/xen/hvmpv.c   |   24 ++++++++++++++++++++++++
 arch/x86/xen/time.c    |   12 +++++++++++-
 arch/x86/xen/xen-ops.h |    1 +
 3 files changed, 36 insertions(+), 1 deletions(-)

diff --git a/arch/x86/xen/hvmpv.c b/arch/x86/xen/hvmpv.c
index 540eef4..e944caf 100644
--- a/arch/x86/xen/hvmpv.c
+++ b/arch/x86/xen/hvmpv.c
@@ -43,6 +43,8 @@ static void __init xen_hvm_pv_banner(void)
                pv_info.name);
        printk(KERN_INFO "Xen version: %d.%d%s\n",
                version >> 16, version & 0xffff, extra.extraversion);
+       if (xen_hvm_pv_clock_enabled())
+               printk(KERN_INFO "PV feature: PV clocksource enabled\n");
 }
 
 static int __init xen_para_available(void)
@@ -82,6 +84,9 @@ static int __init init_hvm_pv_info(void)
        if (!(edx & XEN_CPUID_FEAT2_HVM_PV))
                return -ENODEV;
 
+       if (edx & XEN_CPUID_FEAT2_HVM_PV_CLOCK)
+               xen_hvm_pv_features |= XEN_HVM_PV_CLOCK_ENABLED;
+
        if (pages < 1)
                return -ENODEV;
 
@@ -112,6 +117,23 @@ static int __init init_shared_info(void)
        return 0;
 }
 
+static void __init init_pv_clocksource(void)
+{
+       if (!xen_hvm_pv_clock_enabled())
+               return;
+
+       if (enable_hvm_pv(HVM_PV_CLOCK))
+               BUG();
+
+       pv_time_ops.sched_clock = xen_sched_clock;
+
+       x86_platform.calibrate_tsc = xen_tsc_khz;
+       x86_platform.get_wallclock = xen_get_wallclock;
+       x86_platform.set_wallclock = xen_set_wallclock;
+
+       xen_register_clocksource();
+}
+
 void __init xen_guest_init(void)
 {
        int r;
@@ -134,4 +156,6 @@ void __init xen_guest_init(void)
        pv_info = xen_hvm_pv_info;
 
        xen_domain_type = XEN_HVM_DOMAIN;
+
+       init_pv_clocksource();
 }
diff --git a/arch/x86/xen/time.c b/arch/x86/xen/time.c
index 0d3f07c..06b3e72 100644
--- a/arch/x86/xen/time.c
+++ b/arch/x86/xen/time.c
@@ -472,11 +472,21 @@ void xen_timer_resume(void)
        }
 }
 
+static bool xen_clocksource_enabled;
+
+void xen_register_clocksource(void)
+{
+       if (!xen_clocksource_enabled) {
+               clocksource_register(&xen_clocksource);
+               xen_clocksource_enabled = 1;
+       }
+}
+
 __init void xen_time_init(void)
 {
        int cpu = smp_processor_id();
 
-       clocksource_register(&xen_clocksource);
+       xen_register_clocksource();
 
        if (HYPERVISOR_vcpu_op(VCPUOP_stop_periodic_timer, cpu, NULL) == 0) {
                /* Successfully turned off 100Hz tick, so we have the
diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
index f9153a3..d56b660 100644
--- a/arch/x86/xen/xen-ops.h
+++ b/arch/x86/xen/xen-ops.h
@@ -48,6 +48,7 @@ cycle_t xen_clocksource_read(void);
 void xen_setup_cpu_clockevents(void);
 unsigned long xen_tsc_khz(void);
 void __init xen_time_init(void);
+void xen_register_clocksource(void);
 unsigned long xen_get_wallclock(void);
 int xen_set_wallclock(unsigned long time);
 unsigned long long xen_sched_clock(void);
-- 
1.5.4.5


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel