kvm: add capability for halt polling
KVM_CAP_HALT_POLL is a per-VM capability that lets userspace control the halt-polling time, allowing halt-polling to be tuned or disabled on particular VMs. With dynamic halt-polling, a VM's VCPUs can poll from anywhere from [0, halt_poll_ns] on each halt. KVM_CAP_HALT_POLL sets the upper limit on the poll time. Signed-off-by: David Matlack <dmatlack@google.com> Signed-off-by: Jon Cargille <jcargill@google.com> Reviewed-by: Jim Mattson <jmattson@google.com> Message-Id: <20200417221446.108733-1-jcargill@google.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:

committed by
Paolo Bonzini

parent
87796555d4
commit
acd05785e4
@@ -710,6 +710,8 @@ static struct kvm *kvm_create_vm(unsigned long type)
|
||||
goto out_err_no_arch_destroy_vm;
|
||||
}
|
||||
|
||||
kvm->max_halt_poll_ns = halt_poll_ns;
|
||||
|
||||
r = kvm_arch_init_vm(kvm, type);
|
||||
if (r)
|
||||
goto out_err_no_arch_destroy_vm;
|
||||
@@ -2713,15 +2715,16 @@ out:
|
||||
if (!kvm_arch_no_poll(vcpu)) {
|
||||
if (!vcpu_valid_wakeup(vcpu)) {
|
||||
shrink_halt_poll_ns(vcpu);
|
||||
} else if (halt_poll_ns) {
|
||||
} else if (vcpu->kvm->max_halt_poll_ns) {
|
||||
if (block_ns <= vcpu->halt_poll_ns)
|
||||
;
|
||||
/* we had a long block, shrink polling */
|
||||
else if (vcpu->halt_poll_ns && block_ns > halt_poll_ns)
|
||||
else if (vcpu->halt_poll_ns &&
|
||||
block_ns > vcpu->kvm->max_halt_poll_ns)
|
||||
shrink_halt_poll_ns(vcpu);
|
||||
/* we had a short halt and our poll time is too small */
|
||||
else if (vcpu->halt_poll_ns < halt_poll_ns &&
|
||||
block_ns < halt_poll_ns)
|
||||
else if (vcpu->halt_poll_ns < vcpu->kvm->max_halt_poll_ns &&
|
||||
block_ns < vcpu->kvm->max_halt_poll_ns)
|
||||
grow_halt_poll_ns(vcpu);
|
||||
} else {
|
||||
vcpu->halt_poll_ns = 0;
|
||||
@@ -3510,6 +3513,7 @@ static long kvm_vm_ioctl_check_extension_generic(struct kvm *kvm, long arg)
|
||||
case KVM_CAP_IOEVENTFD_ANY_LENGTH:
|
||||
case KVM_CAP_CHECK_EXTENSION_VM:
|
||||
case KVM_CAP_ENABLE_CAP_VM:
|
||||
case KVM_CAP_HALT_POLL:
|
||||
return 1;
|
||||
#ifdef CONFIG_KVM_MMIO
|
||||
case KVM_CAP_COALESCED_MMIO:
|
||||
@@ -3560,6 +3564,13 @@ static int kvm_vm_ioctl_enable_cap_generic(struct kvm *kvm,
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
case KVM_CAP_HALT_POLL: {
|
||||
if (cap->flags || cap->args[0] != (unsigned int)cap->args[0])
|
||||
return -EINVAL;
|
||||
|
||||
kvm->max_halt_poll_ns = cap->args[0];
|
||||
return 0;
|
||||
}
|
||||
default:
|
||||
return kvm_vm_ioctl_enable_cap(kvm, cap);
|
||||
}
|
||||
|
Reference in New Issue
Block a user