Skip to content

Commit 4622ba9

Browse files
fenrus75rafaeljw
authored andcommitted
intel_idle: refactor state->enter manipulation into its own function
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 <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 858fd16 commit 4622ba9

File tree

1 file changed

+28
-22
lines changed

1 file changed

+28
-22
lines changed

drivers/idle/intel_idle.c

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1839,6 +1839,32 @@ static bool __init intel_idle_verify_cstate(unsigned int mwait_hint)
18391839
return true;
18401840
}
18411841

1842+
static void state_update_enter_method(struct cpuidle_state *state, int cstate)
1843+
{
1844+
if (state->flags & CPUIDLE_FLAG_INIT_XSTATE) {
1845+
/*
1846+
* Combining with XSTATE with IBRS or IRQ_ENABLE flags
1847+
* is not currently supported but this driver.
1848+
*/
1849+
WARN_ON_ONCE(state->flags & CPUIDLE_FLAG_IBRS);
1850+
WARN_ON_ONCE(state->flags & CPUIDLE_FLAG_IRQ_ENABLE);
1851+
state->enter = intel_idle_xstate;
1852+
} else if (cpu_feature_enabled(X86_FEATURE_KERNEL_IBRS) &&
1853+
state->flags & CPUIDLE_FLAG_IBRS) {
1854+
/*
1855+
* IBRS mitigation requires that C-states are entered
1856+
* with interrupts disabled.
1857+
*/
1858+
WARN_ON_ONCE(state->flags & CPUIDLE_FLAG_IRQ_ENABLE);
1859+
state->enter = intel_idle_ibrs;
1860+
} else if (state->flags & CPUIDLE_FLAG_IRQ_ENABLE) {
1861+
state->enter = intel_idle_irq;
1862+
} else if (force_irq_on) {
1863+
pr_info("forced intel_idle_irq for state %d\n", cstate);
1864+
state->enter = intel_idle_irq;
1865+
}
1866+
}
1867+
18421868
static void __init intel_idle_init_cstates_icpu(struct cpuidle_driver *drv)
18431869
{
18441870
int cstate;
@@ -1894,28 +1920,8 @@ static void __init intel_idle_init_cstates_icpu(struct cpuidle_driver *drv)
18941920
drv->states[drv->state_count] = cpuidle_state_table[cstate];
18951921
state = &drv->states[drv->state_count];
18961922

1897-
if (state->flags & CPUIDLE_FLAG_INIT_XSTATE) {
1898-
/*
1899-
* Combining with XSTATE with IBRS or IRQ_ENABLE flags
1900-
* is not currently supported but this driver.
1901-
*/
1902-
WARN_ON_ONCE(state->flags & CPUIDLE_FLAG_IBRS);
1903-
WARN_ON_ONCE(state->flags & CPUIDLE_FLAG_IRQ_ENABLE);
1904-
state->enter = intel_idle_xstate;
1905-
} else if (cpu_feature_enabled(X86_FEATURE_KERNEL_IBRS) &&
1906-
state->flags & CPUIDLE_FLAG_IBRS) {
1907-
/*
1908-
* IBRS mitigation requires that C-states are entered
1909-
* with interrupts disabled.
1910-
*/
1911-
WARN_ON_ONCE(state->flags & CPUIDLE_FLAG_IRQ_ENABLE);
1912-
state->enter = intel_idle_ibrs;
1913-
} else if (state->flags & CPUIDLE_FLAG_IRQ_ENABLE) {
1914-
state->enter = intel_idle_irq;
1915-
} else if (force_irq_on) {
1916-
pr_info("forced intel_idle_irq for state %d\n", cstate);
1917-
state->enter = intel_idle_irq;
1918-
}
1923+
state_update_enter_method(state, cstate);
1924+
19191925

19201926
if ((disabled_states_mask & BIT(drv->state_count)) ||
19211927
((icpu->use_acpi || force_use_acpi) &&

0 commit comments

Comments
 (0)