From nobody Mon Feb 9 10:28:20 2026 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1576871545; cv=none; d=zohomail.com; s=zohoarc; b=M2gij8PTl2IgQLelmzubLo1ZSVzFMRagrqfVlhCe+L+miXJrDQag04CIW0JTepdfAcCNyderkoTVeUi3U6LXCoZhWTh8LNFXXOSC6J90awghhWYDMgruPTAHMWCdcgA7gMYfrTI8zNvzKLYKhy4/opVsrCwoD90nJQ+GoJd4LnE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576871545; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=qKznf90w5/CAEjBGYPk9F7qGa4isGbXpJlq6lC4oI1o=; b=PgbMdsj1ziDJ0V4IG2VuggkPPm02OyFhQYhrCnWGcXvWh78uSvZ1cIxoLyIan5Zvo7SGmAuPP43sdAuZhbrmMVaCYAFmjly2fPc5UjIUYcezb5HegwOl/gy/6Nf7o1pFCbHOouN9mu50rMuFY148ZupKmLwuHnNWQrLoztzalcY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1576871545166741.7102299140084; Fri, 20 Dec 2019 11:52:25 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iiOJY-0005Fv-3M; Fri, 20 Dec 2019 19:51:56 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iiOJX-0005Fb-Cv for xen-devel@lists.xenproject.org; Fri, 20 Dec 2019 19:51:55 +0000 Received: from mail-wm1-x344.google.com (unknown [2a00:1450:4864:20::344]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 24fbc5b2-2362-11ea-88e7-bc764e2007e4; Fri, 20 Dec 2019 19:51:42 +0000 (UTC) Received: by mail-wm1-x344.google.com with SMTP id 20so10285717wmj.4 for ; Fri, 20 Dec 2019 11:51:42 -0800 (PST) Received: from debian.mshome.net (38.163.200.146.dyn.plus.net. [146.200.163.38]) by smtp.gmail.com with ESMTPSA id a184sm11006287wmf.29.2019.12.20.11.51.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2019 11:51:41 -0800 (PST) X-Inumbo-ID: 24fbc5b2-2362-11ea-88e7-bc764e2007e4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=oKZN/wLj0zIyBHSMJP0Pr97AVDWgdWD3HmHzj4XKRDM=; b=R2e3vhA2BVf38bNkDC6p5fSZQ1YgryIIrrdeontJZhXR+oH6o45aWQD/7wVKjePDRs 7oHJ2bX8wJCc9yN1N4CySxL17vFky85X8+aJSOhsMchENgfnXrS4WbBUHOACflse+u3/ pnBRritcowdJD2qZxSe4hocth4vZdpKxAauBxpPl0+9+rpnmtmI3vHlk5rFluqlfHPnA MggJco25FflczTkgWm6Dn9kC/QCw2BHhfRLR2Z5jDAXp6ANcekfQGKZ+tIX9TDA2K4xD WzbOGwOLzbPK0BwNJwqV4fEtLwMREpev1skMhOwn4gf50umQY1IN/TNMleszyM0+qOne vsVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=oKZN/wLj0zIyBHSMJP0Pr97AVDWgdWD3HmHzj4XKRDM=; b=G2+spj4VS1qAJge7WSVnZ/zW0CwxOF0z1EKONz6Avtq5udZzMlv8bT4WCeeowvEehd jdzUgw8XUlho+soGMDItVh+V6fNtlNo500h5oFv+v4v4fTrUMfCl0CuTIVA0t1VYXhZE 3vFZsE180uVVpSN0vNBE7I0LviqyXxdYMVPCv0WdvVHMjrpUBzmRuP4FX6Zrk3iWAnh4 0X27x+tPq8DE+5w9pqSIIWksUmLRVAOrzmMkB3xeogWJkTUTClWkbO6cblIq7LsE6GLY VjcPJUr9aVGxzCCPM3ybegTavOpPkRRj0//vYxNKWLzgHK2Hmb8Rnvi9BOoO9DXXKBkN HEIg== X-Gm-Message-State: APjAAAWbm1MXvJcFJEzhCEy8A8Q+5BnN/8ewZdu3H79QRD+w896wHuz2 KJIGFcYK4+0CHc4CtKo3/mGCOOBc X-Google-Smtp-Source: APXvYqyiPoHMqqFFG4lo8fAXsnK4k2XGj80fQ+TcMt3BZ4QyheBROn3xcy/1YV8NkgvZbfYR3PLbXw== X-Received: by 2002:a05:600c:2046:: with SMTP id p6mr18442661wmg.110.1576871501709; Fri, 20 Dec 2019 11:51:41 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Fri, 20 Dec 2019 19:51:34 +0000 Message-Id: <20191220195135.20130-4-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191220195135.20130-1-liuwe@microsoft.com> References: <20191220195135.20130-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 3/4] x86: provide and use hv_tsc_scale X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Wei Liu , Wei Liu , Paul Durrant , Andrew Cooper , Paul Durrant , Michael Kelley , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) The Hyper-V clock source and Xen's own viridian code need the same functionality. Move the function in viridian/time.c to hyperv.h and use it in both places. No functional change. Signed-off-by: Wei Liu --- xen/arch/x86/hvm/viridian/time.c | 30 ++-------------------------- xen/arch/x86/time.c | 7 +------ xen/include/asm-x86/guest/hyperv.h | 32 ++++++++++++++++++++++++++++-- 3 files changed, 33 insertions(+), 36 deletions(-) diff --git a/xen/arch/x86/hvm/viridian/time.c b/xen/arch/x86/hvm/viridian/t= ime.c index 32e79bbcc4..6b2d745f3a 100644 --- a/xen/arch/x86/hvm/viridian/time.c +++ b/xen/arch/x86/hvm/viridian/time.c @@ -13,6 +13,7 @@ =20 #include #include +#include #include #include =20 @@ -82,33 +83,6 @@ static void update_reference_tsc(const struct domain *d,= bool initialize) p->tsc_sequence =3D seq; } =20 -/* - * The specification says: "The partition reference time is computed - * by the following formula: - * - * ReferenceTime =3D ((VirtualTsc * TscScale) >> 64) + TscOffset - * - * The multiplication is a 64 bit multiplication, which results in a - * 128 bit number which is then shifted 64 times to the right to obtain - * the high 64 bits." - */ -static uint64_t scale_tsc(uint64_t tsc, uint64_t scale, int64_t offset) -{ - uint64_t result; - - /* - * Quadword MUL takes an implicit operand in RAX, and puts the result - * in RDX:RAX. Because we only want the result of the multiplication - * after shifting right by 64 bits, we therefore only need the content - * of RDX. - */ - asm ( "mulq %[scale]" - : "+a" (tsc), "=3Dd" (result) - : [scale] "rm" (scale) ); - - return result + offset; -} - static uint64_t trc_val(const struct domain *d, int64_t offset) { uint64_t tsc, scale; @@ -116,7 +90,7 @@ static uint64_t trc_val(const struct domain *d, int64_t = offset) tsc =3D hvm_get_guest_tsc(pt_global_vcpu_target(d)); scale =3D ((10000ul << 32) / d->arch.tsc_khz) << 32; =20 - return scale_tsc(tsc, scale, offset); + return hv_scale_tsc(tsc, scale, offset); } =20 static void time_ref_count_freeze(const struct domain *d) diff --git a/xen/arch/x86/time.c b/xen/arch/x86/time.c index bbcc9b10b8..d21875de9e 100644 --- a/xen/arch/x86/time.c +++ b/xen/arch/x86/time.c @@ -725,12 +725,7 @@ static inline uint64_t read_hyperv_timer(void) =20 } while ( tsc_page->tsc_sequence !=3D seq ); =20 - /* ret =3D ((tsc * scale) >> 64) + offset; */ - asm ( "mul %[scale]; add %[offset], %[ret]" - : "+a" (tsc), [ret] "=3D&d" (ret) - : [scale] "rm" (scale), [offset] "rm" (offset) ); - - return ret; + return hv_scale_tsc(tsc, scale, offset); } =20 static struct platform_timesource __initdata plt_hyperv_timer =3D diff --git a/xen/include/asm-x86/guest/hyperv.h b/xen/include/asm-x86/guest= /hyperv.h index cc21b9abfc..c7a7f32bd5 100644 --- a/xen/include/asm-x86/guest/hyperv.h +++ b/xen/include/asm-x86/guest/hyperv.h @@ -19,10 +19,38 @@ #ifndef __X86_GUEST_HYPERV_H__ #define __X86_GUEST_HYPERV_H__ =20 -#ifdef CONFIG_HYPERV_GUEST - #include =20 +/* + * The specification says: "The partition reference time is computed + * by the following formula: + * + * ReferenceTime =3D ((VirtualTsc * TscScale) >> 64) + TscOffset + * + * The multiplication is a 64 bit multiplication, which results in a + * 128 bit number which is then shifted 64 times to the right to obtain + * the high 64 bits." + */ +static inline uint64_t hv_scale_tsc(uint64_t tsc, uint64_t scale, + int64_t offset) +{ + uint64_t result; + + /* + * Quadword MUL takes an implicit operand in RAX, and puts the result + * in RDX:RAX. Because we only want the result of the multiplication + * after shifting right by 64 bits, we therefore only need the content + * of RDX. + */ + asm ( "mulq %[scale]" + : "+a" (tsc), "=3Dd" (result) + : [scale] "rm" (scale) ); + + return result + offset; +} + +#ifdef CONFIG_HYPERV_GUEST + #include =20 struct ms_hyperv_info { --=20 2.20.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel