From nobody Sun Nov 24 03:28:56 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=1727726517; cv=none; d=zohomail.com; s=zohoarc; b=SbyfOwVcglCVEnoJTxJyWtkpeDRHdIa1sZUnImIMGWFTAAuxthtaTqHBDZhQyZGB5K7cfG06qpmTTL54XL/K/goCWcLNBce5Hyju3wf+sgWEknCMEhP2T+m3J0MMHI8SFRfqPMOCKwwPjjjVGX/PVDeX6IGQP0vUifA4gXZI82Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1727726517; 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=64NuNC1LXyWR9BlyqFsA8AEgcMwuGH1wwkajjFosllk=; b=ctOUhWhY8cxhOtEIXV4y/mZ94lCqzZtds+X4KJgXaH0f8VmZ0dSJavX50vCanJhpunMknTZxPTHbKTRuKH6izKdAfdz8BZnqVpms1KMjl0Wfq/BA5CSj+1RRzcAle91dmCylUIuWEGtZfQqqvOeYXMwcx+SlCNs+2WqfU5u0px8= 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 1727726517337394.080676874447; Mon, 30 Sep 2024 13:01:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1svMYc-00057A-N0; Mon, 30 Sep 2024 15:59:46 -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 1svMXx-00045N-G2 for qemu-devel@nongnu.org; Mon, 30 Sep 2024 15:59:05 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1svMXt-00041x-SC for qemu-devel@nongnu.org; Mon, 30 Sep 2024 15:59:05 -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-471-w37P3WYJP4ihE5VuugavLA-1; Mon, 30 Sep 2024 15:58:59 -0400 Received: by mail-qt1-f199.google.com with SMTP id d75a77b69052e-45b172569a2so57190211cf.0 for ; Mon, 30 Sep 2024 12:58:59 -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.58.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2024 12:58:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1727726340; 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=64NuNC1LXyWR9BlyqFsA8AEgcMwuGH1wwkajjFosllk=; b=P+weIxhKjRs0gWY1vpHk4f12pj+LURxyNYL8l5tu39fCh7ivrIJp0ZGIWX57D582WW39Ku TlYjLbLLMu0biKy7JoV3VlAABzv72VBtKN4GsswoQLaz7AEvMDSNsc0GtHSBgUxMebB+1D DR6hxBzomFiip4DkhIz1RhObFgEjzwc= X-MC-Unique: w37P3WYJP4ihE5VuugavLA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727726337; x=1728331137; 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=64NuNC1LXyWR9BlyqFsA8AEgcMwuGH1wwkajjFosllk=; b=o3kKthrGP22o4tACQJyjDNo00P4bnMUxAhQD/INphVJVEoAcgVQBZY9kqTJyAKH1d5 33Lt+a764kYMa23uWcyASKHTp1k43wYjIJDATDyRVo07gnaVxhS0/CK/wSjNhnW7chwn 4knoODfD5FzI1kB4I8KUkZRwuKCrFQwJ89NxH386xP4tiaskegRVX+fYcrSGxPeVlPYW sHWBGbiWc4MO59jYabqdq41hjmi1pCFKQXwr8vAVF00sfYF8C/0XfV4G4rZjrtkBwjRz Wr3M2vq2zG11DAiOrUtJmMj8PIkSMC9Z9uodcPRQjKG60IIG71BlvkzkRkT1qdBMlKiN Iykg== X-Gm-Message-State: AOJu0Yydmbmkho5Dd9M7SXcJV4paGTcJ8E98hKZISxuXG+SqAoNJ1iHo yZmSs7afUoRvoz3NfJ5Ii6gG6h7p0SLgZ1cqltsvCU8wkGjXLAHdFAyhG1xPOZlyklsXJ5CP2IV W1vHtRYo1qcknZojw44z3ZBWfhKzbNOebYb9AwjZbbuZ1jIDMXzXpt714mHB1/S3wIVc4miXbmA tWp6j80kXPYt6c1Vec51aImkQdPb3nJO8ZGw== X-Received: by 2002:ac8:5756:0:b0:458:1749:e195 with SMTP id d75a77b69052e-45c9f1b1fe4mr164506131cf.10.1727726336702; Mon, 30 Sep 2024 12:58:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGqiB7b3fIawvfRZqUY0ehIHYZkiFiRJyfeO1PLeLl54hB4ha+h6XAsGKJ/AVLigYDn5juGaA== X-Received: by 2002:ac8:5756:0:b0:458:1749:e195 with SMTP id d75a77b69052e-45c9f1b1fe4mr164505841cf.10.1727726336208; Mon, 30 Sep 2024 12:58:56 -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 4/7] migration: Simplify migration-threads API Date: Mon, 30 Sep 2024 15:58:34 -0400 Message-ID: <20240930195837.825728-5-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.129.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: 1727726519172116600 Content-Type: text/plain; charset="utf-8" There's no need to return a thread struct, because both the add/remove APIs must be used in the working threads so tid would work. Similar to the fact we don't need to pass in tid in each call sites, we don't need the thread struct for removal too because tid is always in the context. Remove it in both add & remove APIs. Instead making sure when remove a thread the tid is always there. Signed-off-by: Peter Xu --- migration/threadinfo.h | 4 ++-- migration/migration.c | 5 ++--- migration/multifd.c | 5 ++--- migration/threadinfo.c | 19 ++++++++++++++----- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/migration/threadinfo.h b/migration/threadinfo.h index d0e4ab0aa3..7c86ae8763 100644 --- a/migration/threadinfo.h +++ b/migration/threadinfo.h @@ -21,5 +21,5 @@ struct MigrationThread { QLIST_ENTRY(MigrationThread) node; }; =20 -MigrationThread *migration_threads_add(const char *name); -void migration_threads_remove(MigrationThread *info); +void migration_threads_add(const char *name); +void migration_threads_remove(void); diff --git a/migration/migration.c b/migration/migration.c index 1ddcf54a70..74b2c1c627 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -3460,14 +3460,13 @@ static void qemu_savevm_wait_unplug(MigrationState = *s, int old_state, static void *migration_thread(void *opaque) { MigrationState *s =3D opaque; - MigrationThread *thread =3D NULL; int64_t setup_start =3D qemu_clock_get_ms(QEMU_CLOCK_HOST); MigThrError thr_error; bool urgent =3D false; Error *local_err =3D NULL; int ret; =20 - thread =3D migration_threads_add(MIGRATION_THREAD_SRC_MAIN); + migration_threads_add(MIGRATION_THREAD_SRC_MAIN); =20 rcu_register_thread(); =20 @@ -3566,7 +3565,7 @@ out: migration_iteration_finish(s); object_unref(OBJECT(s)); rcu_unregister_thread(); - migration_threads_remove(thread); + migration_threads_remove(); return NULL; } =20 diff --git a/migration/multifd.c b/migration/multifd.c index 04db886c7e..2738d78407 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -570,12 +570,11 @@ int multifd_send_sync_main(void) static void *multifd_send_thread(void *opaque) { MultiFDSendParams *p =3D opaque; - MigrationThread *thread =3D NULL; Error *local_err =3D NULL; int ret =3D 0; bool use_packets =3D multifd_use_packets(); =20 - thread =3D migration_threads_add(p->name); + migration_threads_add(p->name); =20 trace_multifd_send_thread_start(p->id); rcu_register_thread(); @@ -669,7 +668,7 @@ out: } =20 rcu_unregister_thread(); - migration_threads_remove(thread); + migration_threads_remove(); trace_multifd_send_thread_end(p->id, p->packets_sent); =20 return NULL; diff --git a/migration/threadinfo.c b/migration/threadinfo.c index 8069413091..25e77404e2 100644 --- a/migration/threadinfo.c +++ b/migration/threadinfo.c @@ -23,7 +23,7 @@ static void __attribute__((constructor)) migration_thread= s_init(void) qemu_mutex_init(&migration_threads_lock); } =20 -MigrationThread *migration_threads_add(const char *name) +void migration_threads_add(const char *name) { MigrationThread *thread =3D g_new0(MigrationThread, 1); =20 @@ -33,17 +33,26 @@ MigrationThread *migration_threads_add(const char *name) WITH_QEMU_LOCK_GUARD(&migration_threads_lock) { QLIST_INSERT_HEAD(&migration_threads, thread, node); } - - return thread; } =20 -void migration_threads_remove(MigrationThread *thread) +void migration_threads_remove(void) { + int tid =3D qemu_get_thread_id(); + MigrationThread *thread; + QEMU_LOCK_GUARD(&migration_threads_lock); - if (thread) { + + QLIST_FOREACH(thread, &migration_threads, node) { + if (tid !=3D thread->thread_id) { + continue; + } + QLIST_REMOVE(thread, node); g_free(thread); + return; } + + g_assert_not_reached(); } =20 MigrationThreadInfoList *qmp_query_migrationthreads(Error **errp) --=20 2.45.0