qemu-kvm cleanups
cover qemu-kvm cleanups
Two minor signal related cleanups.
PATCH 1/2 qemu-kvm: use usptream eventfd code
Upstream code is equivalent.
cpus.c +0 -5
@@ -290,11 +290,6 @@ void qemu_notify_event(void) {CPUState *env = cpu_single_env; -if (kvm_enabled ()) { -qemu_kvm_notify_work (); -return ; - } -qemu_event_increment ();if (env) {cpu_exit (env);
qemu-kvm.c +0 -50
76 lines not on this page · raw message
qemu-kvm.h +0 -2
@@ -863,8 +863,6 @@ void qemu_kvm_aio_wait_start(void);void qemu_kvm_aio_wait (void );void qemu_kvm_aio_wait_end (void ); -void qemu_kvm_notify_work (void ); -void kvm_tpr_access_report (CPUState *env,uint64_t rip,int is_write);int kvm_arch_init_irq_routing (void );
Re: [patch 1/2] qemu-kvm: use usptream eventfd code
Quoted 10 lines · Marcelo Tosatti
Upstream code is equivalent.
Signed-off-by Marcelo Tosatti<[email protected]>Index:
qemu-kvm/cpus.c
===================================================================cpus.c +0
-0@@ -290,11 +290,6 @@ void qemu_notify_event(void) {
cpus.c void qemu_notify_event(void) · line 295
Quoted 10 lines
cpus.c +0
-5CPUState *env = cpu_single_env; -if (kvm_enabled ()) { -qemu_kvm_notify_work (); -return ; - } -qemu_event_increment ();if (env) {cpu_exit (env);
qemu_event_increment() is indeed equivalent, but what about the rest? Are we guaranteed that cpu_single_env == NULL?
Signature · 1 line
error compiling committee.c: too many arguments to function
Re: [patch 1/2] qemu-kvm: use usptream eventfd code
Quoted 13 lines · Avi Kivity
Quoted 12 lines · Marcelo Tosatti
Upstream code is equivalent.
Signed-off-by Marcelo Tosatti<[email protected]>Index:
qemu-kvm/cpus.c
===================================================================cpus.c +0
-0@@ -290,11 +290,6 @@ void qemu_notify_event(void) {CPUState *env = cpu_single_env;
Quoted 11 lines
cpus.c void qemu_notify_event(void) · line 295
Quoted 8 lines
cpus.c +0
-5-if (kvm_enabled ()) { -qemu_kvm_notify_work (); -return ; - } -qemu_event_increment ();if (env) {cpu_exit (env);
qemu_event_increment()is indeed equivalent, but what about the rest? Are we guaranteed thatcpu_single_env== NULL?
No, its not NULL. But env->current is, so its fine.
Re: [patch 1/2] qemu-kvm: use usptream eventfd code
Quoted 24 lines · Marcelo Tosatti
Quoted 13 lines · Avi Kivity
Quoted 12 lines · Marcelo Tosatti
Upstream code is equivalent.
Signed-off-by Marcelo Tosatti<[email protected]>Index:
qemu-kvm/cpus.c
===================================================================cpus.c +0
-0@@ -290,11 +290,6 @@ void qemu_notify_event(void) {CPUState *env = cpu_single_env;Quoted 10 lines
cpus.c void qemu_notify_event(void) · line 295
Quoted 8 lines
cpus.c +0
-5-if (kvm_enabled ()) { -qemu_kvm_notify_work (); -return ; - } -qemu_event_increment ();if (env) {cpu_exit (env);
qemu_event_increment()is indeed equivalent, but what about the rest? Are we guaranteed thatcpu_single_env== NULL?
Quoted 1 line
No, its not NULL. But
env->currentis, so its fine.
Ok, thanks.
Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this signature is too narrow to contain.
PATCH 2/2 qemu-kvm: drop posix-aio-compat.cs signalfd usage
In reply to Marcelo TosattiBlock SIGUSR2, which makes the signal be handled through qemu-kvm.c's signalfd.
posix-aio-compat.c +39 -33
@@ -26,7 +26,6 @@#include "osdep.h" #include "qemu-common.h" #include "block_int.h" -#include "compatfd.h" #include "block/raw-posix-aio.h"
@@ -54,7 +53,7 @@ struct qemu_paiocb { };typedef struct PosixAioState { -int fd; +int rfd, wfd;struct qemu_paiocb *first_aio; }PosixAioState ;
@@ -473,29 +472,18 @@ static int posix_aio_process_queue(voidstatic void posix_aio_read (void *opaque) {PosixAioState *s = opaque; -union { -struct qemu_signalfd_siginfo siginfo; -char buf[128 ]; - } sig; -size_t offset; - -/* try to read from signalfd, don't freak out if we can't read anything */ - offset =0 ; -while (offset <128 ) { -ssize_t len; +ssize_t len; - len =read (s->fd, sig.buf + offset,128 - offset); -if (len ==-1 && errno ==EINTR ) -continue ; -if (len ==-1 && errno ==EAGAIN ) { -/* there is no natural reason for this to happen, -* so we'll spin hard until we get everything just -* to be on the safe side. */ -if (offset >0 ) -continue ; - } +/* read all bytes from signal pipe */ +for (;;) { +char bytes[16 ]; - offset += len; + len =read (s->rfd, bytes,sizeof (bytes)); +if (len ==-1 && errno ==EINTR ) +continue ;/* try again */ +if (len ==sizeof (bytes)) +continue ;/* more to read */ +break ; }posix_aio_process_queue (s);
@@ -509,6 +497,20 @@ static int posix_aio_flush(void *opaque)static PosixAioState *posix_aio_state; +static void aio_signal_handler (int signum) +{ +if (posix_aio_state) { +char byte =0 ; +ssize_t ret; + + ret =write (posix_aio_state->wfd, &byte,sizeof (byte)); +if (ret <0 && errno !=EAGAIN ) +die ("write()" ); + } + +qemu_service_io (); +} +static void paio_remove (struct qemu_paiocb *acb) {struct qemu_paiocb **pacb;
@@ -610,8 +612,9 @@ BlockDriverAIOCB *paio_ioctl(BlockDriverint paio_init (void ) { -sigset_t mask; +struct sigaction act;PosixAioState *s; +int fds[2 ];int ret;if (posix_aio_state)
@@ -619,21 +622,24 @@ int paio_init(void) s =qemu_malloc (sizeof (PosixAioState)); -/* Make sure to block AIO signal */ -sigemptyset (&mask); -sigaddset (&mask,SIGUSR2 ); -sigprocmask (SIG_BLOCK , &mask,NULL ); +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 ; - s->fd =qemu_signalfd (&mask); -if (s->fd ==-1 ) { -fprintf (stderr,"failed to create signalfd\n" ); +if (qemu_pipe (fds) ==-1 ) { +fprintf (stderr,"failed to create pipe\n" );return -1 ; } -fcntl (s->fd,F_SETFL ,O_NONBLOCK ); + s->rfd = fds[0 ]; + s->wfd = fds[1 ]; + +fcntl (s->rfd,F_SETFL ,O_NONBLOCK ); +fcntl (s->wfd,F_SETFL ,O_NONBLOCK ); -qemu_aio_set_fd_handler (s->fd, posix_aio_read,NULL , posix_aio_flush, +qemu_aio_set_fd_handler (s->rfd, posix_aio_read,NULL , posix_aio_flush, posix_aio_process_queue, s); ret =pthread_attr_init (&attr);
qemu-kvm.c +1 -0
@@ -1680,6 +1680,7 @@ int kvm_main_loop(void)sigemptyset (&mask);sigaddset (&mask,SIGIO );sigaddset (&mask,SIGALRM ); +sigaddset (&mask,SIGUSR2 );sigaddset (&mask,SIGBUS );sigprocmask (SIG_BLOCK , &mask,NULL );