Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp2974623lqo; Tue, 14 May 2024 15:54:27 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUR5uyaMyuhgg6PWlVMMWc1DrXghwdhVkzKEHh1EseuZ5/Jo/YIImEuYNTgqQc4knQS89l0TC399Nc7LGDZtipyE7woe3HLb43c0AJ6fA== X-Google-Smtp-Source: AGHT+IGG98aHrFbfoFCbcUhl0dtNukZCUIDrlSmQFI17b48EXyE5f1kQ90u5RJYjPdEEWg9gZDCd X-Received: by 2002:ae9:f402:0:b0:792:9f1a:869b with SMTP id af79cd13be357-792c75af807mr1475962185a.42.1715727267385; Tue, 14 May 2024 15:54:27 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715727267; cv=pass; d=google.com; s=arc-20160816; b=j3JHzjLmS4/GhS1vlxuKw/WhBgLDj8Y83DKSwygpP7BzEIamJFEkm88nwVp9tWZ84Z 5QU0bHoeAwERHNyrQ8/5g94NFLgMUF+4wclHUyaV4Qm+hAIHGrIXbqX8NJGlaKnrkRxk qYrUa/vFGPAYwJTVSE8sDfl+18GLlFyTGioIB41sCJXSWaFdnmUPH+GorlTvLU431RJF 0MFtcjSq/oRb60Yr2dGu8oTl4mabhfUV2Hag40sktXnIR8B3mhsXsaTri7YyL9O/U3yE 4P7OjevYyZGfBdxfxs1OIDDWJ6Jei970CC7sxBLognLxo8yf53XlgHyXWs52GUuaBZAX OL6Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=rdFhNO44xD9sXIMJCC6FMKTg0SoG8S6B+JMIE699nNE=; fh=CRQ6uO5xMxiuSYNHVHy+KsdzvoffpQqjlc8CLM2H92U=; b=F797rXrDutRV9OpJwm99euj+Wwl1mcl/6v64/+WFtabvEdN1OO53TDJWv4UxqxYZ54 DualS5aQ6YyOnebxqlCGLZemS6UZU3yLBCtJbm7bGAxyrpVmzbSxf/oLu+i7yPdfJ7zp iCyFy8km+ZWSjZiCdT+QddKjLZiCCLPaRHjYhWZ+rBRqYUUSNDlceNwRwfC/GBZ/gx0C JSYMiX2p9Av0gEKrD0hpfaSEp7HkL+ZRUFennfG0Mxz3nsF60+2z15UhvHhjxQ211ZE3 WoFkA75aLb01N+AS0qA2UIQqbddC22B8LCdQOsVBSuaQQlOfNrxN+LbTWbKZJ2m1z3uu 36uQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=u9r6tOa+; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-179245-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-179245-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id af79cd13be357-792bf361f60si774214085a.556.2024.05.14.15.54.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 May 2024 15:54:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-179245-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=u9r6tOa+; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-179245-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-179245-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id DB21E1C20BA4 for ; Tue, 14 May 2024 22:54:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 048CC182C92; Tue, 14 May 2024 22:54:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="u9r6tOa+" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2685A181CFB; Tue, 14 May 2024 22:54:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715727258; cv=none; b=gI16P+qAatg0rt8OgrPb31LhW0s4IkTmME644lbmGyL5Tz9LrWoHBGTy/tjs8V/MRP9D+MrVW2NkY/BzDqLzU67R1lwzogLxHJmso3dLxFJbAch9+dUeoAJRCh5lsGPrDMF3msBIGWLmbugR481Vd4DkOC4Ekay8fSOSm/FjdbM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715727258; c=relaxed/simple; bh=ZW2Nbj8GoOGUug2rnm6oGISqRv9Ml9tWbdtZP+OfDHQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=TL5U6dgPfpapfrx/3dcodKkRamzdxtqhqZQGKS0/hJfJp6BKTTxLgf62v4+ja+gdhLYSyp9D3ctypLUyM6i2XJbB5BtqGn4aTbjXU7kP8nm06O+FT27hr0eSEYDKA6it5Yq+HNC2peNHpzMwCAk2gEJzqKMDaCNBc5erN/KIXd4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=u9r6tOa+; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id E79D7C2BD10; Tue, 14 May 2024 22:54:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715727258; bh=ZW2Nbj8GoOGUug2rnm6oGISqRv9Ml9tWbdtZP+OfDHQ=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=u9r6tOa+h89rC+qs1fFPEQXOaR+IHTxetn5eExiWLaHGsOXkyaUgdQjldcmCF0R6R gjzG0oda7SLPU4WpK8HErrTcmLZio1DxHD2ryUR+9iPFEva/eKbHn2/pMWnQ9To1WQ 8TXftfroH8kicxlUbEfUcxmsaD0yS2nAwNV2esA+Zbtvhr+VcrShMIyNNg2yeKcJdn XTHpqPpJyYCJdtnR8g82CKDCJio7RDG6dhpaH/LGya7SgtyNcVkG/AxO4/cWJw2FN1 r6QMMlHRdKIj8ncrlj8y+a8DZ3a4gKaL76c9GJCc94GYhTrR6TGbfshTo4JfUH1FRG S6DfQcmYZsHRw== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 94D09CE0481; Tue, 14 May 2024 15:54:16 -0700 (PDT) Date: Tue, 14 May 2024 15:54:16 -0700 From: "Paul E. McKenney" To: Leonardo Bras Soares Passos Cc: Sean Christopherson , Frederic Weisbecker , Paolo Bonzini , Marcelo Tosatti , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Subject: Re: [RFC PATCH 1/1] kvm: Note an RCU quiescent state on guest exit Message-ID: <68c39823-6b1d-4368-bd1e-a521ade8889b@paulmck-laptop> Reply-To: paulmck@kernel.org References: <20240511020557.1198200-1-leobras@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Mon, May 13, 2024 at 06:47:13PM -0300, Leonardo Bras Soares Passos wrote: > On Mon, May 13, 2024 at 4:40 PM Sean Christopherson wrote: > > > > On Fri, May 10, 2024, Leonardo Bras wrote: > > > As of today, KVM notes a quiescent state only in guest entry, which is good > > > as it avoids the guest being interrupted for current RCU operations. > > > > > > While the guest vcpu runs, it can be interrupted by a timer IRQ that will > > > check for any RCU operations waiting for this CPU. In case there are any of > > > such, it invokes rcu_core() in order to sched-out the current thread and > > > note a quiescent state. > > > > > > This occasional schedule work will introduce tens of microsseconds of > > > latency, which is really bad for vcpus running latency-sensitive > > > applications, such as real-time workloads. > > > > > > So, note a quiescent state in guest exit, so the interrupted guests is able > > > to deal with any pending RCU operations before being required to invoke > > > rcu_core(), and thus avoid the overhead of related scheduler work. > > > > Are there any downsides to this? E.g. extra latency or anything? KVM will note > > a context switch on the next VM-Enter, so even if there is extra latency or > > something, KVM will eventually take the hit in the common case no matter what. > > But I know some setups are sensitive to handling select VM-Exits as soon as possible. > > > > I ask mainly because it seems like a no brainer to me to have both VM-Entry and > > VM-Exit note the context switch, which begs the question of why KVM isn't already > > doing that. I assume it was just oversight when commit 126a6a542446 ("kvm,rcu,nohz: > > use RCU extended quiescent state when running KVM guest") handled the VM-Entry > > case? > > I don't know, by the lore I see it happening in guest entry since the > first time it was introduced at > https://lore.kernel.org/all/1423167832-17609-5-git-send-email-riel@redhat.com/ > > Noting a quiescent state is cheap, but it may cost a few accesses to > possibly non-local cachelines. (Not an expert in this, Paul please let > me know if I got it wrong). Yes, it is cheap, especially if interrupts are already disabled. (As in the scheduler asks RCU to do the same amount of work on its context-switch fastpath.) > I don't have a historic context on why it was just implemented on > guest_entry, but it would make sense when we don't worry about latency > to take the entry-only approach: > - It saves the overhead of calling rcu_virt_note_context_switch() > twice per guest entry in the loop > - KVM will probably run guest entry soon after guest exit (in loop), > so there is no need to run it twice > - Eventually running rcu_core() may be cheaper than noting quiescent > state every guest entry/exit cycle > > Upsides of the new strategy: > - Noting a quiescent state in guest exit avoids calling rcu_core() if > there was a grace period request while guest was running, and timer > interrupt hits the cpu. > - If the loop re-enter quickly there is a high chance that guest > entry's rcu_virt_note_context_switch() will be fast (local cacheline) > as there is low probability of a grace period request happening > between exit & re-entry. > - It allows us to use the rcu patience strategy to avoid rcu_core() > running if any grace period request happens between guest exit and > guest re-entry, which is very important for low latency workloads > running on guests as it reduces maximum latency in long runs. > > What do you think? Try both on the workload of interest with appropriate tracing and see what happens? The hardware's opinion overrides mine. ;-) Thanx, Paul