From patchwork Fri Sep 21 12:00:01 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raghavendra K T X-Patchwork-Id: 1491511 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 9ACD4402E1 for ; Fri, 21 Sep 2012 12:04:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752652Ab2IUMEF (ORCPT ); Fri, 21 Sep 2012 08:04:05 -0400 Received: from e23smtp07.au.ibm.com ([202.81.31.140]:58332 "EHLO e23smtp07.au.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752303Ab2IUMDr (ORCPT ); Fri, 21 Sep 2012 08:03:47 -0400 Received: from /spool/local by e23smtp07.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 21 Sep 2012 22:01:33 +1000 Received: from d23relay05.au.ibm.com (202.81.31.247) by e23smtp07.au.ibm.com (202.81.31.204) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 21 Sep 2012 22:01:30 +1000 Received: from d23av04.au.ibm.com (d23av04.au.ibm.com [9.190.235.139]) by d23relay05.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q8LBsEhY38076656; Fri, 21 Sep 2012 21:54:14 +1000 Received: from d23av04.au.ibm.com (loopback [127.0.0.1]) by d23av04.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q8LC3ejk030280; Fri, 21 Sep 2012 22:03:40 +1000 Received: from [192.168.1.3] ([9.79.201.91]) by d23av04.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id q8LC3WOb030125; Fri, 21 Sep 2012 22:03:35 +1000 From: Raghavendra K T To: Peter Zijlstra , "H. Peter Anvin" , Avi Kivity , Ingo Molnar , Marcelo Tosatti , Rik van Riel Cc: Srikar , "Nikunj A. Dadhania" , KVM , Raghavendra K T , Jiannan Ouyang , chegu vinod , "Andrew M. Theurer" , LKML , Srivatsa Vaddagiri , Gleb Natapov Date: Fri, 21 Sep 2012 17:30:01 +0530 Message-Id: <20120921120000.27611.71321.sendpatchset@codeblue> In-Reply-To: <20120921115942.27611.67488.sendpatchset@codeblue> References: <20120921115942.27611.67488.sendpatchset@codeblue> Subject: [PATCH RFC 1/2] kvm: Handle undercommitted guest case in PLE handler x-cbid: 12092112-0260-0000-0000-000001E160FF Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Raghavendra K T When total number of VCPUs of system is less than or equal to physical CPUs, PLE exits become costly since each VCPU can have dedicated PCPU, and trying to find a target VCPU to yield_to just burns time in PLE handler. This patch reduces overhead, by simply doing a return in such scenarios by checking the length of current cpu runqueue. Reviewed-by: Srikar Dronamraju Signed-off-by: Raghavendra K T --- include/linux/sched.h | 1 + kernel/sched/core.c | 6 ++++++ virt/kvm/kvm_main.c | 3 +++ 3 files changed, 10 insertions(+), 0 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/include/linux/sched.h b/include/linux/sched.h index b8c8664..3645458 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -138,6 +138,7 @@ extern int nr_threads; DECLARE_PER_CPU(unsigned long, process_counts); extern int nr_processes(void); extern unsigned long nr_running(void); +extern unsigned long rq_nr_running(void); extern unsigned long nr_uninterruptible(void); extern unsigned long nr_iowait(void); extern unsigned long nr_iowait_cpu(int cpu); diff --git a/kernel/sched/core.c b/kernel/sched/core.c index fbf1fd0..2170b81 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -4820,6 +4820,12 @@ void __sched yield(void) } EXPORT_SYMBOL(yield); +unsigned long rq_nr_running(void) +{ + return this_rq()->nr_running; +} +EXPORT_SYMBOL(rq_nr_running); + /** * yield_to - yield the current processor to another thread in * your thread group, or accelerate that thread toward the diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 28f00bc..8323685 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -1629,6 +1629,9 @@ void kvm_vcpu_on_spin(struct kvm_vcpu *me) int pass; int i; + if (unlikely(rq_nr_running() == 1)) + return; + kvm_vcpu_set_in_spin_loop(me, true); /* * We boost the priority of a VCPU that is runnable but not