public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Marcelo Tosatti <mtosatti@redhat.com>
To: Avi Kivity <avi@qumranet.com>, Anthony Liguori <aliguori@us.ibm.com>
Cc: kvm-devel@lists.sourceforge.net
Subject: [patch 1/2] QEMU: use SIGARLM for alarm timers, enable SIGIO on qemu_set_fd_handler2()
Date: Fri, 11 Apr 2008 15:38:53 -0300	[thread overview]
Message-ID: <20080411184851.494350385@localhost.localdomain> (raw)
In-Reply-To: 20080411183852.150819622@localhost.localdomain

[-- Attachment #1: sigalrm-sigio --]
[-- Type: text/plain, Size: 3724 bytes --]

From: Anders Melchiorsen <mail@flac.kalibalik.dk>

Without I/O signals, qemu is relying on periodic timer events to poll
the I/O. That seems wrong, even though it works reasonably well
because timers are so frequent. In KVM, timers are less frequent, and
it does not work quite as well.

Here is a quick try at a more elaborate patch.

It attaches a signal to all[1] file descriptors that will be used in
select(). Also, it uses a dedicated SIGIO handler rather than
piggybacking on the alarm handler, so alarm I/O is changed to use
SIGALRM.

I copied the handler function from the alarm case, quite frankly I do
not quite understand what is going on. Also, I left _WIN32 out, since
I have no idea how signals work there.

[1] The slirp file descriptors are not included yet.


Index: kvm-userspace.io/qemu/vl.c
===================================================================
--- kvm-userspace.io.orig/qemu/vl.c
+++ kvm-userspace.io/qemu/vl.c
@@ -1177,6 +1177,25 @@ static int timer_load(QEMUFile *f, void 
     return 0;
 }
 
+#ifndef _WIN32
+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)
@@ -1270,7 +1289,20 @@ static uint64_t qemu_next_deadline(void)
 
 #define RTC_FREQ 1024
 
-static void enable_sigio_timer(int fd)
+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);
+    fcntl(fd, F_SETOWN, getpid());
+}
+
+static void enable_sigalrm(int fd)
 {
     struct sigaction act;
 
@@ -1279,8 +1311,9 @@ static void enable_sigio_timer(int fd)
     act.sa_flags = 0;
     act.sa_handler = host_alarm_handler;
 
-    sigaction(SIGIO, &act, NULL);
+    sigaction(SIGALRM, &act, NULL);
     fcntl(fd, F_SETFL, O_ASYNC);
+    fcntl(fd, F_SETSIG, SIGALRM);
     fcntl(fd, F_SETOWN, getpid());
 }
 
@@ -1317,7 +1350,7 @@ static int hpet_start_timer(struct qemu_
     if (r < 0)
         goto fail;
 
-    enable_sigio_timer(fd);
+    enable_sigalrm(fd);
     t->priv = (void *)(long)fd;
 
     return 0;
@@ -1355,7 +1388,7 @@ static int rtc_start_timer(struct qemu_a
         return -1;
     }
 
-    enable_sigio_timer(rtc_fd);
+    enable_sigalrm(rtc_fd);
 
     t->priv = (void *)(long)rtc_fd;
 
@@ -4029,7 +4062,6 @@ static TAPState *net_tap_fd_init(VLANSta
         return NULL;
     s->fd = fd;
     s->no_poll = 0;
-    enable_sigio_timer(fd);
     s->vc = qemu_new_vlan_client(vlan, tap_receive, NULL, s);
     qemu_set_fd_handler2(s->fd, tap_read_poll, tap_send, NULL, s);
     snprintf(s->vc->info_str, sizeof(s->vc->info_str), "tap: fd=%d", fd);
@@ -5661,6 +5693,10 @@ int qemu_set_fd_handler2(int fd,
             return -1;
         ioh->next = first_io_handler;
         first_io_handler = ioh;
+#ifndef _WIN32
+        enable_sigio(fd);
+#endif
+
     found:
         ioh->fd = fd;
         ioh->fd_read_poll = fd_read_poll;

-- 


-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone

  reply	other threads:[~2008-04-11 18:38 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-04-11 18:38 [patch 0/2] SIGIO handling changes Marcelo Tosatti
2008-04-11 18:38 ` Marcelo Tosatti [this message]
2008-04-11 18:59   ` [patch 1/2] QEMU: use SIGARLM for alarm timers, enable SIGIO on qemu_set_fd_handler2() Anthony Liguori
2008-04-11 19:44     ` Marcelo Tosatti
2008-04-13 15:05       ` Avi Kivity
2008-04-11 19:51     ` Marcelo Tosatti
2008-04-11 18:38 ` [patch 2/2] QEMU: decrease console "refresh rate" with -nographic Marcelo Tosatti
2008-04-13 16:30   ` Anders
2008-04-14 15:02     ` Marcelo Tosatti
2008-04-14 16:24       ` Avi Kivity
2008-04-14 17:24         ` Marcelo Tosatti
2008-04-14 18:31           ` Anthony Liguori
2008-04-15  5:39             ` Avi Kivity
2008-04-15  5:43               ` Carsten Otte
2008-04-15 13:40               ` Anthony Liguori
2008-04-15 13:47                 ` Avi Kivity
2008-04-15 15:12                 ` Marcelo Tosatti
2008-04-15  5:40           ` Avi Kivity
2008-04-15  7:26           ` Anders
2008-04-15  9:27             ` Avi Kivity
2008-04-15 14:20               ` Anthony Liguori
2008-04-15 14:45                 ` Avi Kivity
2008-04-15 15:04                   ` Marcelo Tosatti
2008-04-15 15:34                     ` Anthony Liguori
2008-04-15 15:43                       ` Avi Kivity
2008-04-15 18:14                         ` Anthony Liguori
2008-04-16  8:37                           ` Avi Kivity
2008-04-16 10:26                             ` Anders
2008-04-16 11:23                               ` Avi Kivity
2008-04-16 13:53                             ` Anthony Liguori
2008-04-16 14:24                               ` Carsten Otte
2008-04-17 12:53                                 ` Avi Kivity
2008-04-17  9:37                               ` Avi Kivity

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080411184851.494350385@localhost.localdomain \
    --to=mtosatti@redhat.com \
    --cc=aliguori@us.ibm.com \
    --cc=avi@qumranet.com \
    --cc=kvm-devel@lists.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox