All of lore.kernel.org
 help / color / mirror / Atom feed
* [Xen-devel] [PATCH] x86/vpt: update last_guest_time with cmpxchg and drop pl_time_lock
@ 2019-12-20 21:39 Igor Druzhinin
  2020-02-18 17:00 ` Jan Beulich
  2020-02-19  7:48 ` Jan Beulich
  0 siblings, 2 replies; 9+ messages in thread
From: Igor Druzhinin @ 2019-12-20 21:39 UTC (permalink / raw)
  To: xen-devel; +Cc: andrew.cooper3, Igor Druzhinin, wl, jbeulich, roger.pau

Similarly to PV vTSC emulation, optimize HVM side for consistency
and scalability by dropping a spinlock protecting a single variable.

Signed-off-by: Igor Druzhinin <igor.druzhinin@citrix.com>
---
 xen/arch/x86/hvm/vpt.c        | 19 ++++++++-----------
 xen/include/asm-x86/hvm/vpt.h |  5 ++---
 2 files changed, 10 insertions(+), 14 deletions(-)

diff --git a/xen/arch/x86/hvm/vpt.c b/xen/arch/x86/hvm/vpt.c
index ecd25d7..bf4c432 100644
--- a/xen/arch/x86/hvm/vpt.c
+++ b/xen/arch/x86/hvm/vpt.c
@@ -30,7 +30,6 @@ void hvm_init_guest_time(struct domain *d)
 {
     struct pl_time *pl = d->arch.hvm.pl_time;
 
-    spin_lock_init(&pl->pl_time_lock);
     pl->stime_offset = -(u64)get_s_time();
     pl->last_guest_time = 0;
 }
@@ -38,24 +37,22 @@ void hvm_init_guest_time(struct domain *d)
 uint64_t hvm_get_guest_time_fixed(const struct vcpu *v, uint64_t at_tsc)
 {
     struct pl_time *pl = v->domain->arch.hvm.pl_time;
-    u64 now;
+    s_time_t old, new, now = get_s_time_fixed(at_tsc) + pl->stime_offset;
 
     /* Called from device models shared with PV guests. Be careful. */
     ASSERT(is_hvm_vcpu(v));
 
-    spin_lock(&pl->pl_time_lock);
-    now = get_s_time_fixed(at_tsc) + pl->stime_offset;
-
     if ( !at_tsc )
     {
-        if ( (int64_t)(now - pl->last_guest_time) > 0 )
-            pl->last_guest_time = now;
-        else
-            now = ++pl->last_guest_time;
+        do {
+            old = pl->last_guest_time;
+            new = now > pl->last_guest_time ? now : old + 1;
+        } while ( cmpxchg(&pl->last_guest_time, old, new) != old );
     }
-    spin_unlock(&pl->pl_time_lock);
+    else
+        new = now;
 
-    return now + v->arch.hvm.stime_offset;
+    return new + v->arch.hvm.stime_offset;
 }
 
 void hvm_set_guest_time(struct vcpu *v, u64 guest_time)
diff --git a/xen/include/asm-x86/hvm/vpt.h b/xen/include/asm-x86/hvm/vpt.h
index 99169dd..f5ccb49 100644
--- a/xen/include/asm-x86/hvm/vpt.h
+++ b/xen/include/asm-x86/hvm/vpt.h
@@ -135,10 +135,9 @@ struct pl_time {    /* platform time */
     struct HPETState vhpet;
     struct PMTState  vpmt;
     /* guest_time = Xen sys time + stime_offset */
-    int64_t stime_offset;
+    s_time_t stime_offset;
     /* Ensures monotonicity in appropriate timer modes. */
-    uint64_t last_guest_time;
-    spinlock_t pl_time_lock;
+    s_time_t last_guest_time;
     struct domain *domain;
 };
 
-- 
2.7.4


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

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2020-02-20 16:08 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-20 21:39 [Xen-devel] [PATCH] x86/vpt: update last_guest_time with cmpxchg and drop pl_time_lock Igor Druzhinin
2020-02-18 17:00 ` Jan Beulich
2020-02-18 17:06   ` Igor Druzhinin
2020-02-19  7:48 ` Jan Beulich
2020-02-19 18:52   ` Igor Druzhinin
2020-02-20  8:27     ` Jan Beulich
2020-02-20 15:37       ` Igor Druzhinin
2020-02-20 15:47         ` Jan Beulich
2020-02-20 16:08           ` Igor Druzhinin

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.