[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v2 10/17] migration/multifd: Convert multifd_send()::next_cha
|
From: |
Fabiano Rosas |
|
Subject: |
Re: [PATCH v2 10/17] migration/multifd: Convert multifd_send()::next_channel to atomic |
|
Date: |
Fri, 30 Aug 2024 15:13:36 -0300 |
"Maciej S. Szmigiero" <mail@maciej.szmigiero.name> writes:
> From: "Maciej S. Szmigiero" <maciej.szmigiero@oracle.com>
>
> This is necessary for multifd_send() to be able to be called
> from multiple threads.
>
> Signed-off-by: Maciej S. Szmigiero <maciej.szmigiero@oracle.com>
> ---
> migration/multifd.c | 24 ++++++++++++++++++------
> 1 file changed, 18 insertions(+), 6 deletions(-)
>
> diff --git a/migration/multifd.c b/migration/multifd.c
> index d5a8e5a9c9b5..b25789dde0b3 100644
> --- a/migration/multifd.c
> +++ b/migration/multifd.c
> @@ -343,26 +343,38 @@ bool multifd_send(MultiFDSendData **send_data)
> return false;
> }
>
> - /* We wait here, until at least one channel is ready */
> - qemu_sem_wait(&multifd_send_state->channels_ready);
> -
> /*
> * next_channel can remain from a previous migration that was
> * using more channels, so ensure it doesn't overflow if the
> * limit is lower now.
> */
> - next_channel %= migrate_multifd_channels();
> - for (i = next_channel;; i = (i + 1) % migrate_multifd_channels()) {
> + i = qatomic_load_acquire(&next_channel);
> + if (unlikely(i >= migrate_multifd_channels())) {
> + qatomic_cmpxchg(&next_channel, i, 0);
> + }
Do we still need this? It seems not, because the mod down below would
already truncate to a value less than the number of channels. We don't
need it to start at 0 always, the channels are equivalent.
> +
> + /* We wait here, until at least one channel is ready */
> + qemu_sem_wait(&multifd_send_state->channels_ready);
> +
> + while (true) {
> + int i_next;
> +
> if (multifd_send_should_exit()) {
> return false;
> }
> +
> + i = qatomic_load_acquire(&next_channel);
> + i_next = (i + 1) % migrate_multifd_channels();
> + if (qatomic_cmpxchg(&next_channel, i, i_next) != i) {
> + continue;
> + }
Say channel 'i' is the only one that's idle. What's stopping the other
thread(s) to race at this point and loop around to the same index?
> +
> p = &multifd_send_state->params[i];
> /*
> * Lockless read to p->pending_job is safe, because only multifd
> * sender thread can clear it.
> */
> if (qatomic_read(&p->pending_job) == false) {
With the cmpxchg your other patch adds here, then the race I mentioned
above should be harmless. But we'd need to bring that code into this
patch.
> - next_channel = (i + 1) % migrate_multifd_channels();
> break;
> }
> }
- Re: [PATCH v2 02/17] migration/ram: Add load start trace event, (continued)
- [PATCH v2 03/17] migration/multifd: Zero p->flags before starting filling a packet, Maciej S. Szmigiero, 2024/08/27
- [PATCH v2 06/17] migration: Add save_live_complete_precopy_{begin, end} handlers, Maciej S. Szmigiero, 2024/08/27
- [PATCH v2 08/17] migration: Add load_finish handler and associated functions, Maciej S. Szmigiero, 2024/08/27
- [PATCH v2 07/17] migration: Add qemu_loadvm_load_state_buffer() and its handler, Maciej S. Szmigiero, 2024/08/27
- [PATCH v2 05/17] thread-pool: Implement non-AIO (generic) pool support, Maciej S. Szmigiero, 2024/08/27
- [PATCH v2 09/17] migration/multifd: Device state transfer support - receive side, Maciej S. Szmigiero, 2024/08/27
- [PATCH v2 10/17] migration/multifd: Convert multifd_send()::next_channel to atomic, Maciej S. Szmigiero, 2024/08/27
- Re: [PATCH v2 10/17] migration/multifd: Convert multifd_send()::next_channel to atomic,
Fabiano Rosas <=
- [PATCH v2 11/17] migration/multifd: Add an explicit MultiFDSendData destructor, Maciej S. Szmigiero, 2024/08/27
- [PATCH v2 13/17] migration/multifd: Add migration_has_device_state_support(), Maciej S. Szmigiero, 2024/08/27
- [PATCH v2 16/17] vfio/migration: Add x-migration-multifd-transfer VFIO property, Maciej S. Szmigiero, 2024/08/27
- [PATCH v2 14/17] migration: Add save_live_complete_precopy_thread handler, Maciej S. Szmigiero, 2024/08/27
- [PATCH v2 17/17] vfio/migration: Multifd device state transfer support - send side, Maciej S. Szmigiero, 2024/08/27
- [PATCH v2 12/17] migration/multifd: Device state transfer support - send side, Maciej S. Szmigiero, 2024/08/27