From: Anthony PERARD <anthony.perard@citrix.com>
To: <qemu-devel@nongnu.org>
Cc: Anthony PERARD <anthony.perard@citrix.com>,
xen-devel@lists.xenproject.org,
Peter Maydell <peter.maydell@linaro.org>
Subject: [Qemu-devel] [PULL 4/8] xen-bus / xen-block: add support for event channel polling
Date: Mon, 24 Jun 2019 16:32:53 +0100 [thread overview]
Message-ID: <20190624153257.20163-5-anthony.perard@citrix.com> (raw)
In-Reply-To: <20190624153257.20163-1-anthony.perard@citrix.com>
From: Paul Durrant <paul.durrant@citrix.com>
This patch introduces a poll callback for event channel fd-s and uses
this to invoke the channel callback function.
To properly support polling, it is necessary for the event channel callback
function to return a boolean saying whether it has done any useful work or
not. Thus xen_block_dataplane_event() is modified to directly invoke
xen_block_handle_requests() and the latter only returns true if it actually
processes any requests. This also means that the call to qemu_bh_schedule()
is moved into xen_block_complete_aio(), which is more intuitive since the
only reason for doing a deferred poll of the shared ring should be because
there were previously insufficient resources to fully complete a previous
poll.
Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
Reviewed-by: Anthony PERARD <anthony.perard@citrix.com>
Message-Id: <20190408151617.13025-4-paul.durrant@citrix.com>
Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
---
hw/block/dataplane/xen-block.c | 17 +++++++++--------
hw/xen/xen-bus.c | 11 +++++++++--
include/hw/xen/xen-bus.h | 2 +-
3 files changed, 19 insertions(+), 11 deletions(-)
diff --git a/hw/block/dataplane/xen-block.c b/hw/block/dataplane/xen-block.c
index aadca75644..0f200c5fb0 100644
--- a/hw/block/dataplane/xen-block.c
+++ b/hw/block/dataplane/xen-block.c
@@ -318,7 +318,9 @@ static void xen_block_complete_aio(void *opaque, int ret)
}
xen_block_release_request(request);
- qemu_bh_schedule(dataplane->bh);
+ if (dataplane->more_work) {
+ qemu_bh_schedule(dataplane->bh);
+ }
done:
aio_context_release(dataplane->ctx);
@@ -515,12 +517,13 @@ static int xen_block_get_request(XenBlockDataPlane *dataplane,
*/
#define IO_PLUG_THRESHOLD 1
-static void xen_block_handle_requests(XenBlockDataPlane *dataplane)
+static bool xen_block_handle_requests(XenBlockDataPlane *dataplane)
{
RING_IDX rc, rp;
XenBlockRequest *request;
int inflight_atstart = dataplane->requests_inflight;
int batched = 0;
+ bool done_something = false;
dataplane->more_work = 0;
@@ -552,6 +555,7 @@ static void xen_block_handle_requests(XenBlockDataPlane *dataplane)
}
xen_block_get_request(dataplane, request, rc);
dataplane->rings.common.req_cons = ++rc;
+ done_something = true;
/* parse them */
if (xen_block_parse_request(request) != 0) {
@@ -603,10 +607,7 @@ static void xen_block_handle_requests(XenBlockDataPlane *dataplane)
blk_io_unplug(dataplane->blk);
}
- if (dataplane->more_work &&
- dataplane->requests_inflight < dataplane->max_requests) {
- qemu_bh_schedule(dataplane->bh);
- }
+ return done_something;
}
static void xen_block_dataplane_bh(void *opaque)
@@ -618,11 +619,11 @@ static void xen_block_dataplane_bh(void *opaque)
aio_context_release(dataplane->ctx);
}
-static void xen_block_dataplane_event(void *opaque)
+static bool xen_block_dataplane_event(void *opaque)
{
XenBlockDataPlane *dataplane = opaque;
- qemu_bh_schedule(dataplane->bh);
+ return xen_block_handle_requests(dataplane);
}
XenBlockDataPlane *xen_block_dataplane_create(XenDevice *xendev,
diff --git a/hw/xen/xen-bus.c b/hw/xen/xen-bus.c
index 2210526490..7503eea9e9 100644
--- a/hw/xen/xen-bus.c
+++ b/hw/xen/xen-bus.c
@@ -932,13 +932,20 @@ struct XenEventChannel {
void *opaque;
};
+static bool xen_device_poll(void *opaque)
+{
+ XenEventChannel *channel = opaque;
+
+ return channel->handler(channel->opaque);
+}
+
static void xen_device_event(void *opaque)
{
XenEventChannel *channel = opaque;
unsigned long port = xenevtchn_pending(channel->xeh);
if (port == channel->local_port) {
- channel->handler(channel->opaque);
+ xen_device_poll(channel);
xenevtchn_unmask(channel->xeh, port);
}
@@ -973,7 +980,7 @@ XenEventChannel *xen_device_bind_event_channel(XenDevice *xendev,
channel->ctx = ctx;
aio_set_fd_handler(channel->ctx, xenevtchn_fd(channel->xeh), true,
- xen_device_event, NULL, NULL, channel);
+ xen_device_event, NULL, xen_device_poll, channel);
QLIST_INSERT_HEAD(&xendev->event_channels, channel, list);
diff --git a/include/hw/xen/xen-bus.h b/include/hw/xen/xen-bus.h
index 8183b98c7d..1c2d9dfdb8 100644
--- a/include/hw/xen/xen-bus.h
+++ b/include/hw/xen/xen-bus.h
@@ -119,7 +119,7 @@ void xen_device_copy_grant_refs(XenDevice *xendev, bool to_domain,
XenDeviceGrantCopySegment segs[],
unsigned int nr_segs, Error **errp);
-typedef void (*XenEventHandler)(void *opaque);
+typedef bool (*XenEventHandler)(void *opaque);
XenEventChannel *xen_device_bind_event_channel(XenDevice *xendev,
AioContext *ctx,
--
Anthony PERARD
next prev parent reply other threads:[~2019-06-24 15:35 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-24 15:32 [Qemu-devel] [PULL 0/8] xen queue 2019-06-24 Anthony PERARD
2019-06-24 15:32 ` [Qemu-devel] [PULL 1/8] xen-block: support feature-large-sector-size Anthony PERARD
2019-06-24 15:32 ` [Qemu-devel] [PULL 2/8] xen-bus: use a separate fd for each event channel Anthony PERARD
2019-06-24 15:32 ` [Qemu-devel] [PULL 3/8] xen-bus: allow AioContext to be specified " Anthony PERARD
2019-06-24 15:32 ` Anthony PERARD [this message]
2019-06-24 15:32 ` [Qemu-devel] [PULL 5/8] xen: Avoid VLA Anthony PERARD
2019-06-24 15:32 ` [Qemu-devel] [PULL 6/8] xen: Drop includes of xen/hvm/params.h Anthony PERARD
2019-06-24 15:32 ` [Qemu-devel] [PULL 7/8] Revert xen/io/ring.h of "Clean up a few header guard symbols" Anthony PERARD
2019-06-24 15:32 ` [Qemu-devel] [PULL 8/8] xen: Import other xen/io/*.h Anthony PERARD
2019-06-24 16:10 ` [Qemu-devel] [Xen-devel] [PULL 0/8] xen queue 2019-06-24 no-reply
2019-06-24 16:28 ` no-reply
2019-06-24 16:34 ` no-reply
2019-06-24 16:48 ` no-reply
2019-06-24 17:19 ` no-reply
2019-07-01 12:45 ` [Qemu-devel] " Peter Maydell
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=20190624153257.20163-5-anthony.perard@citrix.com \
--to=anthony.perard@citrix.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=xen-devel@lists.xenproject.org \
/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).