Skip to content

Commit 380f618

Browse files
committed
Merge: Update intel_idle to support MTL
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/4685 JIRA: https://issues.redhat.com/browse/RHEL-47255 Signed-off-by: David Arcari <darcari@redhat.com> Approved-by: Waiman Long <longman@redhat.com> Approved-by: Steve Best <sbest@redhat.com> Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com> Merged-by: Lucas Zampieri <lzampier@redhat.com>
2 parents 939214b + 8c9c98a commit 380f618

File tree

3 files changed

+54
-18
lines changed

3 files changed

+54
-18
lines changed

arch/x86/include/asm/mwait.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ static __always_inline void mwait_idle_with_hints(unsigned long eax, unsigned lo
117117
mb();
118118
}
119119

120-
if (irqs_disabled() &&
120+
if (irqs_disabled() && (ecx & 1) &&
121121
cpu_feature_enabled(X86_FEATURE_KERNEL_IBRS)) {
122122
/* NMI always enable IBRS on exception entry */
123123
ibrs_disabled = true;
@@ -127,9 +127,15 @@ static __always_inline void mwait_idle_with_hints(unsigned long eax, unsigned lo
127127
}
128128

129129
__monitor((void *)&current_thread_info()->flags, 0, 0);
130-
if (!need_resched())
131-
__mwait(eax, ecx);
132130

131+
if (!need_resched()) {
132+
if (ecx & 1) {
133+
__mwait(eax, ecx);
134+
} else {
135+
__sti_mwait(eax, ecx);
136+
raw_local_irq_disable();
137+
}
138+
}
133139
if (ibrs_disabled) {
134140
native_wrmsrl(MSR_IA32_SPEC_CTRL, spec_ctrl);
135141
__this_cpu_write(x86_spec_ctrl_current, spec_ctrl);

arch/x86/kernel/acpi/cstate.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ static long acpi_processor_ffh_cstate_probe_cpu(void *_cx)
131131
cpuid(CPUID_MWAIT_LEAF, &eax, &ebx, &ecx, &edx);
132132

133133
/* Check whether this particular cx_type (in CST) is supported or not */
134-
cstate_type = ((cx->address >> MWAIT_SUBSTATE_SIZE) &
135-
MWAIT_CSTATE_MASK) + 1;
134+
cstate_type = (((cx->address >> MWAIT_SUBSTATE_SIZE) &
135+
MWAIT_CSTATE_MASK) + 1) & MWAIT_CSTATE_MASK;
136136
edx_part = edx >> (cstate_type * MWAIT_SUBSTATE_SIZE);
137137
num_cstate_subtype = edx_part & MWAIT_SUBSTATE_MASK;
138138

drivers/idle/intel_idle.c

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,12 @@ static unsigned int mwait_substates __initdata;
131131
#define MWAIT2flg(eax) ((eax & 0xFF) << 24)
132132

133133
static __always_inline int __intel_idle(struct cpuidle_device *dev,
134-
struct cpuidle_driver *drv, int index)
134+
struct cpuidle_driver *drv,
135+
int index, bool irqoff)
135136
{
136137
struct cpuidle_state *state = &drv->states[index];
137138
unsigned long eax = flg2MWAIT(state->flags);
138-
unsigned long ecx = 1; /* break on interrupt flag */
139+
unsigned long ecx = 1*irqoff; /* break on interrupt flag */
139140

140141
mwait_idle_with_hints(eax, ecx);
141142

@@ -159,19 +160,13 @@ static __always_inline int __intel_idle(struct cpuidle_device *dev,
159160
static __cpuidle int intel_idle(struct cpuidle_device *dev,
160161
struct cpuidle_driver *drv, int index)
161162
{
162-
return __intel_idle(dev, drv, index);
163+
return __intel_idle(dev, drv, index, true);
163164
}
164165

165166
static __cpuidle int intel_idle_irq(struct cpuidle_device *dev,
166167
struct cpuidle_driver *drv, int index)
167168
{
168-
int ret;
169-
170-
raw_local_irq_enable();
171-
ret = __intel_idle(dev, drv, index);
172-
raw_local_irq_disable();
173-
174-
return ret;
169+
return __intel_idle(dev, drv, index, false);
175170
}
176171

177172
static __cpuidle int intel_idle_ibrs(struct cpuidle_device *dev,
@@ -184,7 +179,7 @@ static __cpuidle int intel_idle_ibrs(struct cpuidle_device *dev,
184179
if (smt_active)
185180
__update_spec_ctrl(0);
186181

187-
ret = __intel_idle(dev, drv, index);
182+
ret = __intel_idle(dev, drv, index, true);
188183

189184
if (smt_active)
190185
__update_spec_ctrl(spec_ctrl);
@@ -196,7 +191,7 @@ static __cpuidle int intel_idle_xstate(struct cpuidle_device *dev,
196191
struct cpuidle_driver *drv, int index)
197192
{
198193
fpu_idle_fpregs();
199-
return __intel_idle(dev, drv, index);
194+
return __intel_idle(dev, drv, index, true);
200195
}
201196

202197
/**
@@ -923,6 +918,35 @@ static struct cpuidle_state adl_l_cstates[] __initdata = {
923918
.enter = NULL }
924919
};
925920

921+
static struct cpuidle_state mtl_l_cstates[] __initdata = {
922+
{
923+
.name = "C1E",
924+
.desc = "MWAIT 0x01",
925+
.flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
926+
.exit_latency = 1,
927+
.target_residency = 1,
928+
.enter = &intel_idle,
929+
.enter_s2idle = intel_idle_s2idle, },
930+
{
931+
.name = "C6",
932+
.desc = "MWAIT 0x20",
933+
.flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
934+
.exit_latency = 140,
935+
.target_residency = 420,
936+
.enter = &intel_idle,
937+
.enter_s2idle = intel_idle_s2idle, },
938+
{
939+
.name = "C10",
940+
.desc = "MWAIT 0x60",
941+
.flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
942+
.exit_latency = 310,
943+
.target_residency = 930,
944+
.enter = &intel_idle,
945+
.enter_s2idle = intel_idle_s2idle, },
946+
{
947+
.enter = NULL }
948+
};
949+
926950
static struct cpuidle_state gmt_cstates[] __initdata = {
927951
{
928952
.name = "C1",
@@ -1415,6 +1439,10 @@ static const struct idle_cpu idle_cpu_adl_l __initconst = {
14151439
.state_table = adl_l_cstates,
14161440
};
14171441

1442+
static const struct idle_cpu idle_cpu_mtl_l __initconst = {
1443+
.state_table = mtl_l_cstates,
1444+
};
1445+
14181446
static const struct idle_cpu idle_cpu_gmt __initconst = {
14191447
.state_table = gmt_cstates,
14201448
};
@@ -1501,6 +1529,7 @@ static const struct x86_cpu_id intel_idle_ids[] __initconst = {
15011529
X86_MATCH_INTEL_FAM6_MODEL(ICELAKE_D, &idle_cpu_icx),
15021530
X86_MATCH_INTEL_FAM6_MODEL(ALDERLAKE, &idle_cpu_adl),
15031531
X86_MATCH_INTEL_FAM6_MODEL(ALDERLAKE_L, &idle_cpu_adl_l),
1532+
X86_MATCH_INTEL_FAM6_MODEL(METEORLAKE_L, &idle_cpu_mtl_l),
15041533
X86_MATCH_INTEL_FAM6_MODEL(ATOM_GRACEMONT, &idle_cpu_gmt),
15051534
X86_MATCH_INTEL_FAM6_MODEL(SAPPHIRERAPIDS_X, &idle_cpu_spr),
15061535
X86_MATCH_INTEL_FAM6_MODEL(EMERALDRAPIDS_X, &idle_cpu_spr),
@@ -1905,7 +1934,8 @@ static void __init spr_idle_state_table_update(void)
19051934

19061935
static bool __init intel_idle_verify_cstate(unsigned int mwait_hint)
19071936
{
1908-
unsigned int mwait_cstate = MWAIT_HINT2CSTATE(mwait_hint) + 1;
1937+
unsigned int mwait_cstate = (MWAIT_HINT2CSTATE(mwait_hint) + 1) &
1938+
MWAIT_CSTATE_MASK;
19091939
unsigned int num_substates = (mwait_substates >> mwait_cstate * 4) &
19101940
MWAIT_SUBSTATE_MASK;
19111941

0 commit comments

Comments
 (0)