Skip to contentSkip to conversation

misc intel_idle cleanups

PATCH Applied Artem Bityutskiy 3 participants 21 messages Apr 19, 2023 – Apr 27, 2023 Intel idle driver

lore
Share & tools
lore

Artem Bityutskiy

author maintainer
#0 lore raw

cover misc intel_idle cleanups

From: Artem Bityutskiy <[email protected]>

These are misc. clean-up and minor improvement patches for 'intel_idle'. The common theme in them is improving the 'intel_idle_init_cstates_icpu()' function and things around it.

The patches are against the 'linux-pm' tree, the 'linux-next' branch.

Artem Bityutskiy (7):
intel_idle: use pr_info instead of printk
intel_idle: cleanup 'intel_idle_init_cstates_icpu()'
intel_idle: further 'intel_idle_init_cstates_icpu()' cleanup
intel_idle: improve C-state flags handling robustness
intel_idle: fix confusing message
intel_idle: do not sprinkle module parameters definitions around
intel_idle: mark few variables as '__read_mostly'

 drivers/idle/intel_idle.c | 58 ++++++++++++++++++++++++---------------
 1 file changed, 36 insertions(+), 22 deletions(-)

base-commit: bc538c8be4bd17479f88f2e1a78d5b76b5523319

Signature · 1 line
2.38.1
author maintainer
#1 lore raw

PATCH 1/7 intel_idle: use pr_info instead of printk

From: Artem Bityutskiy <[email protected]>

Substitute 'printk()' with 'pr_info()', because 'intel_idle' already uses 'pr_debug()', so using 'pr_info()' will be more consistent.

In addition to this, this patch addresses the following checkpatch.pl warning:
WARNING: printk() should include KERN_<LEVEL> facility level

---
 drivers/idle/intel_idle.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/idle/intel_idle.c +1 -1
index 938c17f25d94..726a361da422 100644
@@ -1895,7 +1895,7 @@ static void __init intel_idle_init_cstates_icpu(struct cpuidle_driver *drv)
 		drv->states[drv->state_count] = cpuidle_state_table[cstate];
 
 		if ((cpuidle_state_table[cstate].flags & CPUIDLE_FLAG_IRQ_ENABLE) || force_irq_on) {
-			printk("intel_idle: forced intel_idle_irq for state %d\n", cstate);
+			pr_info("forced intel_idle_irq for state %d\n", cstate);
 			drv->states[drv->state_count].enter = intel_idle_irq;
 		}
 
Signature · 1 line
2.38.1
Reviewed-by on v1 1/7
#2 lore raw

Re: [PATCH 1/7] intel_idle: use pr_info instead of printk

Quoted 6 lines · Artem Bityutskiy

From: Artem Bityutskiy <[email protected]>

Substitute 'printk()' with 'pr_info()', because 'intel_idle' already uses
'pr_debug()', so using 'pr_info()' will be more consistent.

Quoted 6 lines

In addition to this, this patch addresses the following checkpatch.pl
warning:
WARNING: printk() should include KERN_<LEVEL> facility level

thanks,
rui

Quoted 23 lines
---
 drivers/idle/intel_idle.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/idle/intel_idle.c +0 -1
index 938c17f25d94..726a361da422 100644
@@ -1895,7 +1895,7 @@ static void __init
 intel_idle_init_cstates_icpu(struct cpuidle_driver *drv)
 		drv->states[drv->state_count] =
 cpuidle_state_table[cstate];
 
 		if ((cpuidle_state_table[cstate].flags &
 CPUIDLE_FLAG_IRQ_ENABLE) || force_irq_on) {
-			printk("intel_idle: forced intel_idle_irq for

state %d\n", cstate);

drivers/idle/intel_idle.c +1 -0
+			pr_info("forced intel_idle_irq for state %d\n",

cstate);
drv->states[drv->state_count].enter =
intel_idle_irq;
}

author maintainer
#3 lore raw

PATCH 2/7 intel_idle: cleanup 'intel_idle_init_cstates_icpu()'

In reply to Artem Bityutskiy

From: Artem Bityutskiy <[email protected]>

The 'intel_idle_init_cstates_icpu()' function includes a loop that iterates over every C-state. Inside the loop, the same C-state data is referenced 2 ways:
1. as 'cpuidle_state_table[cstate]'
2. as 'drv->states[drv->state_count]' (but it is a copy of #1, not the same object).

Make the code be more consistent and easier to read by using only the 2nd way after the been done. So the code structure would be as follows.

1. Use 'cpuidle_state_table[cstate]'
2. Copy ''cpuidle_state_table[cstate]' to 'drv->states[drv->state_count]'
3. Use only 'drv->states[drv->state_count]' from this point.

Note, this change introduces a checkpatch.pl warning (too long line), but it will be addressed in the next patch.

---
 drivers/idle/intel_idle.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/idle/intel_idle.c +5 -5
index 726a361da422..190410fc9ce5 100644
@@ -1894,24 +1894,24 @@ static void __init intel_idle_init_cstates_icpu(struct cpuidle_driver *drv)
 		/* Structure copy. */
 		drv->states[drv->state_count] = cpuidle_state_table[cstate];
 
-		if ((cpuidle_state_table[cstate].flags & CPUIDLE_FLAG_IRQ_ENABLE) || force_irq_on) {
+		if ((drv->states[drv->state_count].flags & CPUIDLE_FLAG_IRQ_ENABLE) || force_irq_on) {
 			pr_info("forced intel_idle_irq for state %d\n", cstate);
 			drv->states[drv->state_count].enter = intel_idle_irq;
 		}
 
 		if (cpu_feature_enabled(X86_FEATURE_KERNEL_IBRS) &&
-		    cpuidle_state_table[cstate].flags & CPUIDLE_FLAG_IBRS) {
-			WARN_ON_ONCE(cpuidle_state_table[cstate].flags & CPUIDLE_FLAG_IRQ_ENABLE);
+		    drv->states[drv->state_count].flags & CPUIDLE_FLAG_IBRS) {
+			WARN_ON_ONCE(drv->states[drv->state_count].flags & CPUIDLE_FLAG_IRQ_ENABLE);
 			drv->states[drv->state_count].enter = intel_idle_ibrs;
 		}
 
-		if (cpuidle_state_table[cstate].flags & CPUIDLE_FLAG_INIT_XSTATE)
+		if (drv->states[drv->state_count].flags & CPUIDLE_FLAG_INIT_XSTATE)
 			drv->states[drv->state_count].enter = intel_idle_xstate;
 
 		if ((disabled_states_mask & BIT(drv->state_count)) ||
 		    ((icpu->use_acpi || force_use_acpi) &&
 		     intel_idle_off_by_default(mwait_hint) &&
-		     !(cpuidle_state_table[cstate].flags & CPUIDLE_FLAG_ALWAYS_ENABLE)))
+		     !(drv->states[drv->state_count].flags & CPUIDLE_FLAG_ALWAYS_ENABLE)))
 			drv->states[drv->state_count].flags |= CPUIDLE_FLAG_OFF;
 
 		if (intel_idle_state_needs_timer_stop(&drv->states[drv->state_count]))
Signature · 1 line
2.38.1
#4 lore raw

Re: [PATCH 2/7] intel_idle: cleanup 'intel_idle_init_cstates_icpu()'

Hi, Artem,

Quoted 12 lines · Artem Bityutskiy

From: Artem Bityutskiy <[email protected]>

The 'intel_idle_init_cstates_icpu()' function includes a loop that iterates
over every C-state. Inside the loop, the same C-state data is referenced 2
ways:
1. as 'cpuidle_state_table[cstate]'
2. as 'drv->states[drv->state_count]' (but it is a copy of #1, not
the same
object).

Quoted 4 lines

Make the code be more consistent and easier to read by using only the 2nd way after

the been done.

is this a typo?

thanks,
rui

author maintainer
#5 lore raw

Re: [PATCH 2/7] intel_idle: cleanup 'intel_idle_init_cstates_icpu()'

Quoted 6 lines · Rui
Quoted 4 lines

Make the code be more consistent and easier to read by using only the 2nd way after

 the been done.

is this a typo?

Yes, some sort of editing leftover, will adjust, thanks.

Artem.

author maintainer
#6 lore raw

PATCH v2 2/7 intel_idle: cleanup 'intel_idle_init_cstates_icpu()'

In reply to Artem Bityutskiy

From: Artem Bityutskiy <[email protected]>

The 'intel_idle_init_cstates_icpu()' function includes a loop that iterates over every C-state. Inside the loop, the same C-state data is referenced 2 ways:
1. as 'cpuidle_state_table[cstate]'
2. as 'drv->states[drv->state_count]' (but it is a copy of #1, not the same object).

Make the code be more consistent and easier to read by using only the 2nd way. So the code structure would be as follows.

1. Use 'cpuidle_state_table[cstate]'
2. Copy ''cpuidle_state_table[cstate]' to 'drv->states[drv->state_count]'
3. Use only 'drv->states[drv->state_count]' from this point.

Note, this change introduces a checkpatch.pl warning (too long line), but it will be addressed in the next patch.

---
 drivers/idle/intel_idle.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

Changelog
* v2
- Adjust commit message (feedback from Rui Zhang).

drivers/idle/intel_idle.c +5 -5
index 726a361da422..190410fc9ce5 100644
@@ -1894,24 +1894,24 @@ static void __init intel_idle_init_cstates_icpu(struct cpuidle_driver *drv)
 		/* Structure copy. */
 		drv->states[drv->state_count] = cpuidle_state_table[cstate];
 
-		if ((cpuidle_state_table[cstate].flags & CPUIDLE_FLAG_IRQ_ENABLE) || force_irq_on) {
+		if ((drv->states[drv->state_count].flags & CPUIDLE_FLAG_IRQ_ENABLE) || force_irq_on) {
 			pr_info("forced intel_idle_irq for state %d\n", cstate);
 			drv->states[drv->state_count].enter = intel_idle_irq;
 		}
 
 		if (cpu_feature_enabled(X86_FEATURE_KERNEL_IBRS) &&
-		    cpuidle_state_table[cstate].flags & CPUIDLE_FLAG_IBRS) {
-			WARN_ON_ONCE(cpuidle_state_table[cstate].flags & CPUIDLE_FLAG_IRQ_ENABLE);
+		    drv->states[drv->state_count].flags & CPUIDLE_FLAG_IBRS) {
+			WARN_ON_ONCE(drv->states[drv->state_count].flags & CPUIDLE_FLAG_IRQ_ENABLE);
 			drv->states[drv->state_count].enter = intel_idle_ibrs;
 		}
 
-		if (cpuidle_state_table[cstate].flags & CPUIDLE_FLAG_INIT_XSTATE)
+		if (drv->states[drv->state_count].flags & CPUIDLE_FLAG_INIT_XSTATE)
 			drv->states[drv->state_count].enter = intel_idle_xstate;
 
 		if ((disabled_states_mask & BIT(drv->state_count)) ||
 		    ((icpu->use_acpi || force_use_acpi) &&
 		     intel_idle_off_by_default(mwait_hint) &&
-		     !(cpuidle_state_table[cstate].flags & CPUIDLE_FLAG_ALWAYS_ENABLE)))
+		     !(drv->states[drv->state_count].flags & CPUIDLE_FLAG_ALWAYS_ENABLE)))
 			drv->states[drv->state_count].flags |= CPUIDLE_FLAG_OFF;
 
 		if (intel_idle_state_needs_timer_stop(&drv->states[drv->state_count]))
Signature · 1 line
2.38.1
Reviewed-by on v2 2/7
#7 lore raw

Re: [PATCH v2 2/7] intel_idle: cleanup 'intel_idle_init_cstates_icpu()'

Quoted 18 lines · Artem Bityutskiy

From: Artem Bityutskiy <[email protected]>

The 'intel_idle_init_cstates_icpu()' function includes a loop that iterates
over every C-state. Inside the loop, the same C-state data is referenced 2
ways:
1. as 'cpuidle_state_table[cstate]'
2. as 'drv->states[drv->state_count]' (but it is a copy of #1, not
the same
object).

Make the code be more consistent and easier to read by using only the 2nd
way. So the code structure would be as follows.

1. Use 'cpuidle_state_table[cstate]'
2. Copy ''cpuidle_state_table[cstate]' to 'drv->states[drv-

Quoted 8 lines
Quoted 1 line

state_count]'

3. Use only 'drv->states[drv->state_count]' from this point.

Note, this change introduces a checkpatch.pl warning (too long line), but it
will be addressed in the next patch.

thanks,
rui

Quoted 60 lines
---
 drivers/idle/intel_idle.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

Changelog
* v2
- Adjust commit message (feedback from Rui Zhang).

drivers/idle/intel_idle.c +3 -4
index 726a361da422..190410fc9ce5 100644
@@ -1894,24 +1894,24 @@ static void __init
 intel_idle_init_cstates_icpu(struct cpuidle_driver *drv)
 		/* Structure copy. */
 		drv->states[drv->state_count] =
 cpuidle_state_table[cstate];
 
-		if ((cpuidle_state_table[cstate].flags &
 CPUIDLE_FLAG_IRQ_ENABLE) || force_irq_on) {
+		if ((drv->states[drv->state_count].flags &
 CPUIDLE_FLAG_IRQ_ENABLE) || force_irq_on) {
 			pr_info("forced intel_idle_irq for state %d\n",
 cstate);
 			drv->states[drv->state_count].enter =
 intel_idle_irq;
 		}
 
 		if (cpu_feature_enabled(X86_FEATURE_KERNEL_IBRS) &&
-		    cpuidle_state_table[cstate].flags &
 CPUIDLE_FLAG_IBRS) {
-			WARN_ON_ONCE(cpuidle_state_table[cstate].flags
 & CPUIDLE_FLAG_IRQ_ENABLE);
+		    drv->states[drv->state_count].flags &
 CPUIDLE_FLAG_IBRS) {
+			WARN_ON_ONCE(drv->states[drv-
 >state_count].flags & CPUIDLE_FLAG_IRQ_ENABLE);
 			drv->states[drv->state_count].enter =
 intel_idle_ibrs;
 		}
 
-		if (cpuidle_state_table[cstate].flags &

CPUIDLE_FLAG_INIT_XSTATE)

drivers/idle/intel_idle.c +1 -0
+		if (drv->states[drv->state_count].flags &

CPUIDLE_FLAG_INIT_XSTATE)
drv->states[drv->state_count].enter =
intel_idle_xstate;

drivers/idle/intel_idle.c +0 -1
 		if ((disabled_states_mask & BIT(drv->state_count)) ||
 		    ((icpu->use_acpi || force_use_acpi) &&
 		     intel_idle_off_by_default(mwait_hint) &&
-		     !(cpuidle_state_table[cstate].flags &

CPUIDLE_FLAG_ALWAYS_ENABLE)))

drivers/idle/intel_idle.c +1 -0
+		     !(drv->states[drv->state_count].flags &

CPUIDLE_FLAG_ALWAYS_ENABLE)))
drv->states[drv->state_count].flags |=
CPUIDLE_FLAG_OFF;

if (intel_idle_state_needs_timer_stop(&drv->states[drv-

Quoted 1 line

state_count]))

author maintainer
#8 lore raw

PATCH 3/7 intel_idle: further 'intel_idle_init_cstates_icpu()' cleanup

In reply to Artem Bityutskiy

From: Artem Bityutskiy <[email protected]>

Introduce a temporary 'state' variable for referencing the currently processed C-state in the 'intel_idle_init_cstates_icpu()' function.

This makes code lines shorter and easier to read.

---
 drivers/idle/intel_idle.c | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)
drivers/idle/intel_idle.c +13 -11
index 190410fc9ce5..73ddb1d8cfcf 100644
@@ -1871,6 +1871,7 @@ static void __init intel_idle_init_cstates_icpu(struct cpuidle_driver *drv)
 	}
 
 	for (cstate = 0; cstate < CPUIDLE_STATE_MAX; ++cstate) {
+		struct cpuidle_state *state;
 		unsigned int mwait_hint;
 
 		if (intel_idle_max_cstate_reached(cstate))
@@ -1893,29 +1894,30 @@ static void __init intel_idle_init_cstates_icpu(struct cpuidle_driver *drv)
 
 		/* Structure copy. */
 		drv->states[drv->state_count] = cpuidle_state_table[cstate];
+		state = &drv->states[drv->state_count];
 
-		if ((drv->states[drv->state_count].flags & CPUIDLE_FLAG_IRQ_ENABLE) || force_irq_on) {
+		if ((state->flags & CPUIDLE_FLAG_IRQ_ENABLE) || force_irq_on) {
 			pr_info("forced intel_idle_irq for state %d\n", cstate);
-			drv->states[drv->state_count].enter = intel_idle_irq;
+			state->enter = intel_idle_irq;
 		}
 
 		if (cpu_feature_enabled(X86_FEATURE_KERNEL_IBRS) &&
-		    drv->states[drv->state_count].flags & CPUIDLE_FLAG_IBRS) {
-			WARN_ON_ONCE(drv->states[drv->state_count].flags & CPUIDLE_FLAG_IRQ_ENABLE);
-			drv->states[drv->state_count].enter = intel_idle_ibrs;
+		    state->flags & CPUIDLE_FLAG_IBRS) {
+			WARN_ON_ONCE(state->flags & CPUIDLE_FLAG_IRQ_ENABLE);
+			state->enter = intel_idle_ibrs;
 		}
 
-		if (drv->states[drv->state_count].flags & CPUIDLE_FLAG_INIT_XSTATE)
-			drv->states[drv->state_count].enter = intel_idle_xstate;
+		if (state->flags & CPUIDLE_FLAG_INIT_XSTATE)
+			state->enter = intel_idle_xstate;
 
 		if ((disabled_states_mask & BIT(drv->state_count)) ||
 		    ((icpu->use_acpi || force_use_acpi) &&
 		     intel_idle_off_by_default(mwait_hint) &&
-		     !(drv->states[drv->state_count].flags & CPUIDLE_FLAG_ALWAYS_ENABLE)))
-			drv->states[drv->state_count].flags |= CPUIDLE_FLAG_OFF;
+		     !(state->flags & CPUIDLE_FLAG_ALWAYS_ENABLE)))
+			state->flags |= CPUIDLE_FLAG_OFF;
 
-		if (intel_idle_state_needs_timer_stop(&drv->states[drv->state_count]))
-			drv->states[drv->state_count].flags |= CPUIDLE_FLAG_TIMER_STOP;
+		if (intel_idle_state_needs_timer_stop(state))
+			state->flags |= CPUIDLE_FLAG_TIMER_STOP;
 
 		drv->state_count++;
 	}
Signature · 1 line
2.38.1
Reviewed-by on v1 3/7
#9 lore raw

Re: [PATCH 3/7] intel_idle: further 'intel_idle_init_cstates_icpu()' cleanup

Quoted 8 lines · Artem Bityutskiy

From: Artem Bityutskiy <[email protected]>

Introduce a temporary 'state' variable for referencing the currently processed C-state in the 'intel_idle_init_cstates_icpu()' function.

This makes code lines shorter and easier to read.

thanks,
rui

Quoted 75 lines
---
 drivers/idle/intel_idle.c | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)
drivers/idle/intel_idle.c +1 -0
index 190410fc9ce5..73ddb1d8cfcf 100644
@@ -1871,6 +1871,7 @@ static void __init
 intel_idle_init_cstates_icpu(struct cpuidle_driver *drv)
 	}
 
 	for (cstate = 0; cstate < CPUIDLE_STATE_MAX; ++cstate) {
+		struct cpuidle_state *state;
 		unsigned int mwait_hint;
 
drivers/idle/intel_idle.c +8 -7
 		if (intel_idle_max_cstate_reached(cstate))
@@ -1893,29 +1894,30 @@ static void __init
 intel_idle_init_cstates_icpu(struct cpuidle_driver *drv)
 
 		/* Structure copy. */
 		drv->states[drv->state_count] =
 cpuidle_state_table[cstate];
+		state = &drv->states[drv->state_count];
 
-		if ((drv->states[drv->state_count].flags &
 CPUIDLE_FLAG_IRQ_ENABLE) || force_irq_on) {
+		if ((state->flags & CPUIDLE_FLAG_IRQ_ENABLE) ||
 force_irq_on) {
 			pr_info("forced intel_idle_irq for state %d\n",
 cstate);
-			drv->states[drv->state_count].enter =
 intel_idle_irq;
+			state->enter = intel_idle_irq;
 		}
 
 		if (cpu_feature_enabled(X86_FEATURE_KERNEL_IBRS) &&
-		    drv->states[drv->state_count].flags &
 CPUIDLE_FLAG_IBRS) {
-			WARN_ON_ONCE(drv->states[drv-
 >state_count].flags & CPUIDLE_FLAG_IRQ_ENABLE);
-			drv->states[drv->state_count].enter =
 intel_idle_ibrs;
+		    state->flags & CPUIDLE_FLAG_IBRS) {
+			WARN_ON_ONCE(state->flags &
 CPUIDLE_FLAG_IRQ_ENABLE);
+			state->enter = intel_idle_ibrs;
 		}
 
-		if (drv->states[drv->state_count].flags &
 CPUIDLE_FLAG_INIT_XSTATE)
-			drv->states[drv->state_count].enter =
 intel_idle_xstate;
+		if (state->flags & CPUIDLE_FLAG_INIT_XSTATE)
+			state->enter = intel_idle_xstate;
drivers/idle/intel_idle.c +0 -1
 		if ((disabled_states_mask & BIT(drv->state_count)) ||
 		    ((icpu->use_acpi || force_use_acpi) &&
 		     intel_idle_off_by_default(mwait_hint) &&
-		     !(drv->states[drv->state_count].flags &

CPUIDLE_FLAG_ALWAYS_ENABLE)))

drivers/idle/intel_idle.c +0 -1
-			drv->states[drv->state_count].flags |=

CPUIDLE_FLAG_OFF;

drivers/idle/intel_idle.c +2 -1
+		     !(state->flags & CPUIDLE_FLAG_ALWAYS_ENABLE)))
+			state->flags |= CPUIDLE_FLAG_OFF;
 
-		if (intel_idle_state_needs_timer_stop(&drv->states[drv-
Quoted 1 line

state_count]))

drivers/idle/intel_idle.c +0 -1
-			drv->states[drv->state_count].flags |=

CPUIDLE_FLAG_TIMER_STOP;

drivers/idle/intel_idle.c +2 -0
+		if (intel_idle_state_needs_timer_stop(state))
+			state->flags |= CPUIDLE_FLAG_TIMER_STOP;
 
 		drv->state_count++;
 	}
author maintainer
#10 lore raw

PATCH 4/7 intel_idle: improve C-state flags handling robustness

In reply to Artem Bityutskiy

From: Artem Bityutskiy <[email protected]>

The following C-state flags are currently mutually-exclusive and should not be combined:
* IRQ_ENABLE
* IBRS
* XSTATE

There is a warning for the situation when the IRQ_ENABLE flag is combined with the IBRS flag, but no warnings for other combinations. This is inconsistent and prone to errors.

Improve the situation by adding warnings for all the unexpected combinations. Add a couple of helpful commentaries too.

---
 drivers/idle/intel_idle.c | 28 ++++++++++++++++++----------
 1 file changed, 18 insertions(+), 10 deletions(-)
drivers/idle/intel_idle.c +18 -10
index 73ddb1d8cfcf..1de36df15d5a 100644
@@ -1896,20 +1896,28 @@ 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_IRQ_ENABLE) || force_irq_on) {
-			pr_info("forced intel_idle_irq for state %d\n", cstate);
-			state->enter = intel_idle_irq;
-		}
-
-		if (cpu_feature_enabled(X86_FEATURE_KERNEL_IBRS) &&
-		    state->flags & CPUIDLE_FLAG_IBRS) {
+		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) ||
+			   force_irq_on) {
+			pr_info("forced intel_idle_irq for state %d\n", cstate);
+			state->enter = intel_idle_irq;
 		}
 
-		if (state->flags & CPUIDLE_FLAG_INIT_XSTATE)
-			state->enter = intel_idle_xstate;
-
 		if ((disabled_states_mask & BIT(drv->state_count)) ||
 		    ((icpu->use_acpi || force_use_acpi) &&
 		     intel_idle_off_by_default(mwait_hint) &&
Signature · 1 line
2.38.1
#11 lore raw

Re: [PATCH 4/7] intel_idle: improve C-state flags handling robustness

Quoted 66 lines · Artem Bityutskiy

From: Artem Bityutskiy <[email protected]>

The following C-state flags are currently mutually-exclusive and should not
be combined:
* IRQ_ENABLE
* IBRS
* XSTATE

There is a warning for the situation when the IRQ_ENABLE flag is combined with the IBRS flag, but no warnings for other combinations.
This is inconsistent and prone to errors.

Improve the situation by adding warnings for all the unexpected combinations. Add a couple of helpful commentaries too.

---
 drivers/idle/intel_idle.c | 28 ++++++++++++++++++----------
 1 file changed, 18 insertions(+), 10 deletions(-)
drivers/idle/intel_idle.c +3 -7
index 73ddb1d8cfcf..1de36df15d5a 100644
@@ -1896,20 +1896,28 @@ 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_IRQ_ENABLE) ||
 force_irq_on) {
-			pr_info("forced intel_idle_irq for state %d\n",
 cstate);
-			state->enter = intel_idle_irq;
-		}
-
-		if (cpu_feature_enabled(X86_FEATURE_KERNEL_IBRS) &&
-		    state->flags & CPUIDLE_FLAG_IBRS) {
+		if (state->flags & CPUIDLE_FLAG_INIT_XSTATE) {
+			/*
+			 * Combining with XSTATE with IBRS or

IRQ_ENABLE flags

drivers/idle/intel_idle.c +4 -0
+			 * is not currently supported but this driver.
+			 */
+			WARN_ON_ONCE(state->flags & CPUIDLE_FLAG_IBRS);
+			WARN_ON_ONCE(state->flags &

CPUIDLE_FLAG_IRQ_ENABLE);

drivers/idle/intel_idle.c +2 -0
+			state->enter = intel_idle_xstate;
+		} else if (cpu_feature_enabled(X86_FEATURE_KERNEL_IBRS)

&&

drivers/idle/intel_idle.c +3 -0
+			   state->flags & CPUIDLE_FLAG_IBRS) {
+			/*
+			 * IBRS mitigation requires that C-states are

entered

drivers/idle/intel_idle.c +2 -0
+			 * with interrupts disabled.
+			 */
 			WARN_ON_ONCE(state->flags &

CPUIDLE_FLAG_IRQ_ENABLE);

drivers/idle/intel_idle.c +3 -0
 			state->enter = intel_idle_ibrs;
+		} else if ((state->flags & CPUIDLE_FLAG_IRQ_ENABLE) ||
+			   force_irq_on) {
+			pr_info("forced intel_idle_irq for state %d\n",

cstate);

drivers/idle/intel_idle.c static void __init intel_idle_init_cstates_icpu(struct cpuidle_driver *drv) · line 1919

Quoted 2 lines
drivers/idle/intel_idle.c +1 -0
+			state->enter = intel_idle_irq;
 		}

what is the expected behavior for a state with CPUIDLE_FLAG_IBRS or CPUIDLE_FLAG_INIT_XSTATE set when using "force_irq_on"?

the CPUIDLE_FLAG_IBRS/CPUIDLE_FLAG_INIT_XSTATE flag always wins, right? I think it would be good to add a comment about this, say in patch 6/7.

thanks,
rui

Quoted 7 lines
drivers/idle/intel_idle.c +0 -3
-		if (state->flags & CPUIDLE_FLAG_INIT_XSTATE)
-			state->enter = intel_idle_xstate;
-
 		if ((disabled_states_mask & BIT(drv->state_count)) ||
 		    ((icpu->use_acpi || force_use_acpi) &&
 		     intel_idle_off_by_default(mwait_hint) &&
author maintainer
#12 lore raw

Re: [PATCH 4/7] intel_idle: improve C-state flags handling robustness

Hi Rui,

Quoted 3 lines · Rui

what is the expected behavior for a state with CPUIDLE_FLAG_IBRS or CPUIDLE_FLAG_INIT_XSTATE set when using "force_irq_on"?
the CPUIDLE_FLAG_IBRS/CPUIDLE_FLAG_INIT_XSTATE flag always wins, right?

Yes.

Quoted 1 line

I think it would be good to add a comment about this, say in patch 6/7.

Sure, will do.

Thanks!

Reviewed-by on v1 4/7
#13 lore raw

Re: [PATCH 4/7] intel_idle: improve C-state flags handling robustness

In reply to Artem Bityutskiy
Quoted 14 lines · Artem Bityutskiy

From: Artem Bityutskiy <[email protected]>

The following C-state flags are currently mutually-exclusive and should not
be combined:
* IRQ_ENABLE
* IBRS
* XSTATE

There is a warning for the situation when the IRQ_ENABLE flag is combined with the IBRS flag, but no warnings for other combinations.
This is inconsistent and prone to errors.

Quoted 4 lines

Improve the situation by adding warnings for all the unexpected combinations. Add a couple of helpful commentaries too.

thanks,
rui

Quoted 57 lines
---
 drivers/idle/intel_idle.c | 28 ++++++++++++++++++----------
 1 file changed, 18 insertions(+), 10 deletions(-)
drivers/idle/intel_idle.c +3 -7
index 73ddb1d8cfcf..1de36df15d5a 100644
@@ -1896,20 +1896,28 @@ 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_IRQ_ENABLE) ||
 force_irq_on) {
-			pr_info("forced intel_idle_irq for state %d\n",
 cstate);
-			state->enter = intel_idle_irq;
-		}
-
-		if (cpu_feature_enabled(X86_FEATURE_KERNEL_IBRS) &&
-		    state->flags & CPUIDLE_FLAG_IBRS) {
+		if (state->flags & CPUIDLE_FLAG_INIT_XSTATE) {
+			/*
+			 * Combining with XSTATE with IBRS or

IRQ_ENABLE flags

drivers/idle/intel_idle.c +4 -0
+			 * is not currently supported but this driver.
+			 */
+			WARN_ON_ONCE(state->flags & CPUIDLE_FLAG_IBRS);
+			WARN_ON_ONCE(state->flags &

CPUIDLE_FLAG_IRQ_ENABLE);

drivers/idle/intel_idle.c +2 -0
+			state->enter = intel_idle_xstate;
+		} else if (cpu_feature_enabled(X86_FEATURE_KERNEL_IBRS)

&&

drivers/idle/intel_idle.c +3 -0
+			   state->flags & CPUIDLE_FLAG_IBRS) {
+			/*
+			 * IBRS mitigation requires that C-states are

entered

drivers/idle/intel_idle.c +2 -0
+			 * with interrupts disabled.
+			 */
 			WARN_ON_ONCE(state->flags &

CPUIDLE_FLAG_IRQ_ENABLE);

drivers/idle/intel_idle.c +3 -0
 			state->enter = intel_idle_ibrs;
+		} else if ((state->flags & CPUIDLE_FLAG_IRQ_ENABLE) ||
+			   force_irq_on) {
+			pr_info("forced intel_idle_irq for state %d\n",

cstate);

drivers/idle/intel_idle.c +1 -3
+			state->enter = intel_idle_irq;
 		}
 
-		if (state->flags & CPUIDLE_FLAG_INIT_XSTATE)
-			state->enter = intel_idle_xstate;
-
 		if ((disabled_states_mask & BIT(drv->state_count)) ||
 		    ((icpu->use_acpi || force_use_acpi) &&
 		     intel_idle_off_by_default(mwait_hint) &&
author maintainer
#14 lore raw

PATCH 5/7 intel_idle: fix confusing message

In reply to Artem Bityutskiy

From: Artem Bityutskiy <[email protected]>

By default, all non-POLL C-states are entered with interrupts disable. There are 2 ways to make 'intel_idle' enter C-states with interrupts enabled:
1. Mark the C-state with the 'CPUIDLE_FLAG_IRQ_ENABLE' flag.
2. Use the 'force_irq_on' module parameter.

The former is the "proper" way of doing it, it is per-C-state and per-platform. The latter is for debugging purposes only.

The problem is that 'intel_idle' prints the "forced intel_idle_irq" message in both cases, even though the former case does not needed this message, because nothing is forced there. This patch addresses the problem.

---
 drivers/idle/intel_idle.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/idle/intel_idle.c +3 -2
index 1de36df15d5a..bff0d17aeda4 100644
@@ -1912,8 +1912,9 @@ static void __init intel_idle_init_cstates_icpu(struct cpuidle_driver *drv)
 			 */
 			WARN_ON_ONCE(state->flags & CPUIDLE_FLAG_IRQ_ENABLE);
 			state->enter = intel_idle_ibrs;
-		} else if ((state->flags & CPUIDLE_FLAG_IRQ_ENABLE) ||
-			   force_irq_on) {
+		} 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;
 		}
Signature · 1 line
2.38.1
Reviewed-by on v1 5/7
#15 lore raw

Re: [PATCH 5/7] intel_idle: fix confusing message

Quoted 12 lines · Artem Bityutskiy

From: Artem Bityutskiy <[email protected]>

By default, all non-POLL C-states are entered with interrupts disable.
There are 2 ways to make 'intel_idle' enter C-states with interrupts enabled:
1. Mark the C-state with the 'CPUIDLE_FLAG_IRQ_ENABLE' flag.
2. Use the 'force_irq_on' module parameter.

The former is the "proper" way of doing it, it is per-C-state and per-platform. The latter is for debugging purposes only.

Quoted 7 lines

The problem is that 'intel_idle' prints the "forced intel_idle_irq" message in both cases, even though the former case does not needed this message, because nothing is forced there. This patch addresses the
problem.

thanks,
rui

Quoted 23 lines
---
 drivers/idle/intel_idle.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/idle/intel_idle.c +3 -2
index 1de36df15d5a..bff0d17aeda4 100644
@@ -1912,8 +1912,9 @@ static void __init
 intel_idle_init_cstates_icpu(struct cpuidle_driver *drv)
 			 */
 			WARN_ON_ONCE(state->flags &
 CPUIDLE_FLAG_IRQ_ENABLE);
 			state->enter = intel_idle_ibrs;
-		} else if ((state->flags & CPUIDLE_FLAG_IRQ_ENABLE) ||
-			   force_irq_on) {
+		} 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);

drivers/idle/intel_idle.c +0 -0
 			state->enter = intel_idle_irq;
 		}
author maintainer
#16 lore raw

PATCH 6/7 intel_idle: do not sprinkle module parameters definitions around

In reply to Artem Bityutskiy

From: Artem Bityutskiy <[email protected]>

This is a cleanup which improves code consistency. Move the 'force_irq_on' module parameter variable and definition to the same place where we have variables and definitions for other module parameters.

---
 drivers/idle/intel_idle.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/idle/intel_idle.c +6 -3
index bff0d17aeda4..9e4105b532da 100644
@@ -68,6 +68,7 @@ static struct cpuidle_driver intel_idle_driver = {
 static int max_cstate = CPUIDLE_STATE_MAX - 1;
 static unsigned int disabled_states_mask;
 static unsigned int preferred_states_mask;
+static bool force_irq_on __read_mostly;
 
 static struct cpuidle_device __percpu *intel_idle_cpuidle_devices;
 
@@ -1838,9 +1839,6 @@ static bool __init intel_idle_verify_cstate(unsigned int mwait_hint)
 	return true;
 }
 
-static bool force_irq_on __read_mostly;
-module_param(force_irq_on, bool, 0444);
-
 static void __init intel_idle_init_cstates_icpu(struct cpuidle_driver *drv)
 {
 	int cstate;
@@ -2157,3 +2155,8 @@ MODULE_PARM_DESC(states_off, "Mask of disabled idle states");
  */
 module_param_named(preferred_cstates, preferred_states_mask, uint, 0444);
 MODULE_PARM_DESC(preferred_cstates, "Mask of preferred idle states");
+/*
+ * Debugging option that forces the driver to enter all C-states with
+ * interrupts enabled.
+ */
+module_param(force_irq_on, bool, 0444);
Signature · 1 line
2.38.1
author maintainer
#17 lore raw

PATCH v2 6/7 intel_idle: do not sprinkle module parameters definitions around

From: Artem Bityutskiy <[email protected]>

This is a cleanup which improves code consistency. Move the 'force_irq_on' module parameter variable and definition to the same place where we have variables and definitions for other module parameters.

---
 drivers/idle/intel_idle.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

Changelog
* v2
- Mention 'XSTATE' and 'IBRS' flags in the 'force_irq_on' commentary (feedback from Rui Zhang).

drivers/idle/intel_idle.c +7 -3
index bff0d17aeda4..35bd284f7763 100644
@@ -68,6 +68,7 @@ static struct cpuidle_driver intel_idle_driver = {
 static int max_cstate = CPUIDLE_STATE_MAX - 1;
 static unsigned int disabled_states_mask;
 static unsigned int preferred_states_mask;
+static bool force_irq_on __read_mostly;
 
 static struct cpuidle_device __percpu *intel_idle_cpuidle_devices;
 
@@ -1838,9 +1839,6 @@ static bool __init intel_idle_verify_cstate(unsigned int mwait_hint)
 	return true;
 }
 
-static bool force_irq_on __read_mostly;
-module_param(force_irq_on, bool, 0444);
-
 static void __init intel_idle_init_cstates_icpu(struct cpuidle_driver *drv)
 {
 	int cstate;
@@ -2157,3 +2155,9 @@ MODULE_PARM_DESC(states_off, "Mask of disabled idle states");
  */
 module_param_named(preferred_cstates, preferred_states_mask, uint, 0444);
 MODULE_PARM_DESC(preferred_cstates, "Mask of preferred idle states");
+/*
+ * Debugging option that forces the driver to enter all C-states with
+ * interrupts enabled. Does not apply to C-states with
+ * 'CPUIDLE_FLAG_INIT_XSTATE' and 'CPUIDLE_FLAG_IBRS' flags.
+ */
+module_param(force_irq_on, bool, 0444);
Signature · 1 line
2.38.1
Reviewed-by on v2 6/7
#18 lore raw

Re: [PATCH v2 6/7] intel_idle: do not sprinkle module parameters definitions around

Quoted 9 lines · Artem Bityutskiy

From: Artem Bityutskiy <[email protected]>

This is a cleanup which improves code consistency. Move the 'force_irq_on'
module parameter variable and definition to the same place where we have
variables and definitions for other module parameters.

thanks,
rui

Quoted 48 lines
---
 drivers/idle/intel_idle.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

Changelog
* v2
- Mention 'XSTATE' and 'IBRS' flags in the 'force_irq_on'
commentary
(feedback from Rui Zhang).

drivers/idle/intel_idle.c +1 -3
index bff0d17aeda4..35bd284f7763 100644
@@ -68,6 +68,7 @@ static struct cpuidle_driver intel_idle_driver = {
 static int max_cstate = CPUIDLE_STATE_MAX - 1;
 static unsigned int disabled_states_mask;
 static unsigned int preferred_states_mask;
+static bool force_irq_on __read_mostly;
 
 static struct cpuidle_device __percpu *intel_idle_cpuidle_devices;
 
@@ -1838,9 +1839,6 @@ static bool __init
 intel_idle_verify_cstate(unsigned int mwait_hint)
 	return true;
 }
 
-static bool force_irq_on __read_mostly;
-module_param(force_irq_on, bool, 0444);
-
 static void __init intel_idle_init_cstates_icpu(struct
 cpuidle_driver *drv)

{

drivers/idle/intel_idle.c +0 -0
 	int cstate;
@@ -2157,3 +2155,9 @@ MODULE_PARM_DESC(states_off, "Mask of disabled
 idle states");
  */
 module_param_named(preferred_cstates, preferred_states_mask, uint,

0444);
MODULE_PARM_DESC(preferred_cstates, "Mask of preferred idle
states");
+/*
+ * Debugging option that forces the driver to enter all C-states with
+ * interrupts enabled. Does not apply to C-states with
+ * 'CPUIDLE_FLAG_INIT_XSTATE' and 'CPUIDLE_FLAG_IBRS' flags.
+ */
+module_param(force_irq_on, bool, 0444);

author maintainer
#19 lore raw

PATCH 7/7 intel_idle: mark few variables as '__read_mostly'

In reply to Artem Bityutskiy

From: Artem Bityutskiy <[email protected]>

The intention of this patch is to clean up the code and make it look a bit more consistent. Mark all unitialized module parameter variables as '__read_mostly', not just one of them. The other parameters are also read-mostly too.

---
 drivers/idle/intel_idle.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/idle/intel_idle.c +2 -2
index 9e4105b532da..1711cfdc45cc 100644
@@ -66,8 +66,8 @@ static struct cpuidle_driver intel_idle_driver = {
 };
 /* intel_idle.max_cstate=0 disables driver */
 static int max_cstate = CPUIDLE_STATE_MAX - 1;
-static unsigned int disabled_states_mask;
-static unsigned int preferred_states_mask;
+static unsigned int disabled_states_mask __read_mostly;
+static unsigned int preferred_states_mask __read_mostly;
 static bool force_irq_on __read_mostly;
 
 static struct cpuidle_device __percpu *intel_idle_cpuidle_devices;
Signature · 1 line
2.38.1
maintainer Applied
#20 lore raw
In reply to Artem Bityutskiy
Quoted 18 lines · Artem Bityutskiy

From: Artem Bityutskiy <[email protected]>

These are misc. clean-up and minor improvement patches for 'intel_idle'. The common theme in them is improving the 'intel_idle_init_cstates_icpu()' function and things around it.

The patches are against the 'linux-pm' tree, the 'linux-next' branch.

Artem Bityutskiy (7):
intel_idle: use pr_info instead of printk
intel_idle: cleanup 'intel_idle_init_cstates_icpu()'
intel_idle: further 'intel_idle_init_cstates_icpu()' cleanup
intel_idle: improve C-state flags handling robustness
intel_idle: fix confusing message
intel_idle: do not sprinkle module parameters definitions around
intel_idle: mark few variables as '__read_mostly'

Quoted 3 lines
 drivers/idle/intel_idle.c | 58 ++++++++++++++++++++++++---------------
 1 file changed, 36 insertions(+), 22 deletions(-)

Applied as 6.4-rc material with patch updates taken into account.

Thanks!