Skip to contentSkip to conversation

Remove SIGUSR2 from posix-aio

PATCH In review Frediano Ziglio 3 participants 6 messages Sep 19, 2011 – Sep 20, 2011

lore
Share & tools
lore
#0 lore raw

cover Remove SIGUSR2 from posix-aio

Now that iothread is always compiled sending a signal seems only an additional step. This patch also avoid writing to two pipe (one from signal and one in qemu_service_io).

Tested and works correctly with KVM enabled. Performances are only sligthly better (as I expected). strace output is more readable.

Doubts:
- any sense having two patches and not only last one?
- comment is perhaps wrong as is also affect main core
- is ok if KVM is disabled? more testing required

Frediano Ziglio (2):
block: avoid storing a constant in qemu_paiocb structure
block: avoid SIGUSR2

 cpus.c             |    5 -----
 posix-aio-compat.c |   17 ++++-------------
 2 files changed, 4 insertions(+), 18 deletions(-)
#1 lore raw

PATCH 1/2 block: avoid storing a constant in qemu_paiocb structure

---
 posix-aio-compat.c |    5 +----
 1 files changed, 1 insertions(+), 4 deletions(-)
posix-aio-compat.c +1 -4
index 3193dbf..7ea63a1 100644
@@ -42,7 +42,6 @@ struct qemu_paiocb {
     int aio_niov;
     size_t aio_nbytes;
 #define aio_ioctl_cmd   aio_nbytes /* for QEMU_AIO_IOCTL */
-    int ev_signo;
     off_t aio_offset;
 
     QTAILQ_ENTRY(qemu_paiocb) node;
@@ -381,7 +380,7 @@ static void *aio_thread(void *unused)
         aiocb->ret = ret;
         mutex_unlock(&lock);
 
-        if (kill(pid, aiocb->ev_signo)) die("kill failed");
+        if (kill(pid, SIGUSR2)) die("kill failed");
     }
 
     cur_threads--;
@@ -623,7 +622,6 @@ BlockDriverAIOCB *paio_submit(BlockDriverState *bs, int fd,
         return NULL;
     acb->aio_type = type;
     acb->aio_fildes = fd;
-    acb->ev_signo = SIGUSR2;
 
     if (qiov) {
         acb->aio_iov = qiov->iov;
@@ -651,7 +649,6 @@ BlockDriverAIOCB *paio_ioctl(BlockDriverState *bs, int fd,
         return NULL;
     acb->aio_type = QEMU_AIO_IOCTL;
     acb->aio_fildes = fd;
-    acb->ev_signo = SIGUSR2;
     acb->aio_offset = 0;
     acb->aio_ioctl_buf = buf;
     acb->aio_ioctl_cmd = req;
Signature · 1 line
1.7.1
#2 lore raw

PATCH 2/2 block: avoid SIGUSR2

In reply to Frediano Ziglio
---
 cpus.c             |    5 -----
 posix-aio-compat.c |   14 ++++----------
 2 files changed, 4 insertions(+), 15 deletions(-)
cpus.c +0 -5
index 54c188c..d0cfe91 100644
@@ -380,11 +380,6 @@ static int qemu_signal_init(void)
     int sigfd;
     sigset_t set;
 
-    /* SIGUSR2 used by posix-aio-compat.c */
-    sigemptyset(&set);
-    sigaddset(&set, SIGUSR2);
-    pthread_sigmask(SIG_UNBLOCK, &set, NULL);
-
     /*
      * SIG_IPI must be blocked in the main thread and must not be caught
      * by sigwait() in the signal thread. Otherwise, the cpu thread will
posix-aio-compat.c +4 -10
index 7ea63a1..72c6dbb 100644
@@ -308,6 +308,8 @@ static ssize_t handle_aiocb_rw(struct qemu_paiocb *aiocb)
     return nbytes;
 }
 
+static void posix_aio_notify_event(void);
+
 static void *aio_thread(void *unused)
 {
     pid_t pid;
@@ -380,7 +382,7 @@ static void *aio_thread(void *unused)
         aiocb->ret = ret;
         mutex_unlock(&lock);
 
-        if (kill(pid, SIGUSR2)) die("kill failed");
+        posix_aio_notify_event();
     }
 
     cur_threads--;
@@ -547,7 +549,7 @@ static int posix_aio_flush(void *opaque)
 
 static PosixAioState *posix_aio_state;
 
-static void aio_signal_handler(int signum)
+static void posix_aio_notify_event(void)
 {
     if (posix_aio_state) {
         char byte = 0;
@@ -557,8 +559,6 @@ static void aio_signal_handler(int signum)
         if (ret < 0 && errno != EAGAIN)
             die("write()");
     }
-
-    qemu_service_io();
 }
 
 static void paio_remove(struct qemu_paiocb *acb)
@@ -662,7 +662,6 @@ BlockDriverAIOCB *paio_ioctl(BlockDriverState *bs, int fd,
 
 int paio_init(void)
 {
-    struct sigaction act;
     PosixAioState *s;
     int fds[2];
     int ret;
@@ -672,11 +671,6 @@ int paio_init(void)
 
     s = g_malloc(sizeof(PosixAioState));
 
-    sigfillset(&act.sa_mask);
-    act.sa_flags = 0; /* do not restart syscalls to interrupt select() */
-    act.sa_handler = aio_signal_handler;
-    sigaction(SIGUSR2, &act, NULL);
-
     s->first_aio = NULL;
     if (qemu_pipe(fds) == -1) {
         fprintf(stderr, "failed to create pipe\n");
Signature · 1 line
1.7.1
#3 lore raw

Re: [Qemu-devel] [PATCH 2/2] block: avoid SIGUSR2

posix-aio-compat.c static int posix_aio_flush(void *opaque) · line 554

Quoted 8 lines · Frediano Ziglio
posix-aio-compat.c +1 -1
@@ -547,7 +549,7 @@ static int posix_aio_flush(void *opaque)
 
  static PosixAioState *posix_aio_state;
 
-static void aio_signal_handler(int signum)
+static void posix_aio_notify_event(void)
  {
     if (posix_aio_state) {

Seems like this if statement is always true, hence the condition can be removed. The posix_aio_state global is always non-NULL here.

Stefan

#4 lore raw

Re: [Qemu-devel] [PATCH 2/2] block: avoid SIGUSR2

Quoted 5 lines · Stefan Hajnoczi
Quoted 4 lines · Frediano Ziglio
(quoted diff) +0 -0
@@ -547,7 +549,7 @@ static int posix_aio_flush(void *opaque)
 
 ?static PosixAioState *posix_aio_state;
 
Quoted 7 lines

posix-aio-compat.c static int posix_aio_flush(void *opaque)

Quoted 4 lines
posix-aio-compat.c +1 -1
-static void aio_signal_handler(int signum)
+static void posix_aio_notify_event(void)
 ?{
 ? ? if (posix_aio_state) {

Seems like this if statement is always true, hence the condition can be removed. The posix_aio_state global is always non-NULL here.

It is. In addition to dropping it I'd also recommend moving the function up so that it's above it's caller.

Btw, what is the point of the qemu_service_io? Calling qemu_notify_event directly would seem a lot more obvious, given that the name actually gives a hint on what it actually does.

#5 lore raw
In reply to Frediano Ziglio
Quoted 9 lines · Frediano Ziglio

Now that iothread is always compiled sending a signal seems only an additional step. This patch also avoid writing to two pipe (one from signal and one in qemu_service_io).

Tested and works correctly with KVM enabled. Performances are only sligthly better (as I expected). strace output is more readable.

Doubts:
- any sense having two patches and not only last one?

Personally I would just send one here.

Quoted 1 line

- is ok if KVM is disabled? more testing required

If I understand correctly it used to interrupt guest code execution whereas now it simply invoked a callback in the I/O thread. Normally this callback will raise a guest interrupt and get the vCPU to notice that I/O has completed. So I think this should work.

Stefan