Received: by 10.223.176.46 with SMTP id f43csp746473wra; Wed, 24 Jan 2018 05:25:13 -0800 (PST) X-Google-Smtp-Source: AH8x225vcKFUoKK70YdsywqrS34m8gICXIYCuF+bGvYVWcfol3w74OfumQL7+ww2cdbKZrvynIyL X-Received: by 2002:a17:902:6005:: with SMTP id r5-v6mr8317734plj.307.1516800313321; Wed, 24 Jan 2018 05:25:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516800313; cv=none; d=google.com; s=arc-20160816; b=z5rEvlEIoEmk5un7AeI1H2FE6M+6VMEnf5IV9gCUFYpw/WCSIDinvdMz0OQKRsLlDw pc3eEnMxLLRXQrkw0l7/U/enAs6pPOe5ttRHHCP3mbT09eaqTy17+Ak5+Ol5JZIavgTy DyFq7bfJxZ2TH7cK1CPhRxu//0yZz7H5t/HGd/nRtSOYNYFJnMn9nPlf53sGe8feuPxk pe3wcSjl3sLsEnoSV6OgdunIRIdFvLjHE14lLEmPqq6MSo1Uv26PTk4b8L3fHKDttBmy 0MqaqaANhzI2/uSXN2yJTtXwuT3t6FdNNb+zlUi6i1Di52bVGnTFXOuBRQegOLowNRkg fGnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=i+8Y+INx3qaa+nQPikNBG60O+OhgF4nuwxZCfc3CwnQ=; b=KOQIJUm9M1VbPanSnMuEaVU8LWx8hnyPz+MCk8Q1NJXvc2bMVlZ3FHBIaK2GOkCGI5 AUP9u35o6NF36QsYZHGaYNE8pfxNu4qSXqujj1oZI51Xl5eLTLhzS4dxuUbiZHOkSPnq t67QD0fdKk+Ph1RPs8koUK7LuljJSCt2ptgAjKT0xqjO5Pj3yu8ijmAHXHsflYegyr/b FZ0x6TGDZAPIs4+lduUFD0WS1yXtN1gp6DYX/020w/OpJ2ciDv3TK6RMXWbYM8P26oPb ApP9Domfj/4mb4HDzWWcUZ0y71eTTEEWhfmGDbq2nQSbEjUPzXCNH1OAkqmgJ1WeIoUV dPHg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z75si2914150pfd.119.2018.01.24.05.24.59; Wed, 24 Jan 2018 05:25:13 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933886AbeAXNYC (ORCPT + 99 others); Wed, 24 Jan 2018 08:24:02 -0500 Received: from mx1.redhat.com ([209.132.183.28]:38700 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933613AbeAXNYA (ORCPT ); Wed, 24 Jan 2018 08:24:00 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D3979C056870; Wed, 24 Jan 2018 13:23:59 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.43.2.155]) by smtp.corp.redhat.com (Postfix) with ESMTP id DD5F47A02F; Wed, 24 Jan 2018 13:23:52 +0000 (UTC) From: Vitaly Kuznetsov To: kvm@vger.kernel.org, x86@kernel.org Cc: Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , "Michael Kelley (EOSG)" , Andy Lutomirski , Mohammed Gamal , Cathy Avery , Roman Kagan , linux-kernel@vger.kernel.org, devel@linuxdriverproject.org Subject: [PATCH v4 2/7] x86/hyper-v: add a function to read both TSC and TSC page value simulateneously Date: Wed, 24 Jan 2018 14:23:32 +0100 Message-Id: <20180124132337.30138-3-vkuznets@redhat.com> In-Reply-To: <20180124132337.30138-1-vkuznets@redhat.com> References: <20180124132337.30138-1-vkuznets@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Wed, 24 Jan 2018 13:23:59 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is going to be used from KVM code where we need to get both TSC and TSC page value. Nobody is supposed to use the function when Hyper-V code is compiled out, just BUG(). Signed-off-by: Vitaly Kuznetsov --- arch/x86/hyperv/hv_init.c | 1 + arch/x86/include/asm/mshyperv.h | 23 +++++++++++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c index 21f9d53d9f00..1a6c63f721bc 100644 --- a/arch/x86/hyperv/hv_init.c +++ b/arch/x86/hyperv/hv_init.c @@ -37,6 +37,7 @@ struct ms_hyperv_tsc_page *hv_get_tsc_page(void) { return tsc_pg; } +EXPORT_SYMBOL_GPL(hv_get_tsc_page); static u64 read_hv_clock_tsc(struct clocksource *arg) { diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h index 8bf450b13d9f..6b1d4ea78270 100644 --- a/arch/x86/include/asm/mshyperv.h +++ b/arch/x86/include/asm/mshyperv.h @@ -325,9 +325,10 @@ static inline void hyperv_setup_mmu_ops(void) {} #ifdef CONFIG_HYPERV_TSCPAGE struct ms_hyperv_tsc_page *hv_get_tsc_page(void); -static inline u64 hv_read_tsc_page(const struct ms_hyperv_tsc_page *tsc_pg) +static inline u64 hv_read_tsc_page_tsc(const struct ms_hyperv_tsc_page *tsc_pg, + u64 *cur_tsc) { - u64 scale, offset, cur_tsc; + u64 scale, offset; u32 sequence; /* @@ -358,7 +359,7 @@ static inline u64 hv_read_tsc_page(const struct ms_hyperv_tsc_page *tsc_pg) scale = READ_ONCE(tsc_pg->tsc_scale); offset = READ_ONCE(tsc_pg->tsc_offset); - cur_tsc = rdtsc_ordered(); + *cur_tsc = rdtsc_ordered(); /* * Make sure we read sequence after we read all other values @@ -368,7 +369,14 @@ static inline u64 hv_read_tsc_page(const struct ms_hyperv_tsc_page *tsc_pg) } while (READ_ONCE(tsc_pg->tsc_sequence) != sequence); - return mul_u64_u64_shr(cur_tsc, scale, 64) + offset; + return mul_u64_u64_shr(*cur_tsc, scale, 64) + offset; +} + +static inline u64 hv_read_tsc_page(const struct ms_hyperv_tsc_page *tsc_pg) +{ + u64 cur_tsc; + + return hv_read_tsc_page_tsc(tsc_pg, &cur_tsc); } #else @@ -376,5 +384,12 @@ static inline struct ms_hyperv_tsc_page *hv_get_tsc_page(void) { return NULL; } + +static inline u64 hv_read_tsc_page_tsc(const struct ms_hyperv_tsc_page *tsc_pg, + u64 *cur_tsc) +{ + BUG(); + return U64_MAX; +} #endif #endif -- 2.14.3