From patchwork Mon Dec 28 16:59:45 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joao Martins X-Patchwork-Id: 7926801 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 878879F350 for ; Mon, 28 Dec 2015 17:03:00 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B52D220251 for ; Mon, 28 Dec 2015 17:02:59 +0000 (UTC) Received: from lists.xen.org (lists.xenproject.org [50.57.142.19]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CCA542024D for ; Mon, 28 Dec 2015 17:02:58 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aDb9k-0008G7-KI; Mon, 28 Dec 2015 17:00:24 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aDb9j-0008Et-Ea for xen-devel@lists.xen.org; Mon, 28 Dec 2015 17:00:23 +0000 Received: from [85.158.139.211] by server-2.bemta-5.messagelabs.com id 3D/5F-31450-6AA61865; Mon, 28 Dec 2015 17:00:22 +0000 X-Env-Sender: joao.m.martins@oracle.com X-Msg-Ref: server-9.tower-206.messagelabs.com!1451322020!13016682!1 X-Originating-IP: [156.151.31.81] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTU2LjE1MS4zMS44MSA9PiAyODgzMzk=\n X-StarScan-Received: X-StarScan-Version: 7.35.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 22389 invoked from network); 28 Dec 2015 17:00:22 -0000 Received: from userp1040.oracle.com (HELO userp1040.oracle.com) (156.151.31.81) by server-9.tower-206.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 28 Dec 2015 17:00:22 -0000 Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id tBSH0J3b021029 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Mon, 28 Dec 2015 17:00:19 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0022.oracle.com (8.13.8/8.13.8) with ESMTP id tBSH0Inw000997 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Mon, 28 Dec 2015 17:00:18 GMT Received: from abhmp0006.oracle.com (abhmp0006.oracle.com [141.146.116.12]) by aserv0122.oracle.com (8.13.8/8.13.8) with ESMTP id tBSH0Ivo013842; Mon, 28 Dec 2015 17:00:18 GMT Received: from paddy.lan (/85.245.89.156) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 28 Dec 2015 09:00:18 -0800 From: Joao Martins To: xen-devel@lists.xen.org Date: Mon, 28 Dec 2015 16:59:45 +0000 Message-Id: <1451321985-13728-7-git-send-email-joao.m.martins@oracle.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1451321985-13728-1-git-send-email-joao.m.martins@oracle.com> References: <1451321985-13728-1-git-send-email-joao.m.martins@oracle.com> X-Source-IP: userv0022.oracle.com [156.151.31.74] Cc: Andrew Cooper , Joao Martins , Keir Fraser , Jan Beulich Subject: [Xen-devel] [PATCH RFC 6/6] x86/time: convert counter to tsc for non-tsc clocksource X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This commit is an attempt at suporting PVCLOCK_TSC_STABLE_BIT when using other clocksources. master_tsc_stamp is set by converting master_stime (returned from read_platform_stime()) and converting it to a TSC by scaling the ns value accordingly. We scale the system time if TSC is reliable, and under the assumption there is a considerable skew between platform timer and TSC. In my machine I was measuring between -15 and 40 us between HPET and TSC. Signed-off-by: Joao Martins --- xen/arch/x86/time.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/xen/arch/x86/time.c b/xen/arch/x86/time.c index e623891..fa5f948 100644 --- a/xen/arch/x86/time.c +++ b/xen/arch/x86/time.c @@ -910,7 +910,7 @@ static void __update_vcpu_system_time(struct vcpu *v, int force) _u.tsc_timestamp = tsc_stamp; _u.system_time = t->stime_local_stamp; - if ( clocksource_is_tsc ) + if ( clocksource_is_tsc || host_tsc_is_safe() ) _u.flags |= PVCLOCK_TSC_STABLE_BIT; if ( is_hvm_domain(d) ) @@ -1378,6 +1378,15 @@ static void time_calibration_std_rendezvous(void *_r) r->master_stime = read_platform_stime(&last_counter); if ( clocksource_is_tsc ) r->master_tsc_stamp = last_counter; + else if ( host_tsc_is_safe() ) + { + struct cpu_time *t = &this_cpu(cpu_time); + struct time_scale plt_scale_r = + scale_reciprocal(t->tsc_scale); + + r->master_tsc_stamp = scale_delta(r->master_stime, + &plt_scale_r); + } mb(); /* write r->master_stime /then/ signal */ atomic_inc(&r->semaphore); } @@ -1389,7 +1398,7 @@ static void time_calibration_std_rendezvous(void *_r) mb(); /* receive signal /then/ read r->master_stime */ } - if ( clocksource_is_tsc ) + if ( clocksource_is_tsc || host_tsc_is_safe() ) c->local_tsc_stamp = r->master_tsc_stamp; else c->local_tsc_stamp = rdtsc();