linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: arjan@linux.intel.com
To: linux-pm@vger.kernel.org
Cc: artem.bityutskiy@linux.intel.com, rafael@kernel.org,
	Arjan van de Ven <arjan.van.de.ven@intel.com>,
	Arjan van de Ven <arjan@linux.intel.com>
Subject: [PATCH 1/7] intel_idle: refactor state->enter manipulation into its own function
Date: Thu,  1 Jun 2023 18:27:55 +0000	[thread overview]
Message-ID: <20230601182801.2622044-2-arjan@linux.intel.com> (raw)
In-Reply-To: <20230601182801.2622044-1-arjan@linux.intel.com>

From: Arjan van de Ven <arjan.van.de.ven@intel.com>

Since the 6.4 kernel, the logic for updating a state's enter method
based on "environmental conditions" (command line options, cpu sidechannel
workarounds etc etc) has gotten pretty complex.
This patch refactors this into a seperate small, self contained function
(no behavior changes) for improved readability and to make future
changes to this logic easier to do and understand.

Signed-off-by: Arjan van de Ven <arjan@linux.intel.com>
---
 drivers/idle/intel_idle.c | 50 ++++++++++++++++++++++-----------------
 1 file changed, 28 insertions(+), 22 deletions(-)

diff --git a/drivers/idle/intel_idle.c b/drivers/idle/intel_idle.c
index aa2d19db2b1d..c351b21c0875 100644
--- a/drivers/idle/intel_idle.c
+++ b/drivers/idle/intel_idle.c
@@ -1839,6 +1839,32 @@ static bool __init intel_idle_verify_cstate(unsigned int mwait_hint)
 	return true;
 }
 
+static void state_update_enter_method(struct cpuidle_state *state, int cstate)
+{
+	if (state->flags & CPUIDLE_FLAG_INIT_XSTATE) {
+		/*
+		 * Combining with XSTATE with IBRS or IRQ_ENABLE flags
+		 * is not currently supported but this driver.
+		 */
+		WARN_ON_ONCE(state->flags & CPUIDLE_FLAG_IBRS);
+		WARN_ON_ONCE(state->flags & CPUIDLE_FLAG_IRQ_ENABLE);
+		state->enter = intel_idle_xstate;
+	} else if (cpu_feature_enabled(X86_FEATURE_KERNEL_IBRS) &&
+			   state->flags & CPUIDLE_FLAG_IBRS) {
+		/*
+		 * IBRS mitigation requires that C-states are entered
+		 * with interrupts disabled.
+		 */
+		WARN_ON_ONCE(state->flags & CPUIDLE_FLAG_IRQ_ENABLE);
+		state->enter = intel_idle_ibrs;
+	} else if (state->flags & CPUIDLE_FLAG_IRQ_ENABLE) {
+		state->enter = intel_idle_irq;
+	} else if (force_irq_on) {
+		pr_info("forced intel_idle_irq for state %d\n", cstate);
+		state->enter = intel_idle_irq;
+	}
+}
+
 static void __init intel_idle_init_cstates_icpu(struct cpuidle_driver *drv)
 {
 	int cstate;
@@ -1894,28 +1920,8 @@ static void __init intel_idle_init_cstates_icpu(struct cpuidle_driver *drv)
 		drv->states[drv->state_count] = cpuidle_state_table[cstate];
 		state = &drv->states[drv->state_count];
 
-		if (state->flags & CPUIDLE_FLAG_INIT_XSTATE) {
-			/*
-			 * Combining with XSTATE with IBRS or IRQ_ENABLE flags
-			 * is not currently supported but this driver.
-			 */
-			WARN_ON_ONCE(state->flags & CPUIDLE_FLAG_IBRS);
-			WARN_ON_ONCE(state->flags & CPUIDLE_FLAG_IRQ_ENABLE);
-			state->enter = intel_idle_xstate;
-		} else if (cpu_feature_enabled(X86_FEATURE_KERNEL_IBRS) &&
-			   state->flags & CPUIDLE_FLAG_IBRS) {
-			/*
-			 * IBRS mitigation requires that C-states are entered
-			 * with interrupts disabled.
-			 */
-			WARN_ON_ONCE(state->flags & CPUIDLE_FLAG_IRQ_ENABLE);
-			state->enter = intel_idle_ibrs;
-		} else if (state->flags & CPUIDLE_FLAG_IRQ_ENABLE) {
-			state->enter = intel_idle_irq;
-		} else if (force_irq_on) {
-			pr_info("forced intel_idle_irq for state %d\n", cstate);
-			state->enter = intel_idle_irq;
-		}
+		state_update_enter_method(state, cstate);
+
 
 		if ((disabled_states_mask & BIT(drv->state_count)) ||
 		    ((icpu->use_acpi || force_use_acpi) &&
-- 
2.40.1


  reply	other threads:[~2023-06-01 18:30 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-01 18:27 [PATCH 00/7 Add support for running in VM guests to intel_idle arjan
2023-06-01 18:27 ` arjan [this message]
2023-06-01 18:27 ` [PATCH 2/7] intel_idle: clean up the (new) state_update_enter_method function arjan
2023-06-04 15:34   ` Rafael J. Wysocki
2023-06-04 22:35     ` Van De Ven, Arjan
2023-06-01 18:27 ` [PATCH 3/7] intel_idle: Add a sanity check in the new " arjan
2023-06-04 15:43   ` Rafael J. Wysocki
2023-06-01 18:27 ` [PATCH 4/7] intel_idle: Add helper functions to support 'hlt' as idle state arjan
2023-06-04 15:46   ` Rafael J. Wysocki
2023-06-01 18:27 ` [PATCH 5/7] intel_idle: Add a way to skip the mwait check on all states arjan
2023-06-04 15:54   ` Rafael J. Wysocki
2023-06-05 15:24     ` Arjan van de Ven
2023-06-01 18:28 ` [PATCH 6/7] intel_idle: Add support for using intel_idle in a VM guest using just hlt arjan
2023-06-04 15:59   ` Rafael J. Wysocki
2023-06-04 22:34     ` Van De Ven, Arjan
2023-06-01 18:28 ` [PATCH 7/7] intel_idle: Add a "Long HLT" C1 state for the VM guest mode arjan
2023-06-04 15:01 ` [PATCH 00/7 Add support for running in VM guests to intel_idle Rafael J. Wysocki

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=20230601182801.2622044-2-arjan@linux.intel.com \
    --to=arjan@linux.intel.com \
    --cc=arjan.van.de.ven@intel.com \
    --cc=artem.bityutskiy@linux.intel.com \
    --cc=linux-pm@vger.kernel.org \
    --cc=rafael@kernel.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).