From patchwork Mon Sep 30 19:58:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 1991171 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ancHlzBp; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XHX4j28Wtz1xtY for ; Tue, 1 Oct 2024 06:00:53 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1svMYW-0004gc-8v; Mon, 30 Sep 2024 15:59:40 -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 1svMXw-000436-2t for qemu-devel@nongnu.org; Mon, 30 Sep 2024 15:59:04 -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 1svMXm-0003xU-QZ for qemu-devel@nongnu.org; Mon, 30 Sep 2024 15:59:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1727726332; 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=AsdoBAm4/H/7Jy2H83poWUQ7xQPm3c8gUhD4CXkcCgo=; b=ancHlzBpOK4eCIoVymHJQpizwEoFMWUVxMQIae5pnLCoH2d+R++cyloHMerph69YiOKgIC IFcpbNknZfclasbQ+rMbn4ms0mG0wfRfZC8KkzakMgH52LmukAFZiGy4Mo6JvUuM7fY9VS vr0F9WMfA2DbBHZ7WkKkOI5xBaHevY8= 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-153-NO7T5VowO7KvxgBRt3ktfQ-1; Mon, 30 Sep 2024 15:58:49 -0400 X-MC-Unique: NO7T5VowO7KvxgBRt3ktfQ-1 Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-458260b3dccso96613651cf.2 for ; Mon, 30 Sep 2024 12:58:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727726324; x=1728331124; 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=AsdoBAm4/H/7Jy2H83poWUQ7xQPm3c8gUhD4CXkcCgo=; b=nXwYT//p1Pde4zs8R0S+qNydMlPkvbug605CfDMtrmnwhD6mfdKSSLWI41tV7Irh2J 5jc/Bt3wHSFpMsU4nm91pGbWZSr5ZHWBWPMncMfiqn0naxqcx2kJAP4dEqfxSSNp5lll K9YstgsLqa/lwzyS+vUxBTQ8XFgPZwGzUasI64ah/4ymmNVbi2tAIdahNChSOwRXRGXE 9eKaIWjX1QRGDu3lahayOeBmYO+aWF/k8rOBxU3qGCSjeAn+xTZrfUWDZyutt+M9UPaF SfJgyO/4rZXzP2qBAETjedb2URvA2rZHWlBJFu9vRnKMOZmgNmmTkj0yI4kODQIVfKs8 F3EA== X-Gm-Message-State: AOJu0YyTzLMIkg51ml5v2nFUaDgiiWKaui6C0ua11HurVmx//TuykoVG J/0a/5CIoazVr9PCDrM3QQhZY5ZEG/JYdn83XJ6WTAnoUYc0JzyesGBA4r88QMbEncs5TGxH0PR fifwln9EXLV+rEum15B8NZf52MuBJ9gXT9JWqAl+ArGWKQZ9JUsMxMYB7llT74FCoVfXbM9nwy4 r4YcrDZbMDOZBvroI0q/Al5axMvcqxE5IRQA== X-Received: by 2002:a05:622a:d1:b0:458:34df:1e6a with SMTP id d75a77b69052e-45c9f292b5bmr212843431cf.48.1727726324003; Mon, 30 Sep 2024 12:58:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFGTck3+ESskPrGJHCUxQNvDlQUXbp+UL5AXiNPooCEFu2ayCsK4lii6fSwoOVPAExbiEAsxg== X-Received: by 2002:a05:622a:d1:b0:458:34df:1e6a with SMTP id d75a77b69052e-45c9f292b5bmr212843141cf.48.1727726323572; Mon, 30 Sep 2024 12:58:43 -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.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2024 12:58:40 -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 1/7] migration: Unify names of migration src main thread Date: Mon, 30 Sep 2024 15:58:31 -0400 Message-ID: <20240930195837.825728-2-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 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Make pthread name match with what we report in query-migrationthreads. We used to report the same, but not anymore after 60ce47675d ("migration: Rename thread debug names"). Not a huge deal but it was still good to follow. Multifd threads are still matched because at least on the src the QMP facility reused p->name. The QMP command missed dest multifd threads though, but that's another thing to address later. Not copy stable, as we'd better keep the names not changed for stable branches in QMP responses (even though we shouldn't guarantee ABI stability on the names anyway). Cc: Juraj Marcin Reported-by: Prasad Pandit Signed-off-by: Peter Xu --- migration/migration.h | 2 ++ migration/migration.c | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/migration/migration.h b/migration/migration.h index 38aa1402d5..519455796d 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -28,6 +28,8 @@ #include "sysemu/runstate.h" #include "migration/misc.h" +#define MIGRATION_THREAD_SRC_MAIN "mig/src/main" + struct PostcopyBlocktimeContext; #define MIGRATION_RESUME_ACK_VALUE (1) diff --git a/migration/migration.c b/migration/migration.c index ae2be31557..505b62c8f3 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -3467,7 +3467,8 @@ static void *migration_thread(void *opaque) Error *local_err = NULL; int ret; - thread = migration_threads_add("live_migration", qemu_get_thread_id()); + thread = migration_threads_add(MIGRATION_THREAD_SRC_MAIN, + qemu_get_thread_id()); rcu_register_thread(); @@ -3820,7 +3821,7 @@ void migrate_fd_connect(MigrationState *s, Error *error_in) qemu_thread_create(&s->thread, "mig/snapshot", bg_migration_thread, s, QEMU_THREAD_JOINABLE); } else { - qemu_thread_create(&s->thread, "mig/src/main", + qemu_thread_create(&s->thread, MIGRATION_THREAD_SRC_MAIN, migration_thread, s, QEMU_THREAD_JOINABLE); } s->migration_thread_running = true; From patchwork Mon Sep 30 19:58:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 1991169 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Be5wUFpd; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XHX3s6pBvz1xtc for ; Tue, 1 Oct 2024 06:00:07 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1svMYE-0004Fj-KY; Mon, 30 Sep 2024 15:59:22 -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 1svMXw-00043g-CL for qemu-devel@nongnu.org; Mon, 30 Sep 2024 15:59:04 -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 1svMXn-0003xk-U4 for qemu-devel@nongnu.org; Mon, 30 Sep 2024 15:59:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1727726334; 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=fBD3pQ9OiqYUxqrsoMFJzeYINwaBKJNjacu1woAbQd0=; b=Be5wUFpdkZQxoqbpkvcu4jqon6HP4pBuWaqLlBuPn1DPeEmuFmz3m6LAhp5Hr++G9XttX/ pIBVSPaakz+QV54MbBJUfpYDgKpGxi63+4LpqYffp5C926PhHjVK89wrTTepa8gWNBVCCl 82JdutpJcaZ3spY2JmMHvAIEE3hvP8c= 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-110-aLZHqKtOMLy4eJQ1k2adGw-1; Mon, 30 Sep 2024 15:58:51 -0400 X-MC-Unique: aLZHqKtOMLy4eJQ1k2adGw-1 Received: by mail-qt1-f199.google.com with SMTP id d75a77b69052e-4581d15ced1so77859281cf.3 for ; Mon, 30 Sep 2024 12:58:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727726330; x=1728331130; 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=fBD3pQ9OiqYUxqrsoMFJzeYINwaBKJNjacu1woAbQd0=; b=GGVgltQOKV0TtbRXYBWAIAPnb9soj3VlOwFXxrVq00Isn8s3s4VsmnTi27BPanULvL ChnVh2CE32YV9R2Y94vaDo4MdSiitJe+UMVHvqjT/M+z/f4o3CVk6za0Xsxguw99AYvE f9P43OqZkiXz8eCgA6LJ9d70DZSGaLtiPFD0qNKeoc4U3ZIVORNhtzD+8ZX8DRz33fiZ hkoywm8iM4uHkPKvRuVN5l7liPgOcUYgDQULNfVts6TGSK7vTGG8powngV9O5Lz3reJ7 Tj7i8Oa3lKQXYH3s5JyjMNDiNmPuNl4SPy5202fZz7yKP55dAX6GF29yMqWAFRJzALUZ 9hEQ== X-Gm-Message-State: AOJu0YwvkrVk5FSiAtHefsEAsgoVWQr2f+di71iGrKjmDNku92vjriuY kNKFg6GG2nZ/jBCJnQ248TBhWNY01WPrxD5L6+6Rc2p3wUPVSAK7g8SyR2ZgrnfwZavTXwQbYuJ vLdWUFsJU+4XgpnUZj3yohdj6scGaQqwWmunKtmr8zAmQfujj7TUEdvkb03XuwjFNKF5uiPtPiq 1H6emBIB+e6EwFBhCVWnP7COs7+5flHyW6xA== X-Received: by 2002:ac8:5709:0:b0:458:35f7:3952 with SMTP id d75a77b69052e-45c9f2877e6mr254328421cf.40.1727726329914; Mon, 30 Sep 2024 12:58:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFDCGKpRszIYZqqocL0QnCe7EYHJTqxIVWBzQMzUlfbALLGQ25mW31KBiyjc7eoOWxSygKg4w== X-Received: by 2002:ac8:5709:0:b0:458:35f7:3952 with SMTP id d75a77b69052e-45c9f2877e6mr254328061cf.40.1727726329482; Mon, 30 Sep 2024 12:58:49 -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.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2024 12:58:44 -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 2/7] migration: Put thread names together with macros Date: Mon, 30 Sep 2024 15:58:32 -0400 Message-ID: <20240930195837.825728-3-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 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Since we have places where there can be more than one reference to the thread names, time to clean up the thread names with macros so that they're even cleaner when put together. Still two functional changes below: - There's one dirty rate thread that we overlooked before, now we add that too and name it as "mig/dirtyrate" following the old rules. - The old name "mig/src/rp-thr" has "-thr" but it may not be useful if it's a thread name anyway, while "rp" can be slightly hard to read. Taking this chance to rename it to "mig/src/return", hopefully a better name. Signed-off-by: Peter Xu --- migration/migration.h | 14 +++++++++++++- migration/colo.c | 3 ++- migration/dirtyrate.c | 6 ++++-- migration/migration.c | 4 ++-- migration/multifd.c | 6 +++--- migration/postcopy-ram.c | 6 ++++-- migration/savevm.c | 3 ++- 7 files changed, 30 insertions(+), 12 deletions(-) diff --git a/migration/migration.h b/migration/migration.h index 519455796d..b9ce5aa4ff 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -28,7 +28,19 @@ #include "sysemu/runstate.h" #include "migration/misc.h" -#define MIGRATION_THREAD_SRC_MAIN "mig/src/main" +#define MIGRATION_THREAD_SNAPSHOT "mig/snapshot" +#define MIGRATION_THREAD_DIRTY_RATE "mig/dirtyrate" + +#define MIGRATION_THREAD_SRC_MAIN "mig/src/main" +#define MIGRATION_THREAD_SRC_MULTIFD "mig/src/send_%d" +#define MIGRATION_THREAD_SRC_RETURN "mig/src/return" +#define MIGRATION_THREAD_SRC_TLS "mig/src/tls" + +#define MIGRATION_THREAD_DST_COLO "mig/dst/colo" +#define MIGRATION_THREAD_DST_MULTIFD "mig/src/recv_%d" +#define MIGRATION_THREAD_DST_FAULT "mig/dst/fault" +#define MIGRATION_THREAD_DST_LISTEN "mig/dst/listen" +#define MIGRATION_THREAD_DST_PREEMPT "mig/dst/preempt" struct PostcopyBlocktimeContext; diff --git a/migration/colo.c b/migration/colo.c index 6449490221..9590f281d0 100644 --- a/migration/colo.c +++ b/migration/colo.c @@ -935,7 +935,8 @@ void coroutine_fn colo_incoming_co(void) assert(bql_locked()); assert(migration_incoming_colo_enabled()); - qemu_thread_create(&th, "mig/dst/colo", colo_process_incoming_thread, + qemu_thread_create(&th, MIGRATION_THREAD_DST_COLO, + colo_process_incoming_thread, mis, QEMU_THREAD_JOINABLE); mis->colo_incoming_co = qemu_coroutine_self(); diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c index 5478d58de3..2339ba400d 100644 --- a/migration/dirtyrate.c +++ b/migration/dirtyrate.c @@ -29,6 +29,7 @@ #include "sysemu/runstate.h" #include "exec/memory.h" #include "qemu/xxhash.h" +#include "migration.h" /* * total_dirty_pages is procted by BQL and is used @@ -839,8 +840,9 @@ void qmp_calc_dirty_rate(int64_t calc_time, init_dirtyrate_stat(config); - qemu_thread_create(&thread, "get_dirtyrate", get_dirtyrate_thread, - (void *)&config, QEMU_THREAD_DETACHED); + qemu_thread_create(&thread, MIGRATION_THREAD_DIRTY_RATE, + get_dirtyrate_thread, (void *)&config, + QEMU_THREAD_DETACHED); } diff --git a/migration/migration.c b/migration/migration.c index 505b62c8f3..813c45ad04 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -2478,7 +2478,7 @@ static int open_return_path_on_source(MigrationState *ms) trace_open_return_path_on_source(); - qemu_thread_create(&ms->rp_state.rp_thread, "mig/src/rp-thr", + qemu_thread_create(&ms->rp_state.rp_thread, MIGRATION_THREAD_SRC_RETURN, source_return_path_thread, ms, QEMU_THREAD_JOINABLE); ms->rp_state.rp_thread_created = true; @@ -3818,7 +3818,7 @@ void migrate_fd_connect(MigrationState *s, Error *error_in) } if (migrate_background_snapshot()) { - qemu_thread_create(&s->thread, "mig/snapshot", + qemu_thread_create(&s->thread, MIGRATION_THREAD_SNAPSHOT, bg_migration_thread, s, QEMU_THREAD_JOINABLE); } else { qemu_thread_create(&s->thread, MIGRATION_THREAD_SRC_MAIN, diff --git a/migration/multifd.c b/migration/multifd.c index 9b200f4ad9..697fe86fdf 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -723,7 +723,7 @@ static bool multifd_tls_channel_connect(MultiFDSendParams *p, args->p = p; p->tls_thread_created = true; - qemu_thread_create(&p->tls_thread, "mig/src/tls", + qemu_thread_create(&p->tls_thread, MIGRATION_THREAD_SRC_TLS, multifd_tls_handshake_thread, args, QEMU_THREAD_JOINABLE); return true; @@ -841,7 +841,7 @@ bool multifd_send_setup(void) + sizeof(uint64_t) * page_count; p->packet = g_malloc0(p->packet_len); } - p->name = g_strdup_printf("mig/src/send_%d", i); + p->name = g_strdup_printf(MIGRATION_THREAD_SRC_MULTIFD, i); p->write_flags = 0; if (!multifd_new_send_channel_create(p, &local_err)) { @@ -1259,7 +1259,7 @@ int multifd_recv_setup(Error **errp) + sizeof(uint64_t) * page_count; p->packet = g_malloc0(p->packet_len); } - p->name = g_strdup_printf("mig/dst/recv_%d", i); + p->name = g_strdup_printf(MIGRATION_THREAD_DST_MULTIFD, i); p->normal = g_new0(ram_addr_t, page_count); p->zero = g_new0(ram_addr_t, page_count); } diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index 83f6160a36..a535fd2e30 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -1230,7 +1230,8 @@ int postcopy_ram_incoming_setup(MigrationIncomingState *mis) return -1; } - postcopy_thread_create(mis, &mis->fault_thread, "mig/dst/fault", + postcopy_thread_create(mis, &mis->fault_thread, + MIGRATION_THREAD_DST_FAULT, postcopy_ram_fault_thread, QEMU_THREAD_JOINABLE); mis->have_fault_thread = true; @@ -1250,7 +1251,8 @@ int postcopy_ram_incoming_setup(MigrationIncomingState *mis) * This thread needs to be created after the temp pages because * it'll fetch RAM_CHANNEL_POSTCOPY PostcopyTmpPage immediately. */ - postcopy_thread_create(mis, &mis->postcopy_prio_thread, "mig/dst/preempt", + postcopy_thread_create(mis, &mis->postcopy_prio_thread, + MIGRATION_THREAD_DST_PREEMPT, postcopy_preempt_thread, QEMU_THREAD_JOINABLE); mis->preempt_thread_status = PREEMPT_THREAD_CREATED; } diff --git a/migration/savevm.c b/migration/savevm.c index 7e1e27182a..e796436979 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -2131,7 +2131,8 @@ static int loadvm_postcopy_handle_listen(MigrationIncomingState *mis) } mis->have_listen_thread = true; - postcopy_thread_create(mis, &mis->listen_thread, "mig/dst/listen", + postcopy_thread_create(mis, &mis->listen_thread, + MIGRATION_THREAD_DST_LISTEN, postcopy_ram_listen_thread, QEMU_THREAD_DETACHED); trace_loadvm_postcopy_handle_listen("return"); From patchwork Mon Sep 30 19:58:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 1991168 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=UJw+dllh; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XHX3s2bhPz1xtY for ; Tue, 1 Oct 2024 06:00:07 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1svMYZ-0004so-7F; Mon, 30 Sep 2024 15:59:43 -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 1svMXw-00044c-UM for qemu-devel@nongnu.org; Mon, 30 Sep 2024 15:59:05 -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 1svMXp-00040A-VN for qemu-devel@nongnu.org; Mon, 30 Sep 2024 15:59:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1727726337; 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=K0KTK9vQGWewvOY3cSlTOqfE9A0WK5IwRE3a47FyV7w=; b=UJw+dllhEVFGBo33uqVpGh4DeSDSccHAthwoYUeQFTQNMx11RazfTwqRpr90GiyCx3s6Hd CZrglxZ2fTlMzKcACdoaxUaqUfCuWp4uF2QOzkFwftqPVZFotJT+ELi5NBxbdUJpmeafG2 II6nNXT0u/0lqwLILgD+b5kvFYbVQvQ= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-250-EU_C1ZyGMQqdCaoV_loPCw-1; Mon, 30 Sep 2024 15:58:55 -0400 X-MC-Unique: EU_C1ZyGMQqdCaoV_loPCw-1 Received: by mail-qt1-f198.google.com with SMTP id d75a77b69052e-458657ce53aso81887981cf.0 for ; Mon, 30 Sep 2024 12:58:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727726332; x=1728331132; 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=K0KTK9vQGWewvOY3cSlTOqfE9A0WK5IwRE3a47FyV7w=; b=YtBJ9jH/6gRaoTbcpZAAha7epivDf6QiTPVH2JyJW1lbn2L+GIxvy7gNYIk1azbjut 2yyWRzPLcb3dq0eT+cTK7agZLMEnLNmSNM1oeUuVRFKajjyy35fo2/qFNtJ1MAG/TP5L talgmKFcDM9DfWtsHTv1nY5qxA3gl207Y0ewb2RaWaQpOalB2j95GAgceZI0KqwTd9gT B9pyncfdoKsR3e6+ENzWKqJ36uaoTSlaD0IIVhug4Tr8QThkTgMvmb05Cg6dgDC3l07D MfZsNcvOGseErCbJoYHU34OxQP+umocbSmtM80DBoQV7ucltgRcCV8IiuVngqquTky0F EVZA== X-Gm-Message-State: AOJu0YyYiXDNipCBAeiNmMNDGR8hfMfqbT75TKcSxCV5E+35wfQyG0wZ um6QWMeyGQ6hAoV75VQinPoFy1YsIl5NBsB6i5vejB/QwgayZjH+GBM5jLNBfulP8yPymGDO5ea Eodg4GRUVqfDW2HiIuDj/jx7B2NQtsXhj7VHCf4iXkbeLq87bD87+DIFfKxnzVH98NlavUzheig +thfzGE8CiHhu9TsR+Pw++/XNeyh9fWEvOuA== X-Received: by 2002:a05:622a:144c:b0:458:5fd0:964c with SMTP id d75a77b69052e-45c9f31955amr203760581cf.50.1727726332489; Mon, 30 Sep 2024 12:58:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH1ietuHwWWS0bbq2F/1PbII+kQ9eUVBriZz3SMMbWS/0Qod2lXONQ3ih789dvVEXAmsYO86Q== X-Received: by 2002:a05:622a:144c:b0:458:5fd0:964c with SMTP id d75a77b69052e-45c9f31955amr203760291cf.50.1727726332105; Mon, 30 Sep 2024 12:58:52 -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.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2024 12:58:50 -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 3/7] migration: Remove thread_id in migration_threads_add() Date: Mon, 30 Sep 2024 15:58:33 -0400 Message-ID: <20240930195837.825728-4-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 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org It always fetches the ID of the curren thread, so there's no point passing it over. Signed-off-by: Peter Xu --- migration/threadinfo.h | 2 +- migration/migration.c | 3 +-- migration/multifd.c | 2 +- migration/threadinfo.c | 5 +++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/migration/threadinfo.h b/migration/threadinfo.h index 2f356ff312..d0e4ab0aa3 100644 --- a/migration/threadinfo.h +++ b/migration/threadinfo.h @@ -21,5 +21,5 @@ struct MigrationThread { QLIST_ENTRY(MigrationThread) node; }; -MigrationThread *migration_threads_add(const char *name, int thread_id); +MigrationThread *migration_threads_add(const char *name); void migration_threads_remove(MigrationThread *info); diff --git a/migration/migration.c b/migration/migration.c index 813c45ad04..1ddcf54a70 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -3467,8 +3467,7 @@ static void *migration_thread(void *opaque) Error *local_err = NULL; int ret; - thread = migration_threads_add(MIGRATION_THREAD_SRC_MAIN, - qemu_get_thread_id()); + thread = migration_threads_add(MIGRATION_THREAD_SRC_MAIN); rcu_register_thread(); diff --git a/migration/multifd.c b/migration/multifd.c index 697fe86fdf..04db886c7e 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -575,7 +575,7 @@ static void *multifd_send_thread(void *opaque) int ret = 0; bool use_packets = multifd_use_packets(); - thread = migration_threads_add(p->name, qemu_get_thread_id()); + thread = migration_threads_add(p->name); trace_multifd_send_thread_start(p->id); rcu_register_thread(); diff --git a/migration/threadinfo.c b/migration/threadinfo.c index 262990dd75..8069413091 100644 --- a/migration/threadinfo.c +++ b/migration/threadinfo.c @@ -23,11 +23,12 @@ static void __attribute__((constructor)) migration_threads_init(void) qemu_mutex_init(&migration_threads_lock); } -MigrationThread *migration_threads_add(const char *name, int thread_id) +MigrationThread *migration_threads_add(const char *name) { MigrationThread *thread = g_new0(MigrationThread, 1); + thread->name = name; - thread->thread_id = thread_id; + thread->thread_id = qemu_get_thread_id(); WITH_QEMU_LOCK_GUARD(&migration_threads_lock) { QLIST_INSERT_HEAD(&migration_threads, thread, node); From patchwork Mon Sep 30 19:58:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 1991175 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=P+weIxhK; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XHX5y0jqMz1xtY for ; Tue, 1 Oct 2024 06:01:58 +1000 (AEST) 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 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= 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 X-MC-Unique: w37P3WYJP4ihE5VuugavLA-1 Received: by mail-qt1-f199.google.com with SMTP id d75a77b69052e-45b172569a2so57190211cf.0 for ; Mon, 30 Sep 2024 12:58:59 -0700 (PDT) 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) 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) 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 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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; }; -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 = opaque; - MigrationThread *thread = NULL; int64_t setup_start = qemu_clock_get_ms(QEMU_CLOCK_HOST); MigThrError thr_error; bool urgent = false; Error *local_err = NULL; int ret; - thread = migration_threads_add(MIGRATION_THREAD_SRC_MAIN); + migration_threads_add(MIGRATION_THREAD_SRC_MAIN); rcu_register_thread(); @@ -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; } 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 = opaque; - MigrationThread *thread = NULL; Error *local_err = NULL; int ret = 0; bool use_packets = multifd_use_packets(); - thread = migration_threads_add(p->name); + migration_threads_add(p->name); trace_multifd_send_thread_start(p->id); rcu_register_thread(); @@ -669,7 +668,7 @@ out: } rcu_unregister_thread(); - migration_threads_remove(thread); + migration_threads_remove(); trace_multifd_send_thread_end(p->id, p->packets_sent); 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_threads_init(void) qemu_mutex_init(&migration_threads_lock); } -MigrationThread *migration_threads_add(const char *name) +void migration_threads_add(const char *name) { MigrationThread *thread = g_new0(MigrationThread, 1); @@ -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; } -void migration_threads_remove(MigrationThread *thread) +void migration_threads_remove(void) { + int tid = qemu_get_thread_id(); + MigrationThread *thread; + QEMU_LOCK_GUARD(&migration_threads_lock); - if (thread) { + + QLIST_FOREACH(thread, &migration_threads, node) { + if (tid != thread->thread_id) { + continue; + } + QLIST_REMOVE(thread, node); g_free(thread); + return; } + + g_assert_not_reached(); } MigrationThreadInfoList *qmp_query_migrationthreads(Error **errp) From patchwork Mon Sep 30 19:58:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 1991173 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=NFUAXDLV; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XHX5J1Jjwz1xtY for ; Tue, 1 Oct 2024 06:01:24 +1000 (AEST) 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 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= 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 X-MC-Unique: eN7qVG16OPSKELawoOx-XA-1 Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-45832b277d9so79429461cf.1 for ; Mon, 30 Sep 2024 12:59:02 -0700 (PDT) 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) 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) 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 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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); +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 = NULL; /* Cache incoming device state */ Error *local_err = NULL; + migration_threads_add(MIGRATION_THREAD_DST_COLO); rcu_register_thread(); qemu_sem_init(&mis->colo_incoming_sem, 0); @@ -831,7 +832,7 @@ static void *colo_process_incoming_thread(void *opaque) if (get_colo_mode() != COLO_MODE_SECONDARY) { error_report("COLO mode must be COLO_MODE_SECONDARY"); - return NULL; + goto out_last; } /* 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; } failover_init_state(); @@ -923,7 +924,9 @@ out: qemu_sem_wait(&mis->colo_incoming_sem); qemu_sem_destroy(&mis->colo_incoming_sem); +out_last: rcu_unregister_thread(); + migration_threads_remove(); return NULL; } 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 = *(struct DirtyRateConfig *)arg; int ret; + + migration_threads_add(MIGRATION_THREAD_DIRTY_RATE); rcu_register_thread(); ret = dirtyrate_set_state(&CalculatingState, DIRTY_RATE_STATUS_UNSTARTED, DIRTY_RATE_STATUS_MEASURING); if (ret == -1) { error_report("change dirtyrate state failed."); - return NULL; + goto out; } calculate_dirtyrate(config); @@ -746,7 +748,10 @@ void *get_dirtyrate_thread(void *arg) error_report("change dirtyrate state failed."); } +out: rcu_unregister_thread(); + migration_threads_remove(); + return NULL; } 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; trace_source_return_path_thread_entry(); + migration_threads_add(MIGRATION_THREAD_SRC_RETURN); rcu_register_thread(); while (migration_is_setup_or_active()) { @@ -2463,8 +2464,9 @@ out: migration_rp_kick(ms); } - trace_source_return_path_thread_end(); rcu_unregister_thread(); + migration_threads_remove(); + trace_source_return_path_thread_end(); return NULL; } @@ -3602,6 +3604,8 @@ static void *bg_migration_thread(void *opaque) Error *local_err = NULL; int ret; + migration_threads_add(MIGRATION_THREAD_SNAPSHOT); + rcu_register_thread(); object_ref(OBJECT(s)); @@ -3726,6 +3730,7 @@ fail_setup: qemu_fclose(fb); object_unref(OBJECT(s)); rcu_unregister_thread(); + migration_threads_remove(); 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 = opaque; + 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); + migration_threads_remove(); + return NULL; } @@ -1122,6 +1126,7 @@ static void *multifd_recv_thread(void *opaque) int ret; trace_multifd_recv_thread_start(p->id); + migration_threads_add(MIGRATION_THREAD_DST_MULTIFD); rcu_register_thread(); while (true) { @@ -1209,6 +1214,7 @@ static void *multifd_recv_thread(void *opaque) } rcu_unregister_thread(); + migration_threads_remove(); trace_multifd_recv_thread_end(p->id, p->packets_recved); 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 = NULL; trace_postcopy_ram_fault_thread_entry(); + migration_threads_add(MIGRATION_THREAD_DST_FAULT); rcu_register_thread(); mis->last_rb = 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; } @@ -1713,7 +1717,7 @@ void *postcopy_preempt_thread(void *opaque) int ret; trace_postcopy_preempt_thread_entry(); - + migration_threads_add(MIGRATION_THREAD_DST_PREEMPT); rcu_register_thread(); 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); rcu_unregister_thread(); - + migration_threads_remove(); trace_postcopy_preempt_thread_exit(); 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 *opaque) int load_res; MigrationState *migr = migrate_get_current(); - object_ref(OBJECT(migr)); + trace_postcopy_ram_listen_thread_start(); + migration_threads_add(MIGRATION_THREAD_DST_LISTEN); + rcu_register_thread(); + 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(); - 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 *opaque) migration_incoming_state_destroy(); qemu_loadvm_state_cleanup(); - rcu_unregister_thread(); mis->have_listen_thread = false; postcopy_state_set(POSTCOPY_INCOMING_END); object_unref(OBJECT(migr)); + rcu_unregister_thread(); + migration_threads_remove(); 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" QemuMutex migration_threads_lock; static QLIST_HEAD(, MigrationThread) migration_threads; From patchwork Mon Sep 30 19:58:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 1991172 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=cl+EtGGn; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XHX4s0PJ3z1xtY for ; Tue, 1 Oct 2024 06:01:01 +1000 (AEST) 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 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= 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 X-MC-Unique: NstkanWxMuSETVVL5Fm1sw-1 Received: by mail-qt1-f199.google.com with SMTP id d75a77b69052e-45856a29545so99100651cf.3 for ; Mon, 30 Sep 2024 12:59:06 -0700 (PDT) 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) 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) 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 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 later. - * 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" QemuMutex migration_threads_lock; -static QLIST_HEAD(, MigrationThread) migration_threads; +static MigrationThreadInfoList *migration_threads; static void __attribute__((constructor)) migration_threads_init(void) { @@ -26,31 +28,40 @@ static void __attribute__((constructor)) migration_threads_init(void) void migration_threads_add(const char *name) { - MigrationThread *thread = g_new0(MigrationThread, 1); + MigrationThreadInfo *thread = g_new0(MigrationThreadInfo, 1); - thread->name = name; + thread->name = g_strdup(name); thread->thread_id = qemu_get_thread_id(); WITH_QEMU_LOCK_GUARD(&migration_threads_lock) { - QLIST_INSERT_HEAD(&migration_threads, thread, node); + QAPI_LIST_PREPEND(migration_threads, thread); } } void migration_threads_remove(void) { int tid = qemu_get_thread_id(); - MigrationThread *thread; + MigrationThreadInfoList *thread, *prev; QEMU_LOCK_GUARD(&migration_threads_lock); - QLIST_FOREACH(thread, &migration_threads, node) { - if (tid != thread->thread_id) { - continue; - } + prev = NULL; + thread = migration_threads; - QLIST_REMOVE(thread, node); - g_free(thread); - return; + while (thread) { + if (tid == thread->value->thread_id) { + if (!prev) { + migration_threads = thread->next; + } else { + prev->next = thread->next; + } + /* Terminate this single object to not free the rest */ + thread->next = NULL; + qapi_free_MigrationThreadInfoList(thread); + return; + } + prev = thread; + thread = thread->next; } g_assert_not_reached(); @@ -58,18 +69,7 @@ void migration_threads_remove(void) MigrationThreadInfoList *qmp_query_migrationthreads(Error **errp) { - MigrationThreadInfoList *head = NULL; - MigrationThreadInfoList **tail = &head; - MigrationThread *thread = NULL; - QEMU_LOCK_GUARD(&migration_threads_lock); - QLIST_FOREACH(thread, &migration_threads, node) { - MigrationThreadInfo *info = g_new0(MigrationThreadInfo, 1); - info->name = g_strdup(thread->name); - info->thread_id = thread->thread_id; - - QAPI_LIST_APPEND(tail, info); - } - return head; + return QAPI_CLONE(MigrationThreadInfoList, migration_threads); } From patchwork Mon Sep 30 19:58:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 1991174 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=gSqmtYi0; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XHX5J6v22z1xtc for ; Tue, 1 Oct 2024 06:01:24 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1svMYW-0004hR-Dm; Mon, 30 Sep 2024 15:59:40 -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 1svMY5-0004AN-MK for qemu-devel@nongnu.org; Mon, 30 Sep 2024 15:59:15 -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 1svMY3-00048s-Ql for qemu-devel@nongnu.org; Mon, 30 Sep 2024 15:59:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1727726351; 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=0IVNh8rkuBzemuMWp2WPFFN8HowcfvDmFRDqv1ADWW0=; b=gSqmtYi0SQ4mYMazWZhULR6Jl95z5t2VT3LBWu7nwkVeWMo3cgypwEGDcvi0owJoka+c7m xz4ySB6Mlmdl3sFo9TdMr6seSQxqX1w5aYZJt0SFjWWqPeg45o4GfT7TbW1RHtDOVgc9XQ IGMDC4lKjqmjr5mHc8iJEA3UogjzHc8= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-557-gC2mVLvGO8qfST2PGrVE-Q-1; Mon, 30 Sep 2024 15:59:09 -0400 X-MC-Unique: gC2mVLvGO8qfST2PGrVE-Q-1 Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-6cb3d5736a4so70540996d6.2 for ; Mon, 30 Sep 2024 12:59:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727726349; x=1728331149; 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=0IVNh8rkuBzemuMWp2WPFFN8HowcfvDmFRDqv1ADWW0=; b=VG1EmUdsIZto3oqFsB6AwO1Ev+RR5CkkMorjQHQ3FzIRQFhTBwJn8Cq4VwXYIHRYBC v+E6DTTtiUbklrNwQ0hD+jUrTQfYvq+pHYtYMqMqkGZOihkhhCd6DgkaOyOx3YKFzzOZ R3mQorJ4vAzGWdz6JXDd0H4Pzpan0LpTm+czwQZgLEpqoHYiwBYb9321iD7onSjSVlrj oHLkGzi9mtZZySdPeNZSUS+lpH3wQhuzjxTK80dcoaPiS4SQiOnqxSXihURj/Fc/OzQQ njALQFGBwpHjGsJ9Ytd2CxU2V+FRDFqxmH+DUPJ5+3POJK9ExluEISmt4lP5EkKqV+h1 Ts7Q== X-Gm-Message-State: AOJu0Yz0ueHEnx1BFapz7rSH3fM+nWEuVajgR9auicpcI04viQ87AjRs 8Jc1Bqg6b0DvHxsYV/5WUPOIiJkPlDbSHj3YsuXMiMpbFOjCowKYHKaUoWPjwstSQ7tmC4idTI9 BQr98KYV9yCV5FDdV0TPyGcA3HTbS6rflWOzmOPW6doXDR8XM/6Nkr7GnCUYgNuryTpLsQwbDS7 uco+ZrRwj8SGsSpck/vMTGSbH+PGWej3DrFw== X-Received: by 2002:a05:6214:328e:b0:6cb:2ad6:78ef with SMTP id 6a1803df08f44-6cb3b5c6732mr186119366d6.4.1727726348852; Mon, 30 Sep 2024 12:59:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFVzVpt6MhFCkdOiTIb7rTrFVkeUwAuegBYrxZJiBIgstHCiSjypMXUonr8bOYSr/TzXdewRw== X-Received: by 2002:a05:6214:328e:b0:6cb:2ad6:78ef with SMTP id 6a1803df08f44-6cb3b5c6732mr186119176d6.4.1727726348511; Mon, 30 Sep 2024 12:59:08 -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.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2024 12:59:05 -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 7/7] hmp: Add "info migrationthreads" Date: Mon, 30 Sep 2024 15:58:37 -0400 Message-ID: <20240930195837.825728-8-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 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org The QMP command was added in 671326201d ("migration: Introduce interface query-migrationthreads", v8.0). Add the HMP version of it. Cc: Markus Armbruster Cc: Dr. David Alan Gilbert Signed-off-by: Peter Xu --- include/monitor/hmp.h | 1 + migration/migration-hmp-cmds.c | 25 +++++++++++++++++++++++++ hmp-commands-info.hx | 13 +++++++++++++ 3 files changed, 39 insertions(+) diff --git a/include/monitor/hmp.h b/include/monitor/hmp.h index ae116d9804..e44a399e4a 100644 --- a/include/monitor/hmp.h +++ b/include/monitor/hmp.h @@ -31,6 +31,7 @@ void hmp_info_mice(Monitor *mon, const QDict *qdict); void hmp_info_migrate(Monitor *mon, const QDict *qdict); void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict); void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict); +void hmp_info_migrationthreads(Monitor *mon, const QDict *qdict); void hmp_info_cpus(Monitor *mon, const QDict *qdict); void hmp_info_vnc(Monitor *mon, const QDict *qdict); void hmp_info_spice(Monitor *mon, const QDict *qdict); diff --git a/migration/migration-hmp-cmds.c b/migration/migration-hmp-cmds.c index 20d1a6e219..63a6ea61f2 100644 --- a/migration/migration-hmp-cmds.c +++ b/migration/migration-hmp-cmds.c @@ -814,3 +814,28 @@ void loadvm_completion(ReadLineState *rs, int nb_args, const char *str) vm_completion(rs, str); } } + +void hmp_info_migrationthreads(Monitor *mon, const QDict *qdict) +{ + MigrationThreadInfoList *list; + MigrationThreadInfo *entry; + Error *err = NULL; + + list = qmp_query_migrationthreads(&err); + + if (!list) { + monitor_printf(mon, "No migration threads found\n"); + return; + } + + monitor_printf(mon, "%-16s%s\n", "TID", "Thread Name"); + while (list) { + entry = list->value; + monitor_printf(mon, "%-16" PRId64 "%s\n", + entry->thread_id, entry->name); + list = list->next; + } + + qapi_free_MigrationThreadInfoList(list); + hmp_handle_error(mon, err); +} diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx index c59cd6637b..a8dc55dbd2 100644 --- a/hmp-commands-info.hx +++ b/hmp-commands-info.hx @@ -512,6 +512,19 @@ SRST Show current migration parameters. ERST + { + .name = "migrationthreads", + .args_type = "", + .params = "", + .help = "show migration threads information", + .cmd = hmp_info_migrationthreads, + }, + +SRST + ``info migrationthreads`` + Show migration threads information. +ERST + { .name = "balloon", .args_type = "",