All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] use SIGALRM for alarm timers, enable SIGIO on qemu_set_fd_handler2()
@ 2008-04-13 17:03 Anders Melchiorsen
  2008-04-13 17:27 ` Jamie Lokier
  2008-04-13 18:20 ` Stuart Brady
  0 siblings, 2 replies; 5+ messages in thread
From: Anders Melchiorsen @ 2008-04-13 17:03 UTC (permalink / raw)
  To: qemu-devel

Here is a patch that lets I/O be signalled immediately with SIGIO,
rather than waiting around for an arbitrary timer to expire. This
improves performance.

The timer code is changed to always use SIGALRM, to not interfere.

The SIGIO handler function is copied from the alarm case. Frankly, I
do not quite understand what is going on, so it might not all be
needed? Also, I left _WIN32 out, since I have no idea how signals work
there.


Regards,
Anders.


diff --git a/vl.c b/vl.c
index 61eb191..d2c5a39 100644
--- a/vl.c
+++ b/vl.c
@@ -1148,6 +1148,25 @@ static int timer_load(QEMUFile *f, void *opaque, int version_id)
     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)
@@ -1240,7 +1259,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|O_NONBLOCK);
+    fcntl(fd, F_SETOWN, getpid());
+}
+
+static void enable_sigalrm(int fd)
 {
     struct sigaction act;
 
@@ -1249,8 +1281,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());
 }
 
@@ -1287,7 +1320,7 @@ static int hpet_start_timer(struct qemu_alarm_timer *t)
     if (r < 0)
         goto fail;
 
-    enable_sigio_timer(fd);
+    enable_sigalrm(fd);
     t->priv = (void *)(long)fd;
 
     return 0;
@@ -1325,7 +1358,7 @@ static int rtc_start_timer(struct qemu_alarm_timer *t)
         return -1;
     }
 
-    enable_sigio_timer(rtc_fd);
+    enable_sigalrm(rtc_fd);
 
     t->priv = (void *)(long)rtc_fd;
 
@@ -5519,6 +5552,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;

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] use SIGALRM for alarm timers, enable SIGIO on qemu_set_fd_handler2()
  2008-04-13 17:03 [Qemu-devel] [PATCH] use SIGALRM for alarm timers, enable SIGIO on qemu_set_fd_handler2() Anders Melchiorsen
@ 2008-04-13 17:27 ` Jamie Lokier
  2008-04-13 17:56   ` Anders Melchiorsen
  2008-04-13 18:20 ` Stuart Brady
  1 sibling, 1 reply; 5+ messages in thread
From: Jamie Lokier @ 2008-04-13 17:27 UTC (permalink / raw)
  To: qemu-devel

Anders Melchiorsen wrote:
> -    sigaction(SIGIO, &act, NULL);
> +    sigaction(SIGALRM, &act, NULL);
>      fcntl(fd, F_SETFL, O_ASYNC);
> +    fcntl(fd, F_SETSIG, SIGALRM);
>      fcntl(fd, F_SETOWN, getpid());

F_SETSIG is specific to Linux.  Other host OSes don't have it.

-- Jamie

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] use SIGALRM for alarm timers, enable SIGIO on qemu_set_fd_handler2()
  2008-04-13 17:27 ` Jamie Lokier
@ 2008-04-13 17:56   ` Anders Melchiorsen
  0 siblings, 0 replies; 5+ messages in thread
From: Anders Melchiorsen @ 2008-04-13 17:56 UTC (permalink / raw)
  To: qemu-devel

Jamie Lokier <jamie@shareable.org> writes:

> Anders Melchiorsen wrote:
>> -    sigaction(SIGIO, &act, NULL);
>> +    sigaction(SIGALRM, &act, NULL);
>>      fcntl(fd, F_SETFL, O_ASYNC);
>> +    fcntl(fd, F_SETSIG, SIGALRM);
>>      fcntl(fd, F_SETOWN, getpid());
>
> F_SETSIG is specific to Linux.  Other host OSes don't have it.

True, and actually it is flagged as such. The function is only called
from the Linux specific timers (hpet/rtc).

I did, however, place the enable_sigio() function inside the same
Linux-only part as well. Here is an update where it is moved out (but
still not into WIN32).


Thanks,
Anders



diff --git a/vl.c b/vl.c
index 61eb191..dc4c5aa 100644
--- a/vl.c
+++ b/vl.c
@@ -1148,6 +1148,25 @@ static int timer_load(QEMUFile *f, void *opaque, int version_id)
     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)
@@ -1236,11 +1255,24 @@ static uint64_t qemu_next_deadline(void)
 
 #ifndef _WIN32
 
+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());
+}
+
 #if defined(__linux__)
 
 #define RTC_FREQ 1024
 
-static void enable_sigio_timer(int fd)
+static void enable_sigalrm(int fd)
 {
     struct sigaction act;
 
@@ -1249,8 +1281,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());
 }
 
@@ -1287,7 +1320,7 @@ static int hpet_start_timer(struct qemu_alarm_timer *t)
     if (r < 0)
         goto fail;
 
-    enable_sigio_timer(fd);
+    enable_sigalrm(fd);
     t->priv = (void *)(long)fd;
 
     return 0;
@@ -1325,7 +1358,7 @@ static int rtc_start_timer(struct qemu_alarm_timer *t)
         return -1;
     }
 
-    enable_sigio_timer(rtc_fd);
+    enable_sigalrm(rtc_fd);
 
     t->priv = (void *)(long)rtc_fd;
 
@@ -5519,6 +5552,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;

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] use SIGALRM for alarm timers, enable SIGIO on qemu_set_fd_handler2()
  2008-04-13 17:03 [Qemu-devel] [PATCH] use SIGALRM for alarm timers, enable SIGIO on qemu_set_fd_handler2() Anders Melchiorsen
  2008-04-13 17:27 ` Jamie Lokier
@ 2008-04-13 18:20 ` Stuart Brady
  2008-04-13 18:42   ` Anders Melchiorsen
  1 sibling, 1 reply; 5+ messages in thread
From: Stuart Brady @ 2008-04-13 18:20 UTC (permalink / raw)
  To: qemu-devel

On Sun, Apr 13, 2008 at 07:03:39PM +0200, Anders Melchiorsen wrote:
> +#ifndef _WIN32
> +        enable_sigio(fd);
> +#endif

Where is enable_sigio() defined on Solaris and the BSDs?
-- 
Stuart Brady

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] use SIGALRM for alarm timers, enable SIGIO on qemu_set_fd_handler2()
  2008-04-13 18:20 ` Stuart Brady
@ 2008-04-13 18:42   ` Anders Melchiorsen
  0 siblings, 0 replies; 5+ messages in thread
From: Anders Melchiorsen @ 2008-04-13 18:42 UTC (permalink / raw)
  To: qemu-devel

Stuart Brady <sdbrady@ntlworld.com> writes:

> Where is enable_sigio() defined on Solaris and the BSDs?

I already moved it out of the __linux__ ifdef in a followup patch, but
it might be that some of the fcntl options are only available in
Linux? In that case, I can move it back, and flag the call instead.

Anyway, I would appreciate some feedback on the entire approach. There
is no point in getting the flags right if the patch is scrapped anyway.


Thanks,
Anders.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2008-04-13 18:42 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-04-13 17:03 [Qemu-devel] [PATCH] use SIGALRM for alarm timers, enable SIGIO on qemu_set_fd_handler2() Anders Melchiorsen
2008-04-13 17:27 ` Jamie Lokier
2008-04-13 17:56   ` Anders Melchiorsen
2008-04-13 18:20 ` Stuart Brady
2008-04-13 18:42   ` Anders Melchiorsen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.