Skip to contentSkip to conversation

migration: support query migration thread information

RFC PATCH In review Jiang Jiacheng via 2 participants 5 messages Feb 3, 2023 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

v2 cover migration: support query migration thread information

We need get more migration thread information to support migration pin, especially thread name and its pid. Add an qmp interface to query migration threads information.

v2 of:
https://lists.nongnu.org/archive/html/qemu-devel/2023-01/msg04618.html

diff to v2:
* remove the event that report thread name
* modify the qmp interface, now it doesn't need thread name and return with all the migration threads information we saved

Jiang Jiacheng (2):
migration: Introduce interface query-migrationthreads
migration: save/delete migration thread info

 migration/meson.build  |  1 +
 migration/migration.c  |  5 ++++
 migration/multifd.c    |  5 ++++
 migration/threadinfo.c | 54 ++++++++++++++++++++++++++++++++++++++++++
 migration/threadinfo.h | 28 ++++++++++++++++++++++
 qapi/migration.json    | 29 +++++++++++++++++++++++
 6 files changed, 122 insertions(+)
 create mode 100644 migration/threadinfo.c
 create mode 100644 migration/threadinfo.h
Signature · 1 line
2.33.0
#1 lore raw

PATCH v2 1/2 migration: Introduce interface query-migrationthreads

Introduce interface query-migrationthreads. The interface is used to query information about migration threads and returns with migration thread's name and its id.
Introduce threadinfo.c to manage threads with migration.

---
 migration/meson.build  |  1 +
 migration/threadinfo.c | 54 ++++++++++++++++++++++++++++++++++++++++++
 migration/threadinfo.h | 28 ++++++++++++++++++++++
 qapi/migration.json    | 29 +++++++++++++++++++++++
 4 files changed, 112 insertions(+)
 create mode 100644 migration/threadinfo.c
 create mode 100644 migration/threadinfo.h
migration/meson.build +1 -0
index 690487cf1a..ed7d27f11a 100644
@@ -25,6 +25,7 @@ softmmu_ss.add(files(
   'savevm.c',
   'socket.c',
   'tls.c',
+  'threadinfo.c',
 ), gnutls)
 
 softmmu_ss.add(when: rdma, if_true: files('rdma.c'))
migration/threadinfo.c new file +54 -0

54 lines not on this page · raw message

migration/threadinfo.h new file +28 -0
new file mode 100644
index 0000000000..ebe86a2699
@@ -0,0 +1,28 @@
+/*
+ *  Migration Threads info
+ *
+ *  Copyright (c) 2022 HUAWEI TECHNOLOGIES CO., LTD.
+ *
+ *  Authors:
+ *  Jiang Jiacheng <[email protected]>
+ *
+ *  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 "qemu/queue.h"
+#include "qemu/osdep.h"
+#include "qapi/error.h"
+#include "qapi/qapi-commands-migration.h"
+
+typedef struct MigrationThread MigrationThread;
+
+struct MigrationThread {
+    char *name; /* the name of migration thread */
+    int thread_id; /* ID of the underlying host thread */
+    QLIST_ENTRY(MigrationThread) node;
+};
+
+MigrationThread *MigrationThreadAdd(const char *name, int thread_id);
+
+void MigrationThreadDel(MigrationThread* info);
qapi/migration.json +29 -0
index 88ecf86ac8..c84fa10e86 100644
@@ -1958,6 +1958,35 @@
 { 'command': 'query-vcpu-dirty-limit',
   'returns': [ 'DirtyLimitInfo' ] }
 
+##
+# @MigrationThreadInfo:
+#
+# Information about migrationthreads
+#
+# @name: the name of migration thread
+#
+# @thread-id: ID of the underlying host thread
+#
+# Since: 7.2
+##
+{ 'struct': 'MigrationThreadInfo',
+  'data': {'name': 'str',
+           'thread-id': 'int'} }
+
+##
+# @query-migrationthreads:
+#
+# Returns information of migration threads
+#
+# data: migration thread name
+#
+# returns: information about migration threads
+#
+# Since: 7.2
+##
+{ 'command': 'query-migrationthreads',
+  'returns': ['MigrationThreadInfo'] }
+
 ##
 # @snapshot-save:
 #
Signature · 1 line
2.33.0
Reviewed-by on v2 1/2
#2 lore raw

Re: [PATCH V2 1/2] migration: Introduce interface query-migrationthreads

Quoted 6 lines · Jiang Jiacheng

Introduce interface query-migrationthreads. The interface is used to query information about migration threads and returns with migration thread's name and its id.
Introduce threadinfo.c to manage threads with migration.

I will fix this by hand.

Quoted 1 line

+MigrationThread* MigrationThreadAdd(const char *name, int thread_id)

* on the left instead of the right.

migration/threadinfo.c line 21

Quoted 4 lines
migration/threadinfo.c new file +4 -0
+{
+    MigrationThread *thread = NULL;
+
+    thread = g_new0(MigrationThread, 1);

This is too much.

      MigrationThread *thread = g_new0(MigrationThread, 1);

If you initialize a variable, don't do a NULL and just in the next line the right value.

Quoted 1 line

+ thread->name = (char*)name;

Why not doing it properly and call it just const char * on the header?

migration/threadinfo.c line 33

Quoted 11 lines
migration/threadinfo.c new file +11 -0
+    thread->thread_id = thread_id;
+
+    QLIST_INSERT_HEAD(&migration_threads, thread, node);
+
+    return thread;
+}
+
+void MigrationThreadDel(MigrationThread* thread)
+{
+    if (thread) {
+        QLIST_REMOVE(thread, node);

Spaces for indentation

migration/threadinfo.c line 34

Quoted 1 line
migration/threadinfo.c new file +1 -0
+	    g_free(thread);

Tabs + spaces.

migration/threadinfo.c line 38

Quoted 4 lines
migration/threadinfo.c new file +4 -0
+    }
+}
+
+MigrationThreadInfoList* qmp_query_migrationthreads(Error **errp)

* on the worong side.

migration/threadinfo.c line 46

Quoted 8 lines
migration/threadinfo.c new file +8 -0
+{
+    MigrationThreadInfoList *head = NULL;
+    MigrationThreadInfoList **tail = &head;
+    MigrationThread *thread = NULL;
+    MigrationThreadInfo *info = NULL;
+
+    QLIST_FOREACH(thread, &migration_threads, node) {
+        info = g_new0(MigrationThreadInfo, 1);

MigrationThreadInfo *info = g_new0(MigrationThreadInfo, 1);

Quoted 50 lines
migration/threadinfo.c new file +8 -0
+        info->name = g_strdup(thread->name);
+        info->thread_id = thread->thread_id;
+
+        QAPI_LIST_APPEND(tail, info);
+    }
+
+    return head;
+}
migration/threadinfo.h new file +28 -0
new file mode 100644
index 0000000000..ebe86a2699
@@ -0,0 +1,28 @@
+/*
+ *  Migration Threads info
+ *
+ *  Copyright (c) 2022 HUAWEI TECHNOLOGIES CO., LTD.
+ *
+ *  Authors:
+ *  Jiang Jiacheng <[email protected]>
+ *
+ *  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 "qemu/queue.h"
+#include "qemu/osdep.h"
+#include "qapi/error.h"
+#include "qapi/qapi-commands-migration.h"
+
+typedef struct MigrationThread MigrationThread;
+
+struct MigrationThread {
+    char *name; /* the name of migration thread */
+    int thread_id; /* ID of the underlying host thread */
+    QLIST_ENTRY(MigrationThread) node;
+};
+
+MigrationThread *MigrationThreadAdd(const char *name, int thread_id);
+
+void MigrationThreadDel(MigrationThread* info);
qapi/migration.json +0 -0
index 88ecf86ac8..c84fa10e86 100644
@@ -1958,6 +1958,35 @@
 { 'command': 'query-vcpu-dirty-limit',
   'returns': [ 'DirtyLimitInfo' ] }
 

qapi/migration.json line 1970

Quoted 10 lines
qapi/migration.json +10 -0
+##
+# @MigrationThreadInfo:
+#
+# Information about migrationthreads
+#
+# @name: the name of migration thread
+#
+# @thread-id: ID of the underlying host thread
+#
+# Since: 7.2
            8.0

Same on the next one.

Quoted 12 lines
qapi/migration.json +12 -0
+##
+{ 'struct': 'MigrationThreadInfo',
+  'data': {'name': 'str',
+           'thread-id': 'int'} }
+
+##
+# @query-migrationthreads:
+#
+# Returns information of migration threads
+#
+# data: migration thread name
+#

qapi/migration.json line 1992

Quoted 10 lines
qapi/migration.json +7 -0
+# returns: information about migration threads
+#
+# Since: 7.2
+##
+{ 'command': 'query-migrationthreads',
+  'returns': ['MigrationThreadInfo'] }
+
 ##
 # @snapshot-save:
 #

Later, Juan.

#3 lore raw

PATCH v2 2/2 migration: save/delete migration thread info

In reply to Jiang Jiacheng via

To support query migration thread infomation, save and delete thread(live_migration and multifdsend) information at thread creation and finish.

---
 migration/migration.c | 5 +++++
 migration/multifd.c   | 5 +++++
 2 files changed, 10 insertions(+)
migration/migration.c +5 -0
index 52b5d39244..cf895b1a3d 100644
@@ -57,6 +57,7 @@
 #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"
@@ -3951,10 +3952,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;
 
+    thread = MigrationThreadAdd("live_migration", qemu_get_thread_id());
+
     rcu_register_thread();
 
     object_ref(OBJECT(s));
@@ -4031,6 +4035,7 @@ static void *migration_thread(void *opaque)
     migration_iteration_finish(s);
     object_unref(OBJECT(s));
     rcu_unregister_thread();
+    MigrationThreadDel(thread);
     return NULL;
 }
 
migration/multifd.c +5 -0
index 000ca4d4ec..c350547562 100644
@@ -24,6 +24,7 @@
 #include "qemu-file.h"
 #include "trace.h"
 #include "multifd.h"
+#include "threadinfo.h"
 
 #include "qemu/yank.h"
 #include "io/channel-socket.h"
@@ -646,10 +647,13 @@ int multifd_send_sync_main(QEMUFile *f)
 static void *multifd_send_thread(void *opaque)
 {
     MultiFDSendParams *p = opaque;
+    MigrationThread *thread = NULL;
     Error *local_err = NULL;
     int ret = 0;
     bool use_zero_copy_send = migrate_use_zero_copy_send();
 
+    thread = MigrationThreadAdd(p->name, qemu_get_thread_id());
+
     trace_multifd_send_thread_start(p->id);
     rcu_register_thread();
 
@@ -759,6 +763,7 @@ out:
     qemu_mutex_unlock(&p->mutex);
 
     rcu_unregister_thread();
+    MigrationThreadDel(thread);
     trace_multifd_send_thread_end(p->id, p->num_packets, p->total_normal_pages);
 
     return NULL;
Signature · 1 line
2.33.0