Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DC016606A31C for ; Fri, 13 Nov 2026 09:27:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=Vkx8UZXO Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xRnYT-0000Y6-3s; Fri, 13 Nov 2026 04:26:46 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xRnYH-0000W0-8d for qemu-devel@nongnu.org; Fri, 13 Nov 2026 04:26:33 -0500 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xRnYF-0005zF-7T for qemu-devel@nongnu.org; Fri, 13 Nov 2026 04:26:33 -0500 Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-2e9995ce866so11560705ad.0 for ; Fri, 13 Nov 2026 01:26:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1794561990; x=1795166790; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=aPt1NnsuR8qHqD/7D5dJIAnQyTdLDa8FSzmcDxHlggQ=; b=Vkx8UZXOviMUWbHO6O4IN9t1ZwECB2PRw/Qb1QAUNmaz168Weq556BOhsJF6toX+pu iN1Zal6SPqkFsk43rSjuCyK/ZTGYxGmQ4msVBCP5ttIm9IK7qQOwfReJzPV+aVdyYdo+ 28xvo6JQJ0UXvVrHbr01WkEyYhevPSP/nqAyLeRCTBkTsiN6mBwi8teiSEo6uzcacpQT 9keltgwLGUmAzc6p7S7KJrP1VrOrEA5MM5cvrN9gqPXx5+C6s7BgxDN7qR0Hlnbq6DGU 6EFsxNEV1KRvF7dWQlQNp/qPyUmgahWKEgkqiPBZoXmrK7pTdaudSDCfrILjNwr8Mxlo VK6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794561990; x=1795166790; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=aPt1NnsuR8qHqD/7D5dJIAnQyTdLDa8FSzmcDxHlggQ=; b=IVDpTmVb7Gwj7Rf8W8MerqG9NW6Rz09MYXB/Vhazhep9Zq9sN/wrkp5XZ6kkxR8ras INjU8nClzwJy/bjiQrcvfTSsuuz5N9Z4bK0ABDEfVFTMp/SpLDoiUNnt5GlEsvDNqids X/V7iF0JoVYHArygIy3RhTP3hfnxIY6JVdSFK2C/I+WWu+iR2xTany/VbQTZTfUKZd8p GnLVEZZPSC1M+KT6UV2Khd5/y+yVmnh6nwehb8o0YithjnD/xmFaw7WvvGmOkIo8vd6r XZ8r3FbRLhc0jJugq0l3s0iJDskIYW82a6Kyw7h7CWKrQMvIlPKbw0As00p6g6GLa8TU RSGw== X-Gm-Message-State: APuU4Z/J9tL/sPNe90oArKj+R42pP74+IK1V+hJMPUfn5NV0euZEvSbX va1FKjzNSsPqRLuuC3ao6//TngbidA+CHL+swJeAByGAWu/4+Uu9blnUPnBuWlIg X-Gm-Gg: AYBFou2LAM7otBEnEzgVfEjrU7hsI+i/tkIuOnDZ8kRhl/froAZwFEV/LkZcdj2jp9r 7218c9oMOYmSI0hjnYlQ2o2r1JBFvO9ElUwrNs6ZrOWrpg5b7e8kXyXKtwhCeDYXxTLplsSbG7H /wexo3KaTemrpZOOqhQNH9AtH33pwP9zvGqX7/zVVW0k6IQ0klGQ465oscGpDoF1XOoXzyOGhlH BFMcWg9zoE/Yw/ukEn4n8WVd3DTOawDB3/QltcuLIx5qBjULU6WfTz321ijLtE614vWAr+lxJIS mCc993ly7nmxr/vh9HV5i4QzokI3ZKyqz/4UZR5OCjmA0IkYtOIxEc6HwbAJtCbtYbiCgbDm3PJ nHl4vUWTZ/gtUxu1eEgVIFvJPkXVD2rZIYldT6uu537JCJE2LYSXMVrAeGjyaFEcY2aiIg5M1pr yBYT6/5XSn+oxpUKYFJYvE3gI78sLQCxzo9d4+A1ud8cvWLEy5VhU8+sw4EcsJrYwbCcjPZpgbC POt13ivj58Rg+lakg6WP4X6CHNXPGCfLHZt/JTjKgHkd1TTtl5MAC7wmk7KYN9THLQZF7naRQ8c jlDB73QhudgDzxBYbF2XVI6xUE7tkcdMzyPXM2GKHo4+ynltQr/v829pPQM= X-Received: by 2002:a17:902:da8d:b0:2e9:7719:40f0 with SMTP id d9443c01a7336-2ee0da9893amr20104315ad.19.1794561989455; Fri, 13 Nov 2026 01:26:29 -0800 (PST) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2ee0f7d0887sm7428605ad.32.2026.11.13.01.26.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Nov 2026 01:26:28 -0800 (PST) From: Zhang Chen To: qemu-devel , Eric Blake , Markus Armbruster , "'Michael S . Tsirkin'" , Stefan Hajnoczi , Paolo Bonzini , =?UTF-8?q?=27Daniel=20P=20=2E=20Berrang=C3=A9=27?= , Jason Wang Cc: Zhang Chen Subject: [PATCH V20 01/14] iothread: introduce holder tracking Date: Fri, 13 Nov 2026 17:25:52 +0800 Message-ID: <20261113092605.942292-2-zhangckid@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261113092605.942292-1-zhangckid@gmail.com> References: <20261113092605.942292-1-zhangckid@gmail.com> X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::631; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x631.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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: qemu development List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 IOThreads do not record the QOM objects and block exports that use them, making runtime introspection and hotplug debugging difficult. Add: - holders: a list describing what is holding an iothread - iothread_ref(): add a holder to the list - iothread_unref(): remove a holder from the list A holder can identify either a QOM object or a block export. A later patch will expose this information through query-iothreads. Reviewed-by: Stefan Hajnoczi Reviewed-by: Markus Armbruster Signed-off-by: Zhang Chen --- include/system/iothread.h | 5 +++ iothread.c | 63 ++++++++++++++++++++++++++ qapi/misc.json | 94 ++++++++++++++++++++++++++++++++++----- 3 files changed, 150 insertions(+), 12 deletions(-) diff --git a/include/system/iothread.h b/include/system/iothread.h index a1ef7696cb..b8aeb32b0e 100644 --- a/include/system/iothread.h +++ b/include/system/iothread.h @@ -18,6 +18,7 @@ #include "qemu/thread.h" #include "qom/object.h" #include "system/event-loop-base.h" +#include "qapi/qapi-types-misc.h" #define TYPE_IOTHREAD "iothread" @@ -50,6 +51,7 @@ struct IOThread { bool stopping; /* has iothread_stop() been called? */ bool running; /* should iothread_run() continue? */ int thread_id; + IOThreadHolderList *holders; /* AioContext poll parameters */ int64_t poll_max_ns; @@ -82,4 +84,7 @@ void iothread_destroy(IOThread *iothread); */ bool qemu_in_iothread(void); +void iothread_ref(IOThread *iothread, const IOThreadHolder *holder); +void iothread_unref(IOThread *iothread, const IOThreadHolder *holder); + #endif /* IOTHREAD_H */ diff --git a/iothread.c b/iothread.c index 3a1601e28b..b9889be845 100644 --- a/iothread.c +++ b/iothread.c @@ -22,10 +22,71 @@ #include "qapi/error.h" #include "qapi/qapi-builtin-type-infos.h" #include "qapi/qapi-commands-misc.h" +#include "qapi/clone-visitor.h" +#include "qapi/qapi-visit-misc.h" #include "qemu/error-report.h" #include "qemu/rcu.h" #include "qemu/main-loop.h" +/* Add a deep copy of @holder to @iothread's list of holders. */ +void iothread_ref(IOThread *iothread, const IOThreadHolder *holder) +{ + assert(holder); + + QAPI_LIST_PREPEND(iothread->holders, QAPI_CLONE(IOThreadHolder, holder)); +} + +static int iothread_holder_compare(const IOThreadHolder *holder_a, + const IOThreadHolder *holder_b) +{ + const char *name_a, *name_b; + + if (holder_a->type != holder_b->type) { + return holder_a->type - holder_b->type; + } + + switch (holder_a->type) { + case IO_THREAD_HOLDER_KIND_QOM_OBJECT: + name_a = holder_a->u.qom_object.qom_path; + name_b = holder_b->u.qom_object.qom_path; + break; + case IO_THREAD_HOLDER_KIND_BLOCK_EXPORT: + name_a = holder_a->u.block_export.export_id; + name_b = holder_b->u.block_export.export_id; + break; + default: + g_assert_not_reached(); + } + + return strcmp(name_a, name_b); +} + +/* + * Remove @holder from @iothread's list of holders. + * + * It is a programming error if @holder is not present. + */ +void iothread_unref(IOThread *iothread, const IOThreadHolder *holder) +{ + IOThreadHolderList **prev = &iothread->holders; + IOThreadHolderList *curr; + + assert(holder); + + while (*prev) { + curr = *prev; + if (iothread_holder_compare(curr->value, holder) == 0) { + *prev = curr->next; + curr->next = NULL; + qapi_free_IOThreadHolderList(curr); + return; + } + prev = &curr->next; + } + + g_assert_not_reached(); +} + static void *iothread_run(void *opaque) { IOThread *iothread = opaque; @@ -130,6 +191,7 @@ static void iothread_instance_finalize(Object *obj) iothread->main_loop = NULL; } qemu_sem_destroy(&iothread->init_done_sem); + qapi_free_IOThreadHolderList(iothread->holders); } static void iothread_init_gcontext(IOThread *iothread, const char *thread_name) @@ -374,6 +436,7 @@ static int query_one_iothread(Object *object, void *opaque) info = g_new0(IOThreadInfo, 1); info->id = iothread_get_id(iothread); info->thread_id = iothread->thread_id; + info->holders = QAPI_CLONE(IOThreadHolderList, iothread->holders); info->poll_max_ns = iothread->poll_max_ns; info->poll_grow = iothread->poll_grow; info->poll_shrink = iothread->poll_shrink; diff --git a/qapi/misc.json b/qapi/misc.json index 4469e44d05..4a3eff4685 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -64,6 +64,55 @@ ## { 'command': 'query-name', 'returns': 'NameInfo', 'allow-preconfig': true } +## +# @IOThreadHolderBlockExport: +# +# @export-id: The unique block export identifier. +# +# Since: 11.2 +# +## +{ 'struct': 'IOThreadHolderBlockExport', + 'data': { 'export-id': 'str' } } + +## +# @IOThreadHolderQomObject: +# +# @qom-path: Path to the object in the QOM tree. +# +# Since: 11.2 +# +## +{ 'struct': 'IOThreadHolderQomObject', + 'data': { 'qom-path': 'str' } } + +## +# @IOThreadHolderKind: +# +# @block-export: A block export. +# @qom-object: A QOM object. +# +# Since: 11.2 +## +{ 'enum': 'IOThreadHolderKind', + 'data': [ 'block-export', 'qom-object' ] } + +## +# @IOThreadHolder: +# +# The block export or QOM object holding the iothread. +# +# @type: the kind of iothread holder. +# +# Since: 11.2 +## +{ 'union': 'IOThreadHolder', + 'base': { 'type': 'IOThreadHolderKind' }, + 'discriminator': 'type', + 'data': { + 'block-export': 'IOThreadHolderBlockExport', + 'qom-object': 'IOThreadHolderQomObject' } } + ## # @IOThreadInfo: # Information about an iothread @@ -72,6 +121,10 @@ # # @thread-id: ID of the underlying host thread # +# @holders: the QOM objects or block exports currently holding this +# iothread. When a holder is detached or destroyed, it is removed +# from this list. (Since 11.2) +# # @poll-max-ns: maximum polling time in ns, 0 means polling is # disabled (since 2.9) # @@ -94,6 +147,7 @@ { 'struct': 'IOThreadInfo', 'data': {'id': 'str', 'thread-id': 'int', + 'holders': ['IOThreadHolder'], 'poll-max-ns': 'int', 'poll-grow': 'int', 'poll-shrink': 'int', @@ -117,20 +171,36 @@ # -> { "execute": "query-iothreads" } # <- { "return": [ # { -# "id":"iothread0", -# "thread-id":3134, -# "poll-max-ns":32768, -# "poll-grow":0, -# "poll-shrink":0, -# "aio-max-batch":0 +# "id": "iothread0", +# "thread-id": 3134, +# "holders": [ +# { +# "qom-path": "/machine/peripheral/blk1/virtio-backend", +# "type": "qom-object" +# }, +# { +# "qom-path": "/machine/peripheral/blk2/virtio-backend", +# "type": "qom-object" +# } +# ], +# "poll-max-ns": 32768, +# "poll-grow": 0, +# "poll-shrink": 0, +# "aio-max-batch": 0 # }, # { -# "id":"iothread1", -# "thread-id":3135, -# "poll-max-ns":32768, -# "poll-grow":0, -# "poll-shrink":0, -# "aio-max-batch":0 +# "id": "iothread1", +# "thread-id": 3135, +# "holders": [ +# { +# "export-id": "export0", +# "type": "block-export" +# } +# ], +# "poll-max-ns": 32768, +# "poll-grow": 0, +# "poll-shrink": 0, +# "aio-max-batch": 0 # } # ] # } -- 2.53.0