All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH V2 0/2] migration: support query migration thread information
@ 2023-02-03  7:35 Jiang Jiacheng via
  2023-02-03  7:35 ` [PATCH V2 1/2] migration: Introduce interface query-migrationthreads Jiang Jiacheng via
  2023-02-03  7:35 ` [PATCH V2 2/2] migration: save/delete migration thread info Jiang Jiacheng via
  0 siblings, 2 replies; 5+ messages in thread
From: Jiang Jiacheng via @ 2023-02-03  7:35 UTC (permalink / raw)
  To: qemu-devel
  Cc: berrange, quintela, dgilbert, yubihong, xiexiangyou, zhengchuan,
	linyilu, jiangjiacheng

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

-- 
2.33.0



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH V2 1/2] migration: Introduce interface query-migrationthreads
  2023-02-03  7:35 [RFC PATCH V2 0/2] migration: support query migration thread information Jiang Jiacheng via
@ 2023-02-03  7:35 ` Jiang Jiacheng via
  2023-02-03 19:47   ` Juan Quintela
  2023-02-03  7:35 ` [PATCH V2 2/2] migration: save/delete migration thread info Jiang Jiacheng via
  1 sibling, 1 reply; 5+ messages in thread
From: Jiang Jiacheng via @ 2023-02-03  7:35 UTC (permalink / raw)
  To: qemu-devel
  Cc: berrange, quintela, dgilbert, yubihong, xiexiangyou, zhengchuan,
	linyilu, jiangjiacheng

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.

Signed-off-by: Jiang Jiacheng <jiangjiacheng@huawei.com>
---
 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

diff --git a/migration/meson.build b/migration/meson.build
index 690487cf1a..ed7d27f11a 100644
--- a/migration/meson.build
+++ b/migration/meson.build
@@ -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'))
diff --git a/migration/threadinfo.c b/migration/threadinfo.c
new file mode 100644
index 0000000000..cfb27be77b
--- /dev/null
+++ b/migration/threadinfo.c
@@ -0,0 +1,54 @@
+/*
+ *  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 "threadinfo.h"
+
+static QLIST_HEAD(, MigrationThread) migration_threads;
+
+MigrationThread* MigrationThreadAdd(const char *name, int thread_id)
+{
+    MigrationThread *thread = NULL;
+
+    thread = g_new0(MigrationThread, 1);
+    thread->name = (char*)name;
+    thread->thread_id = thread_id;
+
+    QLIST_INSERT_HEAD(&migration_threads, thread, node);
+
+    return thread;
+}
+
+void MigrationThreadDel(MigrationThread* thread)
+{
+    if (thread) {
+        QLIST_REMOVE(thread, node);
+	    g_free(thread);
+    }
+}
+
+MigrationThreadInfoList* qmp_query_migrationthreads(Error **errp)
+{
+    MigrationThreadInfoList *head = NULL;
+    MigrationThreadInfoList **tail = &head;
+    MigrationThread *thread = NULL;
+    MigrationThreadInfo *info = NULL;
+
+    QLIST_FOREACH(thread, &migration_threads, node) {
+        info = g_new0(MigrationThreadInfo, 1);
+        info->name = g_strdup(thread->name);
+        info->thread_id = thread->thread_id;
+
+        QAPI_LIST_APPEND(tail, info);
+    }
+
+    return head;
+}
diff --git a/migration/threadinfo.h b/migration/threadinfo.h
new file mode 100644
index 0000000000..ebe86a2699
--- /dev/null
+++ b/migration/threadinfo.h
@@ -0,0 +1,28 @@
+/*
+ *  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 "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);
diff --git a/qapi/migration.json b/qapi/migration.json
index 88ecf86ac8..c84fa10e86 100644
--- a/qapi/migration.json
+++ b/qapi/migration.json
@@ -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:
 #
-- 
2.33.0



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH V2 2/2] migration: save/delete migration thread info
  2023-02-03  7:35 [RFC PATCH V2 0/2] migration: support query migration thread information Jiang Jiacheng via
  2023-02-03  7:35 ` [PATCH V2 1/2] migration: Introduce interface query-migrationthreads Jiang Jiacheng via
@ 2023-02-03  7:35 ` Jiang Jiacheng via
  2023-02-03 19:56   ` Juan Quintela
  1 sibling, 1 reply; 5+ messages in thread
From: Jiang Jiacheng via @ 2023-02-03  7:35 UTC (permalink / raw)
  To: qemu-devel
  Cc: berrange, quintela, dgilbert, yubihong, xiexiangyou, zhengchuan,
	linyilu, jiangjiacheng

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

Signed-off-by: Jiang Jiacheng <jiangjiacheng@huawei.com>
---
 migration/migration.c | 5 +++++
 migration/multifd.c   | 5 +++++
 2 files changed, 10 insertions(+)

diff --git a/migration/migration.c b/migration/migration.c
index 52b5d39244..cf895b1a3d 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -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;
 }
 
diff --git a/migration/multifd.c b/migration/multifd.c
index 000ca4d4ec..c350547562 100644
--- a/migration/multifd.c
+++ b/migration/multifd.c
@@ -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;
-- 
2.33.0



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH V2 1/2] migration: Introduce interface query-migrationthreads
  2023-02-03  7:35 ` [PATCH V2 1/2] migration: Introduce interface query-migrationthreads Jiang Jiacheng via
@ 2023-02-03 19:47   ` Juan Quintela
  0 siblings, 0 replies; 5+ messages in thread
From: Juan Quintela @ 2023-02-03 19:47 UTC (permalink / raw)
  To: Jiang Jiacheng
  Cc: qemu-devel, berrange, dgilbert, yubihong, xiexiangyou, zhengchuan,
	linyilu

Jiang Jiacheng <jiangjiacheng@huawei.com> wrote:
> 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.
>
> Signed-off-by: Jiang Jiacheng <jiangjiacheng@huawei.com>

Reviewed-by: Juan Quintela <quintela@redhat.com>

I will fix this by hand.

> +MigrationThread* MigrationThreadAdd(const char *name, int thread_id)
* on the left instead of the right.

> +{
> +    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.


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

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

> +    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

> +	    g_free(thread);

Tabs + spaces.

> +    }
> +}
> +
> +MigrationThreadInfoList* qmp_query_migrationthreads(Error **errp)

* on the worong side.

> +{
> +    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);

> +        info->name = g_strdup(thread->name);
> +        info->thread_id = thread->thread_id;
> +
> +        QAPI_LIST_APPEND(tail, info);
> +    }
> +
> +    return head;
> +}
> diff --git a/migration/threadinfo.h b/migration/threadinfo.h
> new file mode 100644
> index 0000000000..ebe86a2699
> --- /dev/null
> +++ b/migration/threadinfo.h
> @@ -0,0 +1,28 @@
> +/*
> + *  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 "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);
> diff --git a/qapi/migration.json b/qapi/migration.json
> index 88ecf86ac8..c84fa10e86 100644
> --- a/qapi/migration.json
> +++ b/qapi/migration.json
> @@ -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

            8.0

Same on the next one.

> +##
> +{ '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:
>  #

Later, Juan.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH V2 2/2] migration: save/delete migration thread info
  2023-02-03  7:35 ` [PATCH V2 2/2] migration: save/delete migration thread info Jiang Jiacheng via
@ 2023-02-03 19:56   ` Juan Quintela
  0 siblings, 0 replies; 5+ messages in thread
From: Juan Quintela @ 2023-02-03 19:56 UTC (permalink / raw)
  To: Jiang Jiacheng
  Cc: qemu-devel, berrange, dgilbert, yubihong, xiexiangyou, zhengchuan,
	linyilu

Jiang Jiacheng <jiangjiacheng@huawei.com> wrote:
> To support query migration thread infomation, save and delete
> thread(live_migration and multifdsend) information at thread
> creation and finish.
>
> Signed-off-by: Jiang Jiacheng <jiangjiacheng@huawei.com>

Reviewed-by: Juan Quintela <quintela@redhat.com>



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-02-03 19:57 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-03  7:35 [RFC PATCH V2 0/2] migration: support query migration thread information Jiang Jiacheng via
2023-02-03  7:35 ` [PATCH V2 1/2] migration: Introduce interface query-migrationthreads Jiang Jiacheng via
2023-02-03 19:47   ` Juan Quintela
2023-02-03  7:35 ` [PATCH V2 2/2] migration: save/delete migration thread info Jiang Jiacheng via
2023-02-03 19:56   ` Juan Quintela

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.