From nobody Mon Apr 29 02:22:45 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1528491632089503.33315349835686; Fri, 8 Jun 2018 14:00:32 -0700 (PDT) Received: from localhost ([::1]:38176 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fROUe-0004g8-Vf for importer@patchew.org; Fri, 08 Jun 2018 17:00:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56182) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fROTk-0004ES-T2 for qemu-devel@nongnu.org; Fri, 08 Jun 2018 16:59:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fROTh-0002jG-1E for qemu-devel@nongnu.org; Fri, 08 Jun 2018 16:59:24 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:49402 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fROTg-0002iu-SA for qemu-devel@nongnu.org; Fri, 08 Jun 2018 16:59:20 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 23D1379D36; Fri, 8 Jun 2018 20:59:20 +0000 (UTC) Received: from redhat.com (ovpn-120-126.rdu2.redhat.com [10.10.120.126]) by smtp.corp.redhat.com (Postfix) with SMTP id C4CEB11166E2; Fri, 8 Jun 2018 20:59:19 +0000 (UTC) Date: Fri, 8 Jun 2018 23:59:19 +0300 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Message-ID: <20180608205830.308627-1-mst@redhat.com> MIME-Version: 1.0 Content-Disposition: inline X-Mutt-Fcc: =sent X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 08 Jun 2018 20:59:20 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 08 Jun 2018 20:59:20 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mst@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [RFC untested PATCH] i386/cpu: make -cpu host support monitor/mwait X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Eduardo Habkost , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When guest CPU PM is enabled, and with -cpu host, expose the host CPU MWAIT leaf to guest so guest can make good PM decisions. Signed-off-by: Michael S. Tsirkin Reviewed-by: Eduardo Habkost --- This builds but is untested. Is this a reasonable way to go about it? target/i386/cpu.h | 9 +++++++++ target/i386/cpu.c | 18 +++++++++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 664504610e..309f804573 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1378,6 +1378,15 @@ struct X86CPU { /* if true the CPUID code directly forward host cache leaves to the gu= est */ bool cache_info_passthrough; =20 + /* if true the CPUID code directly forwards + * host monitor/mwait leaves to the guest */ + struct { + uint32_t eax; + uint32_t ebx; + uint32_t ecx; + uint32_t edx; + } mwait; + /* Features that were filtered out because of missing host capabilitie= s */ uint32_t filtered_features[FEATURE_WORDS]; =20 diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 94260412e2..a49443de56 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -3760,11 +3760,11 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index= , uint32_t count, } break; case 5: - /* mwait info: needed for Core compatibility */ - *eax =3D 0; /* Smallest monitor-line size in bytes */ - *ebx =3D 0; /* Largest monitor-line size in bytes */ - *ecx =3D CPUID_MWAIT_EMX | CPUID_MWAIT_IBE; - *edx =3D 0; + /* MONITOR/MWAIT Leaf */ + *eax =3D cpu->mwait.eax; /* Smallest monitor-line size in bytes */ + *ebx =3D cpu->mwait.ebx; /* Largest monitor-line size in bytes */ + *ecx =3D cpu->mwait.ecx; /* flags */ + *edx =3D cpu->mwait.edx; /* mwait substates */ break; case 6: /* Thermal and Power Leaf */ @@ -4595,6 +4595,14 @@ static void x86_cpu_realizefn(DeviceState *dev, Erro= r **errp) goto out; } =20 + if (xcc->host_cpuid_required && enable_cpu_pm) { + host_cpuid(5, 0, &cpu->mwait.eax, &cpu->mwait.ebx, + &cpu->mwait.ecx, &cpu->mwait.edx); + } + /* We always wake on interrupt even if host does not have the capabili= ty */ + /* mwait extended info: needed for Core compatibility */ + cpu->mwait.ecx |=3D CPUID_MWAIT_EMX | CPUID_MWAIT_IBE; + if (cpu->apic_id =3D=3D UNASSIGNED_APIC_ID) { error_setg(errp, "apic-id property was not initialized properly"); return; --=20 MST