Bin Guo <[email protected]> writes:

> multifd_send_sync_main() is called once per RAM synchronization round
> during live migration.  It iterates over all multifd channels twice
> (signal loop + wait loop), calling migrate_multifd_channels()
> independently in each loop header.
>
> Cache migrate_multifd_channels() in a local thread_count variable at
> function entry, matching the pattern already used in
> multifd_send_setup() and multifd_recv_setup().  This eliminates 2
> redundant config lookups per sync call.
>
> Signed-off-by: Bin Guo <[email protected]>
> ---
>  migration/multifd.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/migration/multifd.c b/migration/multifd.c
> index cc2fa90204..bc8aacd660 100644
> --- a/migration/multifd.c
> +++ b/migration/multifd.c
> @@ -611,13 +611,15 @@ static int multifd_zero_copy_flush(QIOChannel *c)
>  int multifd_send_sync_main(MultiFDSyncReq req)
>  {
>      int i;
> +    int thread_count;
>      bool flush_zero_copy;
>  
>      assert(req != MULTIFD_SYNC_NONE);
>  
> +    thread_count = migrate_multifd_channels();
>      flush_zero_copy = migrate_zero_copy_send();
>  
> -    for (i = 0; i < migrate_multifd_channels(); i++) {
> +    for (i = 0; i < thread_count; i++) {
>          MultiFDSendParams *p = &multifd_send_state->params[i];
>  
>          if (multifd_send_should_exit()) {
> @@ -634,7 +636,7 @@ int multifd_send_sync_main(MultiFDSyncReq req)
>          qatomic_set(&p->pending_sync, req);
>          qemu_sem_post(&p->sem);
>      }
> -    for (i = 0; i < migrate_multifd_channels(); i++) {
> +    for (i = 0; i < thread_count; i++) {
>          MultiFDSendParams *p = &multifd_send_state->params[i];
>  
>          if (multifd_send_should_exit()) {

Reviewed-by: Fabiano Rosas <[email protected]>

Reply via email to