Skip to content

Commit c9b35a6

Browse files
lrq-maxbonzini
authored andcommitted
KVM: eventfd: Use synchronize_srcu_expedited() on shutdown
When hot-unplug a device which has many queues, and guest CPU will has huge jitter, and unplugging is very slow. It turns out synchronize_srcu() in irqfd_shutdown() caused the guest jitter and unplugging latency, so replace synchronize_srcu() with synchronize_srcu_expedited(), to accelerate the unplugging, and reduce the guest OS jitter, this accelerates the VM reboot too. Signed-off-by: Li RongQing <lirongqing@baidu.com> Message-ID: <20240711121130.38917-1-lirongqing@baidu.com> [Call it just once in irqfd_resampler_shutdown. - Paolo] Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 238d3d6 commit c9b35a6

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

virt/kvm/eventfd.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,18 +97,19 @@ irqfd_resampler_shutdown(struct kvm_kernel_irqfd *irqfd)
9797
mutex_lock(&kvm->irqfds.resampler_lock);
9898

9999
list_del_rcu(&irqfd->resampler_link);
100-
synchronize_srcu(&kvm->irq_srcu);
101100

102101
if (list_empty(&resampler->list)) {
103102
list_del_rcu(&resampler->link);
104103
kvm_unregister_irq_ack_notifier(kvm, &resampler->notifier);
105104
/*
106-
* synchronize_srcu(&kvm->irq_srcu) already called
105+
* synchronize_srcu_expedited(&kvm->irq_srcu) already called
107106
* in kvm_unregister_irq_ack_notifier().
108107
*/
109108
kvm_set_irq(kvm, KVM_IRQFD_RESAMPLE_IRQ_SOURCE_ID,
110109
resampler->notifier.gsi, 0, false);
111110
kfree(resampler);
111+
} else {
112+
synchronize_srcu_expedited(&kvm->irq_srcu);
112113
}
113114

114115
mutex_unlock(&kvm->irqfds.resampler_lock);
@@ -126,7 +127,7 @@ irqfd_shutdown(struct work_struct *work)
126127
u64 cnt;
127128

128129
/* Make sure irqfd has been initialized in assign path. */
129-
synchronize_srcu(&kvm->irq_srcu);
130+
synchronize_srcu_expedited(&kvm->irq_srcu);
130131

131132
/*
132133
* Synchronize with the wait-queue and unhook ourselves to prevent
@@ -384,7 +385,7 @@ kvm_irqfd_assign(struct kvm *kvm, struct kvm_irqfd *args)
384385
}
385386

386387
list_add_rcu(&irqfd->resampler_link, &irqfd->resampler->list);
387-
synchronize_srcu(&kvm->irq_srcu);
388+
synchronize_srcu_expedited(&kvm->irq_srcu);
388389

389390
mutex_unlock(&kvm->irqfds.resampler_lock);
390391
}
@@ -523,7 +524,7 @@ void kvm_unregister_irq_ack_notifier(struct kvm *kvm,
523524
mutex_lock(&kvm->irq_lock);
524525
hlist_del_init_rcu(&kian->link);
525526
mutex_unlock(&kvm->irq_lock);
526-
synchronize_srcu(&kvm->irq_srcu);
527+
synchronize_srcu_expedited(&kvm->irq_srcu);
527528
kvm_arch_post_irq_ack_notifier_list_update(kvm);
528529
}
529530

@@ -608,7 +609,7 @@ kvm_irqfd_release(struct kvm *kvm)
608609

609610
/*
610611
* Take note of a change in irq routing.
611-
* Caller must invoke synchronize_srcu(&kvm->irq_srcu) afterwards.
612+
* Caller must invoke synchronize_srcu_expedited(&kvm->irq_srcu) afterwards.
612613
*/
613614
void kvm_irq_routing_update(struct kvm *kvm)
614615
{

0 commit comments

Comments
 (0)