From patchwork Fri Sep 23 10:42:44 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joao Martins X-Patchwork-Id: 9347879 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 77327607D0 for ; Fri, 23 Sep 2016 10:43:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6866C2AB0A for ; Fri, 23 Sep 2016 10:43:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5D3102AB26; Fri, 23 Sep 2016 10:43:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 379492AB19 for ; Fri, 23 Sep 2016 10:43:33 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bnNv4-0007yt-Q7; Fri, 23 Sep 2016 10:41:26 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bnNv3-0007yR-8l for xen-devel@lists.xenproject.org; Fri, 23 Sep 2016 10:41:25 +0000 Received: from [193.109.254.147] by server-11.bemta-6.messagelabs.com id 71/2E-08498-4D605E75; Fri, 23 Sep 2016 10:41:24 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrLLMWRWlGSWpSXmKPExsXSO6nOVfcK29N wg6VbuS2+b5nM5MDocfjDFZYAxijWzLyk/IoE1owDb+cwFrTJVKx4FdHAuEusi5GLQ0hgIpPE oYMLWCGcL4wSjTeesEM4GxklPk3ZxgThNDJKrFveD5Th5GAT0JNoPf+ZGcQWEVCSuLdqMlgRs 0AHo8SX86eYQBLCAg4SPSfmsIDYLAKqEpvX/QJr5hXwkOj51MoGYksIyEmcP/4TbBCngKfEq6 ZPYHEhoJpXL3qYIGoMJT5vXMo8gZFvASPDKkaN4tSistQiXUNLvaSizPSMktzEzBxdQwMzvdz U4uLE9NScxKRiveT83E2MwGBhAIIdjD+WBRxilORgUhLlbdz3JFyILyk/pTIjsTgjvqg0J7X4 EKMMB4eSBO9E1qfhQoJFqempFWmZOcCwhUlLcPAoifBOAUnzFhck5hZnpkOkTjEqSonz+oEkB EASGaV5cG2wWLnEKCslzMsIdIgQT0FqUW5mCar8K0ZxDkYlYd6NIFN4MvNK4Ka/AlrMBLT425 0nIItLEhFSUg2M0QfdXSaevlgeFyFzPGnZu6ZFpQueCmw2W+F9UPWA0MNvH95NNmx4zacwh3l 7unTZGqd5aXNf1Vl+UReayKnTEnrpzPyTBQuyj8d9Kjnex9I67UMMz42V7f8zn5Wun/Gtc+vd ToPLLxabTF8iIbN6f9eH1/ETD5qu9dx0zcGTac/5M1vZNTxSw5VYijMSDbWYi4oTAVTXGT6QA gAA X-Env-Sender: joao.m.martins@oracle.com X-Msg-Ref: server-12.tower-27.messagelabs.com!1474627282!60582208!1 X-Originating-IP: [141.146.126.69] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTQxLjE0Ni4xMjYuNjkgPT4gMjc3MjE4\n X-StarScan-Received: X-StarScan-Version: 8.84; banners=-,-,- X-VirusChecked: Checked Received: (qmail 30396 invoked from network); 23 Sep 2016 10:41:23 -0000 Received: from aserp1040.oracle.com (HELO aserp1040.oracle.com) (141.146.126.69) by server-12.tower-27.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 23 Sep 2016 10:41:23 -0000 Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id u8NAfJhD026755 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 23 Sep 2016 10:41:20 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0022.oracle.com (8.14.4/8.13.8) with ESMTP id u8NAfJ1L012260 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 23 Sep 2016 10:41:19 GMT Received: from abhmp0006.oracle.com (abhmp0006.oracle.com [141.146.116.12]) by userv0121.oracle.com (8.13.8/8.13.8) with ESMTP id u8NAfIbg029750; Fri, 23 Sep 2016 10:41:19 GMT Received: from paddy.lan (/89.114.92.174) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 23 Sep 2016 03:41:18 -0700 From: Joao Martins To: xen-devel@lists.xenproject.org Date: Fri, 23 Sep 2016 11:42:44 +0100 Message-Id: <1474627367-8185-3-git-send-email-joao.m.martins@oracle.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1474627367-8185-1-git-send-email-joao.m.martins@oracle.com> References: <1474627367-8185-1-git-send-email-joao.m.martins@oracle.com> X-Source-IP: userv0022.oracle.com [156.151.31.74] Cc: Andrew Cooper , Joao Martins , Jan Beulich Subject: [Xen-devel] [PATCH v5 2/5] x86/time: refactor read_platform_stime() X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP To allow the caller to fetch the last read from the clocksource which was used to calculate system_time. This is a prerequisite for a subsequent patch that will use this last read. Signed-off-by: Joao Martins Acked-by: Jan Beulich --- Cc: Jan Beulich Cc: Andrew Cooper Changes since v4: - Add unlikely when callers provide a stamp argument - Add Acked-by from Jan Changes since v3: - Add mention of this being a prerequisite to a later patch. --- xen/arch/x86/time.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/xen/arch/x86/time.c b/xen/arch/x86/time.c index 0c1ad45..6305a84 100644 --- a/xen/arch/x86/time.c +++ b/xen/arch/x86/time.c @@ -537,18 +537,22 @@ static void plt_overflow(void *unused) set_timer(&plt_overflow_timer, NOW() + plt_overflow_period); } -static s_time_t read_platform_stime(void) +static s_time_t read_platform_stime(u64 *stamp) { - u64 count; + u64 plt_counter, count; s_time_t stime; ASSERT(!local_irq_is_enabled()); spin_lock(&platform_timer_lock); - count = plt_stamp64 + ((plt_src.read_counter() - plt_stamp) & plt_mask); + plt_counter = plt_src.read_counter(); + count = plt_stamp64 + ((plt_counter - plt_stamp) & plt_mask); stime = __read_platform_stime(count); spin_unlock(&platform_timer_lock); + if ( unlikely(stamp) ) + *stamp = plt_counter; + return stime; } @@ -661,7 +665,7 @@ void cstate_restore_tsc(void) if ( boot_cpu_has(X86_FEATURE_NONSTOP_TSC) ) return; - write_tsc(stime2tsc(read_platform_stime())); + write_tsc(stime2tsc(read_platform_stime(NULL))); } /*************************************************************************** @@ -980,7 +984,7 @@ int cpu_frequency_change(u64 freq) local_irq_disable(); /* Platform time /first/, as we may be delayed by platform_timer_lock. */ - t->stamp.master_stime = read_platform_stime(); + t->stamp.master_stime = read_platform_stime(NULL); curr_tsc = rdtsc_ordered(); /* TSC-extrapolated time may be bogus after frequency change. */ /*t->stamp.local_stime = get_s_time_fixed(curr_tsc);*/ @@ -1285,7 +1289,7 @@ static void time_calibration_tsc_rendezvous(void *_r) if ( r->master_stime == 0 ) { - r->master_stime = read_platform_stime(); + r->master_stime = read_platform_stime(NULL); r->master_tsc_stamp = rdtsc_ordered(); } atomic_inc(&r->semaphore); @@ -1325,7 +1329,7 @@ static void time_calibration_std_rendezvous(void *_r) { while ( atomic_read(&r->semaphore) != (total_cpus - 1) ) cpu_relax(); - r->master_stime = read_platform_stime(); + r->master_stime = read_platform_stime(NULL); smp_wmb(); /* write r->master_stime /then/ signal */ atomic_inc(&r->semaphore); } @@ -1364,7 +1368,7 @@ void time_latch_stamps(void) unsigned long flags; local_irq_save(flags); - ap_bringup_ref.master_stime = read_platform_stime(); + ap_bringup_ref.master_stime = read_platform_stime(NULL); ap_bringup_ref.local_tsc = rdtsc_ordered(); local_irq_restore(flags); @@ -1382,7 +1386,7 @@ void init_percpu_time(void) t->tsc_scale = per_cpu(cpu_time, 0).tsc_scale; local_irq_save(flags); - now = read_platform_stime(); + now = read_platform_stime(NULL); tsc = rdtsc_ordered(); local_irq_restore(flags);