linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: "Radim Krčmář" <rkrcmar@redhat.com>, kvm@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Gleb Natapov <gleb@kernel.org>,
	Raghavendra KT <raghavendra.kt@linux.vnet.ibm.com>,
	Vinod Chegu <chegu_vinod@hp.com>, Hui-Zhi <hui-zhi.zhao@hp.com>
Subject: Re: [PATCH 9/9] KVM: VMX: automatic PLE window maximum
Date: Wed, 20 Aug 2014 09:18:37 +0200	[thread overview]
Message-ID: <53F44BCD.1010203@redhat.com> (raw)
In-Reply-To: <53F44B40.6060806@redhat.com>

Il 20/08/2014 09:16, Paolo Bonzini ha scritto:
> Il 19/08/2014 22:35, Radim Krčmář ha scritto:
>> Every increase of ple_window_grow creates potential overflows.
>> They are not serious, because we clamp ple_window and userspace is
>> expected to fix ple_window_max within a second.
>> ---
>>  arch/x86/kvm/vmx.c | 34 +++++++++++++++++++++++++++++++++-
>>  1 file changed, 33 insertions(+), 1 deletion(-)
>>
>> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
>> index d7f58e8..6873a0b 100644
>> --- a/arch/x86/kvm/vmx.c
>> +++ b/arch/x86/kvm/vmx.c
>> @@ -138,7 +138,9 @@ module_param(ple_window, int, S_IRUGO | S_IWUSR);
>>  
>>  /* Default doubles per-vcpu window every exit. */
>>  static int ple_window_grow = KVM_VMX_DEFAULT_PLE_WINDOW_GROW;
>> -module_param(ple_window_grow, int, S_IRUGO | S_IWUSR);
>> +static struct kernel_param_ops ple_window_grow_ops;
>> +module_param_cb(ple_window_grow, &ple_window_grow_ops,
>> +                &ple_window_grow, S_IRUGO | S_IWUSR);
>>  
>>  /* Default resets per-vcpu window every exit to ple_window. */
>>  static int ple_window_shrink = KVM_VMX_DEFAULT_PLE_WINDOW_SHRINK;
>> @@ -5717,6 +5719,36 @@ static void type##_ple_window(struct kvm_vcpu *vcpu) \
>>  make_ple_window_modifier(grow,   *, +) /* grow_ple_window */
>>  make_ple_window_modifier(shrink, /, -) /* shrink_ple_window */
>>  
>> +static void clamp_ple_window_max(void)
>> +{
>> +	int maximum;
>> +
>> +	if (ple_window_grow < 1)
>> +		return;
>> +
>> +	if (ple_window_grow < ple_window)
>> +		maximum = INT_MAX / ple_window_grow;
>> +	else
>> +		maximum = INT_MAX - ple_window_grow;
>> +
>> +	ple_window_max = clamp(ple_window_max, ple_window, maximum);
>> +}
> 
> I think avoiding overflows is better.  In fact, I think you should call
> this function for ple_window_max too.
> 
> You could keep the ple_window_max variable to the user-set value.
> Whenever ple_window_grow or ple_window_max are changed, you can set an
> internal variable (let's call it ple_window_actual_max, but I'm not wed
> to this name) to the computed value, and then do:
> 
> 	if (ple_window_grow < 1 || ple_window_actual_max < ple_window)
> 		new = ple_window;
> 	else if (ple_window_grow < ple_window)
> 		new = max(ple_window_actual_max, old) * ple_window_grow;
> 	else
> 		new = max(ple_window_actual_max, old) + ple_window_grow;

Ehm, this should of course be "min".

Paolo

> (I think the || in the first "if" can be eliminated with some creativity
> in clamp_ple_window_max).
> 
> Paolo
> 
>> +static int set_ple_window_grow(const char *arg, const struct kernel_param *kp)
>> +{
>> +	int ret;
>> +
>> +	clamp_ple_window_max();
>> +	ret = param_set_int(arg, kp);
>> +
>> +	return ret;
>> +}
>> +
>> +static struct kernel_param_ops ple_window_grow_ops = {
>> +	.set = set_ple_window_grow,
>> +	.get = param_get_int,
>> +};
>> +
>>  /*
>>   * Indicate a busy-waiting vcpu in spinlock. We do not enable the PAUSE
>>   * exiting, so only get here on cpu with PAUSE-Loop-Exiting.
>>
> 
> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 


  reply	other threads:[~2014-08-20  7:18 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-19 20:35 [PATCH 0/9] Dynamic Pause Loop Exiting window Radim Krčmář
2014-08-19 20:35 ` [PATCH 1/9] KVM: add kvm_arch_sched_in Radim Krčmář
2014-08-20  7:47   ` Christian Borntraeger
2014-08-20 12:56     ` Radim Krčmář
2014-08-19 20:35 ` [PATCH 2/9] KVM: x86: introduce sched_in to kvm_x86_ops Radim Krčmář
2014-08-19 20:35 ` [PATCH 3/9] KVM: VMX: make PLE window per-vcpu Radim Krčmář
2014-08-20  7:13   ` Paolo Bonzini
2014-08-20 12:26     ` Radim Krčmář
2014-08-19 20:35 ` [PATCH 4/9] KVM: VMX: dynamise PLE window Radim Krčmář
2014-08-19 20:35 ` [PATCH 5/9] KVM: VMX: clamp " Radim Krčmář
2014-08-20  7:18   ` Paolo Bonzini
2014-08-20 12:46     ` Radim Krčmář
2014-08-19 20:35 ` [PATCH 6/9] KVM: trace kvm_ple_window grow/shrink Radim Krčmář
2014-08-19 20:35 ` [PATCH 7/9] KVM: VMX: abstract ple_window modifiers Radim Krčmář
2014-08-20  7:02   ` Paolo Bonzini
2014-08-20 12:25     ` Radim Krčmář
2014-08-19 20:35 ` [PATCH 8/9] KVM: VMX: runtime knobs for dynamic PLE window Radim Krčmář
2014-08-19 20:35 ` [PATCH 9/9] KVM: VMX: automatic PLE window maximum Radim Krčmář
2014-08-20  7:16   ` Paolo Bonzini
2014-08-20  7:18     ` Paolo Bonzini [this message]
2014-08-20 12:41     ` Radim Krčmář
2014-08-20 13:15       ` Paolo Bonzini
2014-08-20 15:31         ` Radim Krčmář
2014-08-20 15:34           ` Paolo Bonzini
2014-08-20 16:01             ` Radim Krčmář
2014-08-20 16:03               ` Paolo Bonzini
2014-08-20 16:26                 ` Radim Krčmář
2014-08-21  6:48 ` [PATCH 0/9] Dynamic Pause Loop Exiting window Zhao, Hui-Zhi (Steven, HPservers-Core-OE-PSC)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=53F44BCD.1010203@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=chegu_vinod@hp.com \
    --cc=gleb@kernel.org \
    --cc=hui-zhi.zhao@hp.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=raghavendra.kt@linux.vnet.ibm.com \
    --cc=rkrcmar@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).