Skip to content

Commit

Permalink
intel_idle: Refactor intel_idle_cpuidle_driver_init()
Browse files Browse the repository at this point in the history
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@intel.com>
  • Loading branch information
Rafael J. Wysocki committed Dec 27, 2019
1 parent 77fb4e0 commit 9f3d6da
Showing 1 changed file with 25 additions and 24 deletions.
49 changes: 25 additions & 24 deletions drivers/idle/intel_idle.c
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,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)
Expand Down Expand Up @@ -1332,45 +1348,30 @@ 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) {
pr_info("max_cstate %d reached\n", max_cstate);
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;
}

mwait_hint = flg2MWAIT(cpuidle_state_table[cstate].flags);
if (!intel_idle_verify_cstate(mwait_hint))
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];

drv->state_count += 1;
/* Structure copy. */
drv->states[drv->state_count++] = cpuidle_state_table[cstate];
}

if (icpu->byt_auto_demotion_disable_flag) {
Expand Down

0 comments on commit 9f3d6da

Please sign in to comment.