From patchwork Fri Dec 20 21:39:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Druzhinin X-Patchwork-Id: 11306355 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DC985139A for ; Fri, 20 Dec 2019 21:40:44 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B89AD20866 for ; Fri, 20 Dec 2019 21:40:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b="EwaUHKFz" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B89AD20866 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org 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 X-Inumbo-ID: 312bb432-2371-11ea-88e7-bc764e2007e4 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) 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 (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 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" 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 = 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; };