diff options
author | Christian Borntraeger <borntraeger@de.ibm.com> | 2014-01-16 07:44:20 -0500 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2014-05-05 10:29:11 -0400 |
commit | 719d93cd5f5c5c8775b7a38192069e8e1d1ac46e (patch) | |
tree | e6d7703b4b69acf92db962fbe96d9f7c380484c8 /virt/kvm/irqchip.c | |
parent | 57b5981cd38cbca3554c5e663b2361d9adea70c2 (diff) |
kvm/irqchip: Speed up KVM_SET_GSI_ROUTING
When starting lots of dataplane devices the bootup takes very long on
Christian's s390 with irqfd patches. With larger setups he is even
able to trigger some timeouts in some components. Turns out that the
KVM_SET_GSI_ROUTING ioctl takes very long (strace claims up to 0.1 sec)
when having multiple CPUs. This is caused by the synchronize_rcu and
the HZ=100 of s390. By changing the code to use a private srcu we can
speed things up. This patch reduces the boot time till mounting root
from 8 to 2 seconds on my s390 guest with 100 disks.
Uses of hlist_for_each_entry_rcu, hlist_add_head_rcu, hlist_del_init_rcu
are fine because they do not have lockdep checks (hlist_for_each_entry_rcu
uses rcu_dereference_raw rather than rcu_dereference, and write-sides
do not do rcu lockdep at all).
Note that we're hardly relying on the "sleepable" part of srcu. We just
want SRCU's faster detection of grace periods.
Testing was done by Andrew Theurer using netperf tests STREAM, MAERTS
and RR. The difference between results "before" and "after" the patch
has mean -0.2% and standard deviation 0.6%. Using a paired t-test on the
data points says that there is a 2.5% probability that the patch is the
cause of the performance difference (rather than a random fluctuation).
(Restricting the t-test to RR, which is the most likely to be affected,
changes the numbers to respectively -0.3% mean, 0.7% stdev, and 8%
probability that the numbers actually say something about the patch.
The probability increases mostly because there are fewer data points).
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Michael S. Tsirkin <mst@redhat.com>
Tested-by: Christian Borntraeger <borntraeger@de.ibm.com> # s390
Reviewed-by: Christian Borntraeger <borntraeger@de.ibm.com>
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'virt/kvm/irqchip.c')
-rw-r--r-- | virt/kvm/irqchip.c | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/virt/kvm/irqchip.c b/virt/kvm/irqchip.c index 20dc9e4a8f6c..b43c275775cd 100644 --- a/virt/kvm/irqchip.c +++ b/virt/kvm/irqchip.c | |||
@@ -26,6 +26,7 @@ | |||
26 | 26 | ||
27 | #include <linux/kvm_host.h> | 27 | #include <linux/kvm_host.h> |
28 | #include <linux/slab.h> | 28 | #include <linux/slab.h> |
29 | #include <linux/srcu.h> | ||
29 | #include <linux/export.h> | 30 | #include <linux/export.h> |
30 | #include <trace/events/kvm.h> | 31 | #include <trace/events/kvm.h> |
31 | #include "irq.h" | 32 | #include "irq.h" |
@@ -33,19 +34,19 @@ | |||
33 | bool kvm_irq_has_notifier(struct kvm *kvm, unsigned irqchip, unsigned pin) | 34 | bool kvm_irq_has_notifier(struct kvm *kvm, unsigned irqchip, unsigned pin) |
34 | { | 35 | { |
35 | struct kvm_irq_ack_notifier *kian; | 36 | struct kvm_irq_ack_notifier *kian; |
36 | int gsi; | 37 | int gsi, idx; |
37 | 38 | ||
38 | rcu_read_lock(); | 39 | idx = srcu_read_lock(&kvm->irq_srcu); |
39 | gsi = rcu_dereference(kvm->irq_routing)->chip[irqchip][pin]; | 40 | gsi = srcu_dereference(kvm->irq_routing, &kvm->irq_srcu)->chip[irqchip][pin]; |
40 | if (gsi != -1) | 41 | if (gsi != -1) |
41 | hlist_for_each_entry_rcu(kian, &kvm->irq_ack_notifier_list, | 42 | hlist_for_each_entry_rcu(kian, &kvm->irq_ack_notifier_list, |
42 | link) | 43 | link) |
43 | if (kian->gsi == gsi) { | 44 | if (kian->gsi == gsi) { |
44 | rcu_read_unlock(); | 45 | srcu_read_unlock(&kvm->irq_srcu, idx); |
45 | return true; | 46 | return true; |
46 | } | 47 | } |
47 | 48 | ||
48 | rcu_read_unlock(); | 49 | srcu_read_unlock(&kvm->irq_srcu, idx); |
49 | 50 | ||
50 | return false; | 51 | return false; |
51 | } | 52 | } |
@@ -54,18 +55,18 @@ EXPORT_SYMBOL_GPL(kvm_irq_has_notifier); | |||
54 | void kvm_notify_acked_irq(struct kvm *kvm, unsigned irqchip, unsigned pin) | 55 | void kvm_notify_acked_irq(struct kvm *kvm, unsigned irqchip, unsigned pin) |
55 | { | 56 | { |
56 | struct kvm_irq_ack_notifier *kian; | 57 | struct kvm_irq_ack_notifier *kian; |
57 | int gsi; | 58 | int gsi, idx; |
58 | 59 | ||
59 | trace_kvm_ack_irq(irqchip, pin); | 60 | trace_kvm_ack_irq(irqchip, pin); |
60 | 61 | ||
61 | rcu_read_lock(); | 62 | idx = srcu_read_lock(&kvm->irq_srcu); |
62 | gsi = rcu_dereference(kvm->irq_routing)->chip[irqchip][pin]; | 63 | gsi = srcu_dereference(kvm->irq_routing, &kvm->irq_srcu)->chip[irqchip][pin]; |
63 | if (gsi != -1) | 64 | if (gsi != -1) |
64 | hlist_for_each_entry_rcu(kian, &kvm->irq_ack_notifier_list, | 65 | hlist_for_each_entry_rcu(kian, &kvm->irq_ack_notifier_list, |
65 | link) | 66 | link) |
66 | if (kian->gsi == gsi) | 67 | if (kian->gsi == gsi) |
67 | kian->irq_acked(kian); | 68 | kian->irq_acked(kian); |
68 | rcu_read_unlock(); | 69 | srcu_read_unlock(&kvm->irq_srcu, idx); |
69 | } | 70 | } |
70 | 71 | ||
71 | void kvm_register_irq_ack_notifier(struct kvm *kvm, | 72 | void kvm_register_irq_ack_notifier(struct kvm *kvm, |
@@ -85,7 +86,7 @@ void kvm_unregister_irq_ack_notifier(struct kvm *kvm, | |||
85 | mutex_lock(&kvm->irq_lock); | 86 | mutex_lock(&kvm->irq_lock); |
86 | hlist_del_init_rcu(&kian->link); | 87 | hlist_del_init_rcu(&kian->link); |
87 | mutex_unlock(&kvm->irq_lock); | 88 | mutex_unlock(&kvm->irq_lock); |
88 | synchronize_rcu(); | 89 | synchronize_srcu(&kvm->irq_srcu); |
89 | #ifdef __KVM_HAVE_IOAPIC | 90 | #ifdef __KVM_HAVE_IOAPIC |
90 | kvm_vcpu_request_scan_ioapic(kvm); | 91 | kvm_vcpu_request_scan_ioapic(kvm); |
91 | #endif | 92 | #endif |
@@ -115,7 +116,7 @@ int kvm_set_irq(struct kvm *kvm, int irq_source_id, u32 irq, int level, | |||
115 | bool line_status) | 116 | bool line_status) |
116 | { | 117 | { |
117 | struct kvm_kernel_irq_routing_entry *e, irq_set[KVM_NR_IRQCHIPS]; | 118 | struct kvm_kernel_irq_routing_entry *e, irq_set[KVM_NR_IRQCHIPS]; |
118 | int ret = -1, i = 0; | 119 | int ret = -1, i = 0, idx; |
119 | struct kvm_irq_routing_table *irq_rt; | 120 | struct kvm_irq_routing_table *irq_rt; |
120 | 121 | ||
121 | trace_kvm_set_irq(irq, level, irq_source_id); | 122 | trace_kvm_set_irq(irq, level, irq_source_id); |
@@ -124,12 +125,12 @@ int kvm_set_irq(struct kvm *kvm, int irq_source_id, u32 irq, int level, | |||
124 | * IOAPIC. So set the bit in both. The guest will ignore | 125 | * IOAPIC. So set the bit in both. The guest will ignore |
125 | * writes to the unused one. | 126 | * writes to the unused one. |
126 | */ | 127 | */ |
127 | rcu_read_lock(); | 128 | idx = srcu_read_lock(&kvm->irq_srcu); |
128 | irq_rt = rcu_dereference(kvm->irq_routing); | 129 | irq_rt = srcu_dereference(kvm->irq_routing, &kvm->irq_srcu); |
129 | if (irq < irq_rt->nr_rt_entries) | 130 | if (irq < irq_rt->nr_rt_entries) |
130 | hlist_for_each_entry(e, &irq_rt->map[irq], link) | 131 | hlist_for_each_entry(e, &irq_rt->map[irq], link) |
131 | irq_set[i++] = *e; | 132 | irq_set[i++] = *e; |
132 | rcu_read_unlock(); | 133 | srcu_read_unlock(&kvm->irq_srcu, idx); |
133 | 134 | ||
134 | while(i--) { | 135 | while(i--) { |
135 | int r; | 136 | int r; |
@@ -226,7 +227,7 @@ int kvm_set_irq_routing(struct kvm *kvm, | |||
226 | kvm_irq_routing_update(kvm, new); | 227 | kvm_irq_routing_update(kvm, new); |
227 | mutex_unlock(&kvm->irq_lock); | 228 | mutex_unlock(&kvm->irq_lock); |
228 | 229 | ||
229 | synchronize_rcu(); | 230 | synchronize_srcu_expedited(&kvm->irq_srcu); |
230 | 231 | ||
231 | new = old; | 232 | new = old; |
232 | r = 0; | 233 | r = 0; |