From: Fam Zheng <famz@redhat.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Stefan Hajnoczi <stefanha@redhat.com>
Subject: [Qemu-devel] [PATCH 0/2] iohandler: Convert to GSource and use epoll on Linux
Date: Fri, 26 Sep 2014 01:21:47 +0800 [thread overview]
Message-ID: <1411665709-2052-1-git-send-email-famz@redhat.com> (raw)
ppoll is not scalable, it has a complexity of O(n). When we have many virtio
queues, the main loop could be slowed down.
epoll, which is O(1), could solve this problem well.
In order to do this, we need to factor out an interface between main loop and
iohandler. What we have now is not good, so patch 1 changed it to GSource,
which is attached to the main context. The posix implementation, which is
identical, attaches each iohandler fd to the iohandler GSrouce. They are
automatically polled by g_poll, or extracted to ppoll.
Patch 2 adds another GSource which attaches a single epoll fd. The epoll fd set
manages all the iohandler fds. Each time the epoll fd is poked by main loop
polling, we call epoll_wait on it to dispatch the fds that are ready to
read/write.
A pitfall is that certain type(s) of fds can't be added to a epoll set. One
such case is the normal file or here document stdin fd. We have to special case
it (where epoll_ctl returns -1 with errno equals to EPERM), and always notify
these fds in the dispatch function.
To show the difference, let's compare the iodepth=1 read test on virtio-blk
by toggling the virtio-serial module (which adds or removes tens of
ioeventfds).
Before:
case rw bs bw iops latency
----------------------------------------------------------------------
vserial=on read 64k 1346 21548 45
vserial=off read 64k 1956 31305 30
After:
case rw bs bw iops latency
----------------------------------------------------------------------
vserial=on read 64k 1727 27647 34
vserial=off read 64k 1741 27868 34
The vserial=on case is better than before because we turned "ppoll with many
fds" into ("ppoll with a few fds" + "epoll with a few fds").
The vserial=off case is worse than before because we turned "ppoll with a few
fds" into ("ppoll with a few fds" + "epoll with a few fds").
To be optimal in both cases, we may dynamically enable/disable epoll depending
on the active ioeventfds. But that's not done yet.
Fam
Fam Zheng (2):
iohandler: Convert I/O handler to GSource
iohandler: Add Linux implementation of iohandler GSource
Makefile.objs | 2 +
include/qemu/iohandler.h | 65 +++++++++++++++
include/qemu/main-loop.h | 2 -
iohandler-linux.c | 213 +++++++++++++++++++++++++++++++++++++++++++++++
iohandler-posix.c | 150 +++++++++++++++++++++++++++++++++
iohandler.c | 90 ++------------------
main-loop.c | 6 +-
7 files changed, 442 insertions(+), 86 deletions(-)
create mode 100644 include/qemu/iohandler.h
create mode 100644 iohandler-linux.c
create mode 100644 iohandler-posix.c
--
1.9.3
next reply other threads:[~2014-09-25 17:22 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-25 17:21 Fam Zheng [this message]
2014-09-25 17:21 ` [Qemu-devel] [PATCH 1/2] iohandler: Convert I/O handler to GSource Fam Zheng
2014-09-25 17:21 ` [Qemu-devel] [PATCH 2/2] iohandler: Add Linux implementation of iohandler GSource Fam Zheng
2014-09-25 19:45 ` Paolo Bonzini
2014-09-26 1:23 ` Fam Zheng
2014-09-26 7:42 ` Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1411665709-2052-1-git-send-email-famz@redhat.com \
--to=famz@redhat.com \
--cc=kwolf@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).