On Thu, 13 Jan 2022 at 18:16, Li,Rongqing <lirongqing@xxxxxxxxx> wrote: > > > > > -----邮件原件----- > > 发件人: Peter Zijlstra <peterz@xxxxxxxxxxxxx> > > 发送时间: 2022年1月13日 5:31 > > 收件人: Sean Christopherson <seanjc@xxxxxxxxxx> > > 抄送: Li,Rongqing <lirongqing@xxxxxxxxx>; pbonzini@xxxxxxxxxx; > > vkuznets@xxxxxxxxxx; wanpengli@xxxxxxxxxxx; jmattson@xxxxxxxxxx; > > tglx@xxxxxxxxxxxxx; bp@xxxxxxxxx; x86@xxxxxxxxxx; kvm@xxxxxxxxxxxxxxx; > > joro@xxxxxxxxxx > > 主题: Re: [PATCH] KVM: X86: set vcpu preempted only if it is preempted > > > > On Wed, Jan 12, 2022 at 05:30:47PM +0000, Sean Christopherson wrote: > > > On Wed, Jan 12, 2022, Peter Zijlstra wrote: > > > > On Wed, Jan 12, 2022 at 08:02:01PM +0800, Li RongQing wrote: > > > > > vcpu can schedule out when run halt instruction, and set itself to > > > > > INTERRUPTIBLE and switch to idle thread, vcpu should not be set > > > > > preempted for this condition > > > > > > > > Uhhmm, why not? Who says the vcpu will run the moment it becomes > > > > runnable again? Another task could be woken up meanwhile occupying > > > > the real cpu. > > > > > > Hrm, but when emulating HLT, e.g. for an idling vCPU, KVM will > > > voluntarily schedule out the vCPU and mark it as preempted from the > > > guest's perspective. The vast majority, probably all, usage of > > > steal_time.preempted expects it to truly mean "preempted" as opposed to > > "not running". > > > > No, the original use-case was locking and that really cares about running. > > > > If the vCPU isn't running, we must not busy-wait for it etc.. > > > > Similar to the scheduler use of it, if the vCPU isn't running, we should not > > consider it so. Getting the vCPU task scheduled back on the CPU can take a 'long' > > time. > > > > If you have pinned vCPU threads and no overcommit, we have other knobs to > > indicate this I think. > > > Is it possible if guest has KVM_HINTS_REALTIME feature, but its HLT instruction is emulated by KVM? > If it is possible, this condition has been performance degradation, since vcpu_is_preempted is not __kvm_vcpu_is_preempted, will return false. > > Similar, guest has nopvspin, but HLT instruction is emulated; https://lkml.kernel.org/r/<20210526133727.42339-1-m.misono760@xxxxxxxxx> So it is the second time guys talk about this, we should tune the dedicated scenario like advertise guest KVM_HINT_REALTIME feature and not intercept mwait/hlt/pause simultaneously to get the best performance. Wanpeng