diff mbox series

[2/3] kvm: better handling for kvm halt polling

Message ID 20201023032944.399861-2-joshdon@google.com (mailing list archive)
State Not Applicable
Headers show
Series None | expand

Commit Message

Josh Don Oct. 23, 2020, 3:29 a.m. UTC
Add the new functions prepare_to_busy_poll() and friends to
kvm_vcpu_block. The busy polling cpu will be considered an
idle target during wake up balancing.

cpu_relax is also added to the polling loop to improve the performance
of other hw threads sharing the busy polling core.

Suggested-by: Xi Wang <xii@google.com>
Signed-off-by: Josh Don <joshdon@google.com>
Signed-off-by: Xi Wang <xii@google.com>
---
 virt/kvm/kvm_main.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index cf88233b819a..8f818f0fc979 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -2772,7 +2772,9 @@  void kvm_vcpu_block(struct kvm_vcpu *vcpu)
 		ktime_t stop = ktime_add_ns(ktime_get(), vcpu->halt_poll_ns);
 
 		++vcpu->stat.halt_attempted_poll;
+		prepare_to_busy_poll(); /* also disables preemption */
 		do {
+			cpu_relax();
 			/*
 			 * This sets KVM_REQ_UNHALT if an interrupt
 			 * arrives.
@@ -2781,10 +2783,12 @@  void kvm_vcpu_block(struct kvm_vcpu *vcpu)
 				++vcpu->stat.halt_successful_poll;
 				if (!vcpu_valid_wakeup(vcpu))
 					++vcpu->stat.halt_poll_invalid;
+				end_busy_poll(false);
 				goto out;
 			}
 			poll_end = cur = ktime_get();
-		} while (single_task_running() && ktime_before(cur, stop));
+		} while (continue_busy_poll() && ktime_before(cur, stop));
+		end_busy_poll(false);
 	}
 
 	prepare_to_rcuwait(&vcpu->wait);