From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752375AbcGGKMz (ORCPT ); Thu, 7 Jul 2016 06:12:55 -0400 Received: from mail-oi0-f65.google.com ([209.85.218.65]:34564 "EHLO mail-oi0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751179AbcGGKMx (ORCPT ); Thu, 7 Jul 2016 06:12:53 -0400 MIME-Version: 1.0 In-Reply-To: <20160707094215.GT30921@twins.programming.kicks-ass.net> References: <1467124991-13164-1-git-send-email-xinhui.pan@linux.vnet.ibm.com> <20160706065255.GH30909@twins.programming.kicks-ass.net> <14a24854-9787-e4a1-c9a8-76eba4e97301@redhat.com> <8e8edf1b-b64b-3c44-b580-b9271663844c@redhat.com> <20160707094215.GT30921@twins.programming.kicks-ass.net> From: Wanpeng Li Date: Thu, 7 Jul 2016 18:12:51 +0800 Message-ID: Subject: Re: [PATCH v2 0/4] implement vcpu preempted check To: Peter Zijlstra Cc: Paolo Bonzini , Pan Xinhui , linux-s390 , Davidlohr Bueso , mpe@ellerman.id.au, boqun.feng@gmail.com, will.deacon@arm.com, "linux-kernel@vger.kernel.org" , Waiman Long , virtualization@lists.linux-foundation.org, Ingo Molnar , Paul Mackerras , benh@kernel.crashing.org, schwidefsky@de.ibm.com, Paul McKenney , linuxppc-dev@lists.ozlabs.org, kvm Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 2016-07-07 17:42 GMT+08:00 Peter Zijlstra : > On Thu, Jul 07, 2016 at 04:48:05PM +0800, Wanpeng Li wrote: >> 2016-07-06 20:28 GMT+08:00 Paolo Bonzini : >> > Hmm, you're right. We can use bit 0 of struct kvm_steal_time's flags to >> > indicate that pad[0] is a "VCPU preempted" field; if pad[0] is 1, the >> > VCPU has been scheduled out since the last time the guest reset the bit. >> > The guest can use an xchg to test-and-clear it. The bit can be >> > accessed at any time, independent of the version field. >> >> If one vCPU is preempted, and guest check it several times before this >> vCPU is scheded in, then the first time we can get "vCPU is >> preempted", however, since the field is cleared, the second time we >> will get "vCPU is running". >> >> Do you mean we should call record_steal_time() in both kvm_sched_in() >> and kvm_sched_out() to record this field? Btw, if we should keep both >> vcpu->preempted and kvm_steal_time's "vCPU preempted" field present >> simultaneous? > > I suspect you want something like so; except this has holes in. > > We clear KVM_ST_PAD_PREEMPT before disabling preemption and we set it > after enabling it, this means that if we get preempted in between, the > vcpu is reported as running even though it very much is not. Paolo also point out this to me offline yesterday: "Please change pad[12] to "__u32 preempted; __u32 pad[11];" too, and remember to update Documentation/virtual/kvm/msr.txt!". Btw, do this in preemption notifier means that the vCPU is real preempted on host, however, depends on vmexit is different semantic I think. Regards, Wanpeng Li From mboxrd@z Thu Jan 1 00:00:00 1970 From: Wanpeng Li Subject: Re: [PATCH v2 0/4] implement vcpu preempted check Date: Thu, 7 Jul 2016 18:12:51 +0800 Message-ID: References: <1467124991-13164-1-git-send-email-xinhui.pan@linux.vnet.ibm.com> <20160706065255.GH30909@twins.programming.kicks-ass.net> <14a24854-9787-e4a1-c9a8-76eba4e97301@redhat.com> <8e8edf1b-b64b-3c44-b580-b9271663844c@redhat.com> <20160707094215.GT30921@twins.programming.kicks-ass.net> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Cc: linux-s390 , Davidlohr Bueso , benh@kernel.crashing.org, kvm , mpe@ellerman.id.au, boqun.feng@gmail.com, will.deacon@arm.com, "linux-kernel@vger.kernel.org" , Waiman Long , virtualization@lists.linux-foundation.org, Ingo Molnar , Paul Mackerras , Pan Xinhui , schwidefsky@de.ibm.com, Paolo Bonzini , Paul McKenney , linuxppc-dev@lists.ozlabs.org To: Peter Zijlstra Return-path: In-Reply-To: <20160707094215.GT30921@twins.programming.kicks-ass.net> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: virtualization-bounces@lists.linux-foundation.org Errors-To: virtualization-bounces@lists.linux-foundation.org List-Id: kvm.vger.kernel.org 2016-07-07 17:42 GMT+08:00 Peter Zijlstra : > On Thu, Jul 07, 2016 at 04:48:05PM +0800, Wanpeng Li wrote: >> 2016-07-06 20:28 GMT+08:00 Paolo Bonzini : >> > Hmm, you're right. We can use bit 0 of struct kvm_steal_time's flags to >> > indicate that pad[0] is a "VCPU preempted" field; if pad[0] is 1, the >> > VCPU has been scheduled out since the last time the guest reset the bit. >> > The guest can use an xchg to test-and-clear it. The bit can be >> > accessed at any time, independent of the version field. >> >> If one vCPU is preempted, and guest check it several times before this >> vCPU is scheded in, then the first time we can get "vCPU is >> preempted", however, since the field is cleared, the second time we >> will get "vCPU is running". >> >> Do you mean we should call record_steal_time() in both kvm_sched_in() >> and kvm_sched_out() to record this field? Btw, if we should keep both >> vcpu->preempted and kvm_steal_time's "vCPU preempted" field present >> simultaneous? > > I suspect you want something like so; except this has holes in. > > We clear KVM_ST_PAD_PREEMPT before disabling preemption and we set it > after enabling it, this means that if we get preempted in between, the > vcpu is reported as running even though it very much is not. Paolo also point out this to me offline yesterday: "Please change pad[12] to "__u32 preempted; __u32 pad[11];" too, and remember to update Documentation/virtual/kvm/msr.txt!". Btw, do this in preemption notifier means that the vCPU is real preempted on host, however, depends on vmexit is different semantic I think. Regards, Wanpeng Li