From mboxrd@z Thu Jan 1 00:00:00 1970 From: Wanpeng Li Subject: Re: [Question] About the behavior of HLT in VMX guest mode Date: Thu, 16 Mar 2017 16:51:29 +0800 Message-ID: References: <58C64672.1070706@huawei.com> <20170315173254.GF14081@potion> <58C9F3A5.3090604@huawei.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= , kvm , Jan Beulich , Gonglei To: "Longpeng (Mike)" Return-path: Received: from mail-wr0-f173.google.com ([209.85.128.173]:36790 "EHLO mail-wr0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751141AbdCPIvc (ORCPT ); Thu, 16 Mar 2017 04:51:32 -0400 Received: by mail-wr0-f173.google.com with SMTP id u108so26852442wrb.3 for ; Thu, 16 Mar 2017 01:51:31 -0700 (PDT) In-Reply-To: <58C9F3A5.3090604@huawei.com> Sender: kvm-owner@vger.kernel.org List-ID: 2017-03-16 10:08 GMT+08:00 Longpeng (Mike) : > Hi, Radim, > > On 2017/3/16 1:32, Radim Kr=C4=8Dm=C3=A1=C5=99 wrote: > >> 2017-03-13 15:12+0800, Longpeng (Mike): >>> Hi guys, >>> >>> I'm confusing about the behavior of HLT instruction in VMX guest mode. >>> >>> I set "hlt exiting" bit to 0 in VMCS, and the vcpu didn't vmexit when e= xecute >>> HLT as expected. However, I used powertop/cpupower on host to watch the= pcpu's >>> c-states, it seems that the pcpu didn't enter C1/C1E state during this = period. >>> >>> I searched the Intel spec vol-3, and only found that guest MWAIT won't = entering >>> a low-power sleep state under certain conditions(ch 25.3), but not ment= ioned HLT. >>> >>> My questions are >>> 1) Does executing HLT instruction in guest-mode won't enter C1/C1E stat= e ? >> >> Do you get a different result when running HLT outside VMX? >> > > > Yep, I'm sure that executing HLT in host will enter C1/C1E state, but it = won't > when executing in guest. Execute hlt will enter C1 state, just mwait can enter C1E state. Regards, Wanpeng Li > >>> 2) If it won't, then whether it would release the hardware resources sh= ared with >>> another hyper-thread ? >> > >> No idea. Aren't hyperthreaded resources scheduled dynamically, so even >> a nop-spinning VCPU won't hinder the other hyper-thread? >> > > > I had wrote a testcase in kvm-unit-tests, and it seems that guest-mode HL= T-ed > vcpu won't compete the hardware resources( maybe including the pipeline )= any more. > > My testcase is: binding vcpu1 and vcpu2 to a core's 2 hyper-threads, and > > (vcpu1) > t1 =3D rdtsc(); > for (int i =3D 0; i < 10000000; ++i) ; > t2 =3D rdtsc(); > costs =3D t2 - t1; > > (vcpu2) > "halt" or "while (1) ;" > > The result is: > ----------------------------------------------------------------------- > (vcpu2)idle=3Dpoll (vcpu2)idle=3Dhalt > (HLT exiting=3D1) > vcpu1 costs 3800931 1900209 > > (HLT exiting=3D0) > vcpu1 costs 3800193 1913514 > ----------------------------------------------------------------------- > > I found that https://www.spinics.net/lists/kvm-commits/msg00137.html had = maked > "HLT exiting" configurable, while > http://lkml.iu.edu/hypermail/linux/kernel/1202.0/03309.html removed it du= e to > redundant with CFS hardlimit. > > I focus on the VM's performance. According the result, I think running HL= T in > guest-mode is better than idle=3Dpoll with HLT-exiting in *certain* scena= rios. > >>> Any suggestion would be greatly appreciated, thanks! >> >> Mostly just more questions, sorry ... >> >> I'd look at temperature sensors while halting inside guests on all cores >> to see if they really enter a power saving mode -- I expect a noticeable >> difference from idle=3Dpoll. :) >> >> > > > -- > Regards, > Longpeng(Mike) >