Commit 2446e0e2 authored by Stefan Hajnoczi's avatar Stefan Hajnoczi
Browse files

block/nvme: poll queues without q->lock



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: default avatarStefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: default avatarSergio Lopez <slp@redhat.com>
Message-id: 20200617132201.1832152-2-stefanha@redhat.com
Signed-off-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
parent d6d1a65c
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -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 */