From nobody Mon Apr 29 05:58:09 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=1576878019; cv=none; d=zohomail.com; s=zohoarc; b=PkDtpm950wxJ/P9ctQfvK99A5Vq+PDstI+qj+l4W0UcLQ0fybGX4+kh4XBWGu3LhE9IAvCNWhKmf2mW7b1zfu5w1rXTggz+EAu012uyBGv36uKoTPUWmr2rXtHoWaFW/ixK8WRwnFWPh5a84ry2CkpJyEEqtkqxeb2ANhvYq2Rc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576878019; 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=b8RUKafSktcteGo4XJpYeriO7ODsGUW/vgmxULQxrVQ=; b=GMNDxCFpqXQCIohWvCoynbtTlqXwcvwvnRPJoXp8YvWY85q3NVQ96T42fpU69jsV03gr092JeAcGQSW1dLxh/GKi1Wp3BboBWPoJ4IYw45FV5tCoCC7CoFjrDN75KXIVVMxeRQ62Lb+0yYi2kDVgF0Fp2SCl2xcWkhQsefEVLbo= 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 1576878019210539.9556841280735; Fri, 20 Dec 2019 13:40:19 -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 1iiPzj-0005ry-US; Fri, 20 Dec 2019 21:39: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 1iiPzi-0005rt-Ff for xen-devel@lists.xenproject.org; Fri, 20 Dec 2019 21:39:34 +0000 Received: from esa6.hc3370-68.iphmx.com (unknown [216.71.155.175]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 312bb432-2371-11ea-88e7-bc764e2007e4; Fri, 20 Dec 2019 21:39:25 +0000 (UTC) X-Inumbo-ID: 312bb432-2371-11ea-88e7-bc764e2007e4 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1576877965; h=from:to:cc:subject:date:message-id:mime-version; bh=ops/9Y7+BX/nqqPJ9rr2gD3UiBXmQP7Tp+C542TQ4Bs=; b=EwaUHKFzhE2k7bifoeTH4jfJbPfVVA/mzbLQA4/LkNnvSD5T6rw2YgFU B+Pknz/E9TxfTC8JgSfTwo3euM4CYlUboVB/tbFphIBl/GobP8w29Hr8z oqaeR0zQtFxeEDLDeys0Ng9p3oeFCSmto8ZZHkwGCQM7+p0yuM8reubMa s=; Authentication-Results: esa6.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 (esa6.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=esa6.hc3370-68.iphmx.com; envelope-from="igor.druzhinin@citrix.com"; x-sender="igor.druzhinin@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa6.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=esa6.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 (esa6.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=esa6.hc3370-68.iphmx.com; envelope-from="igor.druzhinin@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: Kcllwn+RI/79Ks/gQGyFLKPXcpjCEI0DVV3z4+XeF8CQtnMVwyXo1fm3Xj3/6mqawGeWnhn7ti IQl6wvLDhS1cQ+txtgC4P/9kuryGrONH2hlpKT/lZo0l73Gzo4NyRZKeYu4Ssv4DOkc8eyJbdb 6jznq0uT5xGwIEulHk9sxTxRf6sLlg/90JcE1bByE4wlpTKMdH8nXpVa094VOa/N+C5zQa2YYS e8A2VM4p8Svys84YWIEZrsnxqW3wiSWtyrB0r1D/8M8EsbePMQl/HOaZQmYtFoiIeAsb55cyq7 c+Q= X-SBRS: 2.7 X-MesageID: 10436098 X-Ironport-Server: esa6.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.69,337,1571716800"; d="scan'208";a="10436098" From: Igor Druzhinin To: Date: Fri, 20 Dec 2019 21:39:20 +0000 Message-ID: <1576877960-12767-1-git-send-email-igor.druzhinin@citrix.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Subject: [Xen-devel] [PATCH] x86/vpt: update last_guest_time with cmpxchg and drop pl_time_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) 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 --- 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 =3D d->arch.hvm.pl_time; =20 - spin_lock_init(&pl->pl_time_lock); pl->stime_offset =3D -(u64)get_s_time(); pl->last_guest_time =3D 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 =3D v->domain->arch.hvm.pl_time; - u64 now; + s_time_t old, new, now =3D get_s_time_fixed(at_tsc) + pl->stime_offset; =20 /* Called from device models shared with PV guests. Be careful. */ ASSERT(is_hvm_vcpu(v)); =20 - spin_lock(&pl->pl_time_lock); - now =3D 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 =3D now; - else - now =3D ++pl->last_guest_time; + do { + old =3D pl->last_guest_time; + new =3D now > pl->last_guest_time ? now : old + 1; + } while ( cmpxchg(&pl->last_guest_time, old, new) !=3D old ); } - spin_unlock(&pl->pl_time_lock); + else + new =3D now; =20 - return now + v->arch.hvm.stime_offset; + return new + v->arch.hvm.stime_offset; } =20 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 =3D 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; }; =20 --=20 2.7.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel