Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1635894rwb; Mon, 7 Nov 2022 04:09:12 -0800 (PST) X-Google-Smtp-Source: AMsMyM7vRQnivWPrgtDHL5V97CFybqzrOqwojxH+AHjnPFiQz/7C4JRv669wauNCpSMsBHlHexTr X-Received: by 2002:a50:a406:0:b0:463:4fe5:67d1 with SMTP id u6-20020a50a406000000b004634fe567d1mr41364681edb.151.1667822951804; Mon, 07 Nov 2022 04:09:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667822951; cv=none; d=google.com; s=arc-20160816; b=gQ/njUV2ummcZJbEg+jzhWewpKCS0pTTiBISPv15H6DFJj8VBhpaEmjAsUl1Ym3P9c /r1emrGenO/rHc3z5Ra7R05r/wL26iTjABQl9NGVBBD5VIjDKTwtb9RDPwAh8wot5aVk dhld1WkmyaLLP/fz2oDPZ6rHq2QFPM5Fzg/AMF1EvPgpt8usJyE3C68pJhAYXr1O9kOW OndlGmH6I2JJsdxzHNhk+YOGEd30OmhwKWvlz329QHIsRYAqoKIe6H5j1+2x/zxcsA4S 4+taFEuulU2a1zSx+ZrBMu5eOLh9SlLzc/XWBwbvj0H96Xk/Z9Ueh00AsyND59ahTYKl 1cOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=zWvz8bh4+vQKDNdPBDvtEEjozaiA8NxpItsV7tm0Qy0=; b=MR2+2YHBSnB/4nefgL7i/UYD8JJ4H02gjhtjXQ4AfxsMvowmPCRRZh7L7C8fm0VC3S Vu5gufn7U+19MZhtUvLfTRqeWmgNi9FqQAJOAK8of1f1ShSGQAEYMBfqnMILm3r3n8zy dKUm6GwzjNmn07BUFyziVJXFk1s9UFyzrK2ZWPGCCmNkGN6W8t2hq9kcE2oY/k/Y1t6W SrFOfulVYbZAZaFMuAcqwrCTD+FFicjbl1LtVRb2zkBprBjz1AtOiQgPlZTGKes/wfJd /LtxBrRbsCQwO6Np+/joWMLjW8BOkBng8QH+rZozHUUtrLUyWkfD04IVXeQNEAi5fyBi p5+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=RM2XZktv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cs19-20020a170906dc9300b0078bcc872a6esi9373376ejc.360.2022.11.07.04.08.48; Mon, 07 Nov 2022 04:09:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=RM2XZktv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231842AbiKGMA5 (ORCPT + 93 others); Mon, 7 Nov 2022 07:00:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231993AbiKGMAs (ORCPT ); Mon, 7 Nov 2022 07:00:48 -0500 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 49D891AD81 for ; Mon, 7 Nov 2022 04:00:47 -0800 (PST) Received: by mail-wr1-x42f.google.com with SMTP id l14so15870647wrw.2 for ; Mon, 07 Nov 2022 04:00:47 -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=tYoC/927TX6WsEB4G3zK/cUaYWk7+ODj4ccXwjx/8px0u7DVI9w0mq7Zg/d2ZSOKHF AxymfF1n5cXMhGHCYT9oY18vh0RKS+V1Px2/IlQ23Xlu4aaGLwcgFG2ChQIEJm0hK+h9 Wrjy5tXQSyXjBuIYu7l5FyjLWAOLWYu9W1V8jnTV8cbI38OVCDCJal476x4umHwfsvaC GLVdn4dz+LeAhyeLHKBK5eiL4NqKQ6B4JK0nry5j7UShXtLf1UKMs4VbrbSQpnne9pLJ 26kYWaW0z/XAqjXWHdfWt4KTR98lioagweoN7olYrPpeam8S37IwNFie6DlJE0fiRbbg oM6g== X-Gm-Message-State: ACrzQf2imc50rsFtgYfN+KTqqUY1cfjSrqBhP8a4L0oBL6iDj4YoNhRB rsomCO6Aj68K2uGFzjA8fi48Iw== 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> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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 >