From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Lmc0y-000237-TJ for qemu-devel@nongnu.org; Wed, 25 Mar 2009 18:56:05 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Lmc0s-0001td-9p for qemu-devel@nongnu.org; Wed, 25 Mar 2009 18:56:02 -0400 Received: from [199.232.76.173] (port=49785 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Lmc0r-0001sx-UA for qemu-devel@nongnu.org; Wed, 25 Mar 2009 18:55:57 -0400 Received: from mx2.redhat.com ([66.187.237.31]:51070) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Lmc0r-0006HU-7Z for qemu-devel@nongnu.org; Wed, 25 Mar 2009 18:55:57 -0400 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n2PMtuxm032362 for ; Wed, 25 Mar 2009 18:55:56 -0400 Message-Id: <20090325225438.990466524@amt.cnet> Date: Wed, 25 Mar 2009 19:47:18 -0300 From: Marcelo Tosatti References: <20090325224714.853788328@amt.cnet> Content-Disposition: inline; filename=pipefd Subject: [Qemu-devel] [patch 04/10] qemu: introduce main_loop_break Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Marcelo Tosatti Use a pipe to signal pending work for the iothread. Signed-off-by: Marcelo Tosatti Index: trunk/qemu-common.h =================================================================== --- trunk.orig/qemu-common.h +++ trunk/qemu-common.h @@ -186,6 +186,8 @@ int cpu_load(QEMUFile *f, void *opaque, /* Force QEMU to stop what it's doing and service IO */ void qemu_service_io(void); +void main_loop_break(void); + /* Force QEMU to process pending events */ void qemu_notify_event(void); Index: trunk/vl.c =================================================================== --- trunk.orig/vl.c +++ trunk/vl.c @@ -275,6 +275,8 @@ static QEMUTimer *nographic_timer; uint8_t qemu_uuid[16]; +static int io_thread_fd = -1; + /***********************************************************/ /* x86 ISA bus support */ @@ -3631,6 +3633,55 @@ void qemu_notify_event(void) } } +void main_loop_break(void) +{ + uint64_t value = 1; + char buffer[8]; + size_t offset = 0; + + if (io_thread_fd == -1) + return; + + memcpy(buffer, &value, sizeof(value)); + + while (offset < 8) { + ssize_t len; + + len = write(io_thread_fd, buffer + offset, 8 - offset); + if (len == -1 && errno == EINTR) + continue; + + if (len <= 0) + break; + + offset += len; + } + + if (offset != 8) + fprintf(stderr, "failed to notify io thread\n"); +} + +/* Used to break IO thread out of select */ +static void io_thread_wakeup(void *opaque) +{ + int fd = (unsigned long)opaque; + char buffer[8]; + size_t offset = 0; + + while (offset < 8) { + ssize_t len; + + len = read(fd, buffer + offset, 8 - offset); + if (len == -1 && errno == EINTR) + continue; + + if (len <= 0) + break; + + offset += len; + } +} + #ifdef _WIN32 static void host_main_loop_wait(int *timeout) { @@ -3773,6 +3824,20 @@ void main_loop_wait(int timeout) } +static void setup_iothread_fd(void) +{ + int fds[2]; + + if (pipe(fds) == -1) { + fprintf(stderr, "failed to create iothread pipe"); + exit(0); + } + + qemu_set_fd_handler2(fds[0], NULL, io_thread_wakeup, NULL, + (void *)(unsigned long)fds[0]); + io_thread_fd = fds[1]; +} + static int main_loop(void) { int ret, timeout;