From mboxrd@z Thu Jan 1 00:00:00 1970 From: Raghavendra K T Subject: Re: [PATCH RFC V4 3/3] kvm: Choose better candidate for directed yield Date: Tue, 17 Jul 2012 14:39:09 +0530 Message-ID: <50052BB5.2040909@linux.vnet.ibm.com> References: <20120716082445.23477.15128.sendpatchset@codeblue.in.ibm.com> <20120716082529.23477.91096.sendpatchset@codeblue.in.ibm.com> <5003E7ED.2030701@redhat.com> <50043CF3.8020903@redhat.com> <50052272.5020803@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <50052272.5020803@redhat.com> Sender: kvm-owner@vger.kernel.org List-Archive: List-Post: To: Avi Kivity Cc: Rik van Riel , "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , Marcelo Tosatti , Srikar , S390 , Carsten Otte , Christian Borntraeger , KVM , chegu vinod , "Andrew M. Theurer" , LKML , X86 , Gleb Natapov , linux390@de.ibm.com, Srivatsa Vaddagiri , Joerg Roedel List-ID: On 07/17/2012 01:59 PM, Avi Kivity wrote: > On 07/16/2012 07:10 PM, Rik van Riel wrote: >> On 07/16/2012 06:07 AM, Avi Kivity wrote: >> >>>> +{ >>>> + bool eligible; >>>> + >>>> + eligible = !vcpu->ple.cpu_relax_intercepted || >>>> + (vcpu->ple.cpu_relax_intercepted&& >>>> + vcpu->ple.dy_eligible); >>>> + >>>> + if (vcpu->ple.cpu_relax_intercepted) >>>> + vcpu->ple.dy_eligible = !vcpu->ple.dy_eligible; >>> >>> Probably should assign 'true', since the previous value is essentially >>> random. >> >> I suspect the intended purpose of this conditional is to >> flip the eligibility of a vcpu for being selected as a >> direct yield target. >> >> In other words, that bit of the code is correct. > > If vcpu A is in a long spin loop and is preempted away, and vcpu B dips > several times in kvm_vcpu_on_spin(), then it will act as intended. Yes, true. But > if vcpu A is spinning for x% of its time and processing on the other, > then vcpu B will flip its dy_eligible for those x%, and not flip it when > it's processing. I don't understand how this is useful. Suppose A is doing really good job and and has not done pause loop exit, we will not touch it's dy_eligible flag. Also dy_eligible flag will not prevent B doing yield_to to A. Suppose A has started spinning in the beginning itself, it will do pause loop exit if it crosses threshold, and we will now start toggling dy_eligible. Was that you were referring? And it seems we may still have to set dy_eligible flag to false at the beginning of vcpu_on_spin along with cpu_relax_intercepted = true, like below, so that we do not have spill-over status from previous PL exits. vcpu_on_spin() { cpu_relax_intercepted = true; dy_eligible = false; . . . cpu_relax_intercepted = false; } Let me know if that addresses your concern. > > I guess this is an attempt to impose fairness on yielding, and it makes > sense to do this, but I don't know if this is the best way to achieve it. >