From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.5 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_MUTT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DCCD9C072B5 for ; Fri, 24 May 2019 20:23:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A1C2420868 for ; Fri, 24 May 2019 20:23:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2403884AbfEXUXe (ORCPT ); Fri, 24 May 2019 16:23:34 -0400 Received: from mga05.intel.com ([192.55.52.43]:48550 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2403785AbfEXUXe (ORCPT ); Fri, 24 May 2019 16:23:34 -0400 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 24 May 2019 13:23:33 -0700 X-ExtLoop1: 1 Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.36]) by orsmga007.jf.intel.com with ESMTP; 24 May 2019 13:23:33 -0700 Date: Fri, 24 May 2019 13:23:33 -0700 From: Sean Christopherson To: Paolo Bonzini Cc: Radim =?utf-8?B?S3LEjW3DocWZ?= , kvm@vger.kernel.org, Wanpeng Li Subject: Re: [PATCH] KVM: lapic: Reuse auto-adjusted timer advance of first stable vCPU Message-ID: <20190524202333.GG365@linux.intel.com> References: <20190508214702.25317-1-sean.j.christopherson@intel.com> <3ea5ae51-89b2-ee0c-d156-88198af90b95@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3ea5ae51-89b2-ee0c-d156-88198af90b95@redhat.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org On Mon, May 20, 2019 at 03:03:10PM +0200, Paolo Bonzini wrote: > On 08/05/19 23:47, Sean Christopherson wrote: > > + > > + /* > > + * The first vCPU to get a stable advancement time "wins" and > > + * sets the advancement time that is used for *new* vCPUS that > > + * are created with auto-adjusting enabled. > > + */ > > + if (apic->lapic_timer.timer_advance_adjust_done) > > + (void)cmpxchg(&adjusted_timer_advance_ns, -1, > > + timer_advance_ns); > > This is relatively expensive, so it should only be done after setting > timer_advance_adjust_done to true. That's already the case, or am I missing something? This code is inside "if (!apic->lapic_timer.timer_advance_adjust_done)", and apic->lapic_timer.timer_advance_adjust_done is set to true at creation time if "adjusted_timer_advance_ns != -1", i.e. the cmpxchg() will only be reached on vCPUs that are created before adjusted_timer_advance_ns is set and will be reached at most once per vCPU.