All of lore.kernel.org
 help / color / mirror / Atom feed
From: Wei Liu <wl@xen.org>
To: Xen Development List <xen-devel@lists.xenproject.org>
Cc: "Wei Liu" <liuwe@microsoft.com>, "Wei Liu" <wl@xen.org>,
	"Paul Durrant" <paul@xen.org>,
	"Andrew Cooper" <andrew.cooper3@citrix.com>,
	"Paul Durrant" <pdurrant@amazon.com>,
	"Michael Kelley" <mikelley@microsoft.com>,
	"Jan Beulich" <jbeulich@suse.com>,
	"Roger Pau Monné" <roger.pau@citrix.com>
Subject: [Xen-devel] [PATCH 3/4] x86: provide and use hv_tsc_scale
Date: Fri, 20 Dec 2019 19:51:34 +0000	[thread overview]
Message-ID: <20191220195135.20130-4-liuwe@microsoft.com> (raw)
In-Reply-To: <20191220195135.20130-1-liuwe@microsoft.com>

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 <liuwe@microsoft.com>
---
 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/time.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 @@
 
 #include <asm/apic.h>
 #include <asm/event.h>
+#include <asm/guest/hyperv.h>
 #include <asm/guest/hyperv-tlfs.h>
 #include <asm/hvm/support.h>
 
@@ -82,33 +83,6 @@ static void update_reference_tsc(const struct domain *d, bool initialize)
     p->tsc_sequence = seq;
 }
 
-/*
- * The specification says: "The partition reference time is computed
- * by the following formula:
- *
- * ReferenceTime = ((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), "=d" (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 = hvm_get_guest_tsc(pt_global_vcpu_target(d));
     scale = ((10000ul << 32) / d->arch.tsc_khz) << 32;
 
-    return scale_tsc(tsc, scale, offset);
+    return hv_scale_tsc(tsc, scale, offset);
 }
 
 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)
 
     } while ( tsc_page->tsc_sequence != seq );
 
-    /* ret = ((tsc * scale) >> 64) + offset; */
-    asm ( "mul %[scale]; add %[offset], %[ret]"
-          : "+a" (tsc), [ret] "=&d" (ret)
-          : [scale] "rm" (scale), [offset] "rm" (offset) );
-
-    return ret;
+    return hv_scale_tsc(tsc, scale, offset);
 }
 
 static struct platform_timesource __initdata plt_hyperv_timer =
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__
 
-#ifdef CONFIG_HYPERV_GUEST
-
 #include <xen/types.h>
 
+/*
+ * The specification says: "The partition reference time is computed
+ * by the following formula:
+ *
+ * ReferenceTime = ((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), "=d" (result)
+          : [scale] "rm" (scale) );
+
+    return result + offset;
+}
+
+#ifdef CONFIG_HYPERV_GUEST
+
 #include <asm/guest/hypervisor.h>
 
 struct ms_hyperv_info {
-- 
2.20.1


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

  parent reply	other threads:[~2019-12-20 19:52 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-20 19:51 [Xen-devel] [PATCH 0/4] Clean up viridian code Wei Liu
2019-12-20 19:51 ` [Xen-devel] [PATCH 1/4] x86/viridian: drop duplicate defines from private.h and viridian.c Wei Liu
2019-12-21 12:19   ` Durrant, Paul
2019-12-20 19:51 ` [Xen-devel] [PATCH 2/4] x86/viridian: drop private copy of HV_REFERENCE_TSC_PAGE in time.c Wei Liu
2019-12-21 12:20   ` Durrant, Paul
2019-12-20 19:51 ` Wei Liu [this message]
2019-12-21 12:27   ` [Xen-devel] [PATCH 3/4] x86: provide and use hv_tsc_scale Durrant, Paul
2019-12-20 19:51 ` [Xen-devel] [PATCH 4/4] x86: move viridian_guest_os_id_msr to hyperv-tlfs.h Wei Liu
2019-12-21 12:28   ` Durrant, Paul
2019-12-20 21:21 ` [Xen-devel] [PATCH 5/4] x86/viridian: drop a wrong invalid value from reference TSC implementation Wei Liu
2019-12-21 12:06   ` Durrant, Paul

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191220195135.20130-4-liuwe@microsoft.com \
    --to=wl@xen.org \
    --cc=andrew.cooper3@citrix.com \
    --cc=jbeulich@suse.com \
    --cc=liuwe@microsoft.com \
    --cc=mikelley@microsoft.com \
    --cc=paul@xen.org \
    --cc=pdurrant@amazon.com \
    --cc=roger.pau@citrix.com \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.