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 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D85B0C4332F for ; Mon, 7 Nov 2022 12:01:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Content-Type: Content-Transfer-Encoding:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:From:References:Cc:To:Subject: MIME-Version:Date:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=zgy1MhfaAbgcox3pJ7mfh4N9If2tihtk0kzWh0JNS2k=; b=QBdVT9MNnRkrr6 W+bAisgLWuoi8l1iZAOfKwe2glas9HC+INMZQnUbSyZpGyLeN8d5+0/2EqcGwjDgpXZLF76xQI5f8 yMHELYVVHPj3JrOHzxG0clH3WhIwDfOAdCT/NsXvkwcBoSYb34yoDhhG7n6zT8Rz3iR9zklpKLn5p 0KLBU+ocitmSZWYLIhBggpLk893t92E2+egiHL66iC054nkydNq3J+nsjKBURT9yRK2JFRUVLwTE7 boVOtvojC9KtQbCGfCRwz3aoyRh8mZoBBR6Ir6LBAHVpfR58ysgRkfwfZBLb/MbPvVgxWzxyWoCCc a2gObb+Xsd0ak8ME8EHQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1os0o9-00ENIA-2c; Mon, 07 Nov 2022 12:00:53 +0000 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1os0o6-00ENGu-0Z for linux-arm-kernel@lists.infradead.org; Mon, 07 Nov 2022 12:00:52 +0000 Received: by mail-wr1-x431.google.com with SMTP id w14so15825078wru.8 for ; Mon, 07 Nov 2022 04:00:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=zWvz8bh4+vQKDNdPBDvtEEjozaiA8NxpItsV7tm0Qy0=; b=RM2XZktvK25OAmJHVCsqxExlx2YDb8taU5jJP6p51IieAMAC7rVqfwilaQF7Xqqe3G UwMWWVo3jrRu5oK/J3jJN4bG6MrzlcwfXbL/gDA98pemG49BzKD6bgFyow0xVV6hIC4N cf6zx1TH/gu3ilDDICAD4lfW6uErG3Aj8PE+aPiMsDZzvwiNA5Y84Nf0p0SZtWeekrp2 3qdK1/twOpDLX49v/t/ybYncTBiauIlLPODLWk6KsnXmtK/KZ/QbdXqSQ3r7uxN3WAvW bCAtytlDiReH1KhZkxHPGBBrCC7+BrOifMA+vx31z4AXM6SLhrkDGFn6tpeXsfo6CyjO Ug9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=zWvz8bh4+vQKDNdPBDvtEEjozaiA8NxpItsV7tm0Qy0=; b=biyja7uwQNmC/mBq8H102ueUW1o909IMcxGkioiemHhja+YqGIaS4KjX9GZiU0Xz2d nzIzo3fnODqtxNozkR43eZH7dwSEIX7wd++at9F1rJgOtcqeMWIui0YiXRBI4f3UR7pH KADjxLj+9TYTyBMvciOXMs3vucxqTSdYergrBT1soVrm94uMHFmW3rtpsg67oPIR3PPi zbFImRKKBP6UmpwhcTo0/911g5o4tw6mTsNTKOLP3H7fkcYr7hG1c+fixEbMJ+rZFIOs u5ZQ4BnkhLaKvN2fippNwZxNMdz0R/QT+BFtsk6+v65iDUNdJvhXuYNKvhuqS2DnlX3t GRGQ== X-Gm-Message-State: ACrzQf1CiwhzB5JqEe18JVG4ZWeQKEWK4nXLddWW1g+YRUuPqsDNgN35 DwmOlxq6tQ1dMLthDXpc2zvw9A== X-Google-Smtp-Source: AMsMyM59k115pH9o+6WIgEa9CaPh3ktLnt7NSnldWl3F1VAmeY4BCiQWWWW9a39fkvnQOQN6hJYR7A== X-Received: by 2002:adf:e241:0:b0:238:3c64:decc with SMTP id bl1-20020adfe241000000b002383c64deccmr15833238wrb.698.1667822445787; Mon, 07 Nov 2022 04:00:45 -0800 (PST) Received: from ?IPV6:2a02:6b6a:b4d7:0:ebf7:de38:f6bc:8fe8? ([2a02:6b6a:b4d7:0:ebf7:de38:f6bc:8fe8]) by smtp.gmail.com with ESMTPSA id g2-20020a5d4882000000b00236cb3fec8fsm8600966wrq.9.2022.11.07.04.00.45 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 07 Nov 2022 04:00:45 -0800 (PST) Message-ID: <180b91af-a2aa-2cfd-eb7f-b2825c4e3dbe@bytedance.com> Date: Mon, 7 Nov 2022 12:00:44 +0000 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [External] Re: [v2 0/6] KVM: arm64: implement vcpu_is_preempted check Content-Language: en-US To: Marc Zyngier Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, linux-doc@vger.kernel.org, virtualization@lists.linux-foundation.org, linux@armlinux.org.uk, yezengruan@huawei.com, catalin.marinas@arm.com, will@kernel.org, steven.price@arm.com, mark.rutland@arm.com, bagasdotme@gmail.com, fam.zheng@bytedance.com, liangma@liangbit.com, punit.agrawal@bytedance.com References: <20221104062105.4119003-1-usama.arif@bytedance.com> <87k048f3cm.wl-maz@kernel.org> From: Usama Arif In-Reply-To: <87k048f3cm.wl-maz@kernel.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221107_040050_325204_9909B44A X-CRM114-Status: GOOD ( 19.30 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 06/11/2022 16:35, Marc Zyngier wrote: > On Fri, 04 Nov 2022 06:20:59 +0000, > Usama Arif wrote: >> >> This patchset adds support for vcpu_is_preempted in arm64, which >> allows the guest to check if a vcpu was scheduled out, which is >> useful to know incase it was holding a lock. vcpu_is_preempted can >> be used to improve performance in locking (see owner_on_cpu usage in >> mutex_spin_on_owner, mutex_can_spin_on_owner, rtmutex_spin_on_owner >> and osq_lock) and scheduling (see available_idle_cpu which is used >> in several places in kernel/sched/fair.c for e.g. in wake_affine to >> determine which CPU can run soonest): > > [...] > >> pvcy shows a smaller overall improvement (50%) compared to >> vcpu_is_preempted (277%). Host side flamegraph analysis shows that >> ~60% of the host time when using pvcy is spent in kvm_handle_wfx, >> compared with ~1.5% when using vcpu_is_preempted, hence >> vcpu_is_preempted shows a larger improvement. > > And have you worked out *why* we spend so much time handling WFE? > > M. Its from the following change in pvcy patchset: diff --git a/arch/arm64/kvm/handle_exit.c b/arch/arm64/kvm/handle_exit.c index e778eefcf214..915644816a85 100644 --- a/arch/arm64/kvm/handle_exit.c +++ b/arch/arm64/kvm/handle_exit.c @@ -118,7 +118,12 @@ static int kvm_handle_wfx(struct kvm_vcpu *vcpu) } if (esr & ESR_ELx_WFx_ISS_WFE) { - kvm_vcpu_on_spin(vcpu, vcpu_mode_priv(vcpu)); + int state; + while ((state = kvm_pvcy_check_state(vcpu)) == 0) + schedule(); + + if (state == -1) + kvm_vcpu_on_spin(vcpu, vcpu_mode_priv(vcpu)); } else { if (esr & ESR_ELx_WFx_ISS_WFxT) vcpu_set_flag(vcpu, IN_WFIT); If my understanding is correct of the pvcy changes, whenever pvcy returns an unchanged vcpu state, we would schedule to another vcpu. And its the constant scheduling where the time is spent. I guess the affects are much higher when the lock contention is very high. This can be seem from the pvcy host side flamegraph as well with (~67% of the time spent in the schedule() call in kvm_handle_wfx), For reference, I have put the graph at: https://uarif1.github.io/pvlock/perf_host_pvcy_nmi.svg Thanks, Usama > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel