All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] intel_idle fixes for 5.18
@ 2022-04-27  6:08 Artem Bityutskiy
  2022-04-27  6:08 ` [PATCH 1/2] intel_idle: fix the 'preferred_cstates' module parameter Artem Bityutskiy
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Artem Bityutskiy @ 2022-04-27  6:08 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Linux PM Mailing List, Rui Zhang, Jan Beulich, Artem Bityutskiy

Hi Rafael,

these patches fix a couple problems in the intel_idle SPR support code.
Could you please merge these fixes to 5.18?

Both problems were spotted by Jan Beulich, thanks Jan!

Thank you!

Artem Bityutskiy (2):
  intel_idle: fix the 'preferred_cstates' module parameter
  intel_idle: fix SPR C6 optimization

 drivers/idle/intel_idle.c | 27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)

-- 
2.35.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] intel_idle: fix the 'preferred_cstates' module parameter
  2022-04-27  6:08 [PATCH 0/2] intel_idle fixes for 5.18 Artem Bityutskiy
@ 2022-04-27  6:08 ` Artem Bityutskiy
  2022-04-27  6:08 ` [PATCH 2/2] intel_idle: fix SPR C6 optimization Artem Bityutskiy
  2022-04-27 18:40 ` [PATCH 0/2] intel_idle fixes for 5.18 Rafael J. Wysocki
  2 siblings, 0 replies; 4+ messages in thread
From: Artem Bityutskiy @ 2022-04-27  6:08 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Linux PM Mailing List, Rui Zhang, Jan Beulich, Artem Bityutskiy

From: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>

This patch is a fix for the following 5.18-rc1 commit:
   da0e58c038e6 intel_idle: add 'preferred_cstates' module argument

Problem description.

When user boots kernel up with the 'intel_idle.preferred_cstates=4' option,
we enable C1E and disable C1 states on Sapphire Rapids Xeon (SPR). In order
for C1E to work on SPR, we have to enable the C1E promotion bit on all
CPUs.  However, we enable it only on one CPU.

Fix description.

The 'intel_idle' driver already has the infrastructure for disabling C1E
promotion on every CPU. This patch uses the same infrastructure for
enabling C1E promotion on every CPU. It changes the boolean
'disable_promotion_to_c1e' variable to a tri-state 'c1e_promotion'
variable.

Tested on a 2-socket SPR system. I verified the following combinations:
* C1E promotion enabled and disabled in BIOS.
* Booted with and without the 'intel_idle.preferred_cstates=4' kernel
  argument.

In all 4 cases C1E promotion was correctly set on all CPUs.

Also tested on an old Broadwell system, just to make sure it does not cause
a regression. C1E promotion was correctly disabled on that system, both C1
and C1E were exposed (as expected).

Reported-by: Jan Beulich <jbeulich@suse.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
---
 drivers/idle/intel_idle.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/drivers/idle/intel_idle.c b/drivers/idle/intel_idle.c
index b7640cfe0020..cf5ed4c1d02c 100644
--- a/drivers/idle/intel_idle.c
+++ b/drivers/idle/intel_idle.c
@@ -69,7 +69,12 @@ static unsigned int preferred_states_mask;
 static struct cpuidle_device __percpu *intel_idle_cpuidle_devices;
 
 static unsigned long auto_demotion_disable_flags;
-static bool disable_promotion_to_c1e;
+
+static enum {
+	C1E_PROMOTION_PRESERVE,
+	C1E_PROMOTION_ENABLE,
+	C1E_PROMOTION_DISABLE
+} c1e_promotion = C1E_PROMOTION_PRESERVE;
 
 struct idle_cpu {
 	struct cpuidle_state *state_table;
@@ -1398,8 +1403,6 @@ static inline void intel_idle_init_cstates_acpi(struct cpuidle_driver *drv) { }
 static inline bool intel_idle_off_by_default(u32 mwait_hint) { return false; }
 #endif /* !CONFIG_ACPI_PROCESSOR_CSTATE */
 
-static void c1e_promotion_enable(void);
-
 /**
  * ivt_idle_state_table_update - Tune the idle states table for Ivy Town.
  *
@@ -1587,8 +1590,7 @@ static void __init spr_idle_state_table_update(void)
 		spr_cstates[1].flags &= ~CPUIDLE_FLAG_UNUSABLE;
 
 		/* Enable C1E using the "C1E promotion" bit. */
-		c1e_promotion_enable();
-		disable_promotion_to_c1e = false;
+		c1e_promotion = C1E_PROMOTION_ENABLE;
 	}
 
 	/*
@@ -1754,7 +1756,9 @@ static int intel_idle_cpu_init(unsigned int cpu)
 	if (auto_demotion_disable_flags)
 		auto_demotion_disable();
 
-	if (disable_promotion_to_c1e)
+	if (c1e_promotion == C1E_PROMOTION_ENABLE)
+		c1e_promotion_enable();
+	else if (c1e_promotion == C1E_PROMOTION_DISABLE)
 		c1e_promotion_disable();
 
 	return 0;
@@ -1833,7 +1837,8 @@ static int __init intel_idle_init(void)
 	if (icpu) {
 		cpuidle_state_table = icpu->state_table;
 		auto_demotion_disable_flags = icpu->auto_demotion_disable_flags;
-		disable_promotion_to_c1e = icpu->disable_promotion_to_c1e;
+		if (icpu->disable_promotion_to_c1e)
+			c1e_promotion = C1E_PROMOTION_DISABLE;
 		if (icpu->use_acpi || force_use_acpi)
 			intel_idle_acpi_cst_extract();
 	} else if (!intel_idle_acpi_cst_extract()) {
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] intel_idle: fix SPR C6 optimization
  2022-04-27  6:08 [PATCH 0/2] intel_idle fixes for 5.18 Artem Bityutskiy
  2022-04-27  6:08 ` [PATCH 1/2] intel_idle: fix the 'preferred_cstates' module parameter Artem Bityutskiy
@ 2022-04-27  6:08 ` Artem Bityutskiy
  2022-04-27 18:40 ` [PATCH 0/2] intel_idle fixes for 5.18 Rafael J. Wysocki
  2 siblings, 0 replies; 4+ messages in thread
From: Artem Bityutskiy @ 2022-04-27  6:08 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Linux PM Mailing List, Rui Zhang, Jan Beulich, Artem Bityutskiy

From: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>

This patch is a fix for the following 5.18-rc1 commit:
	commit 3a9cf77b60dc intel_idle: add core C6 optimization for SPR

The Sapphire Rapids (SPR) C6 optimization was added to the end of the
'spr_idle_state_table_update()' function. However, the function has a
'return' which may happen before the optimization has a chance to run.
And this may prevent the optimization from happening.

This is an unlikely scenario, but possible if user boots with, say,
the 'intel_idle.preferred_cstates=6' kernel boot option.

This patch fixes the issue by eliminating the 'return'.

Suggested-by: Jan Beulich <jbeulich@suse.com>
Reported-by: Jan Beulich <jbeulich@suse.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
---
 drivers/idle/intel_idle.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/idle/intel_idle.c b/drivers/idle/intel_idle.c
index cf5ed4c1d02c..ae8649a809ea 100644
--- a/drivers/idle/intel_idle.c
+++ b/drivers/idle/intel_idle.c
@@ -1581,11 +1581,9 @@ static void __init spr_idle_state_table_update(void)
 	unsigned long long msr;
 
 	/* Check if user prefers C1E over C1. */
-	if (preferred_states_mask & BIT(2)) {
-		if (preferred_states_mask & BIT(1))
-			/* Both can't be enabled, stick to the defaults. */
-			return;
-
+	if ((preferred_states_mask & BIT(2)) &&
+	    !(preferred_states_mask & BIT(1))) {
+		/* Disable C1 and enable C1E. */
 		spr_cstates[0].flags |= CPUIDLE_FLAG_UNUSABLE;
 		spr_cstates[1].flags &= ~CPUIDLE_FLAG_UNUSABLE;
 
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/2] intel_idle fixes for 5.18
  2022-04-27  6:08 [PATCH 0/2] intel_idle fixes for 5.18 Artem Bityutskiy
  2022-04-27  6:08 ` [PATCH 1/2] intel_idle: fix the 'preferred_cstates' module parameter Artem Bityutskiy
  2022-04-27  6:08 ` [PATCH 2/2] intel_idle: fix SPR C6 optimization Artem Bityutskiy
@ 2022-04-27 18:40 ` Rafael J. Wysocki
  2 siblings, 0 replies; 4+ messages in thread
From: Rafael J. Wysocki @ 2022-04-27 18:40 UTC (permalink / raw)
  To: Artem Bityutskiy
  Cc: Rafael J. Wysocki, Linux PM Mailing List, Rui Zhang, Jan Beulich

On Wed, Apr 27, 2022 at 8:08 AM Artem Bityutskiy <dedekind1@gmail.com> wrote:
>
> Hi Rafael,
>
> these patches fix a couple problems in the intel_idle SPR support code.
> Could you please merge these fixes to 5.18?
>
> Both problems were spotted by Jan Beulich, thanks Jan!
>
> Thank you!
>
> Artem Bityutskiy (2):
>   intel_idle: fix the 'preferred_cstates' module parameter
>   intel_idle: fix SPR C6 optimization
>
>  drivers/idle/intel_idle.c | 27 +++++++++++++++------------
>  1 file changed, 15 insertions(+), 12 deletions(-)
>
> --

Both applied as 5.18-rc material with Fixes: tags added and some minor
changelog edits.

Thanks!

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-04-27 18:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-27  6:08 [PATCH 0/2] intel_idle fixes for 5.18 Artem Bityutskiy
2022-04-27  6:08 ` [PATCH 1/2] intel_idle: fix the 'preferred_cstates' module parameter Artem Bityutskiy
2022-04-27  6:08 ` [PATCH 2/2] intel_idle: fix SPR C6 optimization Artem Bityutskiy
2022-04-27 18:40 ` [PATCH 0/2] intel_idle fixes for 5.18 Rafael J. Wysocki

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.