From patchwork Fri Apr 24 05:27:01 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shannon Zhao X-Patchwork-Id: 47488 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f69.google.com (mail-la0-f69.google.com [209.85.215.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 17CCD20553 for ; Fri, 24 Apr 2015 05:29:28 +0000 (UTC) Received: by layy10 with SMTP id y10sf9408856lay.0 for ; Thu, 23 Apr 2015 22:29:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=gzF6FIb/3KLOVDN58gnwP5w5cuQXsQC5lEce8J4dQoE=; b=e+BGtAqzK7NFouLp/U46IJYJktT+batbUHmu0LPmY7zDy+vHH3k3fHozogtHT5qJlx h3vrk3se9LXoXcwoFAtoMiIxh5OGhZ3owAWoSmGF0lczWhZa1kWStgowEC70eWdVFd5j gqy3QhQ+ZMeklAQKBtJCjpSyON+/on6/NYMinZsdAAMdRgfglVS3KNS9Gne+opTiulsv nf8QcM2Jq/8+xvCvu8MqbjSz1XN2D5v1+U8EbBSc0W22+IrPP+DAXpHxI85RqZhJjsJ0 WP4jjog7jZtqLqwpnP8NndTYrd18Ps1UejhR9TbaGbAl+DWf61t8x+NVV1mFMVtN7t4E Sc4g== X-Gm-Message-State: ALoCoQl0xXhsKUlG+u1Zjzas4RrmwE7CNZ35pn0bVBZj3496CLTzL3QeU28xXHR/S7iU9GIzQj9x X-Received: by 10.180.96.6 with SMTP id do6mr160452wib.4.1429853367008; Thu, 23 Apr 2015 22:29:27 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.203.227 with SMTP id kt3ls373786lac.18.gmail; Thu, 23 Apr 2015 22:29:26 -0700 (PDT) X-Received: by 10.152.1.70 with SMTP id 6mr5413146lak.83.1429853366841; Thu, 23 Apr 2015 22:29:26 -0700 (PDT) Received: from mail-lb0-f172.google.com (mail-lb0-f172.google.com. [209.85.217.172]) by mx.google.com with ESMTPS id lj3si7461041lab.101.2015.04.23.22.29.26 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 Apr 2015 22:29:26 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.172 as permitted sender) client-ip=209.85.217.172; Received: by lbbqq2 with SMTP id qq2so28509100lbb.3 for ; Thu, 23 Apr 2015 22:29:26 -0700 (PDT) X-Received: by 10.152.9.66 with SMTP id x2mr5420807laa.36.1429853366680; Thu, 23 Apr 2015 22:29:26 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.67.65 with SMTP id l1csp976849lbt; Thu, 23 Apr 2015 22:29:25 -0700 (PDT) X-Received: by 10.66.217.129 with SMTP id oy1mr11656608pac.82.1429853364873; Thu, 23 Apr 2015 22:29:24 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id gw3si15799508pac.117.2015.04.23.22.29.24; Thu, 23 Apr 2015 22:29:24 -0700 (PDT) Received-SPF: none (google.com: stable-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754502AbbDXF3X (ORCPT + 2 others); Fri, 24 Apr 2015 01:29:23 -0400 Received: from mail-oi0-f49.google.com ([209.85.218.49]:34069 "EHLO mail-oi0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754481AbbDXF3W (ORCPT ); Fri, 24 Apr 2015 01:29:22 -0400 Received: by oiko83 with SMTP id o83so32446794oik.1 for ; Thu, 23 Apr 2015 22:29:22 -0700 (PDT) X-Received: by 10.202.8.1 with SMTP id 1mr5422332oii.104.1429853362201; Thu, 23 Apr 2015 22:29:22 -0700 (PDT) Received: from localhost ([167.160.116.36]) by mx.google.com with ESMTPSA id w141sm6074541oif.24.2015.04.23.22.29.20 (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 23 Apr 2015 22:29:21 -0700 (PDT) From: shannon.zhao@linaro.org To: stable@vger.kernel.org Cc: jslaby@suse.cz, christoffer.dall@linaro.org, shannon.zhao@linaro.org, Marc Zyngier Subject: [PATCH for 3.12.y stable 03/63] ARM: KVM: Yield CPU when vcpu executes a WFE Date: Fri, 24 Apr 2015 13:27:01 +0800 Message-Id: <1429853281-6136-4-git-send-email-shannon.zhao@linaro.org> X-Mailer: git-send-email 1.9.5.msysgit.1 In-Reply-To: <1429853281-6136-1-git-send-email-shannon.zhao@linaro.org> References: <1429853281-6136-1-git-send-email-shannon.zhao@linaro.org> Sender: stable-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: stable@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: shannon.zhao@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.172 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Marc Zyngier commit 1f5580986a3667e9d67b65d916bb4249fd86a400 upstream. On an (even slightly) oversubscribed system, spinlocks are quickly becoming a bottleneck, as some vcpus are spinning, waiting for a lock to be released, while the vcpu holding the lock may not be running at all. This creates contention, and the observed slowdown is 40x for hackbench. No, this isn't a typo. The solution is to trap blocking WFEs and tell KVM that we're now spinning. This ensures that other vpus will get a scheduling boost, allowing the lock to be released more quickly. Also, using CONFIG_HAVE_KVM_CPU_RELAX_INTERCEPT slightly improves the performance when the VM is severely overcommited. Quick test to estimate the performance: hackbench 1 process 1000 2xA15 host (baseline): 1.843s 2xA15 guest w/o patch: 2.083s 4xA15 guest w/o patch: 80.212s 8xA15 guest w/o patch: Could not be bothered to find out 2xA15 guest w/ patch: 2.102s 4xA15 guest w/ patch: 3.205s 8xA15 guest w/ patch: 6.887s So we go from a 40x degradation to 1.5x in the 2x overcommit case, which is vaguely more acceptable. Signed-off-by: Marc Zyngier Signed-off-by: Christoffer Dall Signed-off-by: Shannon Zhao --- arch/arm/include/asm/kvm_arm.h | 4 +++- arch/arm/kvm/Kconfig | 1 + arch/arm/kvm/handle_exit.c | 6 +++++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/arch/arm/include/asm/kvm_arm.h b/arch/arm/include/asm/kvm_arm.h index d556f03..fe395b7 100644 --- a/arch/arm/include/asm/kvm_arm.h +++ b/arch/arm/include/asm/kvm_arm.h @@ -67,7 +67,7 @@ */ #define HCR_GUEST_MASK (HCR_TSC | HCR_TSW | HCR_TWI | HCR_VM | HCR_BSU_IS | \ HCR_FB | HCR_TAC | HCR_AMO | HCR_IMO | HCR_FMO | \ - HCR_SWIO | HCR_TIDCP) + HCR_TWE | HCR_SWIO | HCR_TIDCP) #define HCR_VIRT_EXCP_MASK (HCR_VA | HCR_VI | HCR_VF) /* System Control Register (SCTLR) bits */ @@ -208,6 +208,8 @@ #define HSR_EC_DABT (0x24) #define HSR_EC_DABT_HYP (0x25) +#define HSR_WFI_IS_WFE (1U << 0) + #define HSR_HVC_IMM_MASK ((1UL << 16) - 1) #define HSR_DABT_S1PTW (1U << 7) diff --git a/arch/arm/kvm/Kconfig b/arch/arm/kvm/Kconfig index ebf5015..466bd29 100644 --- a/arch/arm/kvm/Kconfig +++ b/arch/arm/kvm/Kconfig @@ -20,6 +20,7 @@ config KVM bool "Kernel-based Virtual Machine (KVM) support" select PREEMPT_NOTIFIERS select ANON_INODES + select HAVE_KVM_CPU_RELAX_INTERCEPT select KVM_MMIO select KVM_ARM_HOST depends on ARM_VIRT_EXT && ARM_LPAE diff --git a/arch/arm/kvm/handle_exit.c b/arch/arm/kvm/handle_exit.c index df4c82d..c4c496f 100644 --- a/arch/arm/kvm/handle_exit.c +++ b/arch/arm/kvm/handle_exit.c @@ -84,7 +84,11 @@ static int handle_dabt_hyp(struct kvm_vcpu *vcpu, struct kvm_run *run) static int kvm_handle_wfi(struct kvm_vcpu *vcpu, struct kvm_run *run) { trace_kvm_wfi(*vcpu_pc(vcpu)); - kvm_vcpu_block(vcpu); + if (kvm_vcpu_get_hsr(vcpu) & HSR_WFI_IS_WFE) + kvm_vcpu_on_spin(vcpu); + else + kvm_vcpu_block(vcpu); + return 1; }