From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JnVix-0003RZ-Tb for qemu-devel@nongnu.org; Sun, 20 Apr 2008 05:20:40 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JnViu-0003QO-FG for qemu-devel@nongnu.org; Sun, 20 Apr 2008 05:20:37 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JnVit-0003Pu-IQ for qemu-devel@nongnu.org; Sun, 20 Apr 2008 05:20:35 -0400 Received: from [77.75.163.100] (helo=smtp.hotelhot.dk) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1JnVit-0000QR-1J for qemu-devel@nongnu.org; Sun, 20 Apr 2008 05:20:35 -0400 From: Anders Melchiorsen Date: Sun, 20 Apr 2008 11:20:29 +0200 Message-Id: <12086832311259-git-send-email-mail@flac.kalibalik.dk> In-Reply-To: <12086832303963-git-send-email-mail@flac.kalibalik.dk> References: <12086832292508-git-send-email-mail@flac.kalibalik.dk> <12086832303963-git-send-email-mail@flac.kalibalik.dk> Subject: [Qemu-devel] [PATCH] Use SIGIO in Linux host 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: Anders Melchiorsen Network packets coming over TAP have a latency that is dictated by the periodic timer. That can hurt performance. This patch activates signals for fds that are being used with select(), giving predictable latency. Signed-off-by: Anders Melchiorsen diff --git a/vl.c b/vl.c index ad4f6ef..eb2a75e 100644 --- a/vl.c +++ b/vl.c @@ -1149,6 +1149,25 @@ static int timer_load(QEMUFile *f, void *opaque, int version_id) return 0; } +#if defined(__linux__) +static void host_io_handler(int host_signum) +{ + CPUState *env = next_cpu; + + if (env) { + /* stop the currently executing cpu because io occured */ + cpu_interrupt(env, CPU_INTERRUPT_EXIT); +#ifdef USE_KQEMU + if (env->kqemu_enabled) { + kqemu_cpu_interrupt(env); + } +#endif + } + + event_pending = 1; +} +#endif + #ifdef _WIN32 void CALLBACK host_alarm_handler(UINT uTimerID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2) @@ -1241,6 +1260,19 @@ static uint64_t qemu_next_deadline(void) #define RTC_FREQ 1024 +static void enable_sigio(int fd) +{ + struct sigaction act; + + sigfillset(&act.sa_mask); + act.sa_flags = 0; + act.sa_handler = host_io_handler; + + sigaction(SIGIO, &act, NULL); + fcntl(fd, F_SETFL, O_ASYNC|O_NONBLOCK); + fcntl(fd, F_SETOWN, getpid()); +} + static void enable_sigalrm(int fd) { struct sigaction act; @@ -5530,6 +5562,10 @@ int qemu_set_fd_handler2(int fd, return -1; ioh->next = first_io_handler; first_io_handler = ioh; +#if defined(__linux__) + enable_sigio(fd); +#endif + found: ioh->fd = fd; ioh->fd_read_poll = fd_read_poll; -- 1.5.2.5