From nobody Thu Apr 25 15:40:03 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1642008281796848.3584075997707; Wed, 12 Jan 2022 09:24:41 -0800 (PST) Received: from localhost ([::1]:39708 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n7hMW-00088d-Iw for importer@patchew.org; Wed, 12 Jan 2022 12:24:40 -0500 Received: from eggs.gnu.org ([209.51.188.92]:48804) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n7hES-0000N8-7G for qemu-devel@nongnu.org; Wed, 12 Jan 2022 12:16:20 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:43902) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n7hEO-00062I-EI for qemu-devel@nongnu.org; Wed, 12 Jan 2022 12:16:19 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-481-icBw9g1EPZqkz7e7h-WsJw-1; Wed, 12 Jan 2022 12:16:03 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A890D81EE62; Wed, 12 Jan 2022 17:16:01 +0000 (UTC) Received: from localhost (unknown [10.39.195.79]) by smtp.corp.redhat.com (Postfix) with ESMTP id 85B042DE99; Wed, 12 Jan 2022 17:15:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642007773; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ECSmZIc7ds1+QJoIhivTGdF+uFDXzJPrynOZl8hUQyI=; b=TwQy1UmwBN41Gn6EVnjhfTgmomn5pzxKtZeLDBZEXS5vJrSNYx4kU5r1Hgp+kBDQAArGX8 kG9xub2192o7okWbcFQzg9hR9UDVtl8XfqebECTyM8BLL/hZXoe8i0DpRuBv6twYN5a6sB B4eGQIQk0AhwTUMETPSWUtvn7q0y0FM= X-MC-Unique: icBw9g1EPZqkz7e7h-WsJw-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org, Peter Maydell Subject: [PULL 1/6] aio-posix: split poll check from ready handler Date: Wed, 12 Jan 2022 17:13:57 +0000 Message-Id: <20220112171402.112183-2-stefanha@redhat.com> In-Reply-To: <20220112171402.112183-1-stefanha@redhat.com> References: <20220112171402.112183-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=stefanha@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.595, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng , Stefan Hajnoczi , Paul Durrant , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Stefano Stabellini , qemu-block@nongnu.org, Juan Quintela , "Michael S. Tsirkin" , Stefan Weil , Anthony Perard , xen-devel@lists.xenproject.org, Stefano Garzarella , Peter Lieven , Julia Suvorova , "Dr. David Alan Gilbert" , Ronnie Sahlberg , Aarushi Mehta , Kevin Wolf , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , "Richard W.M. Jones" , Coiby Xu , Hanna Reitz , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1642008282841100001 Content-Type: text/plain; charset="utf-8" Adaptive polling measures the execution time of the polling check plus handlers called when a polled event becomes ready. Handlers can take a significant amount of time, making it look like polling was running for a long time when in fact the event handler was running for a long time. For example, on Linux the io_submit(2) syscall invoked when a virtio-blk device's virtqueue becomes ready can take 10s of microseconds. This can exceed the default polling interval (32 microseconds) and cause adaptive polling to stop polling. By excluding the handler's execution time from the polling check we make the adaptive polling calculation more accurate. As a result, the event loop now stays in polling mode where previously it would have fallen back to file descriptor monitoring. The following data was collected with virtio-blk num-queues=3D2 event_idx=3Doff using an IOThread. Before: 168k IOPS, IOThread syscalls: 9837.115 ( 0.020 ms): IO iothread1/620155 io_submit(ctx_id: 1405125524684= 80, nr: 16, iocbpp: 0x7fcb9f937db0) =3D 16 9837.158 ( 0.002 ms): IO iothread1/620155 write(fd: 103, buf: 0x556a2ef71= b88, count: 8) =3D 8 9837.161 ( 0.001 ms): IO iothread1/620155 write(fd: 104, buf: 0x556a2ef71= b88, count: 8) =3D 8 9837.163 ( 0.001 ms): IO iothread1/620155 ppoll(ufds: 0x7fcb90002800, nfd= s: 4, tsp: 0x7fcb9f1342d0, sigsetsize: 8) =3D 3 9837.164 ( 0.001 ms): IO iothread1/620155 read(fd: 107, buf: 0x7fcb9f939c= c0, count: 512) =3D 8 9837.174 ( 0.001 ms): IO iothread1/620155 read(fd: 105, buf: 0x7fcb9f939c= c0, count: 512) =3D 8 9837.176 ( 0.001 ms): IO iothread1/620155 read(fd: 106, buf: 0x7fcb9f939c= c0, count: 512) =3D 8 9837.209 ( 0.035 ms): IO iothread1/620155 io_submit(ctx_id: 1405125524684= 80, nr: 32, iocbpp: 0x7fca7d0cebe0) =3D 32 174k IOPS (+3.6%), IOThread syscalls: 9809.566 ( 0.036 ms): IO iothread1/623061 io_submit(ctx_id: 1405398050283= 52, nr: 32, iocbpp: 0x7fd0cdd62be0) =3D 32 9809.625 ( 0.001 ms): IO iothread1/623061 write(fd: 103, buf: 0x5647cfba5= f58, count: 8) =3D 8 9809.627 ( 0.002 ms): IO iothread1/623061 write(fd: 104, buf: 0x5647cfba5= f58, count: 8) =3D 8 9809.663 ( 0.036 ms): IO iothread1/623061 io_submit(ctx_id: 1405398050283= 52, nr: 32, iocbpp: 0x7fd0d0388b50) =3D 32 Notice that ppoll(2) and eventfd read(2) syscalls are eliminated because the IOThread stays in polling mode instead of falling back to file descriptor monitoring. As usual, polling is not implemented on Windows so this patch ignores the new io_poll_read() callback in aio-win32.c. Signed-off-by: Stefan Hajnoczi Reviewed-by: Stefano Garzarella Message-id: 20211207132336.36627-2-stefanha@redhat.com [Fixed up aio_set_event_notifier() calls in tests/unit/test-fdmon-epoll.c added after this series was queued. --Stefan] Signed-off-by: Stefan Hajnoczi Reviewed-by: Peter Maydell --- include/block/aio.h | 4 +- util/aio-posix.h | 1 + block/curl.c | 11 +++-- block/export/fuse.c | 4 +- block/io_uring.c | 19 ++++---- block/iscsi.c | 4 +- block/linux-aio.c | 16 ++++--- block/nfs.c | 6 +-- block/nvme.c | 51 +++++++++++++------- block/ssh.c | 4 +- block/win32-aio.c | 4 +- hw/virtio/virtio.c | 16 ++++--- hw/xen/xen-bus.c | 6 +-- io/channel-command.c | 6 ++- io/channel-file.c | 3 +- io/channel-socket.c | 3 +- migration/rdma.c | 8 ++-- tests/unit/test-aio.c | 4 +- tests/unit/test-fdmon-epoll.c | 4 +- util/aio-posix.c | 89 ++++++++++++++++++++++++++--------- util/aio-win32.c | 4 +- util/async.c | 10 +++- util/main-loop.c | 4 +- util/qemu-coroutine-io.c | 5 +- util/vhost-user-server.c | 11 +++-- 25 files changed, 193 insertions(+), 104 deletions(-) diff --git a/include/block/aio.h b/include/block/aio.h index 47fbe9d81f..5634173b12 100644 --- a/include/block/aio.h +++ b/include/block/aio.h @@ -469,6 +469,7 @@ void aio_set_fd_handler(AioContext *ctx, IOHandler *io_read, IOHandler *io_write, AioPollFn *io_poll, + IOHandler *io_poll_ready, void *opaque); =20 /* Set polling begin/end callbacks for a file descriptor that has already = been @@ -490,7 +491,8 @@ void aio_set_event_notifier(AioContext *ctx, EventNotifier *notifier, bool is_external, EventNotifierHandler *io_read, - AioPollFn *io_poll); + AioPollFn *io_poll, + EventNotifierHandler *io_poll_ready); =20 /* Set polling begin/end callbacks for an event notifier that has already = been * registered with aio_set_event_notifier. Do nothing if the event notifi= er is diff --git a/util/aio-posix.h b/util/aio-posix.h index c80c04506a..7f2c37a684 100644 --- a/util/aio-posix.h +++ b/util/aio-posix.h @@ -24,6 +24,7 @@ struct AioHandler { IOHandler *io_read; IOHandler *io_write; AioPollFn *io_poll; + IOHandler *io_poll_ready; IOHandler *io_poll_begin; IOHandler *io_poll_end; void *opaque; diff --git a/block/curl.c b/block/curl.c index 4a8ae2b269..6a6cd72975 100644 --- a/block/curl.c +++ b/block/curl.c @@ -125,7 +125,7 @@ static gboolean curl_drop_socket(void *key, void *value= , void *opaque) BDRVCURLState *s =3D socket->s; =20 aio_set_fd_handler(s->aio_context, socket->fd, false, - NULL, NULL, NULL, NULL); + NULL, NULL, NULL, NULL, NULL); return true; } =20 @@ -173,19 +173,20 @@ static int curl_sock_cb(CURL *curl, curl_socket_t fd,= int action, switch (action) { case CURL_POLL_IN: aio_set_fd_handler(s->aio_context, fd, false, - curl_multi_do, NULL, NULL, socket); + curl_multi_do, NULL, NULL, NULL, socket); break; case CURL_POLL_OUT: aio_set_fd_handler(s->aio_context, fd, false, - NULL, curl_multi_do, NULL, socket); + NULL, curl_multi_do, NULL, NULL, socket); break; case CURL_POLL_INOUT: aio_set_fd_handler(s->aio_context, fd, false, - curl_multi_do, curl_multi_do, NULL, socket); + curl_multi_do, curl_multi_do, + NULL, NULL, socket); break; case CURL_POLL_REMOVE: aio_set_fd_handler(s->aio_context, fd, false, - NULL, NULL, NULL, NULL); + NULL, NULL, NULL, NULL, NULL); break; } =20 diff --git a/block/export/fuse.c b/block/export/fuse.c index 823c126d23..6710d8aed8 100644 --- a/block/export/fuse.c +++ b/block/export/fuse.c @@ -223,7 +223,7 @@ static int setup_fuse_export(FuseExport *exp, const cha= r *mountpoint, =20 aio_set_fd_handler(exp->common.ctx, fuse_session_fd(exp->fuse_session), true, - read_from_fuse_export, NULL, NULL, exp); + read_from_fuse_export, NULL, NULL, NULL, exp); exp->fd_handler_set_up =3D true; =20 return 0; @@ -267,7 +267,7 @@ static void fuse_export_shutdown(BlockExport *blk_exp) if (exp->fd_handler_set_up) { aio_set_fd_handler(exp->common.ctx, fuse_session_fd(exp->fuse_session), true, - NULL, NULL, NULL, NULL); + NULL, NULL, NULL, NULL, NULL); exp->fd_handler_set_up =3D false; } } diff --git a/block/io_uring.c b/block/io_uring.c index dfa475cc87..782afdb433 100644 --- a/block/io_uring.c +++ b/block/io_uring.c @@ -292,12 +292,14 @@ static bool qemu_luring_poll_cb(void *opaque) { LuringState *s =3D opaque; =20 - if (io_uring_cq_ready(&s->ring)) { - luring_process_completions_and_submit(s); - return true; - } + return io_uring_cq_ready(&s->ring); +} =20 - return false; +static void qemu_luring_poll_ready(void *opaque) +{ + LuringState *s =3D opaque; + + luring_process_completions_and_submit(s); } =20 static void ioq_init(LuringQueue *io_q) @@ -402,8 +404,8 @@ int coroutine_fn luring_co_submit(BlockDriverState *bs,= LuringState *s, int fd, =20 void luring_detach_aio_context(LuringState *s, AioContext *old_context) { - aio_set_fd_handler(old_context, s->ring.ring_fd, false, NULL, NULL, NU= LL, - s); + aio_set_fd_handler(old_context, s->ring.ring_fd, false, + NULL, NULL, NULL, NULL, s); qemu_bh_delete(s->completion_bh); s->aio_context =3D NULL; } @@ -413,7 +415,8 @@ void luring_attach_aio_context(LuringState *s, AioConte= xt *new_context) s->aio_context =3D new_context; s->completion_bh =3D aio_bh_new(new_context, qemu_luring_completion_bh= , s); aio_set_fd_handler(s->aio_context, s->ring.ring_fd, false, - qemu_luring_completion_cb, NULL, qemu_luring_poll_c= b, s); + qemu_luring_completion_cb, NULL, + qemu_luring_poll_cb, qemu_luring_poll_ready, s); } =20 LuringState *luring_init(Error **errp) diff --git a/block/iscsi.c b/block/iscsi.c index 57aa07a40d..51f2a5eeaa 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -363,7 +363,7 @@ iscsi_set_events(IscsiLun *iscsilun) false, (ev & POLLIN) ? iscsi_process_read : NULL, (ev & POLLOUT) ? iscsi_process_write : NULL, - NULL, + NULL, NULL, iscsilun); iscsilun->events =3D ev; } @@ -1534,7 +1534,7 @@ static void iscsi_detach_aio_context(BlockDriverState= *bs) IscsiLun *iscsilun =3D bs->opaque; =20 aio_set_fd_handler(iscsilun->aio_context, iscsi_get_fd(iscsilun->iscsi= ), - false, NULL, NULL, NULL, NULL); + false, NULL, NULL, NULL, NULL, NULL); iscsilun->events =3D 0; =20 if (iscsilun->nop_timer) { diff --git a/block/linux-aio.c b/block/linux-aio.c index f53ae72e21..4c423fcccf 100644 --- a/block/linux-aio.c +++ b/block/linux-aio.c @@ -263,12 +263,15 @@ static bool qemu_laio_poll_cb(void *opaque) LinuxAioState *s =3D container_of(e, LinuxAioState, e); struct io_event *events; =20 - if (!io_getevents_peek(s->ctx, &events)) { - return false; - } + return io_getevents_peek(s->ctx, &events); +} + +static void qemu_laio_poll_ready(EventNotifier *opaque) +{ + EventNotifier *e =3D opaque; + LinuxAioState *s =3D container_of(e, LinuxAioState, e); =20 qemu_laio_process_completions_and_submit(s); - return true; } =20 static void ioq_init(LaioQueue *io_q) @@ -427,7 +430,7 @@ int coroutine_fn laio_co_submit(BlockDriverState *bs, L= inuxAioState *s, int fd, =20 void laio_detach_aio_context(LinuxAioState *s, AioContext *old_context) { - aio_set_event_notifier(old_context, &s->e, false, NULL, NULL); + aio_set_event_notifier(old_context, &s->e, false, NULL, NULL, NULL); qemu_bh_delete(s->completion_bh); s->aio_context =3D NULL; } @@ -438,7 +441,8 @@ void laio_attach_aio_context(LinuxAioState *s, AioConte= xt *new_context) s->completion_bh =3D aio_bh_new(new_context, qemu_laio_completion_bh, = s); aio_set_event_notifier(new_context, &s->e, false, qemu_laio_completion_cb, - qemu_laio_poll_cb); + qemu_laio_poll_cb, + qemu_laio_poll_ready); } =20 LinuxAioState *laio_init(Error **errp) diff --git a/block/nfs.c b/block/nfs.c index 577aea1d22..444c40b458 100644 --- a/block/nfs.c +++ b/block/nfs.c @@ -197,7 +197,7 @@ static void nfs_set_events(NFSClient *client) false, (ev & POLLIN) ? nfs_process_read : NULL, (ev & POLLOUT) ? nfs_process_write : NULL, - NULL, client); + NULL, NULL, client); =20 } client->events =3D ev; @@ -372,7 +372,7 @@ static void nfs_detach_aio_context(BlockDriverState *bs) NFSClient *client =3D bs->opaque; =20 aio_set_fd_handler(client->aio_context, nfs_get_fd(client->context), - false, NULL, NULL, NULL, NULL); + false, NULL, NULL, NULL, NULL, NULL); client->events =3D 0; } =20 @@ -390,7 +390,7 @@ static void nfs_client_close(NFSClient *client) if (client->context) { qemu_mutex_lock(&client->mutex); aio_set_fd_handler(client->aio_context, nfs_get_fd(client->context= ), - false, NULL, NULL, NULL, NULL); + false, NULL, NULL, NULL, NULL, NULL); qemu_mutex_unlock(&client->mutex); if (client->fh) { nfs_close(client->context, client->fh); diff --git a/block/nvme.c b/block/nvme.c index fa360b9b3c..dd20de3865 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -605,10 +605,8 @@ out: return ret; } =20 -static bool nvme_poll_queue(NVMeQueuePair *q) +static void nvme_poll_queue(NVMeQueuePair *q) { - bool progress =3D false; - const size_t cqe_offset =3D q->cq.head * NVME_CQ_ENTRY_BYTES; NvmeCqe *cqe =3D (NvmeCqe *)&q->cq.queue[cqe_offset]; =20 @@ -619,30 +617,23 @@ static bool nvme_poll_queue(NVMeQueuePair *q) * cannot race with itself. */ if ((le16_to_cpu(cqe->status) & 0x1) =3D=3D q->cq_phase) { - return false; + return; } =20 qemu_mutex_lock(&q->lock); while (nvme_process_completion(q)) { /* Keep polling */ - progress =3D true; } qemu_mutex_unlock(&q->lock); - - return progress; } =20 -static bool nvme_poll_queues(BDRVNVMeState *s) +static void nvme_poll_queues(BDRVNVMeState *s) { - bool progress =3D false; int i; =20 for (i =3D 0; i < s->queue_count; i++) { - if (nvme_poll_queue(s->queues[i])) { - progress =3D true; - } + nvme_poll_queue(s->queues[i]); } - return progress; } =20 static void nvme_handle_event(EventNotifier *n) @@ -703,8 +694,30 @@ static bool nvme_poll_cb(void *opaque) EventNotifier *e =3D opaque; BDRVNVMeState *s =3D container_of(e, BDRVNVMeState, irq_notifier[MSIX_SHARED_IRQ_IDX]); + int i; =20 - return nvme_poll_queues(s); + for (i =3D 0; i < s->queue_count; i++) { + NVMeQueuePair *q =3D s->queues[i]; + const size_t cqe_offset =3D q->cq.head * NVME_CQ_ENTRY_BYTES; + NvmeCqe *cqe =3D (NvmeCqe *)&q->cq.queue[cqe_offset]; + + /* + * q->lock isn't needed because nvme_process_completion() only run= s in + * the event loop thread and cannot race with itself. + */ + if ((le16_to_cpu(cqe->status) & 0x1) !=3D q->cq_phase) { + return true; + } + } + return false; +} + +static void nvme_poll_ready(EventNotifier *e) +{ + BDRVNVMeState *s =3D container_of(e, BDRVNVMeState, + irq_notifier[MSIX_SHARED_IRQ_IDX]); + + nvme_poll_queues(s); } =20 static int nvme_init(BlockDriverState *bs, const char *device, int namespa= ce, @@ -839,7 +852,8 @@ static int nvme_init(BlockDriverState *bs, const char *= device, int namespace, } aio_set_event_notifier(bdrv_get_aio_context(bs), &s->irq_notifier[MSIX_SHARED_IRQ_IDX], - false, nvme_handle_event, nvme_poll_cb); + false, nvme_handle_event, nvme_poll_cb, + nvme_poll_ready); =20 if (!nvme_identify(bs, namespace, errp)) { ret =3D -EIO; @@ -924,7 +938,7 @@ static void nvme_close(BlockDriverState *bs) g_free(s->queues); aio_set_event_notifier(bdrv_get_aio_context(bs), &s->irq_notifier[MSIX_SHARED_IRQ_IDX], - false, NULL, NULL); + false, NULL, NULL, NULL); event_notifier_cleanup(&s->irq_notifier[MSIX_SHARED_IRQ_IDX]); qemu_vfio_pci_unmap_bar(s->vfio, 0, s->bar0_wo_map, 0, sizeof(NvmeBar) + NVME_DOORBELL_SIZE); @@ -1520,7 +1534,7 @@ static void nvme_detach_aio_context(BlockDriverState = *bs) =20 aio_set_event_notifier(bdrv_get_aio_context(bs), &s->irq_notifier[MSIX_SHARED_IRQ_IDX], - false, NULL, NULL); + false, NULL, NULL, NULL); } =20 static void nvme_attach_aio_context(BlockDriverState *bs, @@ -1530,7 +1544,8 @@ static void nvme_attach_aio_context(BlockDriverState = *bs, =20 s->aio_context =3D new_context; aio_set_event_notifier(new_context, &s->irq_notifier[MSIX_SHARED_IRQ_I= DX], - false, nvme_handle_event, nvme_poll_cb); + false, nvme_handle_event, nvme_poll_cb, + nvme_poll_ready); =20 for (unsigned i =3D 0; i < s->queue_count; i++) { NVMeQueuePair *q =3D s->queues[i]; diff --git a/block/ssh.c b/block/ssh.c index e0fbb4934b..3b5bf34031 100644 --- a/block/ssh.c +++ b/block/ssh.c @@ -990,7 +990,7 @@ static void restart_coroutine(void *opaque) AioContext *ctx =3D bdrv_get_aio_context(bs); =20 trace_ssh_restart_coroutine(restart->co); - aio_set_fd_handler(ctx, s->sock, false, NULL, NULL, NULL, NULL); + aio_set_fd_handler(ctx, s->sock, false, NULL, NULL, NULL, NULL, NULL); =20 aio_co_wake(restart->co); } @@ -1020,7 +1020,7 @@ static coroutine_fn void co_yield(BDRVSSHState *s, Bl= ockDriverState *bs) trace_ssh_co_yield(s->sock, rd_handler, wr_handler); =20 aio_set_fd_handler(bdrv_get_aio_context(bs), s->sock, - false, rd_handler, wr_handler, NULL, &restart); + false, rd_handler, wr_handler, NULL, NULL, &restart= ); qemu_coroutine_yield(); trace_ssh_co_yield_back(s->sock); } diff --git a/block/win32-aio.c b/block/win32-aio.c index b7221a272f..c57e10c997 100644 --- a/block/win32-aio.c +++ b/block/win32-aio.c @@ -172,7 +172,7 @@ int win32_aio_attach(QEMUWin32AIOState *aio, HANDLE hfi= le) void win32_aio_detach_aio_context(QEMUWin32AIOState *aio, AioContext *old_context) { - aio_set_event_notifier(old_context, &aio->e, false, NULL, NULL); + aio_set_event_notifier(old_context, &aio->e, false, NULL, NULL, NULL); aio->aio_ctx =3D NULL; } =20 @@ -181,7 +181,7 @@ void win32_aio_attach_aio_context(QEMUWin32AIOState *ai= o, { aio->aio_ctx =3D new_context; aio_set_event_notifier(new_context, &aio->e, false, - win32_aio_completion_cb, NULL); + win32_aio_completion_cb, NULL, NULL); } =20 QEMUWin32AIOState *win32_aio_init(void) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 5d18868d7d..5db7f69237 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -3536,11 +3536,14 @@ static bool virtio_queue_host_notifier_aio_poll(voi= d *opaque) EventNotifier *n =3D opaque; VirtQueue *vq =3D container_of(n, VirtQueue, host_notifier); =20 - if (!vq->vring.desc || virtio_queue_empty(vq)) { - return false; - } + return vq->vring.desc && !virtio_queue_empty(vq); +} =20 - return virtio_queue_notify_aio_vq(vq); +static void virtio_queue_host_notifier_aio_poll_ready(EventNotifier *n) +{ + VirtQueue *vq =3D container_of(n, VirtQueue, host_notifier); + + virtio_queue_notify_aio_vq(vq); } =20 static void virtio_queue_host_notifier_aio_poll_end(EventNotifier *n) @@ -3558,12 +3561,13 @@ void virtio_queue_aio_set_host_notifier_handler(Vir= tQueue *vq, AioContext *ctx, vq->handle_aio_output =3D handle_output; aio_set_event_notifier(ctx, &vq->host_notifier, true, virtio_queue_host_notifier_aio_read, - virtio_queue_host_notifier_aio_poll); + virtio_queue_host_notifier_aio_poll, + virtio_queue_host_notifier_aio_poll_ready); aio_set_event_notifier_poll(ctx, &vq->host_notifier, virtio_queue_host_notifier_aio_poll_be= gin, virtio_queue_host_notifier_aio_poll_en= d); } else { - aio_set_event_notifier(ctx, &vq->host_notifier, true, NULL, NULL); + aio_set_event_notifier(ctx, &vq->host_notifier, true, NULL, NULL, = NULL); /* Test and clear notifier before after disabling event, * in case poll callback didn't have time to run. */ virtio_queue_host_notifier_aio_read(&vq->host_notifier); diff --git a/hw/xen/xen-bus.c b/hw/xen/xen-bus.c index 416583f130..645a29a5a0 100644 --- a/hw/xen/xen-bus.c +++ b/hw/xen/xen-bus.c @@ -1115,11 +1115,11 @@ void xen_device_set_event_channel_context(XenDevice= *xendev, =20 if (channel->ctx) aio_set_fd_handler(channel->ctx, xenevtchn_fd(channel->xeh), true, - NULL, NULL, NULL, NULL); + NULL, NULL, NULL, NULL, NULL); =20 channel->ctx =3D ctx; aio_set_fd_handler(channel->ctx, xenevtchn_fd(channel->xeh), true, - xen_device_event, NULL, xen_device_poll, channel); + xen_device_event, NULL, xen_device_poll, NULL, chan= nel); } =20 XenEventChannel *xen_device_bind_event_channel(XenDevice *xendev, @@ -1193,7 +1193,7 @@ void xen_device_unbind_event_channel(XenDevice *xende= v, QLIST_REMOVE(channel, list); =20 aio_set_fd_handler(channel->ctx, xenevtchn_fd(channel->xeh), true, - NULL, NULL, NULL, NULL); + NULL, NULL, NULL, NULL, NULL); =20 if (xenevtchn_unbind(channel->xeh, channel->local_port) < 0) { error_setg_errno(errp, errno, "xenevtchn_unbind failed"); diff --git a/io/channel-command.c b/io/channel-command.c index b2a9e27138..338da73ade 100644 --- a/io/channel-command.c +++ b/io/channel-command.c @@ -346,8 +346,10 @@ static void qio_channel_command_set_aio_fd_handler(QIO= Channel *ioc, void *opaque) { QIOChannelCommand *cioc =3D QIO_CHANNEL_COMMAND(ioc); - aio_set_fd_handler(ctx, cioc->readfd, false, io_read, NULL, NULL, opaq= ue); - aio_set_fd_handler(ctx, cioc->writefd, false, NULL, io_write, NULL, op= aque); + aio_set_fd_handler(ctx, cioc->readfd, false, + io_read, NULL, NULL, NULL, opaque); + aio_set_fd_handler(ctx, cioc->writefd, false, + NULL, io_write, NULL, NULL, opaque); } =20 =20 diff --git a/io/channel-file.c b/io/channel-file.c index c4bf799a80..d7cf6d278f 100644 --- a/io/channel-file.c +++ b/io/channel-file.c @@ -191,7 +191,8 @@ static void qio_channel_file_set_aio_fd_handler(QIOChan= nel *ioc, void *opaque) { QIOChannelFile *fioc =3D QIO_CHANNEL_FILE(ioc); - aio_set_fd_handler(ctx, fioc->fd, false, io_read, io_write, NULL, opaq= ue); + aio_set_fd_handler(ctx, fioc->fd, false, io_read, io_write, + NULL, NULL, opaque); } =20 static GSource *qio_channel_file_create_watch(QIOChannel *ioc, diff --git a/io/channel-socket.c b/io/channel-socket.c index 606ec97cf7..459922c874 100644 --- a/io/channel-socket.c +++ b/io/channel-socket.c @@ -761,7 +761,8 @@ static void qio_channel_socket_set_aio_fd_handler(QIOCh= annel *ioc, void *opaque) { QIOChannelSocket *sioc =3D QIO_CHANNEL_SOCKET(ioc); - aio_set_fd_handler(ctx, sioc->fd, false, io_read, io_write, NULL, opaq= ue); + aio_set_fd_handler(ctx, sioc->fd, false, + io_read, io_write, NULL, NULL, opaque); } =20 static GSource *qio_channel_socket_create_watch(QIOChannel *ioc, diff --git a/migration/rdma.c b/migration/rdma.c index f5d3bbe7e9..c7c7a38487 100644 --- a/migration/rdma.c +++ b/migration/rdma.c @@ -3161,14 +3161,14 @@ static void qio_channel_rdma_set_aio_fd_handler(QIO= Channel *ioc, QIOChannelRDMA *rioc =3D QIO_CHANNEL_RDMA(ioc); if (io_read) { aio_set_fd_handler(ctx, rioc->rdmain->recv_comp_channel->fd, - false, io_read, io_write, NULL, opaque); + false, io_read, io_write, NULL, NULL, opaque); aio_set_fd_handler(ctx, rioc->rdmain->send_comp_channel->fd, - false, io_read, io_write, NULL, opaque); + false, io_read, io_write, NULL, NULL, opaque); } else { aio_set_fd_handler(ctx, rioc->rdmaout->recv_comp_channel->fd, - false, io_read, io_write, NULL, opaque); + false, io_read, io_write, NULL, NULL, opaque); aio_set_fd_handler(ctx, rioc->rdmaout->send_comp_channel->fd, - false, io_read, io_write, NULL, opaque); + false, io_read, io_write, NULL, NULL, opaque); } } =20 diff --git a/tests/unit/test-aio.c b/tests/unit/test-aio.c index 6feeb9a4a9..178048d2f2 100644 --- a/tests/unit/test-aio.c +++ b/tests/unit/test-aio.c @@ -130,7 +130,7 @@ static void *test_acquire_thread(void *opaque) static void set_event_notifier(AioContext *ctx, EventNotifier *notifier, EventNotifierHandler *handler) { - aio_set_event_notifier(ctx, notifier, false, handler, NULL); + aio_set_event_notifier(ctx, notifier, false, handler, NULL, NULL); } =20 static void dummy_notifier_read(EventNotifier *n) @@ -390,7 +390,7 @@ static void test_aio_external_client(void) for (i =3D 1; i < 3; i++) { EventNotifierTestData data =3D { .n =3D 0, .active =3D 10, .auto_s= et =3D true }; event_notifier_init(&data.e, false); - aio_set_event_notifier(ctx, &data.e, true, event_ready_cb, NULL); + aio_set_event_notifier(ctx, &data.e, true, event_ready_cb, NULL, N= ULL); event_notifier_set(&data.e); for (j =3D 0; j < i; j++) { aio_disable_external(ctx); diff --git a/tests/unit/test-fdmon-epoll.c b/tests/unit/test-fdmon-epoll.c index 11fd8a2fa9..ef5a856d09 100644 --- a/tests/unit/test-fdmon-epoll.c +++ b/tests/unit/test-fdmon-epoll.c @@ -22,14 +22,14 @@ static void add_event_notifiers(EventNotifier *notifier= s, size_t n) for (size_t i =3D 0; i < n; i++) { event_notifier_init(¬ifiers[i], false); aio_set_event_notifier(ctx, ¬ifiers[i], false, - dummy_fd_handler, NULL); + dummy_fd_handler, NULL, NULL); } } =20 static void remove_event_notifiers(EventNotifier *notifiers, size_t n) { for (size_t i =3D 0; i < n; i++) { - aio_set_event_notifier(ctx, ¬ifiers[i], false, NULL, NULL); + aio_set_event_notifier(ctx, ¬ifiers[i], false, NULL, NULL, NULL= ); event_notifier_cleanup(¬ifiers[i]); } } diff --git a/util/aio-posix.c b/util/aio-posix.c index 2b86777e91..7b9f629218 100644 --- a/util/aio-posix.c +++ b/util/aio-posix.c @@ -23,6 +23,15 @@ #include "trace.h" #include "aio-posix.h" =20 +/* + * G_IO_IN and G_IO_OUT are not appropriate revents values for polling, si= nce + * the handler may not need to access the file descriptor. For example, the + * handler doesn't need to read from an EventNotifier if it polled a memory + * location and a read syscall would be slow. Define our own unique revents + * value to indicate that polling determined this AioHandler is ready. + */ +#define REVENTS_POLL_READY 0 + /* Stop userspace polling on a handler if it isn't active for some time */ #define POLL_IDLE_INTERVAL_NS (7 * NANOSECONDS_PER_SECOND) =20 @@ -93,6 +102,7 @@ void aio_set_fd_handler(AioContext *ctx, IOHandler *io_read, IOHandler *io_write, AioPollFn *io_poll, + IOHandler *io_poll_ready, void *opaque) { AioHandler *node; @@ -101,6 +111,10 @@ void aio_set_fd_handler(AioContext *ctx, bool deleted =3D false; int poll_disable_change; =20 + if (io_poll && !io_poll_ready) { + io_poll =3D NULL; /* polling only makes sense if there is a handle= r */ + } + qemu_lockcnt_lock(&ctx->list_lock); =20 node =3D find_aio_handler(ctx, fd); @@ -127,6 +141,7 @@ void aio_set_fd_handler(AioContext *ctx, new_node->io_read =3D io_read; new_node->io_write =3D io_write; new_node->io_poll =3D io_poll; + new_node->io_poll_ready =3D io_poll_ready; new_node->opaque =3D opaque; new_node->is_external =3D is_external; =20 @@ -182,10 +197,12 @@ void aio_set_event_notifier(AioContext *ctx, EventNotifier *notifier, bool is_external, EventNotifierHandler *io_read, - AioPollFn *io_poll) + AioPollFn *io_poll, + EventNotifierHandler *io_poll_ready) { aio_set_fd_handler(ctx, event_notifier_get_fd(notifier), is_external, - (IOHandler *)io_read, NULL, io_poll, notifier); + (IOHandler *)io_read, NULL, io_poll, + (IOHandler *)io_poll_ready, notifier); } =20 void aio_set_event_notifier_poll(AioContext *ctx, @@ -198,7 +215,8 @@ void aio_set_event_notifier_poll(AioContext *ctx, (IOHandler *)io_poll_end); } =20 -static bool poll_set_started(AioContext *ctx, bool started) +static bool poll_set_started(AioContext *ctx, AioHandlerList *ready_list, + bool started) { AioHandler *node; bool progress =3D false; @@ -228,8 +246,9 @@ static bool poll_set_started(AioContext *ctx, bool star= ted) } =20 /* Poll one last time in case ->io_poll_end() raced with the event= */ - if (!started) { - progress =3D node->io_poll(node->opaque) || progress; + if (!started && node->io_poll(node->opaque)) { + aio_add_ready_handler(ready_list, node, REVENTS_POLL_READY); + progress =3D true; } } qemu_lockcnt_dec(&ctx->list_lock); @@ -240,8 +259,11 @@ static bool poll_set_started(AioContext *ctx, bool sta= rted) =20 bool aio_prepare(AioContext *ctx) { + AioHandlerList ready_list =3D QLIST_HEAD_INITIALIZER(ready_list); + /* Poll mode cannot be used with glib's event loop, disable it. */ - poll_set_started(ctx, false); + poll_set_started(ctx, &ready_list, false); + /* TODO what to do with this list? */ =20 return false; } @@ -321,6 +343,18 @@ static bool aio_dispatch_handler(AioContext *ctx, AioH= andler *node) } QLIST_INSERT_HEAD(&ctx->poll_aio_handlers, node, node_poll); } + if (!QLIST_IS_INSERTED(node, node_deleted) && + revents =3D=3D 0 && + aio_node_check(ctx, node->is_external) && + node->io_poll_ready) { + node->io_poll_ready(node->opaque); + + /* + * Return early since revents was zero. aio_notify() does not coun= t as + * progress. + */ + return node->opaque !=3D &ctx->notifier; + } =20 if (!QLIST_IS_INSERTED(node, node_deleted) && (revents & (G_IO_IN | G_IO_HUP | G_IO_ERR)) && @@ -387,6 +421,7 @@ void aio_dispatch(AioContext *ctx) } =20 static bool run_poll_handlers_once(AioContext *ctx, + AioHandlerList *ready_list, int64_t now, int64_t *timeout) { @@ -397,6 +432,8 @@ static bool run_poll_handlers_once(AioContext *ctx, QLIST_FOREACH_SAFE(node, &ctx->poll_aio_handlers, node_poll, tmp) { if (aio_node_check(ctx, node->is_external) && node->io_poll(node->opaque)) { + aio_add_ready_handler(ready_list, node, REVENTS_POLL_READY); + node->poll_idle_timeout =3D now + POLL_IDLE_INTERVAL_NS; =20 /* @@ -420,7 +457,9 @@ static bool fdmon_supports_polling(AioContext *ctx) return ctx->fdmon_ops->need_wait !=3D aio_poll_disabled; } =20 -static bool remove_idle_poll_handlers(AioContext *ctx, int64_t now) +static bool remove_idle_poll_handlers(AioContext *ctx, + AioHandlerList *ready_list, + int64_t now) { AioHandler *node; AioHandler *tmp; @@ -451,7 +490,11 @@ static bool remove_idle_poll_handlers(AioContext *ctx,= int64_t now) * Nevermind about re-adding the handler in the rare case = where * this causes progress. */ - progress =3D node->io_poll(node->opaque) || progress; + if (node->io_poll(node->opaque)) { + aio_add_ready_handler(ready_list, node, + REVENTS_POLL_READY); + progress =3D true; + } } } } @@ -461,6 +504,7 @@ static bool remove_idle_poll_handlers(AioContext *ctx, = int64_t now) =20 /* run_poll_handlers: * @ctx: the AioContext + * @ready_list: the list to place ready handlers on * @max_ns: maximum time to poll for, in nanoseconds * * Polls for a given time. @@ -469,7 +513,8 @@ static bool remove_idle_poll_handlers(AioContext *ctx, = int64_t now) * * Returns: true if progress was made, false otherwise */ -static bool run_poll_handlers(AioContext *ctx, int64_t max_ns, int64_t *ti= meout) +static bool run_poll_handlers(AioContext *ctx, AioHandlerList *ready_list, + int64_t max_ns, int64_t *timeout) { bool progress; int64_t start_time, elapsed_time; @@ -490,13 +535,15 @@ static bool run_poll_handlers(AioContext *ctx, int64_= t max_ns, int64_t *timeout) =20 start_time =3D qemu_clock_get_ns(QEMU_CLOCK_REALTIME); do { - progress =3D run_poll_handlers_once(ctx, start_time, timeout); + progress =3D run_poll_handlers_once(ctx, ready_list, + start_time, timeout); elapsed_time =3D qemu_clock_get_ns(QEMU_CLOCK_REALTIME) - start_ti= me; max_ns =3D qemu_soonest_timeout(*timeout, max_ns); assert(!(max_ns && progress)); } while (elapsed_time < max_ns && !ctx->fdmon_ops->need_wait(ctx)); =20 - if (remove_idle_poll_handlers(ctx, start_time + elapsed_time)) { + if (remove_idle_poll_handlers(ctx, ready_list, + start_time + elapsed_time)) { *timeout =3D 0; progress =3D true; } @@ -514,6 +561,7 @@ static bool run_poll_handlers(AioContext *ctx, int64_t = max_ns, int64_t *timeout) =20 /* try_poll_mode: * @ctx: the AioContext + * @ready_list: list to add handlers that need to be run * @timeout: timeout for blocking wait, computed by the caller and updated= if * polling succeeds. * @@ -521,7 +569,8 @@ static bool run_poll_handlers(AioContext *ctx, int64_t = max_ns, int64_t *timeout) * * Returns: true if progress was made, false otherwise */ -static bool try_poll_mode(AioContext *ctx, int64_t *timeout) +static bool try_poll_mode(AioContext *ctx, AioHandlerList *ready_list, + int64_t *timeout) { int64_t max_ns; =20 @@ -531,14 +580,14 @@ static bool try_poll_mode(AioContext *ctx, int64_t *t= imeout) =20 max_ns =3D qemu_soonest_timeout(*timeout, ctx->poll_ns); if (max_ns && !ctx->fdmon_ops->need_wait(ctx)) { - poll_set_started(ctx, true); + poll_set_started(ctx, ready_list, true); =20 - if (run_poll_handlers(ctx, max_ns, timeout)) { + if (run_poll_handlers(ctx, ready_list, max_ns, timeout)) { return true; } } =20 - if (poll_set_started(ctx, false)) { + if (poll_set_started(ctx, ready_list, false)) { *timeout =3D 0; return true; } @@ -549,7 +598,6 @@ static bool try_poll_mode(AioContext *ctx, int64_t *tim= eout) bool aio_poll(AioContext *ctx, bool blocking) { AioHandlerList ready_list =3D QLIST_HEAD_INITIALIZER(ready_list); - int ret =3D 0; bool progress; bool use_notify_me; int64_t timeout; @@ -574,7 +622,7 @@ bool aio_poll(AioContext *ctx, bool blocking) } =20 timeout =3D blocking ? aio_compute_timeout(ctx) : 0; - progress =3D try_poll_mode(ctx, &timeout); + progress =3D try_poll_mode(ctx, &ready_list, &timeout); assert(!(timeout && progress)); =20 /* @@ -604,7 +652,7 @@ bool aio_poll(AioContext *ctx, bool blocking) * system call---a single round of run_poll_handlers_once suffices. */ if (timeout || ctx->fdmon_ops->need_wait(ctx)) { - ret =3D ctx->fdmon_ops->wait(ctx, &ready_list, timeout); + ctx->fdmon_ops->wait(ctx, &ready_list, timeout); } =20 if (use_notify_me) { @@ -657,10 +705,7 @@ bool aio_poll(AioContext *ctx, bool blocking) } =20 progress |=3D aio_bh_poll(ctx); - - if (ret > 0) { - progress |=3D aio_dispatch_ready_handlers(ctx, &ready_list); - } + progress |=3D aio_dispatch_ready_handlers(ctx, &ready_list); =20 aio_free_deleted_handlers(ctx); =20 diff --git a/util/aio-win32.c b/util/aio-win32.c index d5b09a1193..7aac89df3a 100644 --- a/util/aio-win32.c +++ b/util/aio-win32.c @@ -68,6 +68,7 @@ void aio_set_fd_handler(AioContext *ctx, IOHandler *io_read, IOHandler *io_write, AioPollFn *io_poll, + IOHandler *io_poll_ready, void *opaque) { /* fd is a SOCKET in our case */ @@ -136,7 +137,8 @@ void aio_set_event_notifier(AioContext *ctx, EventNotifier *e, bool is_external, EventNotifierHandler *io_notify, - AioPollFn *io_poll) + AioPollFn *io_poll, + EventNotifierHandler *io_poll_ready) { AioHandler *node; =20 diff --git a/util/async.c b/util/async.c index 6f6717a34b..08d25feef5 100644 --- a/util/async.c +++ b/util/async.c @@ -362,7 +362,7 @@ aio_ctx_finalize(GSource *source) g_free(bh); } =20 - aio_set_event_notifier(ctx, &ctx->notifier, false, NULL, NULL); + aio_set_event_notifier(ctx, &ctx->notifier, false, NULL, NULL, NULL); event_notifier_cleanup(&ctx->notifier); qemu_rec_mutex_destroy(&ctx->lock); qemu_lockcnt_destroy(&ctx->list_lock); @@ -485,6 +485,11 @@ static bool aio_context_notifier_poll(void *opaque) return qatomic_read(&ctx->notified); } =20 +static void aio_context_notifier_poll_ready(EventNotifier *e) +{ + /* Do nothing, we just wanted to kick the event loop */ +} + static void co_schedule_bh_cb(void *opaque) { AioContext *ctx =3D opaque; @@ -536,7 +541,8 @@ AioContext *aio_context_new(Error **errp) aio_set_event_notifier(ctx, &ctx->notifier, false, aio_context_notifier_cb, - aio_context_notifier_poll); + aio_context_notifier_poll, + aio_context_notifier_poll_ready); #ifdef CONFIG_LINUX_AIO ctx->linux_aio =3D NULL; #endif diff --git a/util/main-loop.c b/util/main-loop.c index 06b18b195c..4d5a5b9943 100644 --- a/util/main-loop.c +++ b/util/main-loop.c @@ -582,7 +582,7 @@ void qemu_set_fd_handler(int fd, { iohandler_init(); aio_set_fd_handler(iohandler_ctx, fd, false, - fd_read, fd_write, NULL, opaque); + fd_read, fd_write, NULL, NULL, opaque); } =20 void event_notifier_set_handler(EventNotifier *e, @@ -590,5 +590,5 @@ void event_notifier_set_handler(EventNotifier *e, { iohandler_init(); aio_set_event_notifier(iohandler_ctx, e, false, - handler, NULL); + handler, NULL, NULL); } diff --git a/util/qemu-coroutine-io.c b/util/qemu-coroutine-io.c index 5b80bb416f..7f5839cb76 100644 --- a/util/qemu-coroutine-io.c +++ b/util/qemu-coroutine-io.c @@ -75,7 +75,8 @@ typedef struct { static void fd_coroutine_enter(void *opaque) { FDYieldUntilData *data =3D opaque; - aio_set_fd_handler(data->ctx, data->fd, false, NULL, NULL, NULL, NULL); + aio_set_fd_handler(data->ctx, data->fd, false, + NULL, NULL, NULL, NULL, NULL); qemu_coroutine_enter(data->co); } =20 @@ -88,6 +89,6 @@ void coroutine_fn yield_until_fd_readable(int fd) data.co =3D qemu_coroutine_self(); data.fd =3D fd; aio_set_fd_handler( - data.ctx, fd, false, fd_coroutine_enter, NULL, NULL, &data); + data.ctx, fd, false, fd_coroutine_enter, NULL, NULL, NULL, &data); qemu_coroutine_yield(); } diff --git a/util/vhost-user-server.c b/util/vhost-user-server.c index 783d847a6d..f68287e811 100644 --- a/util/vhost-user-server.c +++ b/util/vhost-user-server.c @@ -250,7 +250,7 @@ set_watch(VuDev *vu_dev, int fd, int vu_evt, vu_fd_watch->cb =3D cb; qemu_set_nonblock(fd); aio_set_fd_handler(server->ioc->ctx, fd, true, kick_handler, - NULL, NULL, vu_fd_watch); + NULL, NULL, NULL, vu_fd_watch); vu_fd_watch->vu_dev =3D vu_dev; vu_fd_watch->pvt =3D pvt; } @@ -270,7 +270,8 @@ static void remove_watch(VuDev *vu_dev, int fd) if (!vu_fd_watch) { return; } - aio_set_fd_handler(server->ioc->ctx, fd, true, NULL, NULL, NULL, NULL); + aio_set_fd_handler(server->ioc->ctx, fd, true, + NULL, NULL, NULL, NULL, NULL); =20 QTAILQ_REMOVE(&server->vu_fd_watches, vu_fd_watch, next); g_free(vu_fd_watch); @@ -334,7 +335,7 @@ void vhost_user_server_stop(VuServer *server) =20 QTAILQ_FOREACH(vu_fd_watch, &server->vu_fd_watches, next) { aio_set_fd_handler(server->ctx, vu_fd_watch->fd, true, - NULL, NULL, NULL, vu_fd_watch); + NULL, NULL, NULL, NULL, vu_fd_watch); } =20 qio_channel_shutdown(server->ioc, QIO_CHANNEL_SHUTDOWN_BOTH, NULL); @@ -377,7 +378,7 @@ void vhost_user_server_attach_aio_context(VuServer *ser= ver, AioContext *ctx) =20 QTAILQ_FOREACH(vu_fd_watch, &server->vu_fd_watches, next) { aio_set_fd_handler(ctx, vu_fd_watch->fd, true, kick_handler, NULL, - NULL, vu_fd_watch); + NULL, NULL, vu_fd_watch); } =20 aio_co_schedule(ctx, server->co_trip); @@ -391,7 +392,7 @@ void vhost_user_server_detach_aio_context(VuServer *ser= ver) =20 QTAILQ_FOREACH(vu_fd_watch, &server->vu_fd_watches, next) { aio_set_fd_handler(server->ctx, vu_fd_watch->fd, true, - NULL, NULL, NULL, vu_fd_watch); + NULL, NULL, NULL, NULL, vu_fd_watch); } =20 qio_channel_detach_aio_context(server->ioc); --=20 2.34.1 From nobody Thu Apr 25 15:40:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1642008135; cv=none; d=zohomail.com; s=zohoarc; b=blksA681cxCIkCvUK+IksTe8p2oKd4V1U3jNXHzQtcHhCXYXX/7yIcYJaCq2Gz/QDycWtXeIpPrbk10/FLz5u9VIvCbYbn2f0Pgk3e8tQHwUiPIx/z6VeksynRWDxbj4JbvWQ5DR99+AIngcSJhPYszrw34BsGPbRERt8n4HEpU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1642008135; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=yjHInqzmPrCv4N46YVTfuK0G8vvJKHp5wvZGRJen2mw=; b=Z41Mmz6lgBf7oFRG0AMS8Lq3nLWFKF3cSUGvGBU5JFoCTBlj6RTYLj/cYo8SJXU1XHg0LF6yakXT+Kwktk+Tiae6EZvzVirNrpn2PMkBNXgNEarzZSdch8iMaPYHC+HKrfmTCYX7kIvDdSYpQ8lp3ArmyqNPHDGy6flAK0XBSHc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1642008135394777.5700005724218; Wed, 12 Jan 2022 09:22:15 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.256798.440878 (Exim 4.92) (envelope-from ) id 1n7hJg-0000Gg-V5; Wed, 12 Jan 2022 17:21:44 +0000 Received: by outflank-mailman (output) from mailman id 256798.440878; Wed, 12 Jan 2022 17:21:44 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n7hJg-0000GZ-RU; Wed, 12 Jan 2022 17:21:44 +0000 Received: by outflank-mailman (input) for mailman id 256798; Wed, 12 Jan 2022 17:21:43 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n7hJf-0000GR-8T for xen-devel@lists.xenproject.org; Wed, 12 Jan 2022 17:21:43 +0000 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 18ae4c1d-73cc-11ec-9c70-5536b2d1e4e1; Wed, 12 Jan 2022 18:21:41 +0100 (CET) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-433-VJYu9YkOM2CA6tra9T3WQg-1; Wed, 12 Jan 2022 12:17:35 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3651883DD2D; Wed, 12 Jan 2022 17:16:21 +0000 (UTC) Received: from localhost (unknown [10.39.195.79]) by smtp.corp.redhat.com (Postfix) with ESMTP id B2181105C89A; Wed, 12 Jan 2022 17:16:20 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 18ae4c1d-73cc-11ec-9c70-5536b2d1e4e1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642008096; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yjHInqzmPrCv4N46YVTfuK0G8vvJKHp5wvZGRJen2mw=; b=doRjbsuEp2jJqjz9AkB3zOmFo84ureQih+mfg84hHDbvtXoxb0wvQhiH0naCoM3Uy2rtPI djIAasvMXGX1LPVG6hrGh4Ohu0979RgWCLCfryF+ZymohAutqn8QK7EPeoJII/D/SK6kn/ ce9NXcG2O3zLBVmEaHsvgGiqR+uP+kk= X-MC-Unique: VJYu9YkOM2CA6tra9T3WQg-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org, Peter Maydell Cc: Coiby Xu , Fam Zheng , Anthony Perard , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Stefano Garzarella , Peter Lieven , qemu-block@nongnu.org, Julia Suvorova , Kevin Wolf , "Richard W.M. Jones" , Stefan Hajnoczi , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Paul Durrant , Stefan Weil , Juan Quintela , Ronnie Sahlberg , xen-devel@lists.xenproject.org, "Dr. David Alan Gilbert" , Aarushi Mehta , "Michael S. Tsirkin" , Stefano Stabellini , Hanna Reitz Subject: [PULL 2/6] virtio: get rid of VirtIOHandleAIOOutput Date: Wed, 12 Jan 2022 17:13:58 +0000 Message-Id: <20220112171402.112183-3-stefanha@redhat.com> In-Reply-To: <20220112171402.112183-1-stefanha@redhat.com> References: <20220112171402.112183-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=stefanha@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1642008140327100001 Content-Type: text/plain; charset="utf-8" The virtqueue host notifier API virtio_queue_aio_set_host_notifier_handler() polls the virtqueue for new buffers. AioContext previously required a bool progress return value indicating whether an event was handled or not. This is no longer necessary because the AioContext polling API has been split into a poll check function and an event handler function. The event handler is only run when we know there is work to do, so it doesn't return bool. The VirtIOHandleAIOOutput function signature is now the same as VirtIOHandleOutput. Get rid of the bool return value. Further simplifications will be made for virtio-blk and virtio-scsi in the next patch. Signed-off-by: Stefan Hajnoczi Reviewed-by: Stefano Garzarella Message-id: 20211207132336.36627-3-stefanha@redhat.com Signed-off-by: Stefan Hajnoczi Reviewed-by: Peter Maydell --- include/hw/virtio/virtio.h | 3 +-- hw/block/dataplane/virtio-blk.c | 4 ++-- hw/scsi/virtio-scsi-dataplane.c | 18 ++++++------------ hw/virtio/virtio.c | 12 ++++-------- 4 files changed, 13 insertions(+), 24 deletions(-) diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index 8bab9cfb75..b90095628f 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -175,7 +175,6 @@ void virtio_error(VirtIODevice *vdev, const char *fmt, = ...) GCC_FMT_ATTR(2, 3); void virtio_device_set_child_bus_name(VirtIODevice *vdev, char *bus_name); =20 typedef void (*VirtIOHandleOutput)(VirtIODevice *, VirtQueue *); -typedef bool (*VirtIOHandleAIOOutput)(VirtIODevice *, VirtQueue *); =20 VirtQueue *virtio_add_queue(VirtIODevice *vdev, int queue_size, VirtIOHandleOutput handle_output); @@ -318,7 +317,7 @@ EventNotifier *virtio_queue_get_host_notifier(VirtQueue= *vq); void virtio_queue_set_host_notifier_enabled(VirtQueue *vq, bool enabled); void virtio_queue_host_notifier_read(EventNotifier *n); void virtio_queue_aio_set_host_notifier_handler(VirtQueue *vq, AioContext = *ctx, - VirtIOHandleAIOOutput hand= le_output); + VirtIOHandleOutput handle_output); VirtQueue *virtio_vector_first_queue(VirtIODevice *vdev, uint16_t vector); VirtQueue *virtio_vector_next_queue(VirtQueue *vq); =20 diff --git a/hw/block/dataplane/virtio-blk.c b/hw/block/dataplane/virtio-bl= k.c index ee5a5352dc..a2fa407b98 100644 --- a/hw/block/dataplane/virtio-blk.c +++ b/hw/block/dataplane/virtio-blk.c @@ -154,7 +154,7 @@ void virtio_blk_data_plane_destroy(VirtIOBlockDataPlane= *s) g_free(s); } =20 -static bool virtio_blk_data_plane_handle_output(VirtIODevice *vdev, +static void virtio_blk_data_plane_handle_output(VirtIODevice *vdev, VirtQueue *vq) { VirtIOBlock *s =3D (VirtIOBlock *)vdev; @@ -162,7 +162,7 @@ static bool virtio_blk_data_plane_handle_output(VirtIOD= evice *vdev, assert(s->dataplane); assert(s->dataplane_started); =20 - return virtio_blk_handle_vq(s, vq); + virtio_blk_handle_vq(s, vq); } =20 /* Context: QEMU global mutex held */ diff --git a/hw/scsi/virtio-scsi-dataplane.c b/hw/scsi/virtio-scsi-dataplan= e.c index 18eb824c97..76137de67f 100644 --- a/hw/scsi/virtio-scsi-dataplane.c +++ b/hw/scsi/virtio-scsi-dataplane.c @@ -49,49 +49,43 @@ void virtio_scsi_dataplane_setup(VirtIOSCSI *s, Error *= *errp) } } =20 -static bool virtio_scsi_data_plane_handle_cmd(VirtIODevice *vdev, +static void virtio_scsi_data_plane_handle_cmd(VirtIODevice *vdev, VirtQueue *vq) { - bool progress =3D false; VirtIOSCSI *s =3D VIRTIO_SCSI(vdev); =20 virtio_scsi_acquire(s); if (!s->dataplane_fenced) { assert(s->ctx && s->dataplane_started); - progress =3D virtio_scsi_handle_cmd_vq(s, vq); + virtio_scsi_handle_cmd_vq(s, vq); } virtio_scsi_release(s); - return progress; } =20 -static bool virtio_scsi_data_plane_handle_ctrl(VirtIODevice *vdev, +static void virtio_scsi_data_plane_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq) { - bool progress =3D false; VirtIOSCSI *s =3D VIRTIO_SCSI(vdev); =20 virtio_scsi_acquire(s); if (!s->dataplane_fenced) { assert(s->ctx && s->dataplane_started); - progress =3D virtio_scsi_handle_ctrl_vq(s, vq); + virtio_scsi_handle_ctrl_vq(s, vq); } virtio_scsi_release(s); - return progress; } =20 -static bool virtio_scsi_data_plane_handle_event(VirtIODevice *vdev, +static void virtio_scsi_data_plane_handle_event(VirtIODevice *vdev, VirtQueue *vq) { - bool progress =3D false; VirtIOSCSI *s =3D VIRTIO_SCSI(vdev); =20 virtio_scsi_acquire(s); if (!s->dataplane_fenced) { assert(s->ctx && s->dataplane_started); - progress =3D virtio_scsi_handle_event_vq(s, vq); + virtio_scsi_handle_event_vq(s, vq); } virtio_scsi_release(s); - return progress; } =20 static int virtio_scsi_set_host_notifier(VirtIOSCSI *s, VirtQueue *vq, int= n) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 5db7f69237..323f549aad 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -125,7 +125,7 @@ struct VirtQueue =20 uint16_t vector; VirtIOHandleOutput handle_output; - VirtIOHandleAIOOutput handle_aio_output; + VirtIOHandleOutput handle_aio_output; VirtIODevice *vdev; EventNotifier guest_notifier; EventNotifier host_notifier; @@ -2303,22 +2303,18 @@ void virtio_queue_set_align(VirtIODevice *vdev, int= n, int align) } } =20 -static bool virtio_queue_notify_aio_vq(VirtQueue *vq) +static void virtio_queue_notify_aio_vq(VirtQueue *vq) { - bool ret =3D false; - if (vq->vring.desc && vq->handle_aio_output) { VirtIODevice *vdev =3D vq->vdev; =20 trace_virtio_queue_notify(vdev, vq - vdev->vq, vq); - ret =3D vq->handle_aio_output(vdev, vq); + vq->handle_aio_output(vdev, vq); =20 if (unlikely(vdev->start_on_kick)) { virtio_set_started(vdev, true); } } - - return ret; } =20 static void virtio_queue_notify_vq(VirtQueue *vq) @@ -3555,7 +3551,7 @@ static void virtio_queue_host_notifier_aio_poll_end(E= ventNotifier *n) } =20 void virtio_queue_aio_set_host_notifier_handler(VirtQueue *vq, AioContext = *ctx, - VirtIOHandleAIOOutput hand= le_output) + VirtIOHandleOutput handle_output) { if (handle_output) { vq->handle_aio_output =3D handle_output; --=20 2.34.1 From nobody Thu Apr 25 15:40:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1642007819; cv=none; d=zohomail.com; s=zohoarc; b=CmojOsLH6XCkgSz63I3ebtQ1WEGINbkFxxLSq53mR72ZiEvbRurIDwCtir9YWVa2iXwWN3xexRHUcDNvegMjE/7GjMAGlXCyO5k1DHL8/UX9DNP41iy5Wf0qN9wH5LLmskEPMn3dt7CoHca/xH2dlwUJ6jDRinnzY56otehDHVQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1642007819; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ZO4PTDIj23J8uv/+cKDtCuqXWq72LiUYuH0KK782SUk=; b=PIeAfgRAo4sASsZXEWEbVFAif1tsivWwdFY9BKqnUfCnT/FjlMnh7/653Je3qlIlisKqMmIdWAj44hW3ff3pnohoIuMpeMercbfw+1mDBEbgl/7K8yReyFvzOvhrlnGhAY7fAbe5X4oLKou927REGySe2Umj25dm/QpweTMOam4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 164200781912610.384419095492603; Wed, 12 Jan 2022 09:16:59 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.256778.440834 (Exim 4.92) (envelope-from ) id 1n7hEg-00058V-F4; Wed, 12 Jan 2022 17:16:34 +0000 Received: by outflank-mailman (output) from mailman id 256778.440834; Wed, 12 Jan 2022 17:16:34 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n7hEg-00058M-Bq; Wed, 12 Jan 2022 17:16:34 +0000 Received: by outflank-mailman (input) for mailman id 256778; Wed, 12 Jan 2022 17:16:32 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n7hEe-00057V-TS for xen-devel@lists.xenproject.org; Wed, 12 Jan 2022 17:16:32 +0000 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 627151e5-73cb-11ec-bd6f-bfb69f65cdc7; Wed, 12 Jan 2022 18:16:31 +0100 (CET) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-179-yktkATvTO-uTf4aP_dmcXA-1; Wed, 12 Jan 2022 12:16:27 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 47CC41018724; Wed, 12 Jan 2022 17:16:24 +0000 (UTC) Received: from localhost (unknown [10.39.195.79]) by smtp.corp.redhat.com (Postfix) with ESMTP id B7093105C89A; Wed, 12 Jan 2022 17:16:23 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 627151e5-73cb-11ec-bd6f-bfb69f65cdc7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642007790; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZO4PTDIj23J8uv/+cKDtCuqXWq72LiUYuH0KK782SUk=; b=KI+DnpvAGDKmjBkmFYkdqMc706mLrTzYSqbXgDJRFL6LaetE5gjUYrJkfFRPwLY/7+gWmc k7BCU8aVa3/27Sj979GF46Mgp2k2xfXoDS9ZQyUgF8XcZs1u3cGdeP0Od52AadL482wKPx ly344SooNpwTp9NyeHxKvTe9qFdihGc= X-MC-Unique: yktkATvTO-uTf4aP_dmcXA-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org, Peter Maydell Cc: Coiby Xu , Fam Zheng , Anthony Perard , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Stefano Garzarella , Peter Lieven , qemu-block@nongnu.org, Julia Suvorova , Kevin Wolf , "Richard W.M. Jones" , Stefan Hajnoczi , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Paul Durrant , Stefan Weil , Juan Quintela , Ronnie Sahlberg , xen-devel@lists.xenproject.org, "Dr. David Alan Gilbert" , Aarushi Mehta , "Michael S. Tsirkin" , Stefano Stabellini , Hanna Reitz Subject: [PULL 3/6] virtio-blk: drop unused virtio_blk_handle_vq() return value Date: Wed, 12 Jan 2022 17:13:59 +0000 Message-Id: <20220112171402.112183-4-stefanha@redhat.com> In-Reply-To: <20220112171402.112183-1-stefanha@redhat.com> References: <20220112171402.112183-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=stefanha@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1642007820238100001 Content-Type: text/plain; charset="utf-8" The return value of virtio_blk_handle_vq() is no longer used. Get rid of it. This is a step towards unifying the dataplane and non-dataplane virtqueue handler functions. Prepare virtio_blk_handle_output() to be used by both dataplane and non-dataplane by making the condition for starting ioeventfd more specific. This way it won't trigger when dataplane has already been started. Signed-off-by: Stefan Hajnoczi Reviewed-by: Stefano Garzarella Message-id: 20211207132336.36627-4-stefanha@redhat.com Signed-off-by: Stefan Hajnoczi Reviewed-by: Peter Maydell --- include/hw/virtio/virtio-blk.h | 2 +- hw/block/virtio-blk.c | 14 +++----------- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/include/hw/virtio/virtio-blk.h b/include/hw/virtio/virtio-blk.h index 29655a406d..d311c57cca 100644 --- a/include/hw/virtio/virtio-blk.h +++ b/include/hw/virtio/virtio-blk.h @@ -90,7 +90,7 @@ typedef struct MultiReqBuffer { bool is_write; } MultiReqBuffer; =20 -bool virtio_blk_handle_vq(VirtIOBlock *s, VirtQueue *vq); +void virtio_blk_handle_vq(VirtIOBlock *s, VirtQueue *vq); void virtio_blk_process_queued_requests(VirtIOBlock *s, bool is_bh); =20 #endif diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index f139cd7cc9..82676cdd01 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -767,12 +767,11 @@ static int virtio_blk_handle_request(VirtIOBlockReq *= req, MultiReqBuffer *mrb) return 0; } =20 -bool virtio_blk_handle_vq(VirtIOBlock *s, VirtQueue *vq) +void virtio_blk_handle_vq(VirtIOBlock *s, VirtQueue *vq) { VirtIOBlockReq *req; MultiReqBuffer mrb =3D {}; bool suppress_notifications =3D virtio_queue_get_notification(vq); - bool progress =3D false; =20 aio_context_acquire(blk_get_aio_context(s->blk)); blk_io_plug(s->blk); @@ -783,7 +782,6 @@ bool virtio_blk_handle_vq(VirtIOBlock *s, VirtQueue *vq) } =20 while ((req =3D virtio_blk_get_request(s, vq))) { - progress =3D true; if (virtio_blk_handle_request(req, &mrb)) { virtqueue_detach_element(req->vq, &req->elem, 0); virtio_blk_free_request(req); @@ -802,19 +800,13 @@ bool virtio_blk_handle_vq(VirtIOBlock *s, VirtQueue *= vq) =20 blk_io_unplug(s->blk); aio_context_release(blk_get_aio_context(s->blk)); - return progress; -} - -static void virtio_blk_handle_output_do(VirtIOBlock *s, VirtQueue *vq) -{ - virtio_blk_handle_vq(s, vq); } =20 static void virtio_blk_handle_output(VirtIODevice *vdev, VirtQueue *vq) { VirtIOBlock *s =3D (VirtIOBlock *)vdev; =20 - if (s->dataplane) { + if (s->dataplane && !s->dataplane_started) { /* Some guests kick before setting VIRTIO_CONFIG_S_DRIVER_OK so st= art * dataplane here instead of waiting for .set_status(). */ @@ -823,7 +815,7 @@ static void virtio_blk_handle_output(VirtIODevice *vdev= , VirtQueue *vq) return; } } - virtio_blk_handle_output_do(s, vq); + virtio_blk_handle_vq(s, vq); } =20 void virtio_blk_process_queued_requests(VirtIOBlock *s, bool is_bh) --=20 2.34.1 From nobody Thu Apr 25 15:40:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1642007846; cv=none; d=zohomail.com; s=zohoarc; b=P+P7b65L8h7J3of5pLZxrD/pGiZH1+S4ndnucZnLSiXXdCxVJ+QJvGy5MzDaexBT18R3iLPTdXXUTsXlAXmFoWu6/BU2pxmoKXZtN/pLp5JC9J6z5Om++5ZSzg66TU/GfnSsw0kaxt6SVUvLFPI8fwUBfTS7dcl8EtwxnXA9VSE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1642007846; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=UK8vo4KGRsMycUUCEVvMQM5ZQH0imHmhggV9gfr/dgg=; b=BWtnYO8FIhKErHXI9q7XuNribsOMVntRl/brV63zxLDPgRdPwTDG+b6KyebP9r9vot7MRNC6DU2PXp3qPVCa9qzKfYZiUDWg2OoyP3+JHt85w+ARj/6Jq9pYKeeGcoQFdNwFsdFJwBmh9njrtwFEPh6LlnguT+aGQcvmkoxKZ8Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1642007846449525.2635627439678; Wed, 12 Jan 2022 09:17:26 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.256782.440845 (Exim 4.92) (envelope-from ) id 1n7hF2-0005yW-OT; Wed, 12 Jan 2022 17:16:56 +0000 Received: by outflank-mailman (output) from mailman id 256782.440845; Wed, 12 Jan 2022 17:16:56 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n7hF2-0005yP-Ld; Wed, 12 Jan 2022 17:16:56 +0000 Received: by outflank-mailman (input) for mailman id 256782; Wed, 12 Jan 2022 17:16:56 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n7hF2-0005v6-63 for xen-devel@lists.xenproject.org; Wed, 12 Jan 2022 17:16:56 +0000 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 70625e55-73cb-11ec-9c70-5536b2d1e4e1; Wed, 12 Jan 2022 18:16:55 +0100 (CET) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-625-hT09O-VRObKKuGN8fKq_EA-1; Wed, 12 Jan 2022 12:16:52 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D7F1B81CCB8; Wed, 12 Jan 2022 17:16:49 +0000 (UTC) Received: from localhost (unknown [10.39.195.79]) by smtp.corp.redhat.com (Postfix) with ESMTP id 05BE72DE99; Wed, 12 Jan 2022 17:16:26 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 70625e55-73cb-11ec-9c70-5536b2d1e4e1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642007814; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UK8vo4KGRsMycUUCEVvMQM5ZQH0imHmhggV9gfr/dgg=; b=EPBrnLoz/YOuCtSXdI/nB/Y4Z6QLCfr6U9FG/CrcdRc+g/4j8jAp1WU2haRMpjNdx0UYOT gppqHKLpI1NlVBhS4iCihDml8nQjglW437xDEBWhvDs8XCbByBBIc6Q2T6Vnx04Vq05Won ljFSsn2En6BKFXU7PVKJ/yKIoAzPzTg= X-MC-Unique: hT09O-VRObKKuGN8fKq_EA-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org, Peter Maydell Cc: Coiby Xu , Fam Zheng , Anthony Perard , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Stefano Garzarella , Peter Lieven , qemu-block@nongnu.org, Julia Suvorova , Kevin Wolf , "Richard W.M. Jones" , Stefan Hajnoczi , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Paul Durrant , Stefan Weil , Juan Quintela , Ronnie Sahlberg , xen-devel@lists.xenproject.org, "Dr. David Alan Gilbert" , Aarushi Mehta , "Michael S. Tsirkin" , Stefano Stabellini , Hanna Reitz Subject: [PULL 4/6] virtio-scsi: prepare virtio_scsi_handle_cmd for dataplane Date: Wed, 12 Jan 2022 17:14:00 +0000 Message-Id: <20220112171402.112183-5-stefanha@redhat.com> In-Reply-To: <20220112171402.112183-1-stefanha@redhat.com> References: <20220112171402.112183-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=stefanha@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1642007848024100001 Content-Type: text/plain; charset="utf-8" Prepare virtio_scsi_handle_cmd() to be used by both dataplane and non-dataplane by making the condition for starting ioeventfd more specific. This way it won't trigger when dataplane has already been started. Signed-off-by: Stefan Hajnoczi Reviewed-by: Stefano Garzarella Message-id: 20211207132336.36627-5-stefanha@redhat.com Signed-off-by: Stefan Hajnoczi Reviewed-by: Peter Maydell --- hw/scsi/virtio-scsi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c index 51fd09522a..34a968ecfb 100644 --- a/hw/scsi/virtio-scsi.c +++ b/hw/scsi/virtio-scsi.c @@ -720,7 +720,7 @@ static void virtio_scsi_handle_cmd(VirtIODevice *vdev, = VirtQueue *vq) /* use non-QOM casts in the data path */ VirtIOSCSI *s =3D (VirtIOSCSI *)vdev; =20 - if (s->ctx) { + if (s->ctx && !s->dataplane_started) { virtio_device_start_ioeventfd(vdev); if (!s->dataplane_fenced) { return; --=20 2.34.1 From nobody Thu Apr 25 15:40:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1642007871; cv=none; d=zohomail.com; s=zohoarc; b=gXHoyLrOTbHZeMPdfh9pyXKakS+aI10fsFvFbT9cMlDi/ZaYdo1U6r+ihYcAEGSz2AD7xIYdV3sjtr619WqfO5CcjsraLw1tSZcH5M3BmCqzX/i9veQh0UmkLPiHl0Yap6vyoHKpuuU7Z1H/ZvDjfiF04vca1nxJJL+bks6gwkM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1642007871; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=aqsXFWsKyZZ5dZYudB6A80tOB2G/EpTCq3EVK0XRkP8=; b=Zg4heOh8uvm6HxL1HJpI/8yk675MtOMJPeKjdeDG9F6d7Ejaf7/KxuN6y5vBeuIrcfVi2Tibs1YuDZQtNNqNzdCS/Z3baTL/iBpQ4VjsSKHCYfJBQnLDyML//FYtoW8VvyvrzbsuNNYeV2oIpHur9HLSYQQxNVzrWUwe/GFyJ6Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1642007871457134.0587847791952; Wed, 12 Jan 2022 09:17:51 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.256787.440856 (Exim 4.92) (envelope-from ) id 1n7hFg-0006cA-1Y; Wed, 12 Jan 2022 17:17:36 +0000 Received: by outflank-mailman (output) from mailman id 256787.440856; Wed, 12 Jan 2022 17:17:36 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n7hFf-0006c3-UP; Wed, 12 Jan 2022 17:17:35 +0000 Received: by outflank-mailman (input) for mailman id 256787; Wed, 12 Jan 2022 17:17:35 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n7hFf-0006bp-76 for xen-devel@lists.xenproject.org; Wed, 12 Jan 2022 17:17:35 +0000 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 87942e2f-73cb-11ec-bd6f-bfb69f65cdc7; Wed, 12 Jan 2022 18:17:34 +0100 (CET) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-515-EJiA3gwjNV6WDvp4X4azrg-1; Wed, 12 Jan 2022 12:17:29 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B2ADA101F002; Wed, 12 Jan 2022 17:17:25 +0000 (UTC) Received: from localhost (unknown [10.39.195.79]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4BB6B7FB9E; Wed, 12 Jan 2022 17:17:25 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 87942e2f-73cb-11ec-bd6f-bfb69f65cdc7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642007853; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aqsXFWsKyZZ5dZYudB6A80tOB2G/EpTCq3EVK0XRkP8=; b=TX33KMosoxuNWKFdR4EzehaLuASl6kR2agR/knYlF+9CR5Au+EB6atoLYh3ZibVESswall 8YsDrv6upx/L/R/AXDDo70NbqPbCfZqKSv7ifAiiPS+jHauoJ9tKgcomsvB+Bi0yfisryX ZavpiFYinCCf1dRdiSbu67YPZVJSjb0= X-MC-Unique: EJiA3gwjNV6WDvp4X4azrg-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org, Peter Maydell Cc: Coiby Xu , Fam Zheng , Anthony Perard , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Stefano Garzarella , Peter Lieven , qemu-block@nongnu.org, Julia Suvorova , Kevin Wolf , "Richard W.M. Jones" , Stefan Hajnoczi , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Paul Durrant , Stefan Weil , Juan Quintela , Ronnie Sahlberg , xen-devel@lists.xenproject.org, "Dr. David Alan Gilbert" , Aarushi Mehta , "Michael S. Tsirkin" , Stefano Stabellini , Hanna Reitz Subject: [PULL 5/6] virtio: use ->handle_output() instead of ->handle_aio_output() Date: Wed, 12 Jan 2022 17:14:01 +0000 Message-Id: <20220112171402.112183-6-stefanha@redhat.com> In-Reply-To: <20220112171402.112183-1-stefanha@redhat.com> References: <20220112171402.112183-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=stefanha@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1642007874196100001 Content-Type: text/plain; charset="utf-8" The difference between ->handle_output() and ->handle_aio_output() was that ->handle_aio_output() returned a bool return value indicating progress. This was needed by the old polling API but now that the bool return value is gone, the two functions can be unified. Signed-off-by: Stefan Hajnoczi Reviewed-by: Stefano Garzarella Message-id: 20211207132336.36627-6-stefanha@redhat.com Signed-off-by: Stefan Hajnoczi Reviewed-by: Peter Maydell --- hw/virtio/virtio.c | 33 +++------------------------------ 1 file changed, 3 insertions(+), 30 deletions(-) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 323f549aad..e938e6513b 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -125,7 +125,6 @@ struct VirtQueue =20 uint16_t vector; VirtIOHandleOutput handle_output; - VirtIOHandleOutput handle_aio_output; VirtIODevice *vdev; EventNotifier guest_notifier; EventNotifier host_notifier; @@ -2303,20 +2302,6 @@ void virtio_queue_set_align(VirtIODevice *vdev, int = n, int align) } } =20 -static void virtio_queue_notify_aio_vq(VirtQueue *vq) -{ - if (vq->vring.desc && vq->handle_aio_output) { - VirtIODevice *vdev =3D vq->vdev; - - trace_virtio_queue_notify(vdev, vq - vdev->vq, vq); - vq->handle_aio_output(vdev, vq); - - if (unlikely(vdev->start_on_kick)) { - virtio_set_started(vdev, true); - } - } -} - static void virtio_queue_notify_vq(VirtQueue *vq) { if (vq->vring.desc && vq->handle_output) { @@ -2395,7 +2380,6 @@ VirtQueue *virtio_add_queue(VirtIODevice *vdev, int q= ueue_size, vdev->vq[i].vring.num_default =3D queue_size; vdev->vq[i].vring.align =3D VIRTIO_PCI_VRING_ALIGN; vdev->vq[i].handle_output =3D handle_output; - vdev->vq[i].handle_aio_output =3D NULL; vdev->vq[i].used_elems =3D g_malloc0(sizeof(VirtQueueElement) * queue_size); =20 @@ -2407,7 +2391,6 @@ void virtio_delete_queue(VirtQueue *vq) vq->vring.num =3D 0; vq->vring.num_default =3D 0; vq->handle_output =3D NULL; - vq->handle_aio_output =3D NULL; g_free(vq->used_elems); vq->used_elems =3D NULL; virtio_virtqueue_reset_region_cache(vq); @@ -3512,14 +3495,6 @@ EventNotifier *virtio_queue_get_guest_notifier(VirtQ= ueue *vq) return &vq->guest_notifier; } =20 -static void virtio_queue_host_notifier_aio_read(EventNotifier *n) -{ - VirtQueue *vq =3D container_of(n, VirtQueue, host_notifier); - if (event_notifier_test_and_clear(n)) { - virtio_queue_notify_aio_vq(vq); - } -} - static void virtio_queue_host_notifier_aio_poll_begin(EventNotifier *n) { VirtQueue *vq =3D container_of(n, VirtQueue, host_notifier); @@ -3539,7 +3514,7 @@ static void virtio_queue_host_notifier_aio_poll_ready= (EventNotifier *n) { VirtQueue *vq =3D container_of(n, VirtQueue, host_notifier); =20 - virtio_queue_notify_aio_vq(vq); + virtio_queue_notify_vq(vq); } =20 static void virtio_queue_host_notifier_aio_poll_end(EventNotifier *n) @@ -3554,9 +3529,8 @@ void virtio_queue_aio_set_host_notifier_handler(VirtQ= ueue *vq, AioContext *ctx, VirtIOHandleOutput handle_output) { if (handle_output) { - vq->handle_aio_output =3D handle_output; aio_set_event_notifier(ctx, &vq->host_notifier, true, - virtio_queue_host_notifier_aio_read, + virtio_queue_host_notifier_read, virtio_queue_host_notifier_aio_poll, virtio_queue_host_notifier_aio_poll_ready); aio_set_event_notifier_poll(ctx, &vq->host_notifier, @@ -3566,8 +3540,7 @@ void virtio_queue_aio_set_host_notifier_handler(VirtQ= ueue *vq, AioContext *ctx, aio_set_event_notifier(ctx, &vq->host_notifier, true, NULL, NULL, = NULL); /* Test and clear notifier before after disabling event, * in case poll callback didn't have time to run. */ - virtio_queue_host_notifier_aio_read(&vq->host_notifier); - vq->handle_aio_output =3D NULL; + virtio_queue_host_notifier_read(&vq->host_notifier); } } =20 --=20 2.34.1 From nobody Thu Apr 25 15:40:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1642007876; cv=none; d=zohomail.com; s=zohoarc; b=GpjF38Mj2EIxlG/TK4QBFbDjQQKBNQcs2dYJJGXoQtNaru58TNfCfCSIZpHOtUm1QJcQeK0EcoIB5tUhVe35qJSQ29/4RfdW1rl6IugAq3XwJxivfHtzyWwrwj9DxqNtV+1Ae0aYi4x0k23lm8HMDGH8dm18F8m6ZR8Wz03/VN4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1642007876; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=js5bkbA3MR3Yyy5XstjOhtqjgRh3bMz19gvkW1lmJoU=; b=EgJswyuxTpj8kMbqfDrVEUlEV23g6L/i7BfaUX2lE+VHy4B1hryxxCcsBGy0l/erCZJX38mL8w25QUDlFnUkmHAfPwI9kMGS0QcVgCLkZCbcpEbQoEJDO/bzUKs1FWOOfmZejrpvh+80pc9ZL0ty6WfLmU/g1e+gIuXGxRxQuHE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1642007876205983.9253786128203; Wed, 12 Jan 2022 09:17:56 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.256788.440866 (Exim 4.92) (envelope-from ) id 1n7hFl-0006uW-8z; Wed, 12 Jan 2022 17:17:41 +0000 Received: by outflank-mailman (output) from mailman id 256788.440866; Wed, 12 Jan 2022 17:17:41 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n7hFl-0006uP-5L; Wed, 12 Jan 2022 17:17:41 +0000 Received: by outflank-mailman (input) for mailman id 256788; Wed, 12 Jan 2022 17:17:39 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n7hFj-0005v6-9w for xen-devel@lists.xenproject.org; Wed, 12 Jan 2022 17:17:39 +0000 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 8a0f3fa5-73cb-11ec-9c70-5536b2d1e4e1; Wed, 12 Jan 2022 18:17:38 +0100 (CET) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-348-_kXwFZIdOviwuCE4l7lEkA-1; Wed, 12 Jan 2022 12:17:33 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1406F101F001; Wed, 12 Jan 2022 17:17:32 +0000 (UTC) Received: from localhost (unknown [10.39.195.79]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9CF0A7F81A; Wed, 12 Jan 2022 17:17:31 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 8a0f3fa5-73cb-11ec-9c70-5536b2d1e4e1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642007857; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=js5bkbA3MR3Yyy5XstjOhtqjgRh3bMz19gvkW1lmJoU=; b=FdspTRLkLeQSY1ZWy7OQkmmw72pMkR/Z4FGH+39JCvJXMpDJPrUZCU+B9rPAn5W8ZBISx4 nO8jjZoXp0hHAzrNOQX1dQqyZ9dxBmFbtrdvzErigwiXR28pjNXhGTB4J+BH5f/RoV8k07 tcjui87s/0I++/s8R5DRpMNSn+Ca/a0= X-MC-Unique: _kXwFZIdOviwuCE4l7lEkA-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org, Peter Maydell Cc: Coiby Xu , Fam Zheng , Anthony Perard , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Stefano Garzarella , Peter Lieven , qemu-block@nongnu.org, Julia Suvorova , Kevin Wolf , "Richard W.M. Jones" , Stefan Hajnoczi , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Paul Durrant , Stefan Weil , Juan Quintela , Ronnie Sahlberg , xen-devel@lists.xenproject.org, "Dr. David Alan Gilbert" , Aarushi Mehta , "Michael S. Tsirkin" , Stefano Stabellini , Hanna Reitz Subject: [PULL 6/6] virtio: unify dataplane and non-dataplane ->handle_output() Date: Wed, 12 Jan 2022 17:14:02 +0000 Message-Id: <20220112171402.112183-7-stefanha@redhat.com> In-Reply-To: <20220112171402.112183-1-stefanha@redhat.com> References: <20220112171402.112183-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=stefanha@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1642007876921100001 Content-Type: text/plain; charset="utf-8" Now that virtio-blk and virtio-scsi are ready, get rid of the handle_aio_output() callback. It's no longer needed. Signed-off-by: Stefan Hajnoczi Reviewed-by: Stefano Garzarella Message-id: 20211207132336.36627-7-stefanha@redhat.com Signed-off-by: Stefan Hajnoczi Reviewed-by: Peter Maydell --- include/hw/virtio/virtio.h | 4 +-- hw/block/dataplane/virtio-blk.c | 16 ++-------- hw/scsi/virtio-scsi-dataplane.c | 54 ++++----------------------------- hw/virtio/virtio.c | 32 +++++++++---------- 4 files changed, 26 insertions(+), 80 deletions(-) diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index b90095628f..f095637058 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -316,8 +316,8 @@ bool virtio_device_ioeventfd_enabled(VirtIODevice *vdev= ); EventNotifier *virtio_queue_get_host_notifier(VirtQueue *vq); void virtio_queue_set_host_notifier_enabled(VirtQueue *vq, bool enabled); void virtio_queue_host_notifier_read(EventNotifier *n); -void virtio_queue_aio_set_host_notifier_handler(VirtQueue *vq, AioContext = *ctx, - VirtIOHandleOutput handle_output); +void virtio_queue_aio_attach_host_notifier(VirtQueue *vq, AioContext *ctx); +void virtio_queue_aio_detach_host_notifier(VirtQueue *vq, AioContext *ctx); VirtQueue *virtio_vector_first_queue(VirtIODevice *vdev, uint16_t vector); VirtQueue *virtio_vector_next_queue(VirtQueue *vq); =20 diff --git a/hw/block/dataplane/virtio-blk.c b/hw/block/dataplane/virtio-bl= k.c index a2fa407b98..49276e46f2 100644 --- a/hw/block/dataplane/virtio-blk.c +++ b/hw/block/dataplane/virtio-blk.c @@ -154,17 +154,6 @@ void virtio_blk_data_plane_destroy(VirtIOBlockDataPlan= e *s) g_free(s); } =20 -static void virtio_blk_data_plane_handle_output(VirtIODevice *vdev, - VirtQueue *vq) -{ - VirtIOBlock *s =3D (VirtIOBlock *)vdev; - - assert(s->dataplane); - assert(s->dataplane_started); - - virtio_blk_handle_vq(s, vq); -} - /* Context: QEMU global mutex held */ int virtio_blk_data_plane_start(VirtIODevice *vdev) { @@ -258,8 +247,7 @@ int virtio_blk_data_plane_start(VirtIODevice *vdev) for (i =3D 0; i < nvqs; i++) { VirtQueue *vq =3D virtio_get_queue(s->vdev, i); =20 - virtio_queue_aio_set_host_notifier_handler(vq, s->ctx, - virtio_blk_data_plane_handle_output); + virtio_queue_aio_attach_host_notifier(vq, s->ctx); } aio_context_release(s->ctx); return 0; @@ -302,7 +290,7 @@ static void virtio_blk_data_plane_stop_bh(void *opaque) for (i =3D 0; i < s->conf->num_queues; i++) { VirtQueue *vq =3D virtio_get_queue(s->vdev, i); =20 - virtio_queue_aio_set_host_notifier_handler(vq, s->ctx, NULL); + virtio_queue_aio_detach_host_notifier(vq, s->ctx); } } =20 diff --git a/hw/scsi/virtio-scsi-dataplane.c b/hw/scsi/virtio-scsi-dataplan= e.c index 76137de67f..29575cbaf6 100644 --- a/hw/scsi/virtio-scsi-dataplane.c +++ b/hw/scsi/virtio-scsi-dataplane.c @@ -49,45 +49,6 @@ void virtio_scsi_dataplane_setup(VirtIOSCSI *s, Error **= errp) } } =20 -static void virtio_scsi_data_plane_handle_cmd(VirtIODevice *vdev, - VirtQueue *vq) -{ - VirtIOSCSI *s =3D VIRTIO_SCSI(vdev); - - virtio_scsi_acquire(s); - if (!s->dataplane_fenced) { - assert(s->ctx && s->dataplane_started); - virtio_scsi_handle_cmd_vq(s, vq); - } - virtio_scsi_release(s); -} - -static void virtio_scsi_data_plane_handle_ctrl(VirtIODevice *vdev, - VirtQueue *vq) -{ - VirtIOSCSI *s =3D VIRTIO_SCSI(vdev); - - virtio_scsi_acquire(s); - if (!s->dataplane_fenced) { - assert(s->ctx && s->dataplane_started); - virtio_scsi_handle_ctrl_vq(s, vq); - } - virtio_scsi_release(s); -} - -static void virtio_scsi_data_plane_handle_event(VirtIODevice *vdev, - VirtQueue *vq) -{ - VirtIOSCSI *s =3D VIRTIO_SCSI(vdev); - - virtio_scsi_acquire(s); - if (!s->dataplane_fenced) { - assert(s->ctx && s->dataplane_started); - virtio_scsi_handle_event_vq(s, vq); - } - virtio_scsi_release(s); -} - static int virtio_scsi_set_host_notifier(VirtIOSCSI *s, VirtQueue *vq, int= n) { BusState *qbus =3D BUS(qdev_get_parent_bus(DEVICE(s))); @@ -112,10 +73,10 @@ static void virtio_scsi_dataplane_stop_bh(void *opaque) VirtIOSCSICommon *vs =3D VIRTIO_SCSI_COMMON(s); int i; =20 - virtio_queue_aio_set_host_notifier_handler(vs->ctrl_vq, s->ctx, NULL); - virtio_queue_aio_set_host_notifier_handler(vs->event_vq, s->ctx, NULL); + virtio_queue_aio_detach_host_notifier(vs->ctrl_vq, s->ctx); + virtio_queue_aio_detach_host_notifier(vs->event_vq, s->ctx); for (i =3D 0; i < vs->conf.num_queues; i++) { - virtio_queue_aio_set_host_notifier_handler(vs->cmd_vqs[i], s->ctx,= NULL); + virtio_queue_aio_detach_host_notifier(vs->cmd_vqs[i], s->ctx); } } =20 @@ -176,14 +137,11 @@ int virtio_scsi_dataplane_start(VirtIODevice *vdev) memory_region_transaction_commit(); =20 aio_context_acquire(s->ctx); - virtio_queue_aio_set_host_notifier_handler(vs->ctrl_vq, s->ctx, - virtio_scsi_data_plane_handle_= ctrl); - virtio_queue_aio_set_host_notifier_handler(vs->event_vq, s->ctx, - virtio_scsi_data_plane_handle_e= vent); + virtio_queue_aio_attach_host_notifier(vs->ctrl_vq, s->ctx); + virtio_queue_aio_attach_host_notifier(vs->event_vq, s->ctx); =20 for (i =3D 0; i < vs->conf.num_queues; i++) { - virtio_queue_aio_set_host_notifier_handler(vs->cmd_vqs[i], s->ctx, - virtio_scsi_data_plane_handle= _cmd); + virtio_queue_aio_attach_host_notifier(vs->cmd_vqs[i], s->ctx); } =20 s->dataplane_starting =3D false; diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index e938e6513b..aae72fb8b7 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -3525,23 +3525,23 @@ static void virtio_queue_host_notifier_aio_poll_end= (EventNotifier *n) virtio_queue_set_notification(vq, 1); } =20 -void virtio_queue_aio_set_host_notifier_handler(VirtQueue *vq, AioContext = *ctx, - VirtIOHandleOutput handle_output) +void virtio_queue_aio_attach_host_notifier(VirtQueue *vq, AioContext *ctx) { - if (handle_output) { - aio_set_event_notifier(ctx, &vq->host_notifier, true, - virtio_queue_host_notifier_read, - virtio_queue_host_notifier_aio_poll, - virtio_queue_host_notifier_aio_poll_ready); - aio_set_event_notifier_poll(ctx, &vq->host_notifier, - virtio_queue_host_notifier_aio_poll_be= gin, - virtio_queue_host_notifier_aio_poll_en= d); - } else { - aio_set_event_notifier(ctx, &vq->host_notifier, true, NULL, NULL, = NULL); - /* Test and clear notifier before after disabling event, - * in case poll callback didn't have time to run. */ - virtio_queue_host_notifier_read(&vq->host_notifier); - } + aio_set_event_notifier(ctx, &vq->host_notifier, true, + virtio_queue_host_notifier_read, + virtio_queue_host_notifier_aio_poll, + virtio_queue_host_notifier_aio_poll_ready); + aio_set_event_notifier_poll(ctx, &vq->host_notifier, + virtio_queue_host_notifier_aio_poll_begin, + virtio_queue_host_notifier_aio_poll_end); +} + +void virtio_queue_aio_detach_host_notifier(VirtQueue *vq, AioContext *ctx) +{ + aio_set_event_notifier(ctx, &vq->host_notifier, true, NULL, NULL, NULL= ); + /* Test and clear notifier before after disabling event, + * in case poll callback didn't have time to run. */ + virtio_queue_host_notifier_read(&vq->host_notifier); } =20 void virtio_queue_host_notifier_read(EventNotifier *n) --=20 2.34.1