From: Peter Xu <peterx@redhat.com>
To: qemu-devel@nongnu.org
Cc: Prasad Pandit <ppandit@redhat.com>,
Julia Suvorova <jusual@redhat.com>,
Markus Armbruster <armbru@redhat.com>,
peterx@redhat.com, Fabiano Rosas <farosas@suse.de>,
Juraj Marcin <jmarcin@redhat.com>,
"Dr . David Alan Gilbert" <dave@treblig.org>
Subject: [PATCH 6/7] migration: Remove MigrationThread and threadinfo.h
Date: Mon, 30 Sep 2024 15:58:36 -0400 [thread overview]
Message-ID: <20240930195837.825728-7-peterx@redhat.com> (raw)
In-Reply-To: <20240930195837.825728-1-peterx@redhat.com>
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 <peterx@redhat.com>
---
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 <jiangjiacheng@huawei.com>
- *
- * 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);
}
--
2.45.0
next prev parent reply other threads:[~2024-09-30 20:00 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-30 19:58 [PATCH 0/7] migration: query-migrationthreads enhancements and cleanups Peter Xu
2024-09-30 19:58 ` [PATCH 1/7] migration: Unify names of migration src main thread Peter Xu
2024-09-30 19:58 ` [PATCH 2/7] migration: Put thread names together with macros Peter Xu
2024-09-30 19:58 ` [PATCH 3/7] migration: Remove thread_id in migration_threads_add() Peter Xu
2024-09-30 19:58 ` [PATCH 4/7] migration: Simplify migration-threads API Peter Xu
2024-09-30 19:58 ` [PATCH 5/7] migration: Add all threads with QMP query-migrationthreads Peter Xu
2024-09-30 19:58 ` Peter Xu [this message]
2024-09-30 19:58 ` [PATCH 7/7] hmp: Add "info migrationthreads" Peter Xu
2024-09-30 23:43 ` Dr. David Alan Gilbert
2024-10-01 5:46 ` [PATCH 0/7] migration: query-migrationthreads enhancements and cleanups Markus Armbruster
2024-10-01 14:25 ` Daniel P. Berrangé
2024-10-01 15:06 ` Peter Xu
2024-10-02 5:58 ` Markus Armbruster
2024-10-10 19:46 ` Peter Xu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240930195837.825728-7-peterx@redhat.com \
--to=peterx@redhat.com \
--cc=armbru@redhat.com \
--cc=dave@treblig.org \
--cc=farosas@suse.de \
--cc=jmarcin@redhat.com \
--cc=jusual@redhat.com \
--cc=ppandit@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).