From patchwork Tue Oct 21 14:07:50 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Campbell X-Patchwork-Id: 39149 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ee0-f72.google.com (mail-ee0-f72.google.com [74.125.83.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B37A7202DB for ; Tue, 21 Oct 2014 14:11:40 +0000 (UTC) Received: by mail-ee0-f72.google.com with SMTP id d49sf472950eek.7 for ; Tue, 21 Oct 2014 07:11:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:message-id:from:to:date:in-reply-to :references:organization:mime-version:subject:precedence:list-id :list-unsubscribe:list-post:list-help:list-subscribe:sender :errors-to:x-original-sender:x-original-authentication-results :mailing-list:list-archive:content-type; bh=erk/mS4im0oydr4EvYwuAuItd9F5rbjbXvjsmpvA6YU=; b=l1sER+YB/l25XeP2A0Zv2/yXMkfhCCZMU8zT2wBG7ANPOpwNILZORI8lftxTFlrX1R s76qK3qaJi9L2PCW/gnllvWpiCfHcX875yk+RTuc49iwtR4HeTZuDhVdoDp1qFiC65ob smV/ENyQhtsi+QLc/mUeDvb13r2g5A+nJMsPKhi9ssoli8K29N32TnUIBvXHYiSMquW3 hjBZNZ2ZTFOswuD8qCx3+sEOo2irD9jZoCYUKyz0JlIA1CeDv22Wd6TJrCeg3UdP0KTR OfBT/MnhmSCdqd2k3ZTKHUgGPMkPBsQsou0K4pcaypCLmFywGzgAUUbblBymqRGLigfX kt5w== X-Gm-Message-State: ALoCoQk+r5e/AIeim6UG+M5idVyjfo/5kgddmdw7f7x0r/of/GrQX/JJE5Hqt7/5Pm11gf1UnFbZ X-Received: by 10.194.118.197 with SMTP id ko5mr5136691wjb.2.1413900698027; Tue, 21 Oct 2014 07:11:38 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.6.5 with SMTP id w5ls64000law.71.gmail; Tue, 21 Oct 2014 07:11:37 -0700 (PDT) X-Received: by 10.112.247.43 with SMTP id yb11mr35137741lbc.51.1413900697385; Tue, 21 Oct 2014 07:11:37 -0700 (PDT) Received: from mail-lb0-f176.google.com (mail-lb0-f176.google.com. [209.85.217.176]) by mx.google.com with ESMTPS id la5si19106449lac.99.2014.10.21.07.11.37 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 21 Oct 2014 07:11:37 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.176 as permitted sender) client-ip=209.85.217.176; Received: by mail-lb0-f176.google.com with SMTP id p9so1060222lbv.7 for ; Tue, 21 Oct 2014 07:11:37 -0700 (PDT) X-Received: by 10.112.130.41 with SMTP id ob9mr34398939lbb.74.1413900697131; Tue, 21 Oct 2014 07:11:37 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.84.229 with SMTP id c5csp505511lbz; Tue, 21 Oct 2014 07:11:35 -0700 (PDT) X-Received: by 10.220.181.1 with SMTP id bw1mr1298016vcb.66.1413900695189; Tue, 21 Oct 2014 07:11:35 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id e10si4482413vcy.107.2014.10.21.07.11.34 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 21 Oct 2014 07:11:35 -0700 (PDT) Received-SPF: none (google.com: xen-devel-bounces@lists.xen.org does not designate permitted sender hosts) client-ip=50.57.142.19; Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1Xga7U-0007DO-8J; Tue, 21 Oct 2014 14:09:04 +0000 Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1Xga7S-0007DJ-Vf for xen-devel@lists.xen.org; Tue, 21 Oct 2014 14:09:03 +0000 Received: from [85.158.143.35] by server-1.bemta-4.messagelabs.com id 63/07-02952-EF866445; Tue, 21 Oct 2014 14:09:02 +0000 X-Env-Sender: Ian.Campbell@citrix.com X-Msg-Ref: server-15.tower-21.messagelabs.com!1413900538!12194365!1 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 6.12.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 18897 invoked from network); 21 Oct 2014 14:09:01 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-15.tower-21.messagelabs.com with RC4-SHA encrypted SMTP; 21 Oct 2014 14:09:01 -0000 X-IronPort-AV: E=Sophos;i="5.04,762,1406592000"; d="scan'208,223";a="184637286" Message-ID: <1413900470.23337.47.camel@citrix.com> From: Ian Campbell To: Date: Tue, 21 Oct 2014 15:07:50 +0100 In-Reply-To: <1413888616.23337.22.camel@citrix.com> References: <1412328051-20015-1-git-send-email-talex5@gmail.com> <1412328051-20015-2-git-send-email-talex5@gmail.com> <1413888616.23337.22.camel@citrix.com> Organization: Citrix Systems, Inc. X-Mailer: Evolution 3.12.7-1 MIME-Version: 1.0 X-DLP: MIA1 Subject: [Xen-devel] [PATCH incomplete] xen: arm: wallclock support (incomplete, needs work/refactoring) X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Post: , List-Help: , List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ian.campbell@citrix.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.176 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Archive: On Tue, 2014-10-21 at 11:50 +0100, Ian Campbell wrote: > > +/* Wall-clock time is not currently available on ARM, so this is always zero for now: > > + * http://secure-web.cisco.com/1riZQA377dZLKCo5tuoXAK4khWPPIvJePpjzLaQORhQEDB_kQWnA4fzAgRlX09RiW8tAnBtxXwom3oU37PxptJvdEgqAEvbJAHz9mB8G4h6XwnaDr9bcSh1o32Mldi1w6uBD_3Bf3fOL4m9UHxTUsdzkhF1wAMQEQej0ALt0lZHQ/http%3A%2F%2Fwiki.xenproject.org%2Fwiki%2FXen_ARM_TODO#Expose_Wallclock_time_to_guests > > I have some slightly hacky patches for this, I really should dust them > off and submit them... Since that doesn't seem likely to happen soon rather than let them rot in my tree here are the two patches (one for Xen, one for Linux). IMO they need a fair bit of refactoring (e.g. to make useful bits of the x86 support common/generic) and other code cleanup etc. Maybe someone would like to pick them up, or else I'll get to it eventually. Ian. >From 1284ba2380b32bf62789b738dbac4d99da463ea1 Mon Sep 17 00:00:00 2001 From: Ian Campbell Date: Tue, 5 Aug 2014 15:23:23 +0100 Subject: [PATCH] Wallclock time support. Needs much refactoring etc --- arch/arm/include/asm/xen/hypercall.h | 9 +++ arch/arm/xen/enlighten.c | 121 ++++++++++++++++++++++++++++++++++ arch/arm/xen/hypercall.S | 4 +- 3 files changed, 133 insertions(+), 1 deletion(-) diff --git a/arch/arm/include/asm/xen/hypercall.h b/arch/arm/include/asm/xen/hypercall.h index 712b50e..055399a 100644 --- a/arch/arm/include/asm/xen/hypercall.h +++ b/arch/arm/include/asm/xen/hypercall.h @@ -35,6 +35,7 @@ #include #include +#include long privcmd_call(unsigned call, unsigned long a1, unsigned long a2, unsigned long a3, @@ -49,6 +50,14 @@ int HYPERVISOR_memory_op(unsigned int cmd, void *arg); int HYPERVISOR_physdev_op(int cmd, void *arg); int HYPERVISOR_vcpu_op(int cmd, int vcpuid, void *extra_args); int HYPERVISOR_tmem_op(void *arg); +int HYPERVISOR_dom0_op_raw(struct xen_platform_op *platform_op); +static inline int +HYPERVISOR_dom0_op(struct xen_platform_op *platform_op) +{ + platform_op->interface_version = XENPF_INTERFACE_VERSION; + return HYPERVISOR_dom0_op_raw(platform_op); +} + int HYPERVISOR_multicall(struct multicall_entry *calls, uint32_t nr); static inline int diff --git a/arch/arm/xen/enlighten.c b/arch/arm/xen/enlighten.c index 1e63243..0364987 100644 --- a/arch/arm/xen/enlighten.c +++ b/arch/arm/xen/enlighten.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -24,6 +25,7 @@ #include #include #include +#include #include @@ -219,6 +221,122 @@ static irqreturn_t xen_arm_callback(int irq, void *arg) return IRQ_HANDLED; } +unsigned long xen_clocksource_read(void) +{ + unsigned long val = 0; + /* XXX arch timer? Error handling etc etc */ + if (read_current_timer(&val) < 0) + printk("read_current_timer failed?\n"); + return val; +} + +void pvclock_read_wallclock(struct pvclock_wall_clock *wall_clock, + struct pvclock_vcpu_time_info *vcpu_time, + struct timespec *ts) +{ + u32 version; + u64 delta; + struct timespec now; + + /* get wallclock at system boot */ + do { + version = wall_clock->version; + rmb(); /* fetch version before time */ + now.tv_sec = wall_clock->sec; + now.tv_nsec = wall_clock->nsec; + rmb(); /* fetch time before checking version */ + } while ((wall_clock->version & 1) || (version != wall_clock->version)); + + //delta = pvclock_clocksource_read(vcpu_time); /* time since system boot */ + delta = xen_clocksource_read(); + delta += now.tv_sec * (u64)NSEC_PER_SEC + now.tv_nsec; + + now.tv_nsec = do_div(delta, NSEC_PER_SEC); + now.tv_sec = delta; + + set_normalized_timespec(ts, now.tv_sec, now.tv_nsec); +} + +static void xen_read_wallclock(struct timespec *ts) +{ + struct shared_info *s = HYPERVISOR_shared_info; + struct pvclock_wall_clock *wall_clock = &(s->wc); + struct pvclock_vcpu_time_info *vcpu_time; + + vcpu_time = &get_cpu_var(xen_vcpu)->time; + pvclock_read_wallclock(wall_clock, vcpu_time, ts); + put_cpu_var(xen_vcpu); +} + +/* Parts could be common with x86? */ +static int xen_pvclock_gtod_notify(struct notifier_block *nb, + unsigned long was_set, void *priv) +{ + /* Protected by the calling core code serialization */ + static struct timespec next_sync; + + struct xen_platform_op op; + struct timespec now; + + now = __current_kernel_time(); + + /* + * We only take the expensive HV call when the clock was set + * or when the 11 minutes RTC synchronization time elapsed. + */ + if (!was_set && timespec_compare(&now, &next_sync) < 0) + return NOTIFY_OK; + + op.cmd = XENPF_settime; + op.u.settime.secs = now.tv_sec; + op.u.settime.nsecs = now.tv_nsec; + op.u.settime.system_time = xen_clocksource_read(); + printk("GTOD: Setting to %ld.%ld at %lld\n", + (long)op.u.settime.secs, + (long)op.u.settime.nsecs, + (long long)op.u.settime.system_time); + (void)HYPERVISOR_dom0_op(&op); + + /* + * Move the next drift compensation time 11 minutes + * ahead. That's emulating the sync_cmos_clock() update for + * the hardware RTC. + */ + next_sync = now; + next_sync.tv_sec += 11 * 60; + + return NOTIFY_OK; +} + +static struct notifier_block xen_pvclock_gtod_notifier = { + .notifier_call = xen_pvclock_gtod_notify, +}; + +static void __init xen_time_init(void) +{ + //int cpu = smp_processor_id(); + struct timespec tp; + + /* Set initial system time with full resolution */ + xen_read_wallclock(&tp); + do_settimeofday(&tp); + + printk("INITIAL TIME %ld.%ld\n", + (long)tp.tv_sec, + (long)tp.tv_nsec); + { + struct shared_info *s = HYPERVISOR_shared_info; + struct pvclock_wall_clock *wall_clock = &(s->wc); + struct pvclock_vcpu_time_info *vcpu_time; + printk("SHARED INFO TIME %ld.%ld\n", + (long)wall_clock->sec, + (long)wall_clock->nsec); + } + + if (xen_initial_domain()) + pvclock_gtod_register_notifier(&xen_pvclock_gtod_notifier); +} + /* * see Documentation/devicetree/bindings/arm/xen.txt for the * documentation of the Xen Device Tree format. @@ -323,6 +441,8 @@ static int __init xen_guest_init(void) register_cpu_notifier(&xen_cpu_notifier); + xen_time_init(); + return 0; } early_initcall(xen_guest_init); @@ -359,4 +479,5 @@ EXPORT_SYMBOL_GPL(HYPERVISOR_physdev_op); EXPORT_SYMBOL_GPL(HYPERVISOR_vcpu_op); EXPORT_SYMBOL_GPL(HYPERVISOR_tmem_op); EXPORT_SYMBOL_GPL(HYPERVISOR_multicall); +EXPORT_SYMBOL_GPL(HYPERVISOR_dom0_op_raw); EXPORT_SYMBOL_GPL(privcmd_call); diff --git a/arch/arm/xen/hypercall.S b/arch/arm/xen/hypercall.S index 44e3a5f..d3bf35e 100644 --- a/arch/arm/xen/hypercall.S +++ b/arch/arm/xen/hypercall.S @@ -78,7 +78,6 @@ ENTRY(HYPERVISOR_##hypercall) \ ENDPROC(HYPERVISOR_##hypercall) .text - HYPERCALL2(xen_version); HYPERCALL3(console_io); HYPERCALL3(grant_table_op); @@ -91,6 +90,9 @@ HYPERCALL3(vcpu_op); HYPERCALL1(tmem_op); HYPERCALL2(multicall); +#define __HYPERVISOR_dom0_op_raw __HYPERVISOR_dom0_op /* Hack to allow setting interface version from C wrapper */ +HYPERCALL1(dom0_op_raw);/*XXX legacy name for what is now platform_op, used by x86 too*/ + ENTRY(privcmd_call) stmdb sp!, {r4} mov r12, r0 -- 1.7.10.4