From: Klaus Jensen <its@irrelevant.dk>
To: Jinhao Fan <fanjinhao21s@ict.ac.cn>
Cc: qemu-devel@nongnu.org, kbusch@kernel.org, stefanha@gmail.com,
"open list:nvme" <qemu-block@nongnu.org>
Subject: Re: [PATCH v3 4/4] hw/nvme: add polling support
Date: Thu, 20 Oct 2022 13:10:57 +0200 [thread overview]
Message-ID: <Y1EswYz077swwhuc@cormorant.local> (raw)
In-Reply-To: <20220827091258.3589230-5-fanjinhao21s@ict.ac.cn>
[-- Attachment #1: Type: text/plain, Size: 6185 bytes --]
On Aug 27 17:12, Jinhao Fan wrote:
> Add AioContext polling handlers for NVMe SQ and CQ. By employing polling,
> the latency of NVMe IO emulation is greatly reduced. The SQ polling
> handler checks for updates on the SQ tail shadow doorbell buffer. The CQ
> polling handler is an empty function because we procatively polls the CQ
> head shadow doorbell buffer when we want to post a cqe. Updates on the
> SQ eventidx buffer is stopped during polling to avoid the host doing
> unnecessary doorbell buffer writes.
>
> Comparison (KIOPS):
>
> QD 1 4 16 64
> QEMU 53 155 245 309
> polling 123 165 189 191
>
> Signed-off-by: Jinhao Fan <fanjinhao21s@ict.ac.cn>
> ---
> hw/nvme/ctrl.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++----
> hw/nvme/nvme.h | 1 +
> 2 files changed, 70 insertions(+), 5 deletions(-)
>
> diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c
> index 869565d77b..a7f8a4220e 100644
> --- a/hw/nvme/ctrl.c
> +++ b/hw/nvme/ctrl.c
> @@ -298,6 +298,8 @@ static const uint32_t nvme_cse_iocs_zoned[256] = {
>
> static void nvme_process_sq(void *opaque);
> static void nvme_ctrl_reset(NvmeCtrl *n, NvmeResetType rst);
> +static void nvme_update_sq_eventidx(const NvmeSQueue *sq);
> +static void nvme_update_sq_tail(NvmeSQueue *sq);
>
> static uint16_t nvme_sqid(NvmeRequest *req)
> {
> @@ -4447,6 +4449,21 @@ static void nvme_cq_notifier(EventNotifier *e)
> nvme_post_cqes(cq);
> }
>
> +static bool nvme_cq_notifier_aio_poll(void *opaque)
> +{
> + /*
> + * We already "poll" the CQ tail shadow doorbell value in nvme_post_cqes(),
> + * so we do not need to check the value here. However, QEMU's AioContext
> + * polling requires us to provide io_poll and io_poll_ready handlers, so
> + * use dummy functions for CQ.
> + */
> + return false;
> +}
> +
> +static void nvme_cq_notifier_aio_poll_ready(EventNotifier *n)
> +{
> +}
> +
> static int nvme_init_cq_ioeventfd(NvmeCQueue *cq)
> {
> NvmeCtrl *n = cq->ctrl;
> @@ -4459,8 +4476,10 @@ static int nvme_init_cq_ioeventfd(NvmeCQueue *cq)
> }
>
> if (cq->cqid) {
> - aio_set_event_notifier(n->ctx, &cq->notifier, true, nvme_cq_notifier,
> - NULL, NULL);
> + aio_set_event_notifier(n->ctx, &cq->notifier, true,
> + nvme_cq_notifier,
> + nvme_cq_notifier_aio_poll,
> + nvme_cq_notifier_aio_poll_ready);
There is no reason to set up these polling handlers (since they don't do
anything).
> } else {
> event_notifier_set_handler(&cq->notifier, nvme_cq_notifier);
> }
> @@ -4482,6 +4501,44 @@ static void nvme_sq_notifier(EventNotifier *e)
> nvme_process_sq(sq);
> }
>
> +static void nvme_sq_notifier_aio_poll_begin(EventNotifier *n)
> +{
> + NvmeSQueue *sq = container_of(n, NvmeSQueue, notifier);
> +
> + nvme_update_sq_eventidx(sq);
> +
> + /* Stop host doorbell writes by stop updating eventidx */
> + sq->suppress_db = true;
This doesn't do what you expect it to. By not updaring the eventidx it
will fall behind the actual head, causing the host to think that the
device is not processing events (but it is!), resulting in doorbell
ringing.
> +}
> +
> +static bool nvme_sq_notifier_aio_poll(void *opaque)
> +{
> + EventNotifier *n = opaque;
> + NvmeSQueue *sq = container_of(n, NvmeSQueue, notifier);
> + uint32_t old_tail = sq->tail;
> +
> + nvme_update_sq_tail(sq);
> +
> + return sq->tail != old_tail;
> +}
> +
> +static void nvme_sq_notifier_aio_poll_ready(EventNotifier *n)
> +{
> + NvmeSQueue *sq = container_of(n, NvmeSQueue, notifier);
> +
> + nvme_process_sq(sq);
> +}
> +
> +static void nvme_sq_notifier_aio_poll_end(EventNotifier *n)
> +{
> + NvmeSQueue *sq = container_of(n, NvmeSQueue, notifier);
> +
> + nvme_update_sq_eventidx(sq);
> +
> + /* Resume host doorbell writes */
> + sq->suppress_db = false;
> +}
> +
> static int nvme_init_sq_ioeventfd(NvmeSQueue *sq)
> {
> NvmeCtrl *n = sq->ctrl;
> @@ -4494,8 +4551,13 @@ static int nvme_init_sq_ioeventfd(NvmeSQueue *sq)
> }
>
> if (sq->sqid) {
> - aio_set_event_notifier(n->ctx, &sq->notifier, true, nvme_sq_notifier,
> - NULL, NULL);
> + aio_set_event_notifier(n->ctx, &sq->notifier, true,
> + nvme_sq_notifier,
> + nvme_sq_notifier_aio_poll,
> + nvme_sq_notifier_aio_poll_ready);
> + aio_set_event_notifier_poll(n->ctx, &sq->notifier,
> + nvme_sq_notifier_aio_poll_begin,
> + nvme_sq_notifier_aio_poll_end);
You can remove the call to aio_set_event_notifier_poll() since the
supress_db "trick" shouldnt be used anyway.
> } else {
> event_notifier_set_handler(&sq->notifier, nvme_sq_notifier);
> }
> @@ -6530,7 +6592,9 @@ static void nvme_process_sq(void *opaque)
> }
>
> if (n->dbbuf_enabled) {
> - nvme_update_sq_eventidx(sq);
> + if (!sq->suppress_db) {
> + nvme_update_sq_eventidx(sq);
> + }
Remove this change.
> nvme_update_sq_tail(sq);
> }
> }
> diff --git a/hw/nvme/nvme.h b/hw/nvme/nvme.h
> index 224b73e6c4..bd486a8e15 100644
> --- a/hw/nvme/nvme.h
> +++ b/hw/nvme/nvme.h
> @@ -380,6 +380,7 @@ typedef struct NvmeSQueue {
> QEMUTimer *timer;
> EventNotifier notifier;
> bool ioeventfd_enabled;
> + bool suppress_db;
Remove this.
> NvmeRequest *io_req;
> QTAILQ_HEAD(, NvmeRequest) req_list;
> QTAILQ_HEAD(, NvmeRequest) out_req_list;
> --
> 2.25.1
>
I tested with the patch modified for the above and I am not seeing any
difference in performance. But without the supress_db, this seems more
"correct".
--
One of us - No more doubt, silence or taboo about mental illness.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
next prev parent reply other threads:[~2022-10-20 12:02 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-27 9:12 [PATCH v3 0/4] irqfd, iothread and polling support Jinhao Fan
2022-08-27 9:12 ` [PATCH v3 1/4] hw/nvme: support irq(de)assertion with eventfd Jinhao Fan
2022-08-27 9:12 ` [PATCH v3 2/4] hw/nvme: use KVM irqfd when available Jinhao Fan
2022-08-27 9:12 ` [PATCH v3 3/4] hw/nvme: add iothread support Jinhao Fan
2022-10-20 11:13 ` Klaus Jensen
2022-11-03 1:51 ` Jinhao Fan
2022-11-03 12:11 ` Klaus Jensen
2022-11-03 13:10 ` Jinhao Fan
2022-08-27 9:12 ` [PATCH v3 4/4] hw/nvme: add polling support Jinhao Fan
2022-10-20 11:10 ` Klaus Jensen [this message]
2022-11-03 2:18 ` Jinhao Fan
2022-11-03 12:10 ` Klaus Jensen
2022-11-03 13:19 ` Jinhao Fan
2022-11-04 6:32 ` Klaus Jensen
2022-11-08 12:39 ` John Levon
2022-11-08 14:11 ` Klaus Jensen
2022-11-09 4:35 ` Jinhao Fan
2022-10-20 11:16 ` [PATCH v3 0/4] irqfd, iothread and " Klaus Jensen
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=Y1EswYz077swwhuc@cormorant.local \
--to=its@irrelevant.dk \
--cc=fanjinhao21s@ict.ac.cn \
--cc=kbusch@kernel.org \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.