Skip to content

Commit 32d4fd5

Browse files
Peter Zijlstrarafaeljw
authored andcommitted
cpuidle,intel_idle: Fix CPUIDLE_FLAG_IRQ_ENABLE
Commit c227233 ("intel_idle: enable interrupts before C1 on Xeons") wrecked intel_idle in two ways: - must not have tracing in idle functions - must return with IRQs disabled Additionally, it added a branch for no good reason. Fixes: c227233 ("intel_idle: enable interrupts before C1 on Xeons") Signed-off-by: Peter Zijlstra (Intel) <[email protected]> [ rjw: Moved the intel_idle() kerneldoc comment next to the function ] Cc: 5.16+ <[email protected]> # 5.16+ Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent f2906aa commit 32d4fd5

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

drivers/idle/intel_idle.c

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,18 @@ static unsigned int mwait_substates __initdata;
115115
#define flg2MWAIT(flags) (((flags) >> 24) & 0xFF)
116116
#define MWAIT2flg(eax) ((eax & 0xFF) << 24)
117117

118+
static __always_inline int __intel_idle(struct cpuidle_device *dev,
119+
struct cpuidle_driver *drv, int index)
120+
{
121+
struct cpuidle_state *state = &drv->states[index];
122+
unsigned long eax = flg2MWAIT(state->flags);
123+
unsigned long ecx = 1; /* break on interrupt flag */
124+
125+
mwait_idle_with_hints(eax, ecx);
126+
127+
return index;
128+
}
129+
118130
/**
119131
* intel_idle - Ask the processor to enter the given idle state.
120132
* @dev: cpuidle device of the target CPU.
@@ -132,16 +144,19 @@ static unsigned int mwait_substates __initdata;
132144
static __cpuidle int intel_idle(struct cpuidle_device *dev,
133145
struct cpuidle_driver *drv, int index)
134146
{
135-
struct cpuidle_state *state = &drv->states[index];
136-
unsigned long eax = flg2MWAIT(state->flags);
137-
unsigned long ecx = 1; /* break on interrupt flag */
147+
return __intel_idle(dev, drv, index);
148+
}
138149

139-
if (state->flags & CPUIDLE_FLAG_IRQ_ENABLE)
140-
local_irq_enable();
150+
static __cpuidle int intel_idle_irq(struct cpuidle_device *dev,
151+
struct cpuidle_driver *drv, int index)
152+
{
153+
int ret;
141154

142-
mwait_idle_with_hints(eax, ecx);
155+
raw_local_irq_enable();
156+
ret = __intel_idle(dev, drv, index);
157+
raw_local_irq_disable();
143158

144-
return index;
159+
return ret;
145160
}
146161

147162
/**
@@ -1801,6 +1816,9 @@ static void __init intel_idle_init_cstates_icpu(struct cpuidle_driver *drv)
18011816
/* Structure copy. */
18021817
drv->states[drv->state_count] = cpuidle_state_table[cstate];
18031818

1819+
if (cpuidle_state_table[cstate].flags & CPUIDLE_FLAG_IRQ_ENABLE)
1820+
drv->states[drv->state_count].enter = intel_idle_irq;
1821+
18041822
if ((disabled_states_mask & BIT(drv->state_count)) ||
18051823
((icpu->use_acpi || force_use_acpi) &&
18061824
intel_idle_off_by_default(mwait_hint) &&

0 commit comments

Comments
 (0)