From mboxrd@z Thu Jan 1 00:00:00 1970 From: Christian Borntraeger Subject: [PATCH] KVM: halt_polling: allow tuning of grow/shrink Date: Tue, 9 Feb 2016 13:00:43 +0100 Message-ID: <1455019243-87616-1-git-send-email-borntraeger@de.ibm.com> Cc: KVM , Christian Borntraeger , Wanpeng Li To: Paolo Bonzini Return-path: Received: from e06smtp12.uk.ibm.com ([195.75.94.108]:45018 "EHLO e06smtp12.uk.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752643AbcBIMA1 (ORCPT ); Tue, 9 Feb 2016 07:00:27 -0500 Received: from localhost by e06smtp12.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 9 Feb 2016 12:00:26 -0000 Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by d06dlp01.portsmouth.uk.ibm.com (Postfix) with ESMTP id 4F5CD17D805D for ; Tue, 9 Feb 2016 12:00:37 +0000 (GMT) Received: from d06av04.portsmouth.uk.ibm.com (d06av04.portsmouth.uk.ibm.com [9.149.37.216]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u19C0MC416318608 for ; Tue, 9 Feb 2016 12:00:22 GMT Received: from d06av04.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av04.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id u19C0Kh2009743 for ; Tue, 9 Feb 2016 05:00:22 -0700 Sender: kvm-owner@vger.kernel.org List-ID: Right now halt_poll_ns can be change during runtime. The grow and shrink factors can only be set during module load. Let's make this consistent and allow changes during runtime. To avoid dirty tricky like setting shrink to 0 after the check for 0, use READ_ONCE to get a consistent number for all cases. Cc: Wanpeng Li Signed-off-by: Christian Borntraeger --- virt/kvm/kvm_main.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 726d7c8..eafea6f 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -72,11 +72,11 @@ module_param(halt_poll_ns, uint, S_IRUGO | S_IWUSR); /* Default doubles per-vcpu halt_poll_ns. */ static unsigned int halt_poll_ns_grow = 2; -module_param(halt_poll_ns_grow, int, S_IRUGO); +module_param(halt_poll_ns_grow, int, S_IRUGO | S_IWUSR); /* Default resets per-vcpu halt_poll_ns . */ static unsigned int halt_poll_ns_shrink; -module_param(halt_poll_ns_shrink, int, S_IRUGO); +module_param(halt_poll_ns_shrink, int, S_IRUGO | S_IWUSR); /* * Ordering of locks: @@ -1952,14 +1952,15 @@ EXPORT_SYMBOL_GPL(kvm_vcpu_mark_page_dirty); static void grow_halt_poll_ns(struct kvm_vcpu *vcpu) { - int old, val; + int old, val, grow; - old = val = vcpu->halt_poll_ns; + old = val = READ_ONCE(vcpu->halt_poll_ns); + grow = READ_ONCE(halt_poll_ns_grow); /* 10us base */ - if (val == 0 && halt_poll_ns_grow) + if (val == 0 && grow) val = 10000; else - val *= halt_poll_ns_grow; + val *= grow; vcpu->halt_poll_ns = val; trace_kvm_halt_poll_ns_grow(vcpu->vcpu_id, val, old); @@ -1967,13 +1968,14 @@ static void grow_halt_poll_ns(struct kvm_vcpu *vcpu) static void shrink_halt_poll_ns(struct kvm_vcpu *vcpu) { - int old, val; + int old, val, shrink; - old = val = vcpu->halt_poll_ns; - if (halt_poll_ns_shrink == 0) + old = val = READ_ONCE(vcpu->halt_poll_ns); + shrink = READ_ONCE(halt_poll_ns_shrink); + if (shrink == 0) val = 0; else - val /= halt_poll_ns_shrink; + val /= shrink; vcpu->halt_poll_ns = val; trace_kvm_halt_poll_ns_shrink(vcpu->vcpu_id, val, old); -- 2.3.0