[PATCH 04/13] migration/rdma: Allow qemu_rdma_wait_comp_channel work with thread

Peter Xu posted 13 patches 3 weeks, 1 day ago
Maintainers: Alex Williamson <alex@shazbot.org>, "Cédric Le Goater" <clg@redhat.com>, "Daniel P. Berrangé" <berrange@redhat.com>, Hailiang Zhang <zhanghailiang@xfusion.com>, Peter Xu <peterx@redhat.com>, Fabiano Rosas <farosas@suse.de>, Li Zhijian <lizhijian@fujitsu.com>
[PATCH 04/13] migration/rdma: Allow qemu_rdma_wait_comp_channel work with thread
Posted by Peter Xu 3 weeks, 1 day ago
It's almost there, except that currently it relies on a global flag showing
that it's in incoming migration.

Change it to detect coroutine instead.

Then we achieved two things in one shot:

  - Drop migration_started_on_destination, which is not needed anymore, and
  - It starts to work in a thread when loadvm using RDMA

Signed-off-by: Peter Xu <peterx@redhat.com>
---
 migration/rdma.c | 15 +--------------
 1 file changed, 1 insertion(+), 14 deletions(-)

diff --git a/migration/rdma.c b/migration/rdma.c
index e6837184c8..13dd391c14 100644
--- a/migration/rdma.c
+++ b/migration/rdma.c
@@ -357,13 +357,6 @@ typedef struct RDMAContext {
     /* Index of the next RAMBlock received during block registration */
     unsigned int    next_src_index;
 
-    /*
-     * Migration on *destination* started.
-     * Then use coroutine yield function.
-     * Source runs in a thread, so we don't care.
-     */
-    int migration_started_on_destination;
-
     int total_registrations;
     int total_writes;
 
@@ -1352,12 +1345,7 @@ static int qemu_rdma_wait_comp_channel(RDMAContext *rdma,
 {
     struct rdma_cm_event *cm_event;
 
-    /*
-     * Coroutine doesn't start until migration_fd_process_incoming()
-     * so don't yield unless we know we're running inside of a coroutine.
-     */
-    if (rdma->migration_started_on_destination &&
-        migration_incoming_get_current()->state == MIGRATION_STATUS_ACTIVE) {
+    if (qemu_in_coroutine()) {
         yield_until_fd_readable(comp_channel->fd);
     } else {
         /* This is the source side, we're in a separate thread
@@ -3884,7 +3872,6 @@ static void rdma_accept_incoming_migration(void *opaque)
         return;
     }
 
-    rdma->migration_started_on_destination = 1;
     migration_fd_process_incoming(f);
 }
 
-- 
2.50.1
Re: [PATCH 04/13] migration/rdma: Allow qemu_rdma_wait_comp_channel work with thread
Posted by Zhijian Li (Fujitsu) 1 week, 4 days ago

On 23/10/2025 03:26, Peter Xu wrote:
> It's almost there, except that currently it relies on a global flag showing
> that it's in incoming migration.
> 
> Change it to detect coroutine instead.
> 
> Then we achieved two things in one shot:
> 
>    - Drop migration_started_on_destination, which is not needed anymore, and
>    - It starts to work in a thread when loadvm using RDMA
> 
> Signed-off-by: Peter Xu <peterx@redhat.com>


Reviewed-by: Li Zhijian <lizhijian@fujitsu.com>



> ---
>   migration/rdma.c | 15 +--------------
>   1 file changed, 1 insertion(+), 14 deletions(-)
> 
> diff --git a/migration/rdma.c b/migration/rdma.c
> index e6837184c8..13dd391c14 100644
> --- a/migration/rdma.c
> +++ b/migration/rdma.c
> @@ -357,13 +357,6 @@ typedef struct RDMAContext {
>       /* Index of the next RAMBlock received during block registration */
>       unsigned int    next_src_index;
>   
> -    /*
> -     * Migration on *destination* started.
> -     * Then use coroutine yield function.
> -     * Source runs in a thread, so we don't care.
> -     */
> -    int migration_started_on_destination;
> -
>       int total_registrations;
>       int total_writes;
>   
> @@ -1352,12 +1345,7 @@ static int qemu_rdma_wait_comp_channel(RDMAContext *rdma,
>   {
>       struct rdma_cm_event *cm_event;
>   
> -    /*
> -     * Coroutine doesn't start until migration_fd_process_incoming()
> -     * so don't yield unless we know we're running inside of a coroutine.
> -     */
> -    if (rdma->migration_started_on_destination &&
> -        migration_incoming_get_current()->state == MIGRATION_STATUS_ACTIVE) {
> +    if (qemu_in_coroutine()) {
>           yield_until_fd_readable(comp_channel->fd);
>       } else {
>           /* This is the source side, we're in a separate thread
> @@ -3884,7 +3872,6 @@ static void rdma_accept_incoming_migration(void *opaque)
>           return;
>       }
>   
> -    rdma->migration_started_on_destination = 1;
>       migration_fd_process_incoming(f);
>   }
>   
Re: [PATCH 04/13] migration/rdma: Allow qemu_rdma_wait_comp_channel work with thread
Posted by Vladimir Sementsov-Ogievskiy 3 weeks, 1 day ago
On 22.10.25 22:26, Peter Xu wrote:
> It's almost there, except that currently it relies on a global flag showing
> that it's in incoming migration.
> 
> Change it to detect coroutine instead.
> 
> Then we achieved two things in one shot:
> 
>    - Drop migration_started_on_destination, which is not needed anymore, and
>    - It starts to work in a thread when loadvm using RDMA
> 
> Signed-off-by: Peter Xu<peterx@redhat.com>


Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>

-- 
Best regards,
Vladimir