Add a header for MSR_PKG_CST_CONFIG_CONTROL
Subsystems (4)
Artem Bityutskiy
maintainerv2 cover Add a header for MSR_PKG_CST_CONFIG_CONTROL
From: Artem Bityutskiy <[email protected]>
Implement a suggestion from Rafael Wysocki. Previous version of the RFC:
https://lore.kernel.org/linux-pm/[email protected]/T/#t
The suggestion is to add a common helper for switching the C1 demotion feature on/off via MSR_PKG_CST_CONFIG_CONTROL.
Still RFC because I feel like the common helper is not universal enough, because the bit number was different on the Lincroft platform, and the MSR is not architectural, so may change from platform to platform.
Therefore, just to linux-pm as RFC so far, and as a single patch.
This patch applies on top of the following patch-set that I sent to linux-pm a bit earlier today:
Subject: [PATCH v3 0/3] intel_idle: Add C1 demotion on/off sysfs knob
Artem Bityutskiy (1):
x86: msr: add 'msr_pkg_cst_config_control.h' header
.../include/asm/msr_pkg_cst_config_control.h | 41 +++++++++++++++++++ drivers/idle/intel_idle.c | 10 +---- drivers/platform/x86/intel/pmc/cnp.c | 7 ++-- 3 files changed, 46 insertions(+), 12 deletions(-) create mode 100644 arch/x86/include/asm/msr_pkg_cst_config_control.h
Signature · 1 line
2.48.1
Artem Bityutskiy
maintainerRFC PATCH v2 1/1 x86: msr: add 'msr_pkg_cst_config_control.h' header
From: Artem Bityutskiy <[email protected]>
There are now two places where the C1 demotion feature gets enabled/disabled using the read-modify-write semantics:
1. The Intel PMC framework (cnp.c).
2. The intel_idle.c driver.
Introduce a common helper function enabling/disabling C1 demotion bit of the MSR_PKG_CST_CONFIG_CONTROL register.
--- .../include/asm/msr_pkg_cst_config_control.h | 41 +++++++++++++++++++ drivers/idle/intel_idle.c | 10 +---- drivers/platform/x86/intel/pmc/cnp.c | 7 ++-- 3 files changed, 46 insertions(+), 12 deletions(-) create mode 100644 arch/x86/include/asm/msr_pkg_cst_config_control.h
arch/x86/include/asm/msr_pkg_cst_config_control.h new file +41 -0
@@ -0,0 +1,41 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Accessor functions for the MSR_PKG_CST_CONFIG_CONTROL (0xE2) MSR, found on +* some Intel processors. +*/ + +#ifndef _MSR_PKG_CST_CONFIG_CONTROL_H +#define _MSR_PKG_CST_CONFIG_CONTROL_H + +#include <asm/msr-index.h> +#include <asm/msr.h> + +/** +* msr_pkg_cst_config_set_c1_demotion - Enable/disable C1 demotion. +* @set: Enable C1 demotion if true, disable it if false. +* @other_bits: Additional bits to set or clear in the register. +* +* Read-modify-write the MSR_PKG_CST_CONFIG_CONTROL register to enable or +* disable C1 demotion. The caller should take care of locking if necessary. +* +* Return: The new value of the MSR_PKG_CST_CONFIG_CONTROL register after +* modification. +*/ +static inline unsigned long long +msr_pkg_cst_config_set_c1_demotion (bool set,unsigned long long other_bits) +{ +unsigned long long val; + +rdmsrl (MSR_PKG_CST_CONFIG_CONTROL , val); + +if (set) + val |=NHM_C1_AUTO_DEMOTE | other_bits; +else + val &= ~(NHM_C1_AUTO_DEMOTE | other_bits); + +wrmsrl (MSR_PKG_CST_CONFIG_CONTROL , val); + +return val; +} + +#endif /* _MSR_PKG_CST_CONFIG_CONTROL_H */
drivers/idle/intel_idle.c +2 -8
@@ -60,6 +60,7 @@#include <asm/spec-ctrl.h> #include <asm/tsc.h> #include <asm/fpu/api.h> +#include <asm/msr_pkg_cst_config_control.h> #define INTEL_IDLE_VERSION "0.5.1"
@@ -2325,18 +2326,11 @@ static void __init intel_idle_cpuidle_devices_uninit(void)static void intel_c1_demotion_toggle (void *enable) { -unsigned long long msr_val; - -rdmsrl (MSR_PKG_CST_CONFIG_CONTROL , msr_val);/* * Enable/disable C1 undemotion along with C1 demotion, as this is the * most sensible configuration in general. */ -if (enable) - msr_val |=NHM_C1_AUTO_DEMOTE |SNB_C1_AUTO_UNDEMOTE ; -else - msr_val &= ~(NHM_C1_AUTO_DEMOTE |SNB_C1_AUTO_UNDEMOTE ); -wrmsrl (MSR_PKG_CST_CONFIG_CONTROL , msr_val); +msr_pkg_cst_config_set_c1_demotion (!!enable,SNB_C1_AUTO_UNDEMOTE ); } static ssize_t intel_c1_demotion_store(struct device *dev,
drivers/platform/x86/intel/pmc/cnp.c +3 -4
@@ -10,6 +10,7 @@#include <linux/smp.h> #include <linux/suspend.h> +#include <asm/msr_pkg_cst_config_control.h> #include "core.h" /* Cannon Lake: PGD PFET Enable Ack Status Register(s) bitmap */
@@ -227,10 +228,8 @@ static void disable_c1_auto_demote(void *unused)int cpunum =smp_processor_id ();u64 val; -rdmsrl (MSR_PKG_CST_CONFIG_CONTROL , val); -per_cpu (pkg_cst_config, cpunum) = val; - val &= ~NHM_C1_AUTO_DEMOTE ; -wrmsrl (MSR_PKG_CST_CONFIG_CONTROL , val); + val = msr_pkg_cst_config_set_c1_demotion(false, 0) + per_cpu(pkg_cst_config, cpunum) = valpr_debug ("%s: cpu:%d cst %llx\n" , __func__, cpunum, val); }
Signature · 1 line
2.48.1
Artem Bityutskiy
maintainerRe: [RFC PATCH v2 1/1] x86: msr: add 'msr_pkg_cst_config_control.h' header
Hi Rafael,
I was thinking to send this to the x86 mailing list as an RFC, but I have some doubts still. May be you could comment.
I keep the entire patch in the reply for convenience (did not strip the e-mail).
Quoted 29 lines · Artem Bityutskiy
From: Artem Bityutskiy <[email protected]>
There are now two places where the C1 demotion feature gets enabled/disabled using the read-modify-write semantics:
1. The Intel PMC framework (cnp.c).
2. Theintel_idle.cdriver.Introduce a common helper function enabling/disabling C1 demotion bit of the
MSR_PKG_CST_CONFIG_CONTROLregister.Signed-off-by Artem Bityutskiy <[email protected]>---
.../include/asm/msr_pkg_cst_config_control.h | 41 +++++++++++++++++++ drivers/idle/intel_idle.c | 10 +---- drivers/platform/x86/intel/pmc/cnp.c | 7 ++--3 files changed, 46 insertions(+), 12 deletions(-)create mode 100644
arch/x86/include/asm/msr_pkg_cst_config_control.harch/x86/include/asm/msr_pkg_cst_config_control.h new file +4
-0@@ -0,0 +1,41 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Accessor functions for the MSR_PKG_CST_CONFIG_CONTROL (0xE2) MSR, found on +* some Intel processors.
arch/x86/include/asm/msr_pkg_cst_config_control.h line 14
Quoted 10 lines
arch/x86/include/asm/msr_pkg_cst_config_control.h new file +10
-0+*/ + +#ifndef _MSR_PKG_CST_CONFIG_CONTROL_H +#define _MSR_PKG_CST_CONFIG_CONTROL_H + +#include <asm/msr-index.h> +#include <asm/msr.h> + +/** +* msr_pkg_cst_config_set_c1_demotion - Enable/disable C1 demotion.
Doubt #1: on some platforms C1 demotion is enabled/disabled using a different MSR. For example, see
for Bay Trail and Cherry Trail platforms.
arch/x86/include/asm/msr_pkg_cst_config_control.h line 15
Quoted 1 line
arch/x86/include/asm/msr_pkg_cst_config_control.h new file +1
-0+* @set: Enable C1 demotion if true, disable it if false.
Doubt #2: OK, so here we have a boolean - feature enable/disable. No assumption if enabled = some bit set or if enabled = some bit cleared.
In general, not specific for C1 demotion: sometimes feature enabled = some bit set, sometimes feature enabled = some bit cleared.
So far so good.
arch/x86/include/asm/msr_pkg_cst_config_control.h line 16
Quoted 1 line
arch/x86/include/asm/msr_pkg_cst_config_control.h new file +1
-0+* @other_bits: Additional bits to set or clear in the register.
But here:
* if set == True, other_bits will be set
* if set == False, other_bits will be cleared.
So if we happen to have a "FEATURE_X_DISABLE" bit in the same MSR, this new helper function becomes not-so-helpful: we cannot enable/disable C1 demotion and FEATURE_X using one function call.
And also it is just a subtle assumption, reducing the value of this function.
Quoted 85 lines
arch/x86/include/asm/msr_pkg_cst_config_control.h new file +25
-0+* +* Read-modify-write the MSR_PKG_CST_CONFIG_CONTROL register to enable or +* disable C1 demotion. The caller should take care of locking if necessary. +* +* Return: The new value of the MSR_PKG_CST_CONFIG_CONTROL register after +* modification. +*/ +static inline unsigned long long +msr_pkg_cst_config_set_c1_demotion (bool set,unsigned long long other_bits) +{ +unsigned long long val; + +rdmsrl (MSR_PKG_CST_CONFIG_CONTROL , val); + +if (set) + val |=NHM_C1_AUTO_DEMOTE | other_bits; +else + val &= ~(NHM_C1_AUTO_DEMOTE | other_bits); + +wrmsrl (MSR_PKG_CST_CONFIG_CONTROL , val); + +return val; +} + +#endif /* _MSR_PKG_CST_CONFIG_CONTROL_H */ drivers/idle/intel_idle.c +1
-0@@ -60,6 +60,7 @@ #include <asm/spec-ctrl.h> #include <asm/tsc.h> #include <asm/fpu/api.h> +#include <asm/msr_pkg_cst_config_control.h>
#defineINTEL_IDLE_VERSION"0.5.1"drivers/idle/intel_idle.c +0
-0@@ -2325,18 +2326,11 @@ static void __initintel_idle_cpuidle_devices_uninit (void)
static voidintel_c1_demotion_toggle(void *enable){drivers/idle/intel_idle.c +0
-3-unsigned long long msr_val; - -rdmsrl (MSR_PKG_CST_CONFIG_CONTROL , msr_val);/*
* Enable/disable C1 undemotion along with C1 demotion, as this is the
* most sensible configuration in general.
*/drivers/idle/intel_idle.c +1
-5-if (enable) - msr_val |=NHM_C1_AUTO_DEMOTE |SNB_C1_AUTO_UNDEMOTE ; -else - msr_val &= ~(NHM_C1_AUTO_DEMOTE |SNB_C1_AUTO_UNDEMOTE ); -wrmsrl (MSR_PKG_CST_CONFIG_CONTROL , msr_val); +msr_pkg_cst_config_set_c1_demotion (!!enable,SNB_C1_AUTO_UNDEMOTE );}
staticssize_tintel_c1_demotion_store(struct device *dev,drivers/platform/x86/intel/pmc/cnp.c +0
-0@@ -10,6 +10,7 @@
#include <linux/smp.h>
#include <linux/suspend.h>
+#include <asm/msr_pkg_cst_config_control.h>
#include "core.h"
/* Cannon Lake: PGD PFET Enable Ack Status Register(s) bitmap */drivers/platform/x86/intel/pmc/cnp.c +0
-0@@ -227,10 +228,8 @@ static void disable_c1_auto_demote(void *unused) int cpunum = smp_processor_id(); u64 val;drivers/platform/x86/intel/pmc/cnp.c +2
-4-rdmsrl (MSR_PKG_CST_CONFIG_CONTROL , val); -per_cpu (pkg_cst_config, cpunum) = val; - val &= ~NHM_C1_AUTO_DEMOTE ; -wrmsrl (MSR_PKG_CST_CONFIG_CONTROL , val); + val = msr_pkg_cst_config_set_c1_demotion(false, 0) +per_cpu (pkg_cst_config, cpunum) = val
pr_debug("%s: cpu:%d cst %llx\n", __func__, cpunum, val); }
Rafael J. Wysocki
maintainerRe: [RFC PATCH v2 1/1] x86: msr: add 'msr_pkg_cst_config_control.h' header
Hi Artem,
Quoted 72 lines · Artem Bityutskiy
Hi Rafael,
I was thinking to send this to the x86 mailing list as an RFC, but I have some doubts still. May be you could comment.
I keep the entire patch in the reply for convenience (did not strip the e-mail).
Quoted 29 lines · Artem Bityutskiy
From: Artem Bityutskiy <[email protected]>
There are now two places where the C1 demotion feature gets enabled/disabled using the read-modify-write semantics:
1. The Intel PMC framework (cnp.c).
2. Theintel_idle.cdriver.Introduce a common helper function enabling/disabling C1 demotion bit of the
MSR_PKG_CST_CONFIG_CONTROLregister.Signed-off-by Artem Bityutskiy <[email protected]>--- .../include/asm/msr_pkg_cst_config_control.h | 41 +++++++++++++++++++ drivers/idle/intel_idle.c | 10 +---- drivers/platform/x86/intel/pmc/cnp.c | 7 ++-- 3 files changed, 46 insertions(+), 12 deletions(-) create mode 100644 arch/x86/include/asm/msr_pkg_cst_config_control.harch/x86/include/asm/msr_pkg_cst_config_control.h new file +4
-0@@ -0,0 +1,41 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Accessor functions for the MSR_PKG_CST_CONFIG_CONTROL (0xE2) MSR, found on +* some Intel processors. arch/x86/include/asm/msr_pkg_cst_config_control.h line 14
Quoted 10 lines
arch/x86/include/asm/msr_pkg_cst_config_control.h new file +10
-0+*/ + +#ifndef _MSR_PKG_CST_CONFIG_CONTROL_H +#define _MSR_PKG_CST_CONFIG_CONTROL_H + +#include <asm/msr-index.h> +#include <asm/msr.h> + +/** +* msr_pkg_cst_config_set_c1_demotion - Enable/disable C1 demotion. Doubt #1: on some platforms C1 demotion is enabled/disabled using a different MSR. For example, see
for Bay Trail and Cherry Trail platforms.
arch/x86/include/asm/msr_pkg_cst_config_control.h line 15
Quoted 1 line
arch/x86/include/asm/msr_pkg_cst_config_control.h new file +1
-0+* @set: Enable C1 demotion if true, disable it if false. Doubt #2: OK, so here we have a boolean - feature enable/disable. No assumption if enabled = some bit set or if enabled = some bit cleared.
In general, not specific for C1 demotion: sometimes feature enabled = some bit set, sometimes feature enabled = some bit cleared.
So far so good.
arch/x86/include/asm/msr_pkg_cst_config_control.h line 16
Quoted 1 line
arch/x86/include/asm/msr_pkg_cst_config_control.h new file +1
-0+* @other_bits: Additional bits to set or clear in the register. But here:
* if set == True,other_bitswill be set
* if set == False,other_bitswill be cleared.
Quoted 5 lines
So if we happen to have a "
FEATURE_X_DISABLE" bit in the same MSR, this new helper function becomes not-so-helpful: we cannot enable/disable C1 demotion andFEATURE_Xusing one function call.And also it is just a subtle assumption, reducing the value of this function.
Well, I'm not 100% convinced myself, so it's probably better to drop this one for now. It can be revisited later if need be.
Thanks!