From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Kevin Wolf" <kwolf@redhat.com>, "Fam Zheng" <fam@euphon.net>,
qemu-block@nongnu.org, "Max Reitz" <mreitz@redhat.com>,
"Stefan Hajnoczi" <stefanha@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@redhat.com>
Subject: [PATCH v2 1/7] block/nvme: poll queues without q->lock
Date: Wed, 17 Jun 2020 14:21:55 +0100 [thread overview]
Message-ID: <20200617132201.1832152-2-stefanha@redhat.com> (raw)
In-Reply-To: <20200617132201.1832152-1-stefanha@redhat.com>
A lot of CPU time is spent simply locking/unlocking q->lock during
polling. Check for completion outside the lock to make q->lock disappear
from the profile.
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
block/nvme.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/block/nvme.c b/block/nvme.c
index eb2f54dd9d..e4375ec245 100644
--- a/block/nvme.c
+++ b/block/nvme.c
@@ -512,6 +512,18 @@ static bool nvme_poll_queues(BDRVNVMeState *s)
for (i = 0; i < s->nr_queues; i++) {
NVMeQueuePair *q = s->queues[i];
+ const size_t cqe_offset = q->cq.head * NVME_CQ_ENTRY_BYTES;
+ NvmeCqe *cqe = (NvmeCqe *)&q->cq.queue[cqe_offset];
+
+ /*
+ * Do an early check for completions. q->lock isn't needed because
+ * nvme_process_completion() only runs in the event loop thread and
+ * cannot race with itself.
+ */
+ if ((le16_to_cpu(cqe->status) & 0x1) == q->cq_phase) {
+ continue;
+ }
+
qemu_mutex_lock(&q->lock);
while (nvme_process_completion(s, q)) {
/* Keep polling */
--
2.26.2
next prev parent reply other threads:[~2020-06-17 13:23 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-17 13:21 [PATCH v2 0/7] block/nvme: support nested aio_poll() Stefan Hajnoczi
2020-06-17 13:21 ` Stefan Hajnoczi [this message]
2020-06-22 13:54 ` [PATCH v2 1/7] block/nvme: poll queues without q->lock Sergio Lopez
2020-06-17 13:21 ` [PATCH v2 2/7] block/nvme: drop tautologous assertion Stefan Hajnoczi
2020-06-17 13:21 ` [PATCH v2 3/7] block/nvme: don't access CQE after moving cq.head Stefan Hajnoczi
2020-06-17 13:21 ` [PATCH v2 4/7] block/nvme: switch to a NVMeRequest freelist Stefan Hajnoczi
2020-06-17 13:21 ` [PATCH v2 5/7] block/nvme: clarify that free_req_queue is protected by q->lock Stefan Hajnoczi
2020-06-17 13:22 ` [PATCH v2 6/7] block/nvme: keep BDRVNVMeState pointer in NVMeQueuePair Stefan Hajnoczi
2020-06-17 13:22 ` [PATCH v2 7/7] block/nvme: support nested aio_poll() Stefan Hajnoczi
2020-06-23 14:46 ` [PATCH v2 0/7] " Stefan Hajnoczi
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=20200617132201.1832152-2-stefanha@redhat.com \
--to=stefanha@redhat.com \
--cc=fam@euphon.net \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=philmd@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.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).