2017-03-16 10:08+0800, Longpeng (Mike): > Hi, Radim, > > On 2017/3/16 1:32, Radim Krčmář 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 execute >>> 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 mentioned HLT. >>> >>> My questions are >>> 1) Does executing HLT instruction in guest-mode won't enter C1/C1E state ? >> >> 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. I'd go for the thermal monitoring (ideally with constant fan speed) if CPU counters are lacking. Thermal sensors are easily accessible and far more trustworthy for measuring power saving. :) >>> 2) If it won't, then whether it would release the hardware resources shared 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 HLT-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 = rdtsc(); > for (int i = 0; i < 10000000; ++i) ; > t2 = rdtsc(); > costs = t2 - t1; > > (vcpu2) > "halt" or "while (1) ;" > > The result is: > ----------------------------------------------------------------------- > (vcpu2)idle=poll (vcpu2)idle=halt > (HLT exiting=1) > vcpu1 costs 3800931 1900209 > > (HLT exiting=0) > vcpu1 costs 3800193 1913514 > ----------------------------------------------------------------------- Oh, great results. I wonder if the slightly better time on HLT exiting=1 is because the other hyper-thread goes into deeper sleep after exit. Btw. does adding pause() into the while loop bring the performance close to halt? > 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 due to > redundant with CFS hardlimit. > > I focus on the VM's performance. According the result, I think running HLT in > guest-mode is better than idle=poll with HLT-exiting in *certain* scenarios. Yes, and using MWAIT for idle is even better than HLT (you can be woken up without IPI) -- any reason to prefer HLT? Thanks.