block: avoid SIGUSR2
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). Work with kvm enabled or disabled. strace output is more readable (less syscalls). [ kwolf: Merged build fix by Paolo Bonzini ] Signed-off-by: Frediano Ziglio <freddy77@gmail.com> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
bd5da23265
commit
e1d3b25499
5
cpus.c
5
cpus.c
@ -380,11 +380,6 @@ static int qemu_signal_init(void)
|
|||||||
int sigfd;
|
int sigfd;
|
||||||
sigset_t set;
|
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
|
* 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
|
* by sigwait() in the signal thread. Otherwise, the cpu thread will
|
||||||
|
@ -42,7 +42,6 @@ struct qemu_paiocb {
|
|||||||
int aio_niov;
|
int aio_niov;
|
||||||
size_t aio_nbytes;
|
size_t aio_nbytes;
|
||||||
#define aio_ioctl_cmd aio_nbytes /* for QEMU_AIO_IOCTL */
|
#define aio_ioctl_cmd aio_nbytes /* for QEMU_AIO_IOCTL */
|
||||||
int ev_signo;
|
|
||||||
off_t aio_offset;
|
off_t aio_offset;
|
||||||
|
|
||||||
QTAILQ_ENTRY(qemu_paiocb) node;
|
QTAILQ_ENTRY(qemu_paiocb) node;
|
||||||
@ -308,12 +307,10 @@ static ssize_t handle_aiocb_rw(struct qemu_paiocb *aiocb)
|
|||||||
return nbytes;
|
return nbytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void posix_aio_notify_event(void);
|
||||||
|
|
||||||
static void *aio_thread(void *unused)
|
static void *aio_thread(void *unused)
|
||||||
{
|
{
|
||||||
pid_t pid;
|
|
||||||
|
|
||||||
pid = getpid();
|
|
||||||
|
|
||||||
mutex_lock(&lock);
|
mutex_lock(&lock);
|
||||||
pending_threads--;
|
pending_threads--;
|
||||||
mutex_unlock(&lock);
|
mutex_unlock(&lock);
|
||||||
@ -380,7 +377,7 @@ static void *aio_thread(void *unused)
|
|||||||
aiocb->ret = ret;
|
aiocb->ret = ret;
|
||||||
mutex_unlock(&lock);
|
mutex_unlock(&lock);
|
||||||
|
|
||||||
if (kill(pid, aiocb->ev_signo)) die("kill failed");
|
posix_aio_notify_event();
|
||||||
}
|
}
|
||||||
|
|
||||||
cur_threads--;
|
cur_threads--;
|
||||||
@ -547,18 +544,14 @@ static int posix_aio_flush(void *opaque)
|
|||||||
|
|
||||||
static PosixAioState *posix_aio_state;
|
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;
|
||||||
char byte = 0;
|
ssize_t ret;
|
||||||
ssize_t ret;
|
|
||||||
|
|
||||||
ret = write(posix_aio_state->wfd, &byte, sizeof(byte));
|
ret = write(posix_aio_state->wfd, &byte, sizeof(byte));
|
||||||
if (ret < 0 && errno != EAGAIN)
|
if (ret < 0 && errno != EAGAIN)
|
||||||
die("write()");
|
die("write()");
|
||||||
}
|
|
||||||
|
|
||||||
qemu_service_io();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void paio_remove(struct qemu_paiocb *acb)
|
static void paio_remove(struct qemu_paiocb *acb)
|
||||||
@ -622,7 +615,6 @@ BlockDriverAIOCB *paio_submit(BlockDriverState *bs, int fd,
|
|||||||
return NULL;
|
return NULL;
|
||||||
acb->aio_type = type;
|
acb->aio_type = type;
|
||||||
acb->aio_fildes = fd;
|
acb->aio_fildes = fd;
|
||||||
acb->ev_signo = SIGUSR2;
|
|
||||||
|
|
||||||
if (qiov) {
|
if (qiov) {
|
||||||
acb->aio_iov = qiov->iov;
|
acb->aio_iov = qiov->iov;
|
||||||
@ -650,7 +642,6 @@ BlockDriverAIOCB *paio_ioctl(BlockDriverState *bs, int fd,
|
|||||||
return NULL;
|
return NULL;
|
||||||
acb->aio_type = QEMU_AIO_IOCTL;
|
acb->aio_type = QEMU_AIO_IOCTL;
|
||||||
acb->aio_fildes = fd;
|
acb->aio_fildes = fd;
|
||||||
acb->ev_signo = SIGUSR2;
|
|
||||||
acb->aio_offset = 0;
|
acb->aio_offset = 0;
|
||||||
acb->aio_ioctl_buf = buf;
|
acb->aio_ioctl_buf = buf;
|
||||||
acb->aio_ioctl_cmd = req;
|
acb->aio_ioctl_cmd = req;
|
||||||
@ -664,7 +655,6 @@ BlockDriverAIOCB *paio_ioctl(BlockDriverState *bs, int fd,
|
|||||||
|
|
||||||
int paio_init(void)
|
int paio_init(void)
|
||||||
{
|
{
|
||||||
struct sigaction act;
|
|
||||||
PosixAioState *s;
|
PosixAioState *s;
|
||||||
int fds[2];
|
int fds[2];
|
||||||
int ret;
|
int ret;
|
||||||
@ -674,11 +664,6 @@ int paio_init(void)
|
|||||||
|
|
||||||
s = g_malloc(sizeof(PosixAioState));
|
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;
|
s->first_aio = NULL;
|
||||||
if (qemu_pipe(fds) == -1) {
|
if (qemu_pipe(fds) == -1) {
|
||||||
fprintf(stderr, "failed to create pipe\n");
|
fprintf(stderr, "failed to create pipe\n");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user