提交 ab45522c 编写于 作者: R Rafael J. Wysocki 提交者: Yang Yingliang

Intel: intel_idle: Refactor intel_idle_cpuidle_driver_init()

mainline inclusion
from mainline-v5.6-rc1
commit 9f3d6daf
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I47H3V
CVE: NA

--------------------------------

commit 9f3d6daf upstream

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: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Nyjia <yingbao.jia@intel.com>
Signed-off-by: NJackie Liu <liuyun01@kylinos.cn>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
Reviewed-by: NHanjun Guo <guohanjun@huawei.com>
Reviewed-by: NXie XiuQi <xiexiuqi@huawei.com>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
上级 da56a5c8
...@@ -956,6 +956,22 @@ static void intel_idle_s2idle(struct cpuidle_device *dev, ...@@ -956,6 +956,22 @@ static void intel_idle_s2idle(struct cpuidle_device *dev,
mwait_idle_with_hints(eax, ecx); 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) static void __setup_broadcast_timer(bool on)
{ {
if (on) if (on)
...@@ -1346,10 +1362,10 @@ static void __init intel_idle_cpuidle_driver_init(void) ...@@ -1346,10 +1362,10 @@ static void __init intel_idle_cpuidle_driver_init(void)
drv->state_count = 1; drv->state_count = 1;
for (cstate = 0; cstate < CPUIDLE_STATE_MAX; ++cstate) { 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) && if (!cpuidle_state_table[cstate].enter &&
(cpuidle_state_table[cstate].enter_s2idle == NULL)) !cpuidle_state_table[cstate].enter_s2idle)
break; break;
if (cstate + 1 > max_cstate) { if (cstate + 1 > max_cstate) {
...@@ -1357,34 +1373,19 @@ static void __init intel_idle_cpuidle_driver_init(void) ...@@ -1357,34 +1373,19 @@ static void __init intel_idle_cpuidle_driver_init(void)
break; break;
} }
mwait_hint = flg2MWAIT(cpuidle_state_table[cstate].flags); /* If marked as unusable, skip this state. */
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 (cpuidle_state_table[cstate].disabled != 0) { if (cpuidle_state_table[cstate].disabled != 0) {
pr_debug("state %s is disabled\n", pr_debug("state %s is disabled\n",
cpuidle_state_table[cstate].name); cpuidle_state_table[cstate].name);
continue; continue;
} }
mwait_hint = flg2MWAIT(cpuidle_state_table[cstate].flags);
if (!intel_idle_verify_cstate(mwait_hint))
continue;
if (((mwait_cstate + 1) > 2) && /* Structure copy. */
!boot_cpu_has(X86_FEATURE_NONSTOP_TSC)) drv->states[drv->state_count++] = cpuidle_state_table[cstate];
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;
} }
if (icpu->byt_auto_demotion_disable_flag) { if (icpu->byt_auto_demotion_disable_flag) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册