History

KVM: Boost vCPUs that are delivering interrupts

Inspired by commit 9cac38dd5d (KVM/s390: Set preempted flag during vcpu wakeup and interrupt delivery), we want to also boost not just lock holders but also vCPUs that are delivering interrupts. Most smp_call_function_many calls are synchronous, so the IPI target vCPUs are also good yield candidates. This patch introduces vcpu->ready to boost vCPUs during wakeup and interrupt delivery time; unlike s390 we do not reuse vcpu->preempted so that voluntarily preempted vCPUs are taken into account by kvm_vcpu_on_spin, but vmx_vcpu_pi_put is not affected (VT-d PI handles voluntary preemption separately, in pi_pre_block). Testing on 80 HT 2 socket Xeon Skylake server, with 80 vCPUs VM 80GB RAM: ebizzy -M vanilla boosting improved 1VM 21443 23520 9% 2VM 2800 8000 180% 3VM 1800 3100 72% Testing on my Haswell desktop 8 HT, with 8 vCPUs VM 8GB RAM, two VMs, one running ebizzy -M, the other running 'stress --cpu 2': w/ boosting + w/o pv sched yield(vanilla) vanilla boosting improved 1570 4000 155% w/ boosting + w/ pv sched yield(vanilla) vanilla boosting improved 1844 5157 179% w/o boosting, perf top in VM: 72.33% [kernel] [k] smp_call_function_many 4.22% [kernel] [k] call_function_i 3.71% [kernel] [k] async_page_fault w/ boosting, perf top in VM: 38.43% [kernel] [k] smp_call_function_many 6.31% [kernel] [k] async_page_fault 6.13% libc-2.23.so [.] __memcpy_avx_unaligned 4.88% [kernel] [k] call_function_interrupt

Wanpeng Li committed 7 years ago

Commit d73eb571 parent 2417c873 files · +10 −5Browse files

Unified · Split

3 files
  1. arch/s390/kvm/interrupt.c +1 −1
  2. include/linux/kvm_host.h +1 −0
  3. virt/kvm/kvm_main.c +8 −4
arch/s390/kvm/interrupt.c+1−1
@@ -1240,7 +1240,7 @@ void kvm_s390_vcpu_wakeup(struct kvm_vcpu *vcpu) · 1239 unmodified lines
12401240 * The vcpu gave up the cpu voluntarily, mark it as a good
12411241 * yield-candidate.
12421242 */
1243− vcpu->preempted = true;
1243+ vcpu->ready = true;
12441244 swake_up_one(&vcpu->wq);
12451245 vcpu->stat.halt_wakeup++;
12461246 }
include/linux/kvm_host.h+1−0
@@ -318,6 +318,7 @@ struct kvm_vcpu { · 317 unmodified lines
318318 } spin_loop;
319319 #endif
320320 bool preempted;
321+ bool ready;
321322 struct kvm_vcpu_arch arch;
322323 struct dentry *debugfs_dentry;
323324 };
virt/kvm/kvm_main.c+8−4
@@ -314,6 +314,7 @@ int kvm_vcpu_init(struct kvm_vcpu *vcpu, struct kvm *kvm, unsigned id) · 313 unmodified lines
314314 kvm_vcpu_set_in_spin_loop(vcpu, false);
315315 kvm_vcpu_set_dy_eligible(vcpu, false);
316316 vcpu->preempted = false;
317+ vcpu->ready = false;
317318
318319 r = kvm_arch_vcpu_init(vcpu);
319320 if (r < 0)
@@ -2387,6 +2388,7 @@ bool kvm_vcpu_wake_up(struct kvm_vcpu *vcpu) · 2067 unmodified lines
23872388 wqp = kvm_arch_vcpu_wq(vcpu);
23882389 if (swq_has_sleeper(wqp)) {
23892390 swake_up_one(wqp);
2391+ WRITE_ONCE(vcpu->ready, true);
23902392 ++vcpu->stat.halt_wakeup;
23912393 return true;
23922394 }
@@ -2500,7 +2502,7 @@ void kvm_vcpu_on_spin(struct kvm_vcpu *me, bool yield_to_kernel_mode) · 107 unmodified lines
25002502 continue;
25012503 } else if (pass && i > last_boosted_vcpu)
25022504 break;
2503− if (!READ_ONCE(vcpu->preempted))
2505+ if (!READ_ONCE(vcpu->ready))
25042506 continue;
25052507 if (vcpu == me)
25062508 continue;
@@ -4203,8 +4205,8 @@ static void kvm_sched_in(struct preempt_notifier *pn, int cpu) · 1696 unmodified lines
42034205 {
42044206 struct kvm_vcpu *vcpu = preempt_notifier_to_vcpu(pn);
42054207
4206− if (vcpu->preempted)
4207− vcpu->preempted = false;
4208+ vcpu->preempted = false;
4209+ WRITE_ONCE(vcpu->ready, false);
42084210
42094211 kvm_arch_sched_in(vcpu, cpu);
42104212
@@ -4216,8 +4218,10 @@ static void kvm_sched_out(struct preempt_notifier *pn, · 5 unmodified lines
42164218 {
42174219 struct kvm_vcpu *vcpu = preempt_notifier_to_vcpu(pn);
42184220
4219− if (current->state == TASK_RUNNING)
4221+ if (current->state == TASK_RUNNING) {
42204222 vcpu->preempted = true;
4223+ WRITE_ONCE(vcpu->ready, true);
4224+ }
42214225 kvm_arch_vcpu_put(vcpu);
42224226 }
42234227

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t