All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] KVM: halt_polling: allow tuning of grow/shrink
@ 2016-02-09 12:00 Christian Borntraeger
  2016-02-09 12:21 ` Christian Borntraeger
  0 siblings, 1 reply; 2+ messages in thread
From: Christian Borntraeger @ 2016-02-09 12:00 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: KVM, Christian Borntraeger, Wanpeng Li

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 <wanpeng.li@hotmail.com>
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
---
 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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] KVM: halt_polling: allow tuning of grow/shrink
  2016-02-09 12:00 [PATCH] KVM: halt_polling: allow tuning of grow/shrink Christian Borntraeger
@ 2016-02-09 12:21 ` Christian Borntraeger
  0 siblings, 0 replies; 2+ messages in thread
From: Christian Borntraeger @ 2016-02-09 12:21 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: KVM, Wanpeng Li

On 02/09/2016 01:00 PM, Christian Borntraeger wrote:
> 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 <wanpeng.li@hotmail.com>
> Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
> ---
>  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);

Please let me know if I should respin with a global fixup
regarding signedness:

Right now we have a mix of
uint:
>  static unsigned int halt_poll_ns_grow = 2;
int:
> +module_param(halt_poll_ns_grow, int, S_IRUGO | S_IWUSR);
int:
> -	int old, val;

I think having everything as unsigned int would be
the right thing.

Christian


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-02-09 12:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-09 12:00 [PATCH] KVM: halt_polling: allow tuning of grow/shrink Christian Borntraeger
2016-02-09 12:21 ` Christian Borntraeger

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.