From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=45716 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PLAYK-00040n-70 for qemu-devel@nongnu.org; Wed, 24 Nov 2010 03:18:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PLAYJ-0003az-2Y for qemu-devel@nongnu.org; Wed, 24 Nov 2010 03:18:08 -0500 Received: from mx1.redhat.com ([209.132.183.28]:50111) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PLAYI-0003aC-ON for qemu-devel@nongnu.org; Wed, 24 Nov 2010 03:18:06 -0500 Message-ID: <4CECCA39.4060702@redhat.com> Date: Wed, 24 Nov 2010 10:18:01 +0200 From: Avi Kivity MIME-Version: 1.0 References: <1290530963-3448-1-git-send-email-aliguori@us.ibm.com> In-Reply-To: <1290530963-3448-1-git-send-email-aliguori@us.ibm.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] Re: [PATCH] qemu-kvm: response to SIGUSR1 to start/stop a VCPU (v2) List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Anthony Liguori Cc: Chris Wright , qemu-devel@nongnu.org, kvm@vger.kernel.org On 11/23/2010 06:49 PM, Anthony Liguori wrote: > qemu-kvm vcpu threads don't response to SIGSTOP/SIGCONT. Instead of teaching > them to respond to these signals (which cannot be trapped), use SIGUSR1 to > approximate the behavior of SIGSTOP/SIGCONT. > > The purpose of this is to implement CPU hard limits using an external tool that > watches the CPU consumption and stops the VCPU as appropriate. > > This provides a more elegant solution in that it allows the VCPU thread to > release qemu_mutex before going to sleep. > > This current implementation uses a single signal. I think this is too racey > in the long term so I think we should introduce a second signal. If two signals > get coalesced into one, it could confuse the monitoring tool into giving the > VCPU the inverse of it's entitlement. You can use sigqueue() to send an accompanying value. > It might be better to simply move this logic entirely into QEMU to make this > more robust--the question is whether we think this is a good long term feature > to carry in QEMU? > I'm more concerned about lock holder preemption, and interaction of this mechanism with any kernel solution for LHP. > +static __thread int sigusr1_wfd; > + > +static void on_sigusr1(int signo) > +{ > + char ch = 0; > + if (write(sigusr1_wfd,&ch, 1)< 0) { > + /* who cares */ > + } > +} We do have signalfd(). > + > +static void sigusr1_read(void *opaque) > +{ > + CPUState *env = opaque; > + ssize_t len; > + int caught_signal = 0; > + > + do { > + char buffer[256]; > + len = read(env->sigusr1_fd, buffer, sizeof(buffer)); > + caught_signal = 1; > + } while (len> 0); > + > + if (caught_signal) { > + if (env->stopped) { env->stopped is multiplexed among multiple users, so this interferes with vm_stop(). We need to make ->stopped a reference count instead. -- error compiling committee.c: too many arguments to function