Skip to contentSkip to conversation

migration: support query migration thread information

RFC PATCH Superseded Jiang Jiacheng via 2 participants 15 messages Jan 20, 2023 – Jan 31, 2023 Arm/Amlogic Meson SoC support

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

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 thread information by its name and report thread name when migration thread is started.

Jiang Jiacheng (3):
migration: report migration thread name to libvirt
migration: implement query migration threadinfo by name
migration: save/delete migration thread info

 migration/meson.build  |  1 +
 migration/migration.c  |  7 +++++
 migration/multifd.c    |  9 +++++-
 migration/threadinfo.c | 70 ++++++++++++++++++++++++++++++++++++++++++
 migration/threadinfo.h | 30 ++++++++++++++++++
 qapi/migration.json    | 42 +++++++++++++++++++++++++
 6 files changed, 158 insertions(+), 1 deletion(-)
 create mode 100644 migration/threadinfo.c
 create mode 100644 migration/threadinfo.h
Signature · 1 line
2.33.0
#1 lore raw

PATCH 1/3 migration: report migration thread name to libvirt

Report migration thread name to libvirt in order to support query migration thread infomation by its name.

---
 migration/migration.c |  3 +++
 migration/multifd.c   |  5 ++++-
 qapi/migration.json   | 12 ++++++++++++
 3 files changed, 19 insertions(+), 1 deletion(-)
migration/migration.c +3 -0
index 52b5d39244..b4ce458bb9 100644
@@ -3955,6 +3955,9 @@ static void *migration_thread(void *opaque)
     MigThrError thr_error;
     bool urgent = false;
 
+    /* report migration thread name to libvirt */
+    qapi_event_send_migration_name("live_migration");
+
     rcu_register_thread();
 
     object_ref(OBJECT(s));
migration/multifd.c +4 -1
index 000ca4d4ec..6e834c7111 100644
@@ -17,6 +17,7 @@
 #include "exec/ramblock.h"
 #include "qemu/error-report.h"
 #include "qapi/error.h"
+#include "qapi/qapi-events-migration.h"
 #include "ram.h"
 #include "migration.h"
 #include "socket.h"
@@ -24,7 +25,6 @@
 #include "qemu-file.h"
 #include "trace.h"
 #include "multifd.h"
-
 #include "qemu/yank.h"
 #include "io/channel-socket.h"
 #include "yank_functions.h"
@@ -650,6 +650,9 @@ static void *multifd_send_thread(void *opaque)
     int ret = 0;
     bool use_zero_copy_send = migrate_use_zero_copy_send();
 
+    /* report multifd thread name to libvirt */
+    qapi_event_send_migration_name(p->name);
+
     trace_multifd_send_thread_start(p->id);
     rcu_register_thread();
 
qapi/migration.json +12 -0
index 88ecf86ac8..b0cf366ac0 100644
@@ -1286,6 +1286,18 @@
 { 'event': 'MIGRATION_PASS',
   'data': { 'pass': 'int' } }
 
+##
+# @MIGRATION_NAME:
+#
+# Emitted when migration thread appear
+#
+# @name: name of migration thread
+#
+# Since: 7.2
+##
+{ 'event': 'MIGRATION_NAME',
+  'data': { 'name': 'str' } }
+
 ##
 # @COLOMessage:
 #
Signature · 1 line
2.33.0
#2 lore raw

Re: [PATCH 1/3] migration: report migration thread name to libvirt

Quoted 15 lines · Jiang Jiacheng

Report migration thread name to libvirt in order to support query migration thread infomation by its name.

---
 migration/migration.c |  3 +++
 migration/multifd.c   |  5 ++++-
 qapi/migration.json   | 12 ++++++++++++
 3 files changed, 19 insertions(+), 1 deletion(-)
migration/migration.c +0 -0
index 52b5d39244..b4ce458bb9 100644

migration/migration.c static void *migration_thread(void *opaque) · line 3963

Quoted 9 lines
migration/migration.c +3 -0
@@ -3955,6 +3955,9 @@ static void *migration_thread(void *opaque)
     MigThrError thr_error;
     bool urgent = false;
 
+    /* report migration thread name to libvirt */
+    qapi_event_send_migration_name("live_migration");
+
     rcu_register_thread();
 
     object_ref(OBJECT(s));

I am not sure about this.
This is not an event, in my point of view.

What is the problem adding it to info migrate or similar? Looks more logical to me.

Later, Juan.

#3 lore raw

Re: [PATCH 1/3] migration: report migration thread name to libvirt

Quoted 24 lines · Juan Quintela
Quoted 23 lines · Jiang Jiacheng

Report migration thread name to libvirt in order to support query migration thread infomation by its name.

---
 migration/migration.c |  3 +++
 migration/multifd.c   |  5 ++++-
 qapi/migration.json   | 12 ++++++++++++
 3 files changed, 19 insertions(+), 1 deletion(-)
migration/migration.c +3 -0
index 52b5d39244..b4ce458bb9 100644
@@ -3955,6 +3955,9 @@ static void *migration_thread(void *opaque)
     MigThrError thr_error;
     bool urgent = false;
 
+    /* report migration thread name to libvirt */
+    qapi_event_send_migration_name("live_migration");
+
     rcu_register_thread();
 
Quoted 7 lines

migration/migration.c static void *migration_thread(void *opaque) · line 3963

Quoted 1 line
migration/migration.c +0 -0
     object_ref(OBJECT(s));

I am not sure about this.
This is not an event, in my point of view.

What is the problem adding it to info migrate or similar? Looks more logical to me.

I want to implement an interface for libvirt to proactively query information about migration threads. And this event is used to notify libvirt that the thread has been created and to provide the thread name for subsequent operations of querying specified thread's information.

Thanks, Jiang Jiacheng

Quoted 3 lines

Later, Juan.

#4 lore raw

PATCH 2/3 migration: implement query migration threadinfo by name

In reply to Jiang Jiacheng via

Introduce interface query-migrationthreads. The interface is use with the migration thread name reported by qemu and returns with migration thread name and its pid.
Introduce threadinfo.c to manage threads with migration.

---
 migration/meson.build  |  1 +
 migration/threadinfo.c | 70 ++++++++++++++++++++++++++++++++++++++++++
 migration/threadinfo.h | 30 ++++++++++++++++++
 qapi/migration.json    | 30 ++++++++++++++++++
 4 files changed, 131 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 +70 -0

70 lines not on this page · raw message

migration/threadinfo.h new file +30 -0
new file mode 100644
index 0000000000..f62a6ff261
@@ -0,0 +1,30 @@
+/*
+ *  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);
+
+MigrationThread* MigrationThreadQuery(const char* name);
qapi/migration.json +30 -0
index b0cf366ac0..e93c3e560a 100644
@@ -1970,6 +1970,36 @@
 { '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 threadInfo about the thread specified by name
+#
+# data: migration thread name
+#
+# returns: information about the specified thread
+#
+# Since: 7.2
+##
+{ 'command': 'query-migrationthreads',
+  'data': { 'name': 'str' },
+  'returns': 'MigrationThreadInfo' }
+
 ##
 # @snapshot-save:
 #
Signature · 1 line
2.33.0
#5 lore raw

Re: [PATCH 2/3] migration: implement query migration threadinfo by name

Quoted 6 lines · Jiang Jiacheng

Introduce interface query-migrationthreads. The interface is use with the migration thread name reported by qemu and returns with migration thread name and its pid.
Introduce threadinfo.c to manage threads with migration.

I like this query interface better than the way you expose the thread name in the 1st place.

But once that we are here, why don't we just "tweak" abit the interface:

Quoted 12 lines
qapi/migration.json +4 -0
index b0cf366ac0..e93c3e560a 100644
@@ -1970,6 +1970,36 @@
 { 'command': 'query-vcpu-dirty-limit',
   'returns': [ 'DirtyLimitInfo' ] }
 
+##
+# @MigrationThreadInfo:
+#
+# Information about migrationthreads

qapi/migration.json line 1986

Quoted 10 lines
qapi/migration.json +10 -0
+#
+# @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'} }

1st, it is an int enough for all architectures? I know that for linux and friends it is, but not sure about windows and other weird systems.

qapi/migration.json line 1988

Quoted 2 lines
qapi/migration.json +2 -0
+##
+# @query-migrationthreads:

What about renaming this to:

@query-migrationthread (I removed the last 's')

because it returns the info of a single thread.

Quoted 6 lines
qapi/migration.json +6 -0
+#
+# Returns threadInfo about the thread specified by name
+#
+# data: migration thread name
+#
+# returns: information about the specified thread

qapi/migration.json line 2005

Quoted 10 lines
qapi/migration.json +7 -0
+#
+# Since: 7.2
+##
+{ 'command': 'query-migrationthreads',
+  'data': { 'name': 'str' },
+  'returns': 'MigrationThreadInfo' }
+
 ##
 # @snapshot-save:
 #

And leaves the @query-migrationthreads name for something in the spirit of

qapi/migration.json

Quoted 2 lines
qapi/migration.json +2 -0
+{ 'command': 'query-migrationthreads',
+  'returns': ['str'] }

That returns all the migration threads names.

Or perhaps even

qapi/migration.json

Quoted 2 lines
qapi/migration.json +2 -0
+{ 'command': 'query-migrationthreads',
+  'returns': ['MigrationThreadInfo'] }

And call it a day?

Later, Juan.

#6 lore raw

Re: [PATCH 2/3] migration: implement query migration threadinfo by name

Quoted 10 lines · Juan Quintela
Quoted 6 lines · Jiang Jiacheng

Introduce interface query-migrationthreads. The interface is use with the migration thread name reported by qemu and returns with migration thread name and its pid.
Introduce threadinfo.c to manage threads with migration.

I like this query interface better than the way you expose the thread name in the 1st place.

The event in patch1 is used to pass the thread name since libvirt doesn't know the name of the migration thread but the interface below need its name.
I think the event can be dropped if we store the thread name in libvirt(if the migration thread name is fixed in qemu) or using the 'query-migrationthreads' you mentioned below.

Quoted 20 lines

But once that we are here, why don't we just "tweak" abit the interface:

Quoted 17 lines
qapi/migration.json +9 -0
index b0cf366ac0..e93c3e560a 100644
@@ -1970,6 +1970,36 @@
 { '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
+#
Quoted 9 lines

qapi/migration.json line 1986

Quoted 5 lines
qapi/migration.json +5 -0
+# Since: 7.2
+##
+{ 'struct': 'MigrationThreadInfo',
+  'data': {'name': 'str',
+           'thread-id': 'int'} }

1st, it is an int enough for all architectures? I know that for linux and friends it is, but not sure about windows and other weird systems.

It is only enough for migration pin which I want to implement. But I think this struct can be easily expand if we need other information about migration thread.

Quoted 31 lines

qapi/migration.json line 1988

Quoted 2 lines
qapi/migration.json +2 -0
+##
+# @query-migrationthreads:

What about renaming this to:

@query-migrationthread (I removed the last 's')

because it returns the info of a single thread.

Quoted 6 lines
qapi/migration.json +6 -0
+#
+# Returns threadInfo about the thread specified by name
+#
+# data: migration thread name
+#
+# returns: information about the specified thread

qapi/migration.json line 2005

Quoted 10 lines
qapi/migration.json +7 -0
+#
+# Since: 7.2
+##
+{ 'command': 'query-migrationthreads',
+  'data': { 'name': 'str' },
+  'returns': 'MigrationThreadInfo' }
+
 ##
 # @snapshot-save:
 #

And leaves the @query-migrationthreads name for something in the spirit of

qapi/migration.json

Quoted 2 lines
qapi/migration.json +2 -0
+{ 'command': 'query-migrationthreads',
+  'returns': ['str'] }
Quoted 8 lines

That returns all the migration threads names.

Or perhaps even

qapi/migration.json

Quoted 2 lines
qapi/migration.json +2 -0
+{ 'command': 'query-migrationthreads',
+  'returns': ['MigrationThreadInfo'] }

And call it a day?

I think it's the best. If in this way, should we keep the interface to query specified thread?

Thanks, Jiang Jiacheng

Quoted 3 lines

Later, Juan.

#7 lore raw

Re: [PATCH 2/3] migration: implement query migration threadinfo by name

Quoted 12 lines · Jiang Jiacheng
Quoted 10 lines · Juan Quintela
Quoted 6 lines · Jiang Jiacheng

Introduce interface query-migrationthreads. The interface is use with the migration thread name reported by qemu and returns with migration thread name and its pid.
Introduce threadinfo.c to manage threads with migration.

I like this query interface better than the way you expose the thread name in the 1st place.

Quoted 6 lines

The event in patch1 is used to pass the thread name since libvirt doesn't know the name of the migration thread but the interface below need its name.
I think the event can be dropped if we store the thread name in libvirt(if the migration thread name is fixed in qemu) or using the 'query-migrationthreads' you mentioned below.

I preffer the query migrationthreads, thanks.

Quoted 31 lines
Quoted 21 lines

But once that we are here, why don't we just "tweak" abit the interface:

Quoted 17 lines
qapi/migration.json +9 -0
index b0cf366ac0..e93c3e560a 100644
@@ -1970,6 +1970,36 @@
 { '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
+#
Quoted 9 lines

qapi/migration.json line 1986

Quoted 5 lines
qapi/migration.json +5 -0
+# Since: 7.2
+##
+{ 'struct': 'MigrationThreadInfo',
+  'data': {'name': 'str',
+           'thread-id': 'int'} }

1st, it is an int enough for all architectures? I know that for linux and friends it is, but not sure about windows and other weird systems.

Quoted 3 lines

It is only enough for migration pin which I want to implement. But I think this struct can be easily expand if we need other information about migration thread.

I mean that pthread_t (what you are passing here) is an int on linux. Not sure on other OS's.

Quoted 35 lines
Quoted 35 lines

qapi/migration.json line 1988

Quoted 2 lines
qapi/migration.json +2 -0
+##
+# @query-migrationthreads:

What about renaming this to:

@query-migrationthread (I removed the last 's')

because it returns the info of a single thread.

Quoted 6 lines
qapi/migration.json +6 -0
+#
+# Returns threadInfo about the thread specified by name
+#
+# data: migration thread name
+#
+# returns: information about the specified thread

qapi/migration.json line 2005

Quoted 10 lines
qapi/migration.json +7 -0
+#
+# Since: 7.2
+##
+{ 'command': 'query-migrationthreads',
+  'data': { 'name': 'str' },
+  'returns': 'MigrationThreadInfo' }
+
 ##
 # @snapshot-save:
 #

And leaves the @query-migrationthreads name for something in the spirit of

qapi/migration.json

Quoted 2 lines
qapi/migration.json +2 -0
+{ 'command': 'query-migrationthreads',
+  'returns': ['str'] }

That returns all the migration threads names.

Or perhaps even

Quoted 7 lines
Quoted 4 lines

qapi/migration.json

Quoted 2 lines
qapi/migration.json +2 -0
+{ 'command': 'query-migrationthreads',
+  'returns': ['MigrationThreadInfo'] }

And call it a day?

I think it's the best. If in this way, should we keep the interface to query specified thread?

I wouldn't do it, but it is up to you.

My (little) understanding of what you want to do is that you want all the threads, so I see no reason to have a query for a single one.

Later, Juan.

#8 lore raw

Re: [PATCH 2/3] migration: implement query migration threadinfo by name

Quoted 52 lines · Juan Quintela
Quoted 12 lines · Jiang Jiacheng
Quoted 10 lines · Juan Quintela
Quoted 6 lines · Jiang Jiacheng

Introduce interface query-migrationthreads. The interface is use with the migration thread name reported by qemu and returns with migration thread name and its pid.
Introduce threadinfo.c to manage threads with migration.

I like this query interface better than the way you expose the thread name in the 1st place.

Quoted 6 lines

The event in patch1 is used to pass the thread name since libvirt doesn't know the name of the migration thread but the interface below need its name.
I think the event can be dropped if we store the thread name in libvirt(if the migration thread name is fixed in qemu) or using the 'query-migrationthreads' you mentioned below.

I preffer the query migrationthreads, thanks.

Quoted 31 lines
Quoted 30 lines

But once that we are here, why don't we just "tweak" abit the interface:

Quoted 12 lines
qapi/migration.json +4 -0
index b0cf366ac0..e93c3e560a 100644
@@ -1970,6 +1970,36 @@
 { 'command': 'query-vcpu-dirty-limit',
   'returns': [ 'DirtyLimitInfo' ] }
 
+##
+# @MigrationThreadInfo:
+#
+# Information about migrationthreads

qapi/migration.json line 1986

Quoted 10 lines
qapi/migration.json +10 -0
+#
+# @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'} }

1st, it is an int enough for all architectures? I know that for linux and friends it is, but not sure about windows and other weird systems.

Quoted 7 lines
Quoted 3 lines

It is only enough for migration pin which I want to implement. But I think this struct can be easily expand if we need other information about migration thread.

I mean that pthread_t (what you are passing here) is an int on linux. Not sure on other OS's.

I'm sorry about my misunderstanding. I use 'int' for thread-id just like cpu or iothread's thread-id, and it is get from 'qemu_get_thread_id'. So I think it is enough.

Quoted 40 lines
Quoted 40 lines
Quoted 39 lines

qapi/migration.json line 1988

Quoted 2 lines
qapi/migration.json +2 -0
+##
+# @query-migrationthreads:

What about renaming this to:

@query-migrationthread (I removed the last 's')

because it returns the info of a single thread.

Quoted 6 lines
qapi/migration.json +6 -0
+#
+# Returns threadInfo about the thread specified by name
+#
+# data: migration thread name
+#
+# returns: information about the specified thread

qapi/migration.json line 2005

Quoted 10 lines
qapi/migration.json +7 -0
+#
+# Since: 7.2
+##
+{ 'command': 'query-migrationthreads',
+  'data': { 'name': 'str' },
+  'returns': 'MigrationThreadInfo' }
+
 ##
 # @snapshot-save:
 #

And leaves the @query-migrationthreads name for something in the spirit of

qapi/migration.json

Quoted 2 lines
qapi/migration.json +2 -0
+{ 'command': 'query-migrationthreads',
+  'returns': ['str'] }

That returns all the migration threads names.

Or perhaps even

qapi/migration.json

Quoted 2 lines
qapi/migration.json +2 -0
+{ 'command': 'query-migrationthreads',
+  'returns': ['MigrationThreadInfo'] }

And call it a day?

Quoted 8 lines
Quoted 2 lines

I think it's the best. If in this way, should we keep the interface to query specified thread?

I wouldn't do it, but it is up to you.

My (little) understanding of what you want to do is that you want all the threads, so I see no reason to have a query for a single one.

Thanks for your suggestion. As you said, I need all the threads info, and the specified thread info can be got easily from the new interface. The old interface seems to be redundant indeed.

Thanks, Jiang Jiacheng

Quoted 2 lines

Later, Juan.

#9 lore raw

Re: [PATCH 2/3] migration: implement query migration threadinfo by name

Quoted 13 lines · Jiang Jiacheng
Quoted 12 lines · Juan Quintela
Quoted 10 lines · Jiang Jiacheng
Quoted 4 lines · Juan Quintela

1st, it is an int enough for all architectures? I know that for linux and friends it is, but not sure about windows and other weird systems.

It is only enough for migration pin which I want to implement. But I think this struct can be easily expand if we need other information about migration thread.

Quoted 7 lines
Quoted 3 lines

I mean that pthread_t (what you are passing here) is an int on linux. Not sure on other OS's.

I'm sorry about my misunderstanding. I use 'int' for thread-id just like cpu or iothread's thread-id, and it is get from 'qemu_get_thread_id'. So I think it is enough.

Ok, fine enough. Thanks.

Later, Juan.

#10 lore raw

PATCH 3/3 migration: save/delete migration thread info

In reply to Jiang Jiacheng via

To support query migration thread infomation, save and delete thread information at thread creation and end.

---
 migration/migration.c | 4 ++++
 migration/multifd.c   | 4 ++++
 2 files changed, 8 insertions(+)
migration/migration.c +4 -0
index b4ce458bb9..957205e693 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,12 @@ 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());
     /* report migration thread name to libvirt */
     qapi_event_send_migration_name("live_migration");
 
@@ -4034,6 +4037,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 +4 -0
index 6e834c7111..fca06284de 100644
@@ -25,6 +25,7 @@
 #include "qemu-file.h"
 #include "trace.h"
 #include "multifd.h"
+#include "threadinfo.h"
 #include "qemu/yank.h"
 #include "io/channel-socket.h"
 #include "yank_functions.h"
@@ -646,10 +647,12 @@ 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());
     /* report multifd thread name to libvirt */
     qapi_event_send_migration_name(p->name);
 
@@ -762,6 +765,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
#11 lore raw

Re: [PATCH 3/3] migration: save/delete migration thread info

Quoted 4 lines · Jiang Jiacheng

To support query migration thread infomation, save and delete thread information at thread creation and end.

Don't disagree with this, but if we create this on the sending side, why this is not needed for the multifd_recv_threads?

Later, Juan.

Quoted 73 lines
---
 migration/migration.c | 4 ++++
 migration/multifd.c   | 4 ++++
 2 files changed, 8 insertions(+)
migration/migration.c +4 -0
index b4ce458bb9..957205e693 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,12 @@ 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());
     /* report migration thread name to libvirt */
     qapi_event_send_migration_name("live_migration");
 
@@ -4034,6 +4037,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 +4 -0
index 6e834c7111..fca06284de 100644
@@ -25,6 +25,7 @@
 #include "qemu-file.h"
 #include "trace.h"
 #include "multifd.h"
+#include "threadinfo.h"
 #include "qemu/yank.h"
 #include "io/channel-socket.h"
 #include "yank_functions.h"
@@ -646,10 +647,12 @@ 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());
     /* report multifd thread name to libvirt */
     qapi_event_send_migration_name(p->name);
 
@@ -762,6 +765,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;
#12 lore raw

Re: [PATCH 3/3] migration: save/delete migration thread info

Quoted 9 lines · Juan Quintela
Quoted 4 lines · Jiang Jiacheng

To support query migration thread infomation, save and delete thread information at thread creation and end.

Don't disagree with this, but if we create this on the sending side, why this is not needed for the multifd_recv_threads?

I only add several threads which i'm interested in into the list till now, whose information will be used for setting cpu affinity for migration thread.
For consistency, we can add other threads to the list, but those information won't be used so far.

Thanks, Jiang Jiacheng

Quoted 76 lines

Later, Juan.

Quoted 73 lines
---
 migration/migration.c | 4 ++++
 migration/multifd.c   | 4 ++++
 2 files changed, 8 insertions(+)
migration/migration.c +4 -0
index b4ce458bb9..957205e693 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,12 @@ 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());
     /* report migration thread name to libvirt */
     qapi_event_send_migration_name("live_migration");
 
@@ -4034,6 +4037,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 +4 -0
index 6e834c7111..fca06284de 100644
@@ -25,6 +25,7 @@
 #include "qemu-file.h"
 #include "trace.h"
 #include "multifd.h"
+#include "threadinfo.h"
 #include "qemu/yank.h"
 #include "io/channel-socket.h"
 #include "yank_functions.h"
@@ -646,10 +647,12 @@ 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());
     /* report multifd thread name to libvirt */
     qapi_event_send_migration_name(p->name);
 
@@ -762,6 +765,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;
#13 lore raw

Re: [PATCH 3/3] migration: save/delete migration thread info

Quoted 11 lines · Jiang Jiacheng
Quoted 9 lines · Juan Quintela
Quoted 4 lines · Jiang Jiacheng

To support query migration thread infomation, save and delete thread information at thread creation and end.

Don't disagree with this, but if we create this on the sending side, why this is not needed for the multifd_recv_threads?

Quoted 5 lines

I only add several threads which i'm interested in into the list till now, whose information will be used for setting cpu affinity for migration thread.
For consistency, we can add other threads to the list, but those information won't be used so far.

It is just curiosity, why do you want to set cpu affinity on the source but not on destination?

Later, Juan.

#14 lore raw

Re: [PATCH 3/3] migration: save/delete migration thread info

Quoted 12 lines · Juan Quintela
Quoted 11 lines · Jiang Jiacheng
Quoted 9 lines · Juan Quintela
Quoted 4 lines · Jiang Jiacheng

To support query migration thread infomation, save and delete thread information at thread creation and end.

Don't disagree with this, but if we create this on the sending side, why this is not needed for the multifd_recv_threads?

Quoted 9 lines
Quoted 5 lines

I only add several threads which i'm interested in into the list till now, whose information will be used for setting cpu affinity for migration thread.
For consistency, we can add other threads to the list, but those information won't be used so far.

It is just curiosity, why do you want to set cpu affinity on the source but not on destination?

Mainly considering the application scenarios. To improve the migration performance, I want to set cpu affinity for migration thread when migration a VM whose service threads preempt most of the CPU resources. So the source side can benefit more from cpu affinity.
And on the destination side, the pressure is lighter (generally), setting cpu affinity may not be so much useful as source side.

Thanks, Jiang Jiacheng

Quoted 3 lines

Later, Juan.