xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Xen-devel <xen-devel@lists.xen.org>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
	Jan Beulich <JBeulich@suse.com>
Subject: [PATCH 5/5] x86/monitor: Capture Xen's intent to use monitor at boot time
Date: Fri, 12 Jan 2018 18:37:24 +0000	[thread overview]
Message-ID: <1515782244-6412-6-git-send-email-andrew.cooper3@citrix.com> (raw)
In-Reply-To: <1515782244-6412-1-git-send-email-andrew.cooper3@citrix.com>

The ACPI idle driver uses an IPI to retrieve cpuid_ecx(5).  This is wasteful.

Introduce X86_FEATURE_XEN_MONITOR as a synthetic feature bit meaning MONITOR
&& EXTENSIONS && INTERRUPT_BREAK, and calculate it when a cpu comes up rather
than repeatedly at runtime.

Drop the duplicate defines for MWAIT cpuid information, and use the
definitions from mwait.h

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Jan Beulich <JBeulich@suse.com>
---
 xen/arch/x86/acpi/lib.c           | 16 +---------------
 xen/arch/x86/cpu/common.c         |  7 +++++++
 xen/include/asm-x86/cpufeature.h  |  5 +----
 xen/include/asm-x86/cpufeatures.h |  1 +
 xen/include/asm-x86/mwait.h       |  3 +++
 5 files changed, 13 insertions(+), 19 deletions(-)

diff --git a/xen/arch/x86/acpi/lib.c b/xen/arch/x86/acpi/lib.c
index 7d7c718..1d64e74 100644
--- a/xen/arch/x86/acpi/lib.c
+++ b/xen/arch/x86/acpi/lib.c
@@ -80,16 +80,10 @@ unsigned int acpi_get_processor_id(unsigned int cpu)
 	return INVALID_ACPIID;
 }
 
-static void get_mwait_ecx(void *info)
-{
-	*(u32 *)info = cpuid_ecx(CPUID_MWAIT_LEAF);
-}
-
 int arch_acpi_set_pdc_bits(u32 acpi_id, u32 *pdc, u32 mask)
 {
 	unsigned int cpu = get_cpu_id(acpi_id);
 	struct cpuinfo_x86 *c;
-	u32 ecx;
 
 	if (!(acpi_id + 1))
 		c = &boot_cpu_data;
@@ -110,15 +104,7 @@ int arch_acpi_set_pdc_bits(u32 acpi_id, u32 *pdc, u32 mask)
 	 * If mwait/monitor or its break-on-interrupt extension are
 	 * unsupported, Cx_FFH will be disabled.
 	 */
-	if (!cpu_has(c, X86_FEATURE_MONITOR) ||
-	    c->cpuid_level < CPUID_MWAIT_LEAF)
-		ecx = 0;
-	else if (c == &boot_cpu_data || cpu == smp_processor_id())
-		ecx = cpuid_ecx(CPUID_MWAIT_LEAF);
-	else
-		on_selected_cpus(cpumask_of(cpu), get_mwait_ecx, &ecx, 1);
-	if (!(ecx & CPUID5_ECX_EXTENSIONS_SUPPORTED) ||
-	    !(ecx & CPUID5_ECX_INTERRUPT_BREAK))
+	if ( !cpu_has_xen_monitor )
 		pdc[2] &= ~(ACPI_PDC_C_C1_FFH | ACPI_PDC_C_C2C3_FFH);
 
 	return 0;
diff --git a/xen/arch/x86/cpu/common.c b/xen/arch/x86/cpu/common.c
index 0a5c6ad..ffc5230 100644
--- a/xen/arch/x86/cpu/common.c
+++ b/xen/arch/x86/cpu/common.c
@@ -12,6 +12,7 @@
 #include <mach_apic.h>
 #include <asm/setup.h>
 #include <public/sysctl.h> /* for XEN_INVALID_{SOCKET,CORE}_ID */
+#include <asm/mwait.h>
 
 #include "cpu.h"
 
@@ -312,6 +313,12 @@ static void generic_identify(struct cpuinfo_x86 *c)
 	if ( cpu_has(c, X86_FEATURE_CLFLUSH) )
 		c->x86_clflush_size = ((ebx >> 8) & 0xff) * 8;
 
+	/* Xen only uses MONITOR if INTERRUPT_BREAK is available. */
+	if ( cpu_has(c, X86_FEATURE_MONITOR) &&
+	     ((cpuid_ecx(CPUID_MWAIT_LEAF) & CPUID_MWAIT_MIN_FEATURES) ==
+	      CPUID_MWAIT_MIN_FEATURES) )
+		set_bit(X86_FEATURE_XEN_MONITOR, c->x86_capability);
+
 	if ( (c->cpuid_level >= CPUID_PM_LEAF) &&
 	     (cpuid_ecx(CPUID_PM_LEAF) & CPUID6_ECX_APERFMPERF_CAPABILITY) )
 		set_bit(X86_FEATURE_APERFMPERF, c->x86_capability);
diff --git a/xen/include/asm-x86/cpufeature.h b/xen/include/asm-x86/cpufeature.h
index 84cc51d..8b24e0e 100644
--- a/xen/include/asm-x86/cpufeature.h
+++ b/xen/include/asm-x86/cpufeature.h
@@ -22,10 +22,6 @@
 #define cpu_has(c, bit)		test_bit(bit, (c)->x86_capability)
 #define boot_cpu_has(bit)	test_bit(bit, boot_cpu_data.x86_capability)
 
-#define CPUID_MWAIT_LEAF                5
-#define CPUID5_ECX_EXTENSIONS_SUPPORTED 0x1
-#define CPUID5_ECX_INTERRUPT_BREAK      0x2
-
 #define CPUID_PM_LEAF                    6
 #define CPUID6_ECX_APERFMPERF_CAPABILITY 0x1
 
@@ -104,6 +100,7 @@
 #define cpu_has_arch_perfmon    boot_cpu_has(X86_FEATURE_ARCH_PERFMON)
 #define cpu_has_cpuid_faulting  boot_cpu_has(X86_FEATURE_CPUID_FAULTING)
 #define cpu_has_aperfmperf      boot_cpu_has(X86_FEATURE_APERFMPERF)
+#define cpu_has_xen_monitor     boot_cpu_has(X86_FEATURE_XEN_MONITOR)
 
 enum _cache_type {
     CACHE_TYPE_NULL = 0,
diff --git a/xen/include/asm-x86/cpufeatures.h b/xen/include/asm-x86/cpufeatures.h
index bc98227..98637d0 100644
--- a/xen/include/asm-x86/cpufeatures.h
+++ b/xen/include/asm-x86/cpufeatures.h
@@ -22,3 +22,4 @@ XEN_CPUFEATURE(APERFMPERF,      (FSCAPINTS+0)*32+ 8) /* APERFMPERF */
 XEN_CPUFEATURE(MFENCE_RDTSC,    (FSCAPINTS+0)*32+ 9) /* MFENCE synchronizes RDTSC */
 XEN_CPUFEATURE(XEN_SMEP,        (FSCAPINTS+0)*32+10) /* SMEP gets used by Xen itself */
 XEN_CPUFEATURE(XEN_SMAP,        (FSCAPINTS+0)*32+11) /* SMAP gets used by Xen itself */
+XEN_CPUFEATURE(XEN_MONITOR,     (FSCAPINTS+0)*32+12) /* Xen uses MONITOR */
diff --git a/xen/include/asm-x86/mwait.h b/xen/include/asm-x86/mwait.h
index ba9c0ea..a1bfeb1 100644
--- a/xen/include/asm-x86/mwait.h
+++ b/xen/include/asm-x86/mwait.h
@@ -9,6 +9,9 @@
 #define CPUID5_ECX_EXTENSIONS_SUPPORTED 0x1
 #define CPUID5_ECX_INTERRUPT_BREAK	0x2
 
+#define CPUID_MWAIT_MIN_FEATURES \
+    (CPUID5_ECX_EXTENSIONS_SUPPORTED | CPUID5_ECX_INTERRUPT_BREAK)
+
 #define MWAIT_ECX_INTERRUPT_BREAK	0x1
 
 void mwait_idle_with_hints(unsigned int eax, unsigned int ecx);
-- 
2.1.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

  parent reply	other threads:[~2018-01-12 18:37 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-12 18:37 [PATCH 0/5] x86: Misc improvements from KAISER-prep work Andrew Cooper
2018-01-12 18:37 ` [PATCH 1/5] x86/idt: Factor out enabling and disabling of ISTs Andrew Cooper
2018-01-12 20:12   ` Doug Goldstein
2018-01-17 14:43   ` Wei Liu
2018-01-18  7:43     ` Jan Beulich
2018-01-12 18:37 ` [PATCH 2/5] x86/pv: Rename invalidate_shadow_ldt() to pv_destroy_ldt() Andrew Cooper
2018-01-12 20:15   ` Doug Goldstein
2018-01-17 14:43   ` Wei Liu
2018-01-18  7:45     ` Jan Beulich
2018-01-12 18:37 ` [PATCH 3/5] x86/pv: Break handle_ldt_mapping_fault() out of handle_gdt_ldt_mapping_fault() Andrew Cooper
2018-01-12 20:22   ` Doug Goldstein
2018-01-18  7:48   ` Jan Beulich
2018-01-12 18:37 ` [PATCH 4/5] x86/pv: Drop support for paging out the LDT Andrew Cooper
2018-01-12 21:53   ` Doug Goldstein
2018-01-18  7:59   ` Jan Beulich
2018-01-18 10:38     ` George Dunlap
2018-01-18 10:57       ` Jan Beulich
2018-01-18 10:57       ` Andrew Cooper
2018-01-18 11:00         ` Andrew Cooper
2018-01-18 11:37           ` Jan Beulich
2018-01-12 18:37 ` Andrew Cooper [this message]
2018-01-18  8:05   ` [PATCH 5/5] x86/monitor: Capture Xen's intent to use monitor at boot time Jan Beulich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1515782244-6412-6-git-send-email-andrew.cooper3@citrix.com \
    --to=andrew.cooper3@citrix.com \
    --cc=JBeulich@suse.com \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).