All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ricardo Neri <ricardo.neri-calderon@linux.intel.com>
To: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
Cc: Len Brown <len.brown@intel.com>,
	Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>,
	Stanislaw Gruszka <stanislaw.gruszka@linux.intel.com>,
	Zhao Liu <zhao1.liu@intel.com>,
	Zhuocheng Ding <zhuocheng.ding@intel.com>,
	x86@kernel.org, linux-pm@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Ricardo Neri <ricardo.neri-calderon@linux.intel.com>,
	Zhao Liu <zhao1.liu@linux.intel.com>
Subject: [PATCH 9/9] x86/cpu: Introduce interface to reset hardware history
Date: Fri,  2 Feb 2024 20:05:15 -0800	[thread overview]
Message-ID: <20240203040515.23947-10-ricardo.neri-calderon@linux.intel.com> (raw)
In-Reply-To: <20240203040515.23947-1-ricardo.neri-calderon@linux.intel.com>

KVM needs an interface to reset the history of vCPU at context switch.
When called, hardware will start the classification of the next task
from scratch.

Cc: Len Brown <len.brown@intel.com>
Cc: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Cc: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Cc: Stanislaw Gruszka <stanislaw.gruszka@linux.intel.com>
Cc: Zhao Liu <zhao1.liu@linux.intel.com>
Cc: Zhuocheng Ding <zhuocheng.ding@intel.com>
Cc: x86@kernel.org
Cc: linux-pm@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ricardo Neri <ricardo.neri-calderon@linux.intel.com>
---
Patch cherry-picked from the IPC classes patchset. Removed calls to
reset_hardware_history() from context switch. Now KVM will call it
directly when needed.
---
 * Measurements of the cost of the HRESET instruction

   Methodology:
   I created a tight loop with interrupts and preemption disabled. I
   recorded the value of the TSC counter before and after executing
   HRESET or RDTSC. I repeated the measurement 100,000 times.
   I performed the experiment using an Alder Lake S system. I set the
   frequency of the CPUs at a fixed value.

   The table below compares the cost of HRESET with RDTSC (expressed in
   the elapsed TSC count). The cost of the two instructions is
   comparable.

                              PCore      ECore
        Frequency (GHz)        5.0        3.8
        HRESET (avg)          28.5       44.7
        HRESET (stdev %)       3.6        2.3
        RDTSC  (avg)          25.2       35.7
        RDTSC  (stdev %)       3.9        2.6
---
 arch/x86/include/asm/hreset.h | 30 ++++++++++++++++++++++++++++++
 arch/x86/kernel/cpu/common.c  |  8 ++++++++
 2 files changed, 38 insertions(+)
 create mode 100644 arch/x86/include/asm/hreset.h

diff --git a/arch/x86/include/asm/hreset.h b/arch/x86/include/asm/hreset.h
new file mode 100644
index 000000000000..d68ca2fb8642
--- /dev/null
+++ b/arch/x86/include/asm/hreset.h
@@ -0,0 +1,30 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _ASM_X86_HRESET_H
+
+/**
+ * HRESET - History reset. Available since binutils v2.36.
+ *
+ * Request the processor to reset the history of task classification on the
+ * current logical processor. The history components to be
+ * reset are specified in %eax. Only bits specified in CPUID(0x20).EBX
+ * and enabled in the IA32_HRESET_ENABLE MSR can be selected.
+ *
+ * The assembly code looks like:
+ *
+ *	hreset %eax
+ *
+ * The corresponding machine code looks like:
+ *
+ *	F3 0F 3A F0 ModRM Imm
+ *
+ * The value of ModRM is 0xc0 to specify %eax register addressing.
+ * The ignored immediate operand is set to 0.
+ *
+ * The instruction is documented in the Intel SDM.
+ */
+
+#define __ASM_HRESET  ".byte 0xf3, 0xf, 0x3a, 0xf0, 0xc0, 0x0"
+
+void reset_hardware_history(void);
+
+#endif /* _ASM_X86_HRESET_H */
diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
index bce8719b47c9..ab9809520164 100644
--- a/arch/x86/kernel/cpu/common.c
+++ b/arch/x86/kernel/cpu/common.c
@@ -57,6 +57,7 @@
 #include <asm/mce.h>
 #include <asm/msr.h>
 #include <asm/cacheinfo.h>
+#include <asm/hreset.h>
 #include <asm/memtype.h>
 #include <asm/microcode.h>
 #include <asm/intel-family.h>
@@ -383,6 +384,13 @@ static __always_inline void setup_umip(struct cpuinfo_x86 *c)
 
 static u32 hardware_history_features __ro_after_init;
 
+void reset_hardware_history(void)
+{
+	asm_inline volatile (ALTERNATIVE("", __ASM_HRESET, X86_FEATURE_HRESET)
+			     : : "a" (hardware_history_features) : "memory");
+}
+EXPORT_SYMBOL(reset_hardware_history);
+
 static __always_inline void setup_hreset(struct cpuinfo_x86 *c)
 {
 	if (!cpu_feature_enabled(X86_FEATURE_HRESET))
-- 
2.25.1


  parent reply	other threads:[~2024-02-03  4:04 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-03  4:05 [PATCH 0/9] thermal: intel: hfi: Prework for the virtualization of HFI Ricardo Neri
2024-02-03  4:05 ` [PATCH 1/9] thermal: intel: hfi: Relocate bit definitions of HFI registers Ricardo Neri
2024-02-03  4:05 ` [PATCH 2/9] thermal: intel: hfi: Introduce the hfi_table structure Ricardo Neri
2024-02-03  4:05 ` [PATCH 3/9] thermal: intel: hfi: Move selected data structures to a header file Ricardo Neri
2024-02-03  4:05 ` [PATCH 4/9] thermal: intel: hfi: Introduce Intel Thread Director classes Ricardo Neri
2024-02-03  4:05 ` [PATCH 5/9] x86/cpufeatures: Add the Intel Thread Director feature definitions Ricardo Neri
2024-02-03  4:05 ` [PATCH 6/9] thermal: intel: hfi: Enable Intel Thread Director Ricardo Neri
2024-02-05 10:28   ` Stanislaw Gruszka
2024-02-06  2:57     ` Ricardo Neri
2024-02-03  4:05 ` [PATCH 7/9] x86/cpufeatures: Add feature bit for HRESET Ricardo Neri
2024-02-03  9:36   ` Borislav Petkov
2024-02-04  3:49     ` Ricardo Neri
2024-02-03  4:05 ` [PATCH 8/9] x86/hreset: Configure history reset Ricardo Neri
2024-02-03  9:38   ` Borislav Petkov
2024-02-04  3:55     ` Ricardo Neri
2024-02-04 10:49       ` Borislav Petkov
2024-02-06  2:37         ` Ricardo Neri
2024-02-03  4:05 ` Ricardo Neri [this message]
2024-02-03  9:40   ` [PATCH 9/9] x86/cpu: Introduce interface to reset hardware history Borislav Petkov
2024-02-04  3:48     ` Ricardo Neri
2024-02-06  2:59 ` [PATCH 0/9] thermal: intel: hfi: Prework for the virtualization of HFI Ricardo Neri

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=20240203040515.23947-10-ricardo.neri-calderon@linux.intel.com \
    --to=ricardo.neri-calderon@linux.intel.com \
    --cc=len.brown@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=rafael.j.wysocki@intel.com \
    --cc=srinivas.pandruvada@linux.intel.com \
    --cc=stanislaw.gruszka@linux.intel.com \
    --cc=x86@kernel.org \
    --cc=zhao1.liu@intel.com \
    --cc=zhao1.liu@linux.intel.com \
    --cc=zhuocheng.ding@intel.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.