* [PATCH v2] KVM: halt_polling: improve grow/shrink settings
@ 2016-02-09 12:47 Christian Borntraeger
2016-02-09 15:16 ` Paolo Bonzini
0 siblings, 1 reply; 2+ messages in thread
From: Christian Borntraeger @ 2016-02-09 12:47 UTC (permalink / raw)
To: Paolo Bonzini; +Cc: KVM, Christian Borntraeger
Right now halt_poll_ns can be change during runtime. The
grow and shrink factors can only be set during module load.
Lets fix several aspects of grow shrink:
- make grow/shrink changeable by root
- make all variables unsigned int
- read the variables once to prevent races
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
---
V1->V2:
- no need to use READ_ONCE for the vcpu variables
- make grow/shrink unsigned everywhere
include/trace/events/kvm.h | 9 +++++----
virt/kvm/kvm_main.c | 18 ++++++++++--------
2 files changed, 15 insertions(+), 12 deletions(-)
diff --git a/include/trace/events/kvm.h b/include/trace/events/kvm.h
index d6f8322..aa69253 100644
--- a/include/trace/events/kvm.h
+++ b/include/trace/events/kvm.h
@@ -359,14 +359,15 @@ TRACE_EVENT(
#endif
TRACE_EVENT(kvm_halt_poll_ns,
- TP_PROTO(bool grow, unsigned int vcpu_id, int new, int old),
+ TP_PROTO(bool grow, unsigned int vcpu_id, unsigned int new,
+ unsigned int old),
TP_ARGS(grow, vcpu_id, new, old),
TP_STRUCT__entry(
__field(bool, grow)
__field(unsigned int, vcpu_id)
- __field(int, new)
- __field(int, old)
+ __field(unsigned int, new)
+ __field(unsigned int, old)
),
TP_fast_assign(
@@ -376,7 +377,7 @@ TRACE_EVENT(kvm_halt_poll_ns,
__entry->old = old;
),
- TP_printk("vcpu %u: halt_poll_ns %d (%s %d)",
+ TP_printk("vcpu %u: halt_poll_ns %u (%s %u)",
__entry->vcpu_id,
__entry->new,
__entry->grow ? "grow" : "shrink",
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 726d7c8..b6b5ccb 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, uint, 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, uint, 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;
+ unsigned int old, val, grow;
old = val = 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;
+ unsigned int old, val, shrink;
old = val = vcpu->halt_poll_ns;
- if (halt_poll_ns_shrink == 0)
+ 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 v2] KVM: halt_polling: improve grow/shrink settings
2016-02-09 12:47 [PATCH v2] KVM: halt_polling: improve grow/shrink settings Christian Borntraeger
@ 2016-02-09 15:16 ` Paolo Bonzini
0 siblings, 0 replies; 2+ messages in thread
From: Paolo Bonzini @ 2016-02-09 15:16 UTC (permalink / raw)
To: Christian Borntraeger; +Cc: KVM
On 09/02/2016 13:47, 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.
> Lets fix several aspects of grow shrink:
> - make grow/shrink changeable by root
> - make all variables unsigned int
> - read the variables once to prevent races
>
> Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
Applying to kvm/queue, thanks.
Paolo
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-02-09 15:16 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:47 [PATCH v2] KVM: halt_polling: improve grow/shrink settings Christian Borntraeger
2016-02-09 15:16 ` Paolo Bonzini
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox