From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marcelo Tosatti Subject: [patch 1/2] qemu-kvm: use usptream eventfd code Date: Mon, 06 Sep 2010 17:20:16 -0300 Message-ID: <20100906202301.291967128@amt.cnet> References: <20100906202015.433641568@amt.cnet> Cc: avi@redhat.com, Anthony Liguori , Marcelo Tosatti To: kvm@vger.kernel.org Return-path: Received: from mx1.redhat.com ([209.132.183.28]:31624 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751175Ab0IFU0Z (ORCPT ); Mon, 6 Sep 2010 16:26:25 -0400 Content-Disposition: inline; filename=qemu-notify-event Sender: kvm-owner@vger.kernel.org List-ID: Upstream code is equivalent. Signed-off-by: Marcelo Tosatti Index: qemu-kvm/cpus.c =================================================================== --- qemu-kvm.orig/cpus.c +++ qemu-kvm/cpus.c @@ -290,11 +290,6 @@ void qemu_notify_event(void) { CPUState *env = cpu_single_env; - if (kvm_enabled()) { - qemu_kvm_notify_work(); - return; - } - qemu_event_increment (); if (env) { cpu_exit(env); Index: qemu-kvm/qemu-kvm.c =================================================================== --- qemu-kvm.orig/qemu-kvm.c +++ qemu-kvm/qemu-kvm.c @@ -71,7 +71,6 @@ static int qemu_system_ready; #define SIG_IPI (SIGRTMIN+4) pthread_t io_thread; -static int io_thread_fd = -1; static int io_thread_sigfd = -1; static CPUState *kvm_debug_cpu_requested; @@ -1634,28 +1633,6 @@ int kvm_init_ap(void) return 0; } -void qemu_kvm_notify_work(void) -{ - /* Write 8 bytes to be compatible with eventfd. */ - static uint64_t val = 1; - ssize_t ret; - - if (io_thread_fd == -1) { - return; - } - - do { - ret = write(io_thread_fd, &val, sizeof(val)); - } while (ret < 0 && errno == EINTR); - - /* EAGAIN is fine in case we have a pipe. */ - if (ret < 0 && errno != EAGAIN) { - fprintf(stderr, "qemu_kvm_notify_work: write() filed: %s\n", - strerror(errno)); - exit (1); - } -} - /* If we have signalfd, we mask out the signals we want to handle and then * use signalfd to listen for them. We rely on whatever the current signal * handler is to dispatch the signals when we receive them. @@ -1692,41 +1669,14 @@ static void sigfd_handler(void *opaque) } } -/* Used to break IO thread out of select */ -static void io_thread_wakeup(void *opaque) -{ - int fd = (unsigned long) opaque; - ssize_t len; - char buffer[512]; - - /* Drain the notify pipe. For eventfd, only 8 bytes will be read. */ - do { - len = read(fd, buffer, sizeof(buffer)); - } while ((len == -1 && errno == EINTR) || len == sizeof(buffer)); -} - int kvm_main_loop(void) { - int fds[2]; sigset_t mask; int sigfd; io_thread = pthread_self(); qemu_system_ready = 1; - if (qemu_eventfd(fds) == -1) { - fprintf(stderr, "failed to create eventfd\n"); - return -errno; - } - - fcntl(fds[0], F_SETFL, O_NONBLOCK); - fcntl(fds[1], F_SETFL, O_NONBLOCK); - - qemu_set_fd_handler2(fds[0], NULL, io_thread_wakeup, NULL, - (void *)(unsigned long) fds[0]); - - io_thread_fd = fds[1]; - sigemptyset(&mask); sigaddset(&mask, SIGIO); sigaddset(&mask, SIGALRM); Index: qemu-kvm/qemu-kvm.h =================================================================== --- qemu-kvm.orig/qemu-kvm.h +++ qemu-kvm/qemu-kvm.h @@ -863,8 +863,6 @@ void qemu_kvm_aio_wait_start(void); void qemu_kvm_aio_wait(void); void qemu_kvm_aio_wait_end(void); -void qemu_kvm_notify_work(void); - void kvm_tpr_access_report(CPUState *env, uint64_t rip, int is_write); int kvm_arch_init_irq_routing(void);