From patchwork Mon Sep 24 12:36:05 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 1497501 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 C5CE13FE80 for ; Mon, 24 Sep 2012 12:36:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754963Ab2IXMgX (ORCPT ); Mon, 24 Sep 2012 08:36:23 -0400 Received: from casper.infradead.org ([85.118.1.10]:37716 "EHLO casper.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751799Ab2IXMgW convert rfc822-to-8bit (ORCPT ); Mon, 24 Sep 2012 08:36:22 -0400 Received: from dhcp-089-099-019-018.chello.nl ([89.99.19.18] helo=twins) by casper.infradead.org with esmtpsa (Exim 4.76 #1 (Red Hat Linux)) id 1TG7tS-0003PX-3W; Mon, 24 Sep 2012 12:36:10 +0000 Received: by twins (Postfix, from userid 1000) id EEEBA83DA7C2; Mon, 24 Sep 2012 14:36:05 +0200 (CEST) Message-ID: <1348490165.11847.58.camel@twins> Subject: Re: [PATCH RFC 0/2] kvm: Improving undercommit, overcommit scenarios in PLE handler From: Peter Zijlstra To: Raghavendra K T Cc: "H. Peter Anvin" , Marcelo Tosatti , Ingo Molnar , Avi Kivity , Rik van Riel , Srikar , "Nikunj A. Dadhania" , KVM , Jiannan Ouyang , chegu vinod , "Andrew M. Theurer" , LKML , Srivatsa Vaddagiri , Gleb Natapov , Andrew Jones Date: Mon, 24 Sep 2012 14:36:05 +0200 In-Reply-To: <50604988.2030506@linux.vnet.ibm.com> References: <20120921115942.27611.67488.sendpatchset@codeblue> <1348486479.11847.46.camel@twins> <50604988.2030506@linux.vnet.ibm.com> X-Mailer: Evolution 3.2.2- Mime-Version: 1.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org On Mon, 2012-09-24 at 17:22 +0530, Raghavendra K T wrote: > On 09/24/2012 05:04 PM, Peter Zijlstra wrote: > > On Fri, 2012-09-21 at 17:29 +0530, Raghavendra K T wrote: > >> In some special scenarios like #vcpu<= #pcpu, PLE handler may > >> prove very costly, because there is no need to iterate over vcpus > >> and do unsuccessful yield_to burning CPU. > > > > What's the costly thing? The vm-exit, the yield (which should be a nop > > if its the only task there) or something else entirely? > > > Both vmexit and yield_to() actually, > > because unsuccessful yield_to() overall is costly in PLE handler. > > This is because when we have large guests, say 32/16 vcpus, and one > vcpu is holding lock, rest of the vcpus waiting for the lock, when they > do PL-exit, each of the vcpu try to iterate over rest of vcpu list in > the VM and try to do directed yield (unsuccessful). (O(n^2) tries). > > this results is fairly high amount of cpu burning and double run queue > lock contention. > > (if they were spinning probably lock progress would have been faster). > As Avi/Chegu Vinod had felt it is better to avoid vmexit itself, which > seems little complex to achieve currently. OK, so the vmexit stays and we need to improve yield_to. How about something like the below, that would allow breaking out of the for-each-vcpu loop and simply going back into the vm, right? --- kernel/sched/core.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 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/kernel/sched/core.c b/kernel/sched/core.c index b38f00e..5d5b355 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -4272,7 +4272,10 @@ EXPORT_SYMBOL(yield); * It's the caller's job to ensure that the target task struct * can't go away on us before we can do any checks. * - * Returns true if we indeed boosted the target task. + * Returns: + * true (>0) if we indeed boosted the target task. + * false (0) if we failed to boost the target. + * -ESRCH if there's no task to yield to. */ bool __sched yield_to(struct task_struct *p, bool preempt) { @@ -4284,6 +4287,15 @@ bool __sched yield_to(struct task_struct *p, bool preempt) local_irq_save(flags); rq = this_rq(); + /* + * If we're the only runnable task on the rq, there's absolutely no + * point in yielding. + */ + if (rq->nr_running == 1) { + yielded = -ESRCH; + goto out_irq; + } + again: p_rq = task_rq(p); double_rq_lock(rq, p_rq); @@ -4293,13 +4305,13 @@ bool __sched yield_to(struct task_struct *p, bool preempt) } if (!curr->sched_class->yield_to_task) - goto out; + goto out_unlock; if (curr->sched_class != p->sched_class) - goto out; + goto out_unlock; if (task_running(p_rq, p) || p->state) - goto out; + goto out_unlock; yielded = curr->sched_class->yield_to_task(rq, p, preempt); if (yielded) { @@ -4312,11 +4324,12 @@ bool __sched yield_to(struct task_struct *p, bool preempt) resched_task(p_rq->curr); } -out: +out_unlock: double_rq_unlock(rq, p_rq); +out_irq: local_irq_restore(flags); - if (yielded) + if (yielded > 0) schedule(); return yielded;