qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH] Use SIGIO in Linux host


From: Anders Melchiorsen
Subject: [Qemu-devel] [PATCH] Use SIGIO in Linux host
Date: Sun, 20 Apr 2008 11:20:29 +0200

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 <address@hidden>

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





reply via email to

[Prev in Thread] Current Thread [Next in Thread]