From patchwork Wed Aug 24 12:43:50 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joao Martins X-Patchwork-Id: 9297619 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 9332360757 for ; Wed, 24 Aug 2016 12:44:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8480A27F10 for ; Wed, 24 Aug 2016 12:44:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 795D32858E; Wed, 24 Aug 2016 12:44:55 +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 2D7B227F10 for ; Wed, 24 Aug 2016 12:44:54 +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 1bcXW8-0000Al-KL; Wed, 24 Aug 2016 12:42:52 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bcXW7-00009I-1U for xen-devel@lists.xenproject.org; Wed, 24 Aug 2016 12:42:51 +0000 Received: from [85.158.137.68] by server-6.bemta-3.messagelabs.com id 97/9F-28813-A469DB75; Wed, 24 Aug 2016 12:42:50 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrLLMWRWlGSWpSXmKPExsUyZ7p8oK7ntL3 hBpO/6Fh83zKZyYHR4/CHKywBjFGsmXlJ+RUJrBkHZj9jKlgiU3Fz9mrmBsY7Yl2MXBxCAhOZ JJ727mWCcL4xStzY8IEVwtnIKHHp+x0op5FR4u+pZ8xdjJwcbAJ6Eq3nP4PZIgJKEvdWTWYCs ZkF/CSadh1gBbGFBRwk5s/8yw5iswioSsyac5URxOYV8JRYMW0VWK+EgJzE+eM/wWxOAS+JW0 e+sYDYQkA1y9ZsYIWoMZT4vHEp8wRGvgWMDKsYNYpTi8pSi3QNDfSSijLTM0pyEzNzgDxjvdz U4uLE9NScxKRiveT83E2MwGCpZ2Bg3MG4rcv5EKMkB5OSKG94095wIb6k/JTKjMTijPii0pzU 4kOMMhwcShK8x6YA5QSLUtNTK9Iyc4BhC5OW4OBREuHtBknzFhck5hZnpkOkTjEqSonzvgFJC IAkMkrz4NpgsXKJUVZKmJeRgYFBiKcgtSg3swRV/hWjOAejkjDvf5ApPJl5JXDTXwEtZgJa3H J/N8jikkSElFQD40T3tnlG06I1ZdP/fVniKtvlnMk4P//bosNL+2ba7nzgNfP8W4+QnwKvA98 76vWzKNcUfvbZ9OYHW3xmQOQ0wwsPTywWEm1aJB6/oPX3S+/ktLDjb9OOvjkxIZS5a7GZ4834 CV/SVoZ/19C/sXHS1GU2KbfFD0st5mhcvpFl+70bEy47rrusNV+JpTgj0VCLuag4EQALQkq+k AIAAA== X-Env-Sender: joao.m.martins@oracle.com X-Msg-Ref: server-7.tower-31.messagelabs.com!1472042567!49610579!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: 8.84; banners=-,-,- X-VirusChecked: Checked Received: (qmail 34063 invoked from network); 24 Aug 2016 12:42:49 -0000 Received: from userp1040.oracle.com (HELO userp1040.oracle.com) (156.151.31.81) by server-7.tower-31.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 24 Aug 2016 12:42:49 -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 u7OCgkv1026543 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 24 Aug 2016 12:42:46 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userv0022.oracle.com (8.14.4/8.13.8) with ESMTP id u7OCgjJg002471 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 24 Aug 2016 12:42:46 GMT Received: from abhmp0016.oracle.com (abhmp0016.oracle.com [141.146.116.22]) by aserv0121.oracle.com (8.13.8/8.13.8) with ESMTP id u7OCgiUW016502; Wed, 24 Aug 2016 12:42:45 GMT Received: from paddy.lan (/89.114.92.174) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 24 Aug 2016 05:42:44 -0700 From: Joao Martins To: xen-devel@lists.xenproject.org Date: Wed, 24 Aug 2016 13:43:50 +0100 Message-Id: <1472042632-12883-5-git-send-email-joao.m.martins@oracle.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1472042632-12883-1-git-send-email-joao.m.martins@oracle.com> References: <1472042632-12883-1-git-send-email-joao.m.martins@oracle.com> X-Source-IP: userv0022.oracle.com [156.151.31.74] Cc: Andrew Cooper , Jan Beulich Subject: [Xen-devel] [PATCH v3 4/6] 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 fetch the last read from the clocksource which was used to calculate system_time. In the case of clocksource=tsc we will use it to set tsc_timestamp. Signed-off-by: Joao Martins --- Cc: Jan Beulich Cc: Andrew Cooper Changes since v2: - s/plt_stamp_counter/plt_counter/g - Move conditional write of stamp out of the locked region. Changes since v1: - Add missing spaces between brackets - Move plt_stamp_counter to read_platform_stime() - Add signature change in time_calibration_std_rendezvous() --- 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 a03127e..57c1b47 100644 --- a/xen/arch/x86/time.c +++ b/xen/arch/x86/time.c @@ -575,18 +575,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 ( stamp ) + *stamp = plt_counter; + return stime; } @@ -731,7 +735,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))); } /*************************************************************************** @@ -1050,7 +1054,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);*/ @@ -1355,7 +1359,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); @@ -1395,7 +1399,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); } @@ -1434,7 +1438,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); @@ -1452,7 +1456,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);