Lines Matching +full:idle +full:- +full:state +full:- +full:name

1 // SPDX-License-Identifier: GPL-2.0-only
3 * intel_idle.c - native hardware idle loop for modern Intel processors
5 * Copyright (c) 2013 - 2020, Intel Corporation.
20 * All CPUs have same idle states as boot CPU
23 * for preventing entry into deep C-states
25 * CPU will flush caches as needed when entering a C-state via MWAIT
33 * ACPI has a .suspend hack to turn off deep c-statees during suspend
39 /* un-comment DEBUG to enable pr_debug() statements */
56 #include <asm/intel-family.h>
58 #include <asm/spec-ctrl.h>
65 .name = "intel_idle",
69 static int max_cstate = CPUIDLE_STATE_MAX - 1;
89 * Hardware C-state auto-demotion may not always be optimal.
104 * Enable interrupts before entering the C-state. On some platforms and for
105 * some C-states, this may measurably decrease interrupt latency.
110 * Enable this state by default even if the ACPI _CST does not list it.
115 * Disable IBRS across idle (when KERNEL_IBRS), is exclusive vs IRQ_ENABLE
121 * Initialize large xstate for the C6-state entrance.
126 * Ignore the sub-state when matching mwait hints between the ACPI _CST and
132 * MWAIT takes an 8-bit "hint" in EAX "suggesting"
133 * the C-state (top nibble) and sub-state (bottom nibble)
136 * We store the hint at the top of our "flags" for each state.
145 struct cpuidle_state *state = &drv->states[index]; in __intel_idle() local
146 unsigned long eax = flg2MWAIT(state->flags); in __intel_idle()
155 * intel_idle - Ask the processor to enter the given idle state.
158 * @index: Target idle state index.
161 * @dev is idle and it can try to enter the idle state corresponding to @index.
163 * If the local APIC timer is not known to be reliable in the target idle state,
164 * enable one-shot tick broadcasting for the target CPU before executing MWAIT.
206 * intel_idle_s2idle - Ask the processor to enter the given idle state.
209 * @index: Target idle state index.
212 * @dev is idle and it can try to enter the idle state corresponding to @index.
214 * Invoked as a suspend-to-idle callback routine with frozen user space, frozen
221 struct cpuidle_state *state = &drv->states[index]; in intel_idle_s2idle() local
222 unsigned long eax = flg2MWAIT(state->flags); in intel_idle_s2idle()
224 if (state->flags & CPUIDLE_FLAG_INIT_XSTATE) in intel_idle_s2idle()
239 .name = "C1",
247 .name = "C1E",
255 .name = "C3",
263 .name = "C6",
276 .name = "C1",
284 .name = "C1E",
292 .name = "C3",
300 .name = "C6",
308 .name = "C7",
321 .name = "C1",
329 .name = "C6N",
337 .name = "C6S",
345 .name = "C7",
353 .name = "C7S",
366 .name = "C1",
374 .name = "C6N",
382 .name = "C6S",
390 .name = "C7",
398 .name = "C7S",
411 .name = "C1",
419 .name = "C1E",
427 .name = "C3",
435 .name = "C6",
443 .name = "C7",
456 .name = "C1",
464 .name = "C1E",
472 .name = "C3",
480 .name = "C6",
493 .name = "C1",
501 .name = "C1E",
509 .name = "C3",
517 .name = "C6",
530 .name = "C1",
538 .name = "C1E",
546 .name = "C3",
554 .name = "C6",
567 .name = "C1",
575 .name = "C1E",
583 .name = "C3",
591 .name = "C6",
599 .name = "C7s",
607 .name = "C8",
615 .name = "C9",
623 .name = "C10",
635 .name = "C1",
643 .name = "C1E",
651 .name = "C3",
659 .name = "C6",
667 .name = "C7s",
675 .name = "C8",
683 .name = "C9",
691 .name = "C10",
704 .name = "C1",
712 .name = "C1E",
720 .name = "C3",
728 .name = "C6",
736 .name = "C7s",
744 .name = "C8",
752 .name = "C9",
760 .name = "C10",
773 .name = "C1",
781 .name = "C1E",
789 .name = "C6",
802 .name = "C1",
810 .name = "C1E",
818 .name = "C6",
841 .name = "C1",
849 .name = "C1E",
857 .name = "C6",
865 .name = "C8",
873 .name = "C10",
886 .name = "C1",
894 .name = "C1E",
902 .name = "C6",
910 .name = "C8",
918 .name = "C10",
931 .name = "C1E",
939 .name = "C6",
947 .name = "C10",
960 .name = "C1",
968 .name = "C1E",
976 .name = "C6",
984 .name = "C8",
992 .name = "C10",
1005 .name = "C1",
1013 .name = "C1E",
1021 .name = "C6",
1035 .name = "C1",
1043 .name = "C1E",
1051 .name = "C6",
1061 .name = "C6P",
1076 .name = "C1",
1084 .name = "C1E",
1092 .name = "C6",
1102 .name = "C6P",
1117 .name = "C1E",
1125 .name = "C2",
1133 .name = "C4",
1141 .name = "C6",
1153 .name = "C1",
1161 .name = "C4",
1169 .name = "C6",
1177 .name = "C7",
1185 .name = "C9",
1197 .name = "C1",
1205 .name = "C6",
1217 .name = "C1",
1225 .name = "C6",
1238 .name = "C1",
1246 .name = "C1E",
1254 .name = "C6",
1262 .name = "C7s",
1270 .name = "C8",
1278 .name = "C9",
1286 .name = "C10",
1299 .name = "C1",
1307 .name = "C1E",
1315 .name = "C6",
1332 .name = "C1",
1340 .name = "C1E",
1348 .name = "C6",
1361 .name = "C1",
1369 .name = "C1E",
1377 .name = "C6S",
1390 .name = "C1",
1398 .name = "C1E",
1406 .name = "C6S",
1415 .name = "C6SP",
1674 static bool __init intel_idle_state_needs_timer_stop(struct cpuidle_state *state) in intel_idle_state_needs_timer_stop() argument
1676 unsigned long eax = flg2MWAIT(state->flags); in intel_idle_state_needs_timer_stop()
1682 * Switch over to one-shot tick broadcast if the target C-state in intel_idle_state_needs_timer_stop()
1693 MODULE_PARM_DESC(no_acpi, "Do not use ACPI _CST for building the idle states list");
1697 MODULE_PARM_DESC(use_acpi, "Use ACPI _CST for building the idle states list");
1702 * intel_idle_cst_usable - Check if the _CST information can be used.
1704 * Check if all of the C-states listed by _CST in the max_cstate range are
1717 if (cx->entry_method != ACPI_CSTATE_FFH) in intel_idle_cst_usable()
1739 if (acpi_processor_evaluate_cst(pr->handle, cpu, &acpi_state_table)) in intel_idle_acpi_cst_extract()
1768 struct cpuidle_state *state; in intel_idle_init_cstates_acpi() local
1770 if (intel_idle_max_cstate_reached(cstate - 1)) in intel_idle_init_cstates_acpi()
1775 state = &drv->states[drv->state_count++]; in intel_idle_init_cstates_acpi()
1777 snprintf(state->name, CPUIDLE_NAME_LEN, "C%d_ACPI", cstate); in intel_idle_init_cstates_acpi()
1778 strscpy(state->desc, cx->desc, CPUIDLE_DESC_LEN); in intel_idle_init_cstates_acpi()
1779 state->exit_latency = cx->latency; in intel_idle_init_cstates_acpi()
1781 * For C1-type C-states use the same number for both the exit in intel_idle_init_cstates_acpi()
1783 * C1 in the majority of the static C-states tables above. in intel_idle_init_cstates_acpi()
1784 * For the other types of C-states, however, set the target in intel_idle_init_cstates_acpi()
1786 * a reasonable balance between energy-efficiency and in intel_idle_init_cstates_acpi()
1789 state->target_residency = cx->latency; in intel_idle_init_cstates_acpi()
1790 if (cx->type > ACPI_STATE_C1) in intel_idle_init_cstates_acpi()
1791 state->target_residency *= 3; in intel_idle_init_cstates_acpi()
1793 state->flags = MWAIT2flg(cx->address); in intel_idle_init_cstates_acpi()
1794 if (cx->type > ACPI_STATE_C2) in intel_idle_init_cstates_acpi()
1795 state->flags |= CPUIDLE_FLAG_TLB_FLUSHED; in intel_idle_init_cstates_acpi()
1798 state->flags |= CPUIDLE_FLAG_OFF; in intel_idle_init_cstates_acpi()
1800 if (intel_idle_state_needs_timer_stop(state)) in intel_idle_init_cstates_acpi()
1801 state->flags |= CPUIDLE_FLAG_TIMER_STOP; in intel_idle_init_cstates_acpi()
1803 if (cx->type > ACPI_STATE_C1 && !boot_cpu_has(X86_FEATURE_NONSTOP_TSC)) in intel_idle_init_cstates_acpi()
1804 mark_tsc_unstable("TSC halts in idle"); in intel_idle_init_cstates_acpi()
1806 state->enter = intel_idle; in intel_idle_init_cstates_acpi()
1807 state->enter_s2idle = intel_idle_s2idle; in intel_idle_init_cstates_acpi()
1816 * If there are no _CST C-states, do not disable any C-states by in intel_idle_off_by_default()
1853 * ivt_idle_state_table_update - Tune the idle states table for Ivy Town.
1855 * Tune IVT multi-socket targets.
1860 /* IVT uses a different table for 1-2, 3-4, and > 4 sockets */ in ivt_idle_state_table_update()
1882 * irtl_2_usec - IRTL to microseconds conversion.
1903 * bxt_idle_state_table_update - Fix up the Broxton idle states table.
1951 * sklh_idle_state_table_update - Fix up the Sky Lake idle states table.
1953 * On SKL-H (model 0x5e) skip C8 and C9 if C10 is enabled and SGX disabled.
1971 /* PC10 is not enabled in PKG C-state limit */ in sklh_idle_state_table_update()
1988 skl_cstates[5].flags |= CPUIDLE_FLAG_UNUSABLE; /* C8-SKL */ in sklh_idle_state_table_update()
1989 skl_cstates[6].flags |= CPUIDLE_FLAG_UNUSABLE; /* C9-SKL */ in sklh_idle_state_table_update()
1993 * skx_idle_state_table_update - Adjust the Sky Lake/Cascade Lake
1994 * idle states table.
2003 * 000b: C0/C1 (no package C-state support) in skx_idle_state_table_update()
2005 * 010b: C6 (non-retention) in skx_idle_state_table_update()
2007 * 111b: No Package C state limits. in skx_idle_state_table_update()
2023 * adl_idle_state_table_update - Adjust AlderLake idle states table.
2042 * spr_idle_state_table_update - Adjust Sapphire Rapids idle states table.
2049 * By default, the C6 state assumes the worst-case scenario of package in spr_idle_state_table_update()
2069 /* Ignore the C-state if there are NO sub-states in CPUID for it. */ in intel_idle_verify_cstate()
2074 mark_tsc_unstable("TSC halts in idle states deeper than C2"); in intel_idle_verify_cstate()
2079 static void state_update_enter_method(struct cpuidle_state *state, int cstate) in state_update_enter_method() argument
2081 if (state->flags & CPUIDLE_FLAG_INIT_XSTATE) { in state_update_enter_method()
2086 WARN_ON_ONCE(state->flags & CPUIDLE_FLAG_IBRS); in state_update_enter_method()
2087 WARN_ON_ONCE(state->flags & CPUIDLE_FLAG_IRQ_ENABLE); in state_update_enter_method()
2088 state->enter = intel_idle_xstate; in state_update_enter_method()
2093 ((state->flags & CPUIDLE_FLAG_IBRS) || ibrs_off)) { in state_update_enter_method()
2095 * IBRS mitigation requires that C-states are entered in state_update_enter_method()
2098 if (ibrs_off && (state->flags & CPUIDLE_FLAG_IRQ_ENABLE)) in state_update_enter_method()
2099 state->flags &= ~CPUIDLE_FLAG_IRQ_ENABLE; in state_update_enter_method()
2100 WARN_ON_ONCE(state->flags & CPUIDLE_FLAG_IRQ_ENABLE); in state_update_enter_method()
2101 state->enter = intel_idle_ibrs; in state_update_enter_method()
2105 if (state->flags & CPUIDLE_FLAG_IRQ_ENABLE) { in state_update_enter_method()
2106 state->enter = intel_idle_irq; in state_update_enter_method()
2111 pr_info("forced intel_idle_irq for state %d\n", cstate); in state_update_enter_method()
2112 state->enter = intel_idle_irq; in state_update_enter_method()
2146 struct cpuidle_state *state; in intel_idle_init_cstates_icpu() local
2156 /* If marked as unusable, skip this state. */ in intel_idle_init_cstates_icpu()
2158 pr_debug("state %s is disabled\n", in intel_idle_init_cstates_icpu()
2159 cpuidle_state_table[cstate].name); in intel_idle_init_cstates_icpu()
2168 drv->states[drv->state_count] = cpuidle_state_table[cstate]; in intel_idle_init_cstates_icpu()
2169 state = &drv->states[drv->state_count]; in intel_idle_init_cstates_icpu()
2171 state_update_enter_method(state, cstate); in intel_idle_init_cstates_icpu()
2174 if ((disabled_states_mask & BIT(drv->state_count)) || in intel_idle_init_cstates_icpu()
2175 ((icpu->use_acpi || force_use_acpi) && in intel_idle_init_cstates_icpu()
2176 intel_idle_off_by_default(state->flags, mwait_hint) && in intel_idle_init_cstates_icpu()
2177 !(state->flags & CPUIDLE_FLAG_ALWAYS_ENABLE))) in intel_idle_init_cstates_icpu()
2178 state->flags |= CPUIDLE_FLAG_OFF; in intel_idle_init_cstates_icpu()
2180 if (intel_idle_state_needs_timer_stop(state)) in intel_idle_init_cstates_icpu()
2181 state->flags |= CPUIDLE_FLAG_TIMER_STOP; in intel_idle_init_cstates_icpu()
2183 drv->state_count++; in intel_idle_init_cstates_icpu()
2186 if (icpu->byt_auto_demotion_disable_flag) { in intel_idle_init_cstates_icpu()
2193 * intel_idle_cpuidle_driver_init - Create the list of available idle states.
2201 drv->states[0].flags |= CPUIDLE_FLAG_OFF; in intel_idle_cpuidle_driver_init()
2203 drv->state_count = 1; in intel_idle_cpuidle_driver_init()
2205 if (icpu && icpu->state_table) in intel_idle_cpuidle_driver_init()
2239 * intel_idle_cpu_init - Register the target CPU with the cpuidle core.
2250 dev->cpu = cpu; in intel_idle_cpu_init()
2254 return -EIO; in intel_idle_cpu_init()
2281 if (!dev->registered) in intel_idle_cpu_online()
2288 * intel_idle_cpuidle_devices_uninit - Unregister all cpuidle devices.
2304 /* Do not load intel_idle at all for now if idle= is passed */ in intel_idle_init()
2306 return -ENODEV; in intel_idle_init()
2310 return -EPERM; in intel_idle_init()
2317 return -ENODEV; in intel_idle_init()
2322 return -ENODEV; in intel_idle_init()
2330 return -ENODEV; in intel_idle_init()
2334 icpu = (const struct idle_cpu *)id->driver_data; in intel_idle_init()
2336 if (icpu->state_table) in intel_idle_init()
2337 cpuidle_state_table = icpu->state_table; in intel_idle_init()
2339 return -ENODEV; in intel_idle_init()
2341 auto_demotion_disable_flags = icpu->auto_demotion_disable_flags; in intel_idle_init()
2342 if (icpu->disable_promotion_to_c1e) in intel_idle_init()
2344 if (icpu->use_acpi || force_use_acpi) in intel_idle_init()
2347 return -ENODEV; in intel_idle_init()
2355 return -ENOMEM; in intel_idle_init()
2363 drv ? drv->name : "none"); in intel_idle_init()
2367 retval = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "idle/intel:online", in intel_idle_init()
2373 boot_cpu_has(X86_FEATURE_ARAT) ? "all C-states" : "C1"); in intel_idle_init()
2389 * support "intel_idle.max_cstate=..." at boot and also a read-only export of
2390 * it at /sys/module/intel_idle/parameters/max_cstate -- so using module_param
2396 * idle states to be disabled by default (as reflected by the names of the
2397 * corresponding idle state directories in sysfs, "state0", "state1" ...
2398 * "state<i>" ..., where <i> is the index of the given state).
2401 MODULE_PARM_DESC(states_off, "Mask of disabled idle states");
2403 * Some platforms come with mutually exclusive C-states, so that if one is
2404 * enabled, the other C-states must not be used. Example: C1 and C1E on
2406 * preferred C-states among the groups of mutually exclusive C-states - the
2407 * selected C-states will be registered, the other C-states from the mutually
2409 * exclusive C-states, this parameter has no effect.
2412 MODULE_PARM_DESC(preferred_cstates, "Mask of preferred idle states");
2414 * Debugging option that forces the driver to enter all C-states with
2415 * interrupts enabled. Does not apply to C-states with
2424 MODULE_PARM_DESC(ibrs_off, "Disable IBRS when idle");