mirror of
https://git.proxmox.com/git/qemu
synced 2025-08-13 22:22:37 +00:00
use eventfd for iothread
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Avi Kivity <avi@redhat.com>
This commit is contained in:
parent
bf76bafa5a
commit
f3dfda6114
32
osdep.c
32
osdep.c
@ -37,6 +37,10 @@
|
|||||||
#include <sys/statvfs.h>
|
#include <sys/statvfs.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_EVENTFD
|
||||||
|
#include <sys/eventfd.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#elif defined(CONFIG_BSD)
|
#elif defined(CONFIG_BSD)
|
||||||
@ -280,6 +284,34 @@ ssize_t qemu_write_full(int fd, const void *buf, size_t count)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
|
/*
|
||||||
|
* Creates an eventfd that looks like a pipe and has EFD_CLOEXEC set.
|
||||||
|
*/
|
||||||
|
int qemu_eventfd(int fds[2])
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
#ifdef CONFIG_EVENTFD
|
||||||
|
ret = eventfd(0, 0);
|
||||||
|
if (ret >= 0) {
|
||||||
|
fds[0] = ret;
|
||||||
|
qemu_set_cloexec(ret);
|
||||||
|
if ((fds[1] = dup(ret)) == -1) {
|
||||||
|
close(ret);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
qemu_set_cloexec(fds[1]);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (errno != ENOSYS) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return qemu_pipe(fds);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Creates a pipe with FD_CLOEXEC set on both file descriptors
|
* Creates a pipe with FD_CLOEXEC set on both file descriptors
|
||||||
*/
|
*/
|
||||||
|
@ -170,6 +170,7 @@ ssize_t qemu_write_full(int fd, const void *buf, size_t count)
|
|||||||
void qemu_set_cloexec(int fd);
|
void qemu_set_cloexec(int fd);
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
|
int qemu_eventfd(int pipefd[2]);
|
||||||
int qemu_pipe(int pipefd[2]);
|
int qemu_pipe(int pipefd[2]);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
9
vl.c
9
vl.c
@ -3211,14 +3211,15 @@ static int io_thread_fd = -1;
|
|||||||
|
|
||||||
static void qemu_event_increment(void)
|
static void qemu_event_increment(void)
|
||||||
{
|
{
|
||||||
static const char byte = 0;
|
/* Write 8 bytes to be compatible with eventfd. */
|
||||||
|
static uint64_t val = 1;
|
||||||
ssize_t ret;
|
ssize_t ret;
|
||||||
|
|
||||||
if (io_thread_fd == -1)
|
if (io_thread_fd == -1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
ret = write(io_thread_fd, &byte, sizeof(byte));
|
ret = write(io_thread_fd, &val, sizeof(val));
|
||||||
} while (ret < 0 && errno == EINTR);
|
} while (ret < 0 && errno == EINTR);
|
||||||
|
|
||||||
/* EAGAIN is fine, a read must be pending. */
|
/* EAGAIN is fine, a read must be pending. */
|
||||||
@ -3235,7 +3236,7 @@ static void qemu_event_read(void *opaque)
|
|||||||
ssize_t len;
|
ssize_t len;
|
||||||
char buffer[512];
|
char buffer[512];
|
||||||
|
|
||||||
/* Drain the notify pipe */
|
/* Drain the notify pipe. For eventfd, only 8 bytes will be read. */
|
||||||
do {
|
do {
|
||||||
len = read(fd, buffer, sizeof(buffer));
|
len = read(fd, buffer, sizeof(buffer));
|
||||||
} while ((len == -1 && errno == EINTR) || len == sizeof(buffer));
|
} while ((len == -1 && errno == EINTR) || len == sizeof(buffer));
|
||||||
@ -3246,7 +3247,7 @@ static int qemu_event_init(void)
|
|||||||
int err;
|
int err;
|
||||||
int fds[2];
|
int fds[2];
|
||||||
|
|
||||||
err = qemu_pipe(fds);
|
err = qemu_eventfd(fds);
|
||||||
if (err == -1)
|
if (err == -1)
|
||||||
return -errno;
|
return -errno;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user