[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v7 14/15] block/nvme: Extract nvme_poll_queue()
From: |
Philippe Mathieu-Daudé |
Subject: |
[PATCH v7 14/15] block/nvme: Extract nvme_poll_queue() |
Date: |
Thu, 3 Sep 2020 14:28:02 +0200 |
As we want to do per-queue polling, extract the nvme_poll_queue()
method which operates on a single queue.
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
block/nvme.c | 44 +++++++++++++++++++++++++++-----------------
1 file changed, 27 insertions(+), 17 deletions(-)
diff --git a/block/nvme.c b/block/nvme.c
index 914a3c4ab31..e3719d3bd14 100644
--- a/block/nvme.c
+++ b/block/nvme.c
@@ -590,31 +590,41 @@ out:
qemu_vfree(id);
}
+static bool nvme_poll_queue(NVMeQueuePair *q)
+{
+ bool progress = false;
+
+ 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) {
+ return false;
+ }
+
+ qemu_mutex_lock(&q->lock);
+ while (nvme_process_completion(q)) {
+ /* Keep polling */
+ progress = true;
+ }
+ qemu_mutex_unlock(&q->lock);
+
+ return progress;
+}
+
static bool nvme_poll_queues(BDRVNVMeState *s)
{
bool progress = false;
int i;
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(q)) {
- /* Keep polling */
+ if (nvme_poll_queue(s->queues[i])) {
progress = true;
}
- qemu_mutex_unlock(&q->lock);
}
return progress;
}
--
2.26.2
- [PATCH v7 04/15] block/nvme: Define INDEX macros to ease code review, (continued)
- [PATCH v7 04/15] block/nvme: Define INDEX macros to ease code review, Philippe Mathieu-Daudé, 2020/09/03
- [PATCH v7 05/15] block/nvme: Improve error message when IO queue creation failed, Philippe Mathieu-Daudé, 2020/09/03
- [PATCH v7 06/15] block/nvme: Use common error path in nvme_add_io_queue(), Philippe Mathieu-Daudé, 2020/09/03
- [PATCH v7 07/15] block/nvme: Rename local variable, Philippe Mathieu-Daudé, 2020/09/03
- [PATCH v7 08/15] block/nvme: Use union of NvmeIdCtrl / NvmeIdNs structures, Philippe Mathieu-Daudé, 2020/09/03
- [PATCH v7 09/15] block/nvme: Replace qemu_try_blockalign0 by qemu_try_blockalign/memset, Philippe Mathieu-Daudé, 2020/09/03
- [PATCH v7 10/15] block/nvme: Replace qemu_try_blockalign(bs) by qemu_try_memalign(pg_sz), Philippe Mathieu-Daudé, 2020/09/03
- [PATCH v7 11/15] block/nvme: Simplify nvme_init_queue() arguments, Philippe Mathieu-Daudé, 2020/09/03
- [PATCH v7 12/15] block/nvme: Replace BDRV_POLL_WHILE by AIO_WAIT_WHILE, Philippe Mathieu-Daudé, 2020/09/03
- [PATCH v7 13/15] block/nvme: Simplify nvme_create_queue_pair() arguments, Philippe Mathieu-Daudé, 2020/09/03
- [PATCH v7 14/15] block/nvme: Extract nvme_poll_queue(),
Philippe Mathieu-Daudé <=
- [PATCH v7 15/15] block/nvme: Use an array of EventNotifier, Philippe Mathieu-Daudé, 2020/09/03