From nobody Sun Nov 24 02:37:46 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1727726460; cv=none; d=zohomail.com; s=zohoarc; b=JvZxIRt94xSjnI4CQ3vvqqwetmktskgZcHUkGMkApbD/nhrGB2kpmvbdyqos7Rl+mzbcJv5o/gLrbO0ZrGA9BsfpLzGGZeqJ1KZzi07wzYk68Ue9+39kg+Ee1GpM8QV/PnT26a/JHLJ3qxhzH1Az1gscoTVyzVYytpkatL+75Wo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1727726460; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=yDBWKslzG5nwdIt7YxzIRAMdilvoFhU+JDma5UP115Q=; b=N2y2fu8GFQBoctbDidZ47VnDcAzo8pYuPC0GbllxLk6Od89tUetFGm9hhSNVqjrcM1c6OUr0YevFLoz7c3N9upBxJH41B1PaqRJ216aQenCy2m2RczyLedgxcdjeWyZz2mstM46hQtO4nM4GrP/nZ1FEjUvvcVvA2BKXK68xhHA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1727726460232716.3720249799782; Mon, 30 Sep 2024 13:01:00 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1svMYK-0004Qw-Gj; Mon, 30 Sep 2024 15:59:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1svMY2-00049Q-MG for qemu-devel@nongnu.org; Mon, 30 Sep 2024 15:59:12 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1svMY0-00047c-Tj for qemu-devel@nongnu.org; Mon, 30 Sep 2024 15:59:10 -0400 Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-448-NstkanWxMuSETVVL5Fm1sw-1; Mon, 30 Sep 2024 15:59:06 -0400 Received: by mail-qt1-f199.google.com with SMTP id d75a77b69052e-45856a29545so99100651cf.3 for ; Mon, 30 Sep 2024 12:59:06 -0700 (PDT) Received: from x1n.redhat.com (pool-99-254-121-117.cpe.net.cable.rogers.com. [99.254.121.117]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-45c9f28e481sm38879371cf.16.2024.09.30.12.59.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2024 12:59:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1727726347; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yDBWKslzG5nwdIt7YxzIRAMdilvoFhU+JDma5UP115Q=; b=cl+EtGGnys4iz0IciZh2L47g0TxlojJlbYWnzpqOGP0YYf2nuBSsZU07E9hgykTUx69Liz KVTr7X/gigJIeyWliLeFqeEk/t0iA0F8InOAn6ycIASWkCNGlq4U/L+7w+ofIB36AVIcTj VyawdcAz1NdnXArPWKdtkMy+Aa8XptQ= X-MC-Unique: NstkanWxMuSETVVL5Fm1sw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727726345; x=1728331145; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yDBWKslzG5nwdIt7YxzIRAMdilvoFhU+JDma5UP115Q=; b=VOfuzNAqvQpLJP3ppZ4feFchwm4XcETngCcCZdQTkz1lgda7G1Q1d9WsShvij6/OSN oUkjYd26uYR6EtjzYOzVLTTK+NphMR2rSioH+59ymkm5UOYEtN0XKQ2BH1ctRc+TOtAk 9X2Wfa8G4NlJR8mgMD4GwKaGgyCjDreC0xrgq+o8sJYbpqmCa4xqZr/B9J/oMHadbLnE iNpZF1Fiy+k2o9AGvvKanPrmxZCdgDv3RaNjp7aLeeHwnMshwVDxH9PgLkWRXF0MXnTE NUSR4LdYudOyyaPzgjs+UmJnrljhr9irCAtPx++DaJubIRhhExoC68187fW4BdGvfKvK c+QQ== X-Gm-Message-State: AOJu0Yz21JXGVP6AMRu4pzy8YwlO+bt6ImM6dJFZqS3ciaTGmykabR3p tQa5JGH2PIoVotJIKEw14wFHCag5LcLdQ6JTz2vV5E3sLTQjj2l7++CpQnDRe1wJALg1fiFe6xo eNpO6ktfe6OefQgD/gUUPO7tU7TGyzQkpvV398ANETtzLy7vN70Bs8KSgl5wTKpLrXhb2AzAJKB D72sjF8PFUe5KUPUC8M1q17EPsrsmpTqwEJw== X-Received: by 2002:ac8:7f09:0:b0:45b:5596:f785 with SMTP id d75a77b69052e-45c9f2a3ccamr217341481cf.44.1727726344594; Mon, 30 Sep 2024 12:59:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF00fm5R2Yl9uT792JudZsOBV9gQxJc9d2Ztjd5aqJ+8ReyVARVuAaZm4316X4jDrwIXTThdA== X-Received: by 2002:ac8:7f09:0:b0:45b:5596:f785 with SMTP id d75a77b69052e-45c9f2a3ccamr217341161cf.44.1727726344203; Mon, 30 Sep 2024 12:59:04 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Prasad Pandit , Julia Suvorova , Markus Armbruster , peterx@redhat.com, Fabiano Rosas , Juraj Marcin , "Dr . David Alan Gilbert" Subject: [PATCH 6/7] migration: Remove MigrationThread and threadinfo.h Date: Mon, 30 Sep 2024 15:58:36 -0400 Message-ID: <20240930195837.825728-7-peterx@redhat.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240930195837.825728-1-peterx@redhat.com> References: <20240930195837.825728-1-peterx@redhat.com> MIME-Version: 1.0 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.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.144, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1727726461047116600 Content-Type: text/plain; charset="utf-8" The MigrationThread struct is mostly the same as MigrationThreadInfoList, except that it's a double-linked list so removal doesn't need to remember prev pointer. That might not be necessary, especially considering that the defintion of that struct is the only thing in threadinfo.h now. Reuse MigrationThreadInfoList, then let's drop the header. Need to manage a single list entry removal, but after I saw the diff, it's not so bad. With that, query-migrationthreads is much easier, as we can simply do QAPI_CLONE() now. Signed-off-by: Peter Xu --- migration/threadinfo.h | 22 ------------------- migration/migration.c | 1 - migration/multifd.c | 1 - migration/threadinfo.c | 50 +++++++++++++++++++++--------------------- 4 files changed, 25 insertions(+), 49 deletions(-) delete mode 100644 migration/threadinfo.h diff --git a/migration/threadinfo.h b/migration/threadinfo.h deleted file mode 100644 index 59f334af21..0000000000 --- a/migration/threadinfo.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Migration Threads info - * - * Copyright (c) 2022 HUAWEI TECHNOLOGIES CO., LTD. - * - * Authors: - * Jiang Jiacheng - * - * This work is licensed under the terms of the GNU GPL, version 2 or lat= er. - * See the COPYING file in the top-level directory. - */ - -#include "qapi/error.h" -#include "qapi/qapi-commands-migration.h" - -typedef struct MigrationThread MigrationThread; - -struct MigrationThread { - const char *name; /* the name of migration thread */ - int thread_id; /* ID of the underlying host thread */ - QLIST_ENTRY(MigrationThread) node; -}; diff --git a/migration/migration.c b/migration/migration.c index 04c4272e46..1034668a90 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -57,7 +57,6 @@ #include "net/announce.h" #include "qemu/queue.h" #include "multifd.h" -#include "threadinfo.h" #include "qemu/yank.h" #include "sysemu/cpus.h" #include "yank_functions.h" diff --git a/migration/multifd.c b/migration/multifd.c index b96aaffebb..0baa760ccf 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -26,7 +26,6 @@ #include "qemu-file.h" #include "trace.h" #include "multifd.h" -#include "threadinfo.h" #include "options.h" #include "qemu/yank.h" #include "io/channel-file.h" diff --git a/migration/threadinfo.c b/migration/threadinfo.c index 73db26dc82..6c1278b4ea 100644 --- a/migration/threadinfo.c +++ b/migration/threadinfo.c @@ -13,11 +13,13 @@ #include "qemu/osdep.h" #include "qemu/queue.h" #include "qemu/lockable.h" -#include "threadinfo.h" #include "migration.h" +#include "qapi/qapi-commands-migration.h" +#include "qapi/qapi-visit-migration.h" +#include "qapi/clone-visitor.h" =20 QemuMutex migration_threads_lock; -static QLIST_HEAD(, MigrationThread) migration_threads; +static MigrationThreadInfoList *migration_threads; =20 static void __attribute__((constructor)) migration_threads_init(void) { @@ -26,31 +28,40 @@ static void __attribute__((constructor)) migration_thre= ads_init(void) =20 void migration_threads_add(const char *name) { - MigrationThread *thread =3D g_new0(MigrationThread, 1); + MigrationThreadInfo *thread =3D g_new0(MigrationThreadInfo, 1); =20 - thread->name =3D name; + thread->name =3D g_strdup(name); thread->thread_id =3D qemu_get_thread_id(); =20 WITH_QEMU_LOCK_GUARD(&migration_threads_lock) { - QLIST_INSERT_HEAD(&migration_threads, thread, node); + QAPI_LIST_PREPEND(migration_threads, thread); } } =20 void migration_threads_remove(void) { int tid =3D qemu_get_thread_id(); - MigrationThread *thread; + MigrationThreadInfoList *thread, *prev; =20 QEMU_LOCK_GUARD(&migration_threads_lock); =20 - QLIST_FOREACH(thread, &migration_threads, node) { - if (tid !=3D thread->thread_id) { - continue; - } + prev =3D NULL; + thread =3D migration_threads; =20 - QLIST_REMOVE(thread, node); - g_free(thread); - return; + while (thread) { + if (tid =3D=3D thread->value->thread_id) { + if (!prev) { + migration_threads =3D thread->next; + } else { + prev->next =3D thread->next; + } + /* Terminate this single object to not free the rest */ + thread->next =3D NULL; + qapi_free_MigrationThreadInfoList(thread); + return; + } + prev =3D thread; + thread =3D thread->next; } =20 g_assert_not_reached(); @@ -58,18 +69,7 @@ void migration_threads_remove(void) =20 MigrationThreadInfoList *qmp_query_migrationthreads(Error **errp) { - MigrationThreadInfoList *head =3D NULL; - MigrationThreadInfoList **tail =3D &head; - MigrationThread *thread =3D NULL; - QEMU_LOCK_GUARD(&migration_threads_lock); - QLIST_FOREACH(thread, &migration_threads, node) { - MigrationThreadInfo *info =3D g_new0(MigrationThreadInfo, 1); - info->name =3D g_strdup(thread->name); - info->thread_id =3D thread->thread_id; - - QAPI_LIST_APPEND(tail, info); - } =20 - return head; + return QAPI_CLONE(MigrationThreadInfoList, migration_threads); } --=20 2.45.0