From mboxrd@z Thu Jan 1 00:00:00 1970 From: Avi Kivity Subject: Re: [PATCH] vhost: don't forget to schedule() Date: Tue, 28 Feb 2012 15:07:25 +0200 Message-ID: <4F4CD18D.6000703@redhat.com> References: <20120227130729.GA9880@fermat.math.technion.ac.il> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: kvm@vger.kernel.org, mst@redhat.com, abelg@il.ibm.com To: "Nadav Har'El" Return-path: Received: from mx1.redhat.com ([209.132.183.28]:29522 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755128Ab2B1NHh (ORCPT ); Tue, 28 Feb 2012 08:07:37 -0500 In-Reply-To: <20120227130729.GA9880@fermat.math.technion.ac.il> Sender: kvm-owner@vger.kernel.org List-ID: On 02/27/2012 03:07 PM, Nadav Har'El wrote: > This is a tiny, but important, patch to vhost. > > Vhost's worker thread only called schedule() when it had no work to do, and > it wanted to go to sleep. But if there's always work to do, e.g., the guest > is running a network-intensive program like netperf with small message sizes, > schedule() was *never* called. This had several negative implications (on > non-preemptive kernels): > > 1. Passing time was not properly accounted to the "vhost" process (ps and > top would wrongly show it using zero CPU time). > > 2. Sometimes error messages about RCU timeouts would be printed, if the > core running the vhost thread didn't schedule() for a very long time. > > 3. Worst of all, a vhost thread would "hog" the core. If several vhost > threads need to share the same core, typically one would get most of the > CPU time (and its associated guest most of the performance), while the > others hardly get any work done. > > The trivial solution is to add > > if (need_resched()) > schedule(); > > After doing every piece of work. This will not do the heavy schedule() all > the time, just when the timer interrupt decided a reschedule is warranted > (so need_resched returns true). > > Thanks to Abel Gordon for this patch. > > Signed-off-by: Nadav Har'El > --- > vhost.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c > index c14c42b..ae66278 100644 > --- a/drivers/vhost/vhost.c > +++ b/drivers/vhost/vhost.c > @@ -222,6 +222,8 @@ static int vhost_worker(void *data) > if (work) { > __set_current_state(TASK_RUNNING); > work->fn(work); > + if (need_resched()) > + schedule(); > This is cond_resched(), no? -- error compiling committee.c: too many arguments to function