From nobody Mon May 6 21:38:45 2024 Delivered-To: importer@patchew.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; dmarc=fail(p=none dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1576771450; cv=none; d=zohomail.com; s=zohoarc; b=Br0BN7xz4+n4RqvlTQd7QKt59gRGIeZUkoa9otdNvi+jc/kTp1sxJLbyGHlhsQitChh6RPp9znjZZPnzn/VcRktOdfiT8ugez3hHtgaF3eJPgppXo+RlfuAlIyUrcPDE7eRY4zDIxHcCtUBEa1XWlDk07RYSYkmO0ucwr9wgf3s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576771450; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=wiMueOc8/KEP0Eua8Mgcf5QBs/6LuH57ZOolgas3eKM=; b=c8CQMIQPI+GFGb70sbiKOuhraWA2N/dsXYtZkLhdRsk/c7jYSPOuoqK6AwnQyHtMsO/0Ed0py2Y9YmhvsdzZGtuHWbm2t6OvIpBKybXCXJhdQfgcZ8E+8jg7pC9g1CqqhUYdUoe1ymYgWLjoNdbxpSpQQKqju+IHAouetTL74DA= 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; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1576771450944371.33858953140714; Thu, 19 Dec 2019 08:04:10 -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 1ihyH1-0006iT-M8; Thu, 19 Dec 2019 16:03:35 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ihyH0-0006iJ-Kh for xen-devel@lists.xenproject.org; Thu, 19 Dec 2019 16:03:34 +0000 Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 164e12d4-2279-11ea-a1e1-bc764e2007e4; Thu, 19 Dec 2019 16:03:25 +0000 (UTC) X-Inumbo-ID: 164e12d4-2279-11ea-a1e1-bc764e2007e4 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1576771406; h=from:to:cc:subject:date:message-id:mime-version; bh=PjMrQre1Cj9Xz8rjwAVg9EjtRp2Z5C8/u7DGgz04HDg=; b=RpzSGnRKqdRKIYUIbS29AXyYja/iZwuHrJh2PFZnYhnwGnC+6UFOao41 cGsjVewBIM42Iq83ta8pCQnPw2ak4TFlmtVRnEoFxOKUgjdSziVDM8H9C ud9JUsQU2nLY3bGswcBLoFYTC0JPukoLco0rhKuSLW0vJhsFnAkCiQqJ2 8=; Authentication-Results: esa1.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=igor.druzhinin@citrix.com; spf=Pass smtp.mailfrom=igor.druzhinin@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com 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; Received-SPF: None (esa1.hc3370-68.iphmx.com: no sender authenticity information available from domain of igor.druzhinin@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="igor.druzhinin@citrix.com"; x-sender="igor.druzhinin@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa1.hc3370-68.iphmx.com: domain of igor.druzhinin@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="igor.druzhinin@citrix.com"; x-sender="igor.druzhinin@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ip4:168.245.78.127 ~all" Received-SPF: None (esa1.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="igor.druzhinin@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: kLXDOWm1ICA7NBShFw8DKsqelSd2Fzuk9FGlakKHPIcWz8vX+bwC1zz9avTb40KnPtnmUvwjcA GQ36Mg9CFUK8zBzJ6ieAmXG4GpyYWjNH9EaO/sGDRvcgCBZ3I+mIVe/QA7O5Sx/Mzn2r6TPan4 JUOt6dcSQcoS05MZ1bXuBWdeajSm4djcmuicnsDCnduLgNhita9OM3MrXtpkPGd8CfJkNYV5iG 1+NfwTvtVssXGAI4kPLTiG5ehKUygzN3fZnDLztGrgGhni1m6JCXcudkuPS3Kfp59Wc+J3lwLP 6/Y= X-SBRS: 2.7 X-MesageID: 10090357 X-Ironport-Server: esa1.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.69,332,1571716800"; d="scan'208";a="10090357" From: Igor Druzhinin To: Date: Thu, 19 Dec 2019 16:03:19 +0000 Message-ID: <1576771399-14654-1-git-send-email-igor.druzhinin@citrix.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v2] x86/time: update vtsc_last with cmpxchg and drop vtsc_lock 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: andrew.cooper3@citrix.com, Igor Druzhinin , wl@xen.org, jbeulich@suse.com, roger.pau@citrix.com 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) Now that vtsc_last is the only entity protected by vtsc_lock we can simply update it using a single atomic operation and drop the spinlock entirely. This is extremely important for the case of running nested (e.g. shim instance with lots of vCPUs assigned) since if preemption happens somewhere inside the critical section that would immediately mean that other vCPU stop progressing (and probably being preempted as well) waiting for the spinlock to be freed. This fixes constant shim guest boot lockups with ~32 vCPUs if there is vCPU overcommit present (which increases the likelihood of preemption). Signed-off-by: Igor Druzhinin Reviewed-by: Jan Beulich --- v2: simplify the condition as suggested --- xen/arch/x86/domain.c | 1 - xen/arch/x86/time.c | 16 ++++++---------- xen/include/asm-x86/domain.h | 1 - 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index 7cb7fd3..d9c6337 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -539,7 +539,6 @@ int arch_domain_create(struct domain *d, INIT_PAGE_LIST_HEAD(&d->arch.relmem_list); =20 spin_lock_init(&d->arch.e820_lock); - spin_lock_init(&d->arch.vtsc_lock); =20 /* Minimal initialisation for the idle domain. */ if ( unlikely(is_idle_domain(d)) ) diff --git a/xen/arch/x86/time.c b/xen/arch/x86/time.c index 216169a..63dd5a2 100644 --- a/xen/arch/x86/time.c +++ b/xen/arch/x86/time.c @@ -2130,19 +2130,15 @@ u64 gtsc_to_gtime(struct domain *d, u64 tsc) =20 uint64_t pv_soft_rdtsc(const struct vcpu *v, const struct cpu_user_regs *r= egs) { - s_time_t now =3D get_s_time(); + s_time_t old, new, now =3D get_s_time(); struct domain *d =3D v->domain; =20 - spin_lock(&d->arch.vtsc_lock); - - if ( (int64_t)(now - d->arch.vtsc_last) > 0 ) - d->arch.vtsc_last =3D now; - else - now =3D ++d->arch.vtsc_last; - - spin_unlock(&d->arch.vtsc_lock); + do { + old =3D d->arch.vtsc_last; + new =3D now > d->arch.vtsc_last ? now : old + 1; + } while ( cmpxchg(&d->arch.vtsc_last, old, new) !=3D old ); =20 - return gtime_to_gtsc(d, now); + return gtime_to_gtsc(d, new); } =20 bool clocksource_is_tsc(void) diff --git a/xen/include/asm-x86/domain.h b/xen/include/asm-x86/domain.h index 3780287..e4da373 100644 --- a/xen/include/asm-x86/domain.h +++ b/xen/include/asm-x86/domain.h @@ -364,7 +364,6 @@ struct arch_domain int tsc_mode; /* see include/asm-x86/time.h */ bool_t vtsc; /* tsc is emulated (may change after migrate)= */ s_time_t vtsc_last; /* previous TSC value (guarantee monotonicity= ) */ - spinlock_t vtsc_lock; uint64_t vtsc_offset; /* adjustment for save/restore/migrate */ uint32_t tsc_khz; /* cached guest khz for certain emulated or hardware TSC scaling cases */ --=20 2.7.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel