]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
qio: Minor optimization when callback function is unchanged
authorEric Blake <eblake@redhat.com>
Thu, 13 Nov 2025 01:11:31 +0000 (19:11 -0600)
committerEric Blake <eblake@redhat.com>
Thu, 13 Nov 2025 15:51:51 +0000 (09:51 -0600)
In qemu-nbd and other NBD server setups where parallel clients are
supported, it is common that the caller will re-register the same
callback function as long as it has not reached its limit on
simultaneous clients.  In that case, there is no need to tear down and
reinstall GSource watches in the GMainContext.

In practice, all existing callers currently pass NULL for notify, and
no caller ever changes context across calls (for async uses, either
the caller consistently uses qio_net_listener_set_client_func_full
with the same context, or the caller consistently uses only
qio_net_listener_set_client_func which always uses the global
context); but the time spent checking these two fields in addition to
the more important func and data is still less than the savings of not
churning through extra GSource manipulations when the result will be
unchanged.

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Message-ID: <20251113011625.878876-21-eblake@redhat.com>

io/net-listener.c

index f70acdfc5ce544ebf30642d678a7c9835f949244..93100a2d25358d8d780ec2134e4d0efaf7790a61 100644 (file)
@@ -169,6 +169,11 @@ void qio_net_listener_set_client_func_full(QIONetListener *listener,
     size_t i;
 
     QEMU_LOCK_GUARD(&listener->lock);
+    if (listener->io_func == func && listener->io_data == data &&
+        listener->io_notify == notify && listener->context == context) {
+        return;
+    }
+
     trace_qio_net_listener_unwatch(listener, listener->io_func,
                                    listener->context, "set_client_func");