From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751916AbdJEKpT (ORCPT ); Thu, 5 Oct 2017 06:45:19 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56658 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751489AbdJEKpP (ORCPT ); Thu, 5 Oct 2017 06:45:15 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 1793E5AFC8 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=pbonzini@redhat.com Subject: Re: [PATCH RFC hack dont apply] intel_idle: support running within a VM To: Jacob Pan , "Michael S. Tsirkin" Cc: "Rafael J. Wysocki" , Yang Zhang , Linux Kernel Mailing List , kvm@vger.kernel.org, Wanpeng Li , Thomas Gleixner , rkrcmar@redhat.com, dmatlack@google.com, agraf@suse.de, Peter Zijlstra , Len Brown , Linux PM , "Raj, Ashok" References: <20170930005046-mutt-send-email-mst@kernel.org> <20171002101249.69b5611a@jacob-builder> <20171004050706-mutt-send-email-mst@kernel.org> <20171004100939.1893e4a7@jacob-builder> <20171004201125-mutt-send-email-mst@kernel.org> <20171004113143.503032f0@jacob-builder> From: Paolo Bonzini Message-ID: <79e169dc-9848-ff48-4a20-50a98adfeb44@redhat.com> Date: Thu, 5 Oct 2017 12:44:53 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <20171004113143.503032f0@jacob-builder> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Thu, 05 Oct 2017 10:45:15 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 04/10/2017 20:31, Jacob Pan wrote: > On Wed, 4 Oct 2017 20:12:28 +0300 > "Michael S. Tsirkin" wrote: > >> On Wed, Oct 04, 2017 at 10:09:39AM -0700, Jacob Pan wrote: >>> On Wed, 4 Oct 2017 05:09:09 +0300 >>> "Michael S. Tsirkin" wrote: >>> >>>> On Mon, Oct 02, 2017 at 10:12:49AM -0700, Jacob Pan wrote: >>>>> On Sat, 30 Sep 2017 01:21:43 +0200 >>>>> "Rafael J. Wysocki" wrote: >>>>> >>>>>> On Sat, Sep 30, 2017 at 12:01 AM, Michael S. Tsirkin >>>>>> wrote: >>>>>>> intel idle driver does not DTRT when running within a VM: >>>>>>> when going into a deep power state, the right thing to >>>>>>> do is to exit to hypervisor rather than to keep polling >>>>>>> within guest using mwait. >>>>>>> >>>>>>> Currently the solution is just to exit to hypervisor each >>>>>>> time we go idle - this is why kvm does not expose the mwait >>>>>>> leaf to guests even when it allows guests to do mwait. >>>>>>> >>>>>>> But that's not ideal - it seems better to use the idle >>>>>>> driver to guess when will the next interrupt arrive. >>>>>> >>>>>> The idle driver alone is not sufficient for that, though. >>>>>> >>>>> I second that. Why try to solve this problem at vendor specific >>>>> driver level? >>>> >>>> Well we still want to e.g. mwait if possible - saves power. >>>> >>>>> perhaps just a pv idle driver that decide whether to vmexit >>>>> based on something like local per vCPU timer expiration? I >>>>> guess we can't predict other wake events such as interrupts. >>>>> e.g. >>>>> if (get_next_timer_interrupt() > kvm_halt_target_residency) >>>>> vmexit >>>>> else >>>>> poll >>>>> >>>>> Jacob >>>> >>>> It's not always a poll, on x86 putting the CPU in a low power >>>> state is possible within a VM. >>>> >>> Are you talking about using mwait/monitor in the user space which >>> are available on some Intel CPUs, such as Xeon Phi? I guess if the >>> guest can identify host CPU id, it is doable. >> >> Not really. >> >> Please take a look at the patch in question - it does mwait in guest >> kernel and no need to identify host CPU id. >> > I may be missing something, in your patch I only see HLT being used in > the guest OS, that would cause VM exit right? If you do mwait in the > guest kernel, it will also exit. So I don't see how you can enter low > power state within VM guest. KVM does not exit on MWAIT (though it doesn't show it in CPUID by default), see commit 668fffa3f838edfcb1679f842f7ef1afa61c3e9a. Paolo > > +static int intel_halt(struct cpuidle_device *dev, > + struct cpuidle_driver *drv, int index) > +{ > + printk_once(KERN_ERR "safe_halt started\n"); > + safe_halt(); > + printk_once(KERN_ERR "safe_halt done\n"); > + return index; > +} >> >>>> Does not seem possible on other CPUs that's why it's vendor >>>> specific. >>> >>> [Jacob Pan] > > [Jacob Pan] >