From nobody Sun Nov 24 02:27:57 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=1727726483; cv=none; d=zohomail.com; s=zohoarc; b=Vy8lNACTzF13TUsircNcSx5L/0FvuuoSIKTeown8xz/15bG3G5AlMriWvHOBZjuEFlaBqxMMxRaIGsR2bvjCSjQaOAgsN8uWtsnplgyHWQIGLFzQO4I/RfcGxAPn+hffUhHDXtdfc0/Z26dZKHiYAuwTj7ASuMyVC8Em8M023l4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1727726483; 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=AZVd4Pug3ifuQz90VwbIAIsYrOTo120GMYeAvFDr5kM=; b=ZedtnpT/Dbzl/sYrU0eU+K7wevCRt9LdCh7qP/PTQD0LgJF3iqZCm1Y2dluk3lINHrD+px6mheekjaWywXuwp1UDQ73IcMCQuoWhMjhUaBPAbfst5ceL3afPCfAwiDLz74/dT5ewSXhkhFroDpoArHMlKsPVeqNGUbSsdg2lH08= 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 1727726483560583.307134064451; Mon, 30 Sep 2024 13:01:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1svMYc-00057j-Rn; 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 1svMXz-00047P-Hc for qemu-devel@nongnu.org; Mon, 30 Sep 2024 15:59:08 -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 1svMXx-000466-Ki for qemu-devel@nongnu.org; Mon, 30 Sep 2024 15:59:07 -0400 Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-167-eN7qVG16OPSKELawoOx-XA-1; Mon, 30 Sep 2024 15:59:02 -0400 Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-45832b277d9so79429461cf.1 for ; Mon, 30 Sep 2024 12:59:02 -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.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2024 12:58:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1727726345; 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=AZVd4Pug3ifuQz90VwbIAIsYrOTo120GMYeAvFDr5kM=; b=NFUAXDLV9h9hsWKVcty6O9fzpzpinC6CkqCn7RRl/6owAGKbdfHkGW6XCpwe6X1Gy7+17H XCMhMhCHeTFFvLYTw9OAmxlwZ1X6jklfAhlaWEe9+jBCiq14wZlFAz5jdJnwzvBMjeBvzq 2louDRTAUa3MFIjEmQpjmpGDWg6kVqQ= X-MC-Unique: eN7qVG16OPSKELawoOx-XA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727726342; x=1728331142; 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=AZVd4Pug3ifuQz90VwbIAIsYrOTo120GMYeAvFDr5kM=; b=oNUoIAVqpAGsmL+Mv4aJKObzIBd/pzzBn7cV7NSyrbqGXOlfGM8rkL/4aLR42i1hsF nn3mvhlAQZmp9SVsEwoCSHeCV3himeRsBPkylBmfEFKKLHcoWtu3Y+lzXcBZU3ruHivO zsGgbHh61ec5VaQ3w43CWQQLcxSTSs1Nz1UhSsYUfqBUH+BfPiQzzwTCnInyWP6J0dLQ /oE0qXxnscnYFEkJmfaCjjJbh2pBlRktf9uFJA2RQRzMG+FItPlUrDtCkIDfrGjP91kI OZfO4In6X/xTCZD4V4PiZMfvrXurAct4F4EdUB8LyGZRlFhjDC7/+8Rj05phIFudGykF wL8g== X-Gm-Message-State: AOJu0YyUsFm8wgYs9yBum1hyGA6t5KkbPO/HgiBNhNBR05yxjF8rLjQN dduDVtUJr+rl9eSzMT/dBOEAIrRJLIhtkLQQK/XdJT3vjsZXRAQTy6VWmd/r9uOq1rlUJehIOM7 kIBEC/w35Dbsb7X2sWDKM6YJzfrKNEq/XGIT4jHEaL/b8u8VuNSZ3jzTawm/v+yjJ0qlyoPwAxn 2/nNVLh9M3fY5Nq1bYlhWK4Czq3H8nc/XF5Q== X-Received: by 2002:a05:622a:54d:b0:45b:5cdf:54b8 with SMTP id d75a77b69052e-45c9f1fba6amr208457121cf.19.1727726341518; Mon, 30 Sep 2024 12:59:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFqPysoEctDd1HPNkOdQUXjHclJJZtuerEr6FAqLthVfUIXv32H0mWurxxO8/0bKDzYGmDekw== X-Received: by 2002:a05:622a:54d:b0:45b:5cdf:54b8 with SMTP id d75a77b69052e-45c9f1fba6amr208456741cf.19.1727726340978; Mon, 30 Sep 2024 12:59:00 -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 5/7] migration: Add all threads with QMP query-migrationthreads Date: Mon, 30 Sep 2024 15:58:35 -0400 Message-ID: <20240930195837.825728-6-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: 1727726485016116600 Content-Type: text/plain; charset="utf-8" The QMP interface query-migrationthreads lacks a lot of migration threads but only reports multifd sender threads. That's incomplete. Since I'm at this, make all threads available to the QMP responses. NOTE: there're a few changes that should fix some bugs on e.g. not unregister rcu threads on failure paths, but I didn't make them separate because they do not exist in live migration main logics but only either COLO or dirty rate thread on rare failures. I'd not bother, but if anyone things we should split it out feel free to shoot. Signed-off-by: Peter Xu --- migration/migration.h | 3 +++ migration/threadinfo.h | 3 --- migration/colo.c | 7 +++++-- migration/dirtyrate.c | 7 ++++++- migration/migration.c | 7 ++++++- migration/multifd.c | 6 ++++++ migration/postcopy-ram.c | 10 +++++++--- migration/savevm.c | 10 ++++++---- migration/threadinfo.c | 1 + 9 files changed, 40 insertions(+), 14 deletions(-) diff --git a/migration/migration.h b/migration/migration.h index b9ce5aa4ff..85ec203a01 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -551,4 +551,7 @@ int migration_rp_wait(MigrationState *s); */ void migration_rp_kick(MigrationState *s); =20 +void migration_threads_add(const char *name); +void migration_threads_remove(void); + #endif diff --git a/migration/threadinfo.h b/migration/threadinfo.h index 7c86ae8763..59f334af21 100644 --- a/migration/threadinfo.h +++ b/migration/threadinfo.h @@ -20,6 +20,3 @@ struct MigrationThread { int thread_id; /* ID of the underlying host thread */ QLIST_ENTRY(MigrationThread) node; }; - -void migration_threads_add(const char *name); -void migration_threads_remove(void); diff --git a/migration/colo.c b/migration/colo.c index 9590f281d0..2f5cb96a90 100644 --- a/migration/colo.c +++ b/migration/colo.c @@ -823,6 +823,7 @@ static void *colo_process_incoming_thread(void *opaque) QIOChannelBuffer *bioc =3D NULL; /* Cache incoming device state */ Error *local_err =3D NULL; =20 + migration_threads_add(MIGRATION_THREAD_DST_COLO); rcu_register_thread(); qemu_sem_init(&mis->colo_incoming_sem, 0); =20 @@ -831,7 +832,7 @@ static void *colo_process_incoming_thread(void *opaque) =20 if (get_colo_mode() !=3D COLO_MODE_SECONDARY) { error_report("COLO mode must be COLO_MODE_SECONDARY"); - return NULL; + goto out_last; } =20 /* Make sure all file formats throw away their mutable metadata */ @@ -840,7 +841,7 @@ static void *colo_process_incoming_thread(void *opaque) bql_unlock(); if (local_err) { error_report_err(local_err); - return NULL; + goto out_last; } =20 failover_init_state(); @@ -923,7 +924,9 @@ out: qemu_sem_wait(&mis->colo_incoming_sem); qemu_sem_destroy(&mis->colo_incoming_sem); =20 +out_last: rcu_unregister_thread(); + migration_threads_remove(); return NULL; } =20 diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c index 2339ba400d..555c599c17 100644 --- a/migration/dirtyrate.c +++ b/migration/dirtyrate.c @@ -729,13 +729,15 @@ void *get_dirtyrate_thread(void *arg) { struct DirtyRateConfig config =3D *(struct DirtyRateConfig *)arg; int ret; + + migration_threads_add(MIGRATION_THREAD_DIRTY_RATE); rcu_register_thread(); =20 ret =3D dirtyrate_set_state(&CalculatingState, DIRTY_RATE_STATUS_UNSTA= RTED, DIRTY_RATE_STATUS_MEASURING); if (ret =3D=3D -1) { error_report("change dirtyrate state failed."); - return NULL; + goto out; } =20 calculate_dirtyrate(config); @@ -746,7 +748,10 @@ void *get_dirtyrate_thread(void *arg) error_report("change dirtyrate state failed."); } =20 +out: rcu_unregister_thread(); + migration_threads_remove(); + return NULL; } =20 diff --git a/migration/migration.c b/migration/migration.c index 74b2c1c627..04c4272e46 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -2321,6 +2321,7 @@ static void *source_return_path_thread(void *opaque) int res; =20 trace_source_return_path_thread_entry(); + migration_threads_add(MIGRATION_THREAD_SRC_RETURN); rcu_register_thread(); =20 while (migration_is_setup_or_active()) { @@ -2463,8 +2464,9 @@ out: migration_rp_kick(ms); } =20 - trace_source_return_path_thread_end(); rcu_unregister_thread(); + migration_threads_remove(); + trace_source_return_path_thread_end(); =20 return NULL; } @@ -3602,6 +3604,8 @@ static void *bg_migration_thread(void *opaque) Error *local_err =3D NULL; int ret; =20 + migration_threads_add(MIGRATION_THREAD_SNAPSHOT); + rcu_register_thread(); object_ref(OBJECT(s)); =20 @@ -3726,6 +3730,7 @@ fail_setup: qemu_fclose(fb); object_unref(OBJECT(s)); rcu_unregister_thread(); + migration_threads_remove(); =20 return NULL; } diff --git a/migration/multifd.c b/migration/multifd.c index 2738d78407..b96aaffebb 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -685,6 +685,8 @@ static void *multifd_tls_handshake_thread(void *opaque) { MultiFDTLSThreadArgs *args =3D opaque; =20 + migration_threads_add(MIGRATION_THREAD_SRC_TLS); + qio_channel_tls_handshake(args->tioc, multifd_new_send_channel_async, args->p, @@ -692,6 +694,8 @@ static void *multifd_tls_handshake_thread(void *opaque) NULL); g_free(args); =20 + migration_threads_remove(); + return NULL; } =20 @@ -1122,6 +1126,7 @@ static void *multifd_recv_thread(void *opaque) int ret; =20 trace_multifd_recv_thread_start(p->id); + migration_threads_add(MIGRATION_THREAD_DST_MULTIFD); rcu_register_thread(); =20 while (true) { @@ -1209,6 +1214,7 @@ static void *multifd_recv_thread(void *opaque) } =20 rcu_unregister_thread(); + migration_threads_remove(); trace_multifd_recv_thread_end(p->id, p->packets_recved); =20 return NULL; diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index a535fd2e30..ee8f2eac77 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -962,6 +962,7 @@ static void *postcopy_ram_fault_thread(void *opaque) RAMBlock *rb =3D NULL; =20 trace_postcopy_ram_fault_thread_entry(); + migration_threads_add(MIGRATION_THREAD_DST_FAULT); rcu_register_thread(); mis->last_rb =3D NULL; /* last RAMBlock we sent part of */ qemu_sem_post(&mis->thread_sync_sem); @@ -1142,9 +1143,12 @@ retry: } } } + + g_free(pfd); rcu_unregister_thread(); + migration_threads_remove(); trace_postcopy_ram_fault_thread_exit(); - g_free(pfd); + return NULL; } =20 @@ -1713,7 +1717,7 @@ void *postcopy_preempt_thread(void *opaque) int ret; =20 trace_postcopy_preempt_thread_entry(); - + migration_threads_add(MIGRATION_THREAD_DST_PREEMPT); rcu_register_thread(); =20 qemu_sem_post(&mis->thread_sync_sem); @@ -1740,7 +1744,7 @@ void *postcopy_preempt_thread(void *opaque) qemu_mutex_unlock(&mis->postcopy_prio_thread_mutex); =20 rcu_unregister_thread(); - + migration_threads_remove(); trace_postcopy_preempt_thread_exit(); =20 return NULL; diff --git a/migration/savevm.c b/migration/savevm.c index e796436979..90f87a90c9 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -2002,14 +2002,15 @@ static void *postcopy_ram_listen_thread(void *opaqu= e) int load_res; MigrationState *migr =3D migrate_get_current(); =20 - object_ref(OBJECT(migr)); + trace_postcopy_ram_listen_thread_start(); + migration_threads_add(MIGRATION_THREAD_DST_LISTEN); + rcu_register_thread(); =20 + object_ref(OBJECT(migr)); migrate_set_state(&mis->state, MIGRATION_STATUS_ACTIVE, MIGRATION_STATUS_POSTCOPY_ACTIVE); qemu_sem_post(&mis->thread_sync_sem); - trace_postcopy_ram_listen_thread_start(); =20 - rcu_register_thread(); /* * Because we're a thread and not a coroutine we can't yield * in qemu_file, and thus we must be blocking now. @@ -2078,11 +2079,12 @@ static void *postcopy_ram_listen_thread(void *opaqu= e) migration_incoming_state_destroy(); qemu_loadvm_state_cleanup(); =20 - rcu_unregister_thread(); mis->have_listen_thread =3D false; postcopy_state_set(POSTCOPY_INCOMING_END); =20 object_unref(OBJECT(migr)); + rcu_unregister_thread(); + migration_threads_remove(); =20 return NULL; } diff --git a/migration/threadinfo.c b/migration/threadinfo.c index 25e77404e2..73db26dc82 100644 --- a/migration/threadinfo.c +++ b/migration/threadinfo.c @@ -14,6 +14,7 @@ #include "qemu/queue.h" #include "qemu/lockable.h" #include "threadinfo.h" +#include "migration.h" =20 QemuMutex migration_threads_lock; static QLIST_HEAD(, MigrationThread) migration_threads; --=20 2.45.0