Received: from eggs.gnu.org ([2001:4830:134:3::10]:57880) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cBgQG-0004Af-7j for qemu-devel@nongnu.org; Tue, 29 Nov 2016 06:18:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cBgQC-0003XB-86 for qemu-devel@nongnu.org; Tue, 29 Nov 2016 06:18:04 -0500 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]:33924) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cBgQC-0003UW-1L for qemu-devel@nongnu.org; Tue, 29 Nov 2016 06:18:00 -0500 Received: by mail-wm0-x242.google.com with SMTP id g23so23785035wme.1 for ; Tue, 29 Nov 2016 03:17:59 -0800 (PST) Sender: Paolo Bonzini References: <20161124151225.GA11963@stefanha-x1.localdomain> <20161129103236.GE15786@lemon> From: Paolo Bonzini Message-ID: <14abb3dd-b639-3c31-cade-073fff209ca6@redhat.com> Date: Tue, 29 Nov 2016 12:17:56 +0100 MIME-Version: 1.0 In-Reply-To: <20161129103236.GE15786@lemon> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit Subject: Re: [Qemu-devel] Linux kernel polling for QEMU List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Fam Zheng , Stefan Hajnoczi Cc: Eliezer Tamir , "Michael S. Tsirkin" , qemu-devel@nongnu.org, Jens Axboe , Christian Borntraeger , Davide Libenzi , Christoph Hellwig On 29/11/2016 11:32, Fam Zheng wrote: > > The kernel change will be a new prctl operation (should it be a different > syscall to extend?) to register a new type of eventfd called "idle eventfd": > > prctl(PR_ADD_IDLE_EVENTFD, int eventfd); > prctl(PR_DEL_IDLE_EVENTFD, int eventfd); > > It will be notified by kernel each time when the thread's local core has no > runnable threads (i.e., entering idle state). > > QEMU can then add this eventfd to its event loop when it has events to poll, and > watch virtqueue/linux-aio memory from userspace in the fd handlers. Effectiely, > if a ppoll() would have blocked because there are no new events, it could now > return immediately because of idle_eventfd events, and do the idle polling. This has two issues: * it only reports the leading edge of single_task_running(). Is it also useful to stop polling on the trailing edge? * it still needs a system call before polling is entered. Ideally, QEMU could run without any system call while in polling mode. Another possibility is to add a system call for single_task_running(). It should be simple enough that you can implement it in the vDSO and avoid a context switch. There are convenient hooking points in add_nr_running and sub_nr_running. Paolo