From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45218) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cBjEI-0002dS-6b for qemu-devel@nongnu.org; Tue, 29 Nov 2016 09:17:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cBjED-0007sI-8h for qemu-devel@nongnu.org; Tue, 29 Nov 2016 09:17:54 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46892) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cBjED-0007rd-2O for qemu-devel@nongnu.org; Tue, 29 Nov 2016 09:17:49 -0500 Date: Tue, 29 Nov 2016 22:17:46 +0800 From: Fam Zheng Message-ID: <20161129141746.GA2043@lemon> References: <20161124151225.GA11963@stefanha-x1.localdomain> <20161129103236.GE15786@lemon> <14abb3dd-b639-3c31-cade-073fff209ca6@redhat.com> <20161129132354.GF15786@lemon> <04fa01e1-0613-fc14-527b-e3432c6fec1a@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <04fa01e1-0613-fc14-527b-e3432c6fec1a@redhat.com> Subject: Re: [Qemu-devel] Linux kernel polling for QEMU List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: Stefan Hajnoczi , Eliezer Tamir , "Michael S. Tsirkin" , qemu-devel@nongnu.org, Jens Axboe , Christian Borntraeger , Davide Libenzi , Christoph Hellwig On Tue, 11/29 14:27, Paolo Bonzini wrote: > > > On 29/11/2016 14:24, Fam Zheng wrote: > > On Tue, 11/29 12:17, Paolo Bonzini wrote: > >> > >> > >> 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? > > > > QEMU can clear the eventfd right after event firing so I don't think it is > > necessary. > > Yes, but how would QEMU know that the eventfd has fired? It would be > very expensive to read the eventfd on each iteration of polling. The idea is to ppoll() the eventfd together with other fds (ioeventfd and linux-aio etc.), and in the handler, call event_notifier_test_and_clear() followed by a polling loop for some period. Fam > > Paolo > > >> * 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. > > > > That sounds good! > > > > Fam > >