CMT: [SRU][focal:linux-gcp][PATCH 09/17] intel_idle: Refactor intel_idle_cpuidle_driver_init()
Cengiz Can
cengiz.can at canonical.com
Tue Sep 24 15:31:14 UTC 2024
On 11-09-24 01:27:18, Marcelo Henrique Cerri wrote:
> From: "Rafael J. Wysocki" <rafael.j.wysocki at intel.com>
>
> BugLink: https://bugs.launchpad.net/bugs/2080324
>
> Move the C-state verification and checks from
> intel_idle_cpuidle_driver_init() to a separate function,
> intel_idle_verify_cstate(), and make the former call it after
> checking the CPUIDLE_FLAG_UNUSABLE state flag.
>
> Also combine the drv->states[] updates with the incrementation of
> drv->state_count.
>
> No intentional functional impact.
>
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki at intel.com>
> (back ported from commit 9f3d6daf61e5156139cd05643f7f1c2a9b7b49b0)
Very minor nitpick: I've always seen this as `backported from` until now. The
scripts might probably depend on it. I'm not sure if it's only for human
consumption though.
> [marcelo.cerri: Updated context to keep current IBRS fix]
> Signed-off-by: Marcelo Henrique Cerri <marcelo.cerri at canonical.com>
> ---
> drivers/idle/intel_idle.c | 49 ++++++++++++++++++++-------------------
> 1 file changed, 25 insertions(+), 24 deletions(-)
>
> diff --git a/drivers/idle/intel_idle.c b/drivers/idle/intel_idle.c
> index 945afa633345..6148ec3290c2 100644
> --- a/drivers/idle/intel_idle.c
> +++ b/drivers/idle/intel_idle.c
> @@ -970,6 +970,22 @@ static void intel_idle_s2idle(struct cpuidle_device *dev,
> mwait_idle_with_hints(eax, ecx);
> }
>
> +static bool intel_idle_verify_cstate(unsigned int mwait_hint)
> +{
> + unsigned int mwait_cstate = MWAIT_HINT2CSTATE(mwait_hint) + 1;
> + unsigned int num_substates = (mwait_substates >> mwait_cstate * 4) &
> + MWAIT_SUBSTATE_MASK;
> +
> + /* Ignore the C-state if there are NO sub-states in CPUID for it. */
> + if (num_substates == 0)
> + return false;
> +
> + if (mwait_cstate > 2 && !boot_cpu_has(X86_FEATURE_NONSTOP_TSC))
> + mark_tsc_unstable("TSC halts in idle states deeper than C2");
> +
> + return true;
> +}
> +
> static void __setup_broadcast_timer(bool on)
> {
> if (on)
> @@ -1358,10 +1374,10 @@ static void __init intel_idle_cpuidle_driver_init(void)
> drv->state_count = 1;
>
> for (cstate = 0; cstate < CPUIDLE_STATE_MAX; ++cstate) {
> - int num_substates, mwait_hint, mwait_cstate;
> + unsigned int mwait_hint;
>
> - if ((cpuidle_state_table[cstate].enter == NULL) &&
> - (cpuidle_state_table[cstate].enter_s2idle == NULL))
> + if (!cpuidle_state_table[cstate].enter &&
> + !cpuidle_state_table[cstate].enter_s2idle)
> break;
>
> if (cstate + 1 > max_cstate) {
> @@ -1369,39 +1385,24 @@ static void __init intel_idle_cpuidle_driver_init(void)
> break;
> }
>
> - mwait_hint = flg2MWAIT(cpuidle_state_table[cstate].flags);
> - mwait_cstate = MWAIT_HINT2CSTATE(mwait_hint);
> -
> - /* number of sub-states for this state in CPUID.MWAIT */
> - num_substates = (mwait_substates >> ((mwait_cstate + 1) * 4))
> - & MWAIT_SUBSTATE_MASK;
> -
> - /* if NO sub-states for this state in CPUID, skip it */
> - if (num_substates == 0)
> - continue;
> -
> - /* if state marked as disabled, skip it */
> + /* If marked as unusable, skip this state. */
> if (cpuidle_state_table[cstate].flags & CPUIDLE_FLAG_UNUSABLE) {
> pr_debug("state %s is disabled\n",
> cpuidle_state_table[cstate].name);
> continue;
> }
>
> -
> - if (((mwait_cstate + 1) > 2) &&
> - !boot_cpu_has(X86_FEATURE_NONSTOP_TSC))
> - mark_tsc_unstable("TSC halts in idle"
> - " states deeper than C2");
> -
> - drv->states[drv->state_count] = /* structure copy */
> - cpuidle_state_table[cstate];
> + mwait_hint = flg2MWAIT(cpuidle_state_table[cstate].flags);
> + if (!intel_idle_verify_cstate(mwait_hint))
> + continue;
>
> if (cpu_feature_enabled(X86_FEATURE_KERNEL_IBRS) &&
> cpuidle_state_table[cstate].flags & CPUIDLE_FLAG_IBRS) {
> drv->states[drv->state_count].enter = intel_idle_ibrs;
> }
>
> - drv->state_count += 1;
> + /* Structure copy. */
> + drv->states[drv->state_count++] = cpuidle_state_table[cstate];
> }
>
> if (icpu->byt_auto_demotion_disable_flag) {
> --
> 2.34.1
>
>
> --
> kernel-team mailing list
> kernel-team at lists.ubuntu.com
> https://lists.ubuntu.com/mailman/listinfo/kernel-team
More information about the kernel-team
mailing list