Skip to content

Commit 40ab82e

Browse files
committed
intel_idle: Simplify LAPIC timer reliability checks
The lapic_timer_always_reliable variable really takes only two values and some arithmetic in intel_idle() related to comparing it with the target C-state's MWAIT hint value is unnecessary. Simplify the code by replacing lapic_timer_always_reliable with a bool variable lapic_timer_always_reliable and dropping the LAPIC_TIMER_ALWAYS_RELIABLE symbol along with the excess computations in intel_idle(). While at it, add a comment explaining the branch taken in intel_idle() if the LAPIC timer is only reliable in C1 and modify the related debug message in intel_idle_init() accordingly (the modification of this message in the only expected functional impact of the change made here). Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent bb6d3fb commit 40ab82e

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

drivers/idle/intel_idle.c

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,7 @@ static int max_cstate = CPUIDLE_STATE_MAX - 1;
6666
static unsigned int disabled_states_mask;
6767

6868
static unsigned int mwait_substates;
69-
70-
#define LAPIC_TIMER_ALWAYS_RELIABLE 0xFFFFFFFF
71-
/* Reliable LAPIC Timer States, bit 1 for C1 etc. */
72-
static unsigned int lapic_timer_reliable_states = (1 << 1); /* Default to only C1 */
69+
static bool lapic_timer_always_reliable;
7370

7471
struct idle_cpu {
7572
struct cpuidle_state *state_table;
@@ -908,7 +905,6 @@ static __cpuidle int intel_idle(struct cpuidle_device *dev,
908905
unsigned long ecx = 1; /* break on interrupt flag */
909906
struct cpuidle_state *state = &drv->states[index];
910907
unsigned long eax = flg2MWAIT(state->flags);
911-
unsigned int cstate;
912908
bool uninitialized_var(tick);
913909
int cpu = smp_processor_id();
914910

@@ -919,13 +915,16 @@ static __cpuidle int intel_idle(struct cpuidle_device *dev,
919915
if (state->flags & CPUIDLE_FLAG_TLB_FLUSHED)
920916
leave_mm(cpu);
921917

922-
if (!static_cpu_has(X86_FEATURE_ARAT)) {
923-
cstate = (((eax) >> MWAIT_SUBSTATE_SIZE) &
924-
MWAIT_CSTATE_MASK) + 1;
925-
tick = false;
926-
if (!(lapic_timer_reliable_states & (1 << (cstate)))) {
918+
if (!static_cpu_has(X86_FEATURE_ARAT) && !lapic_timer_always_reliable) {
919+
/*
920+
* Switch over to one-shot tick broadcast if the target C-state
921+
* is deeper than C1.
922+
*/
923+
if ((eax >> MWAIT_SUBSTATE_SIZE) & MWAIT_CSTATE_MASK) {
927924
tick = true;
928925
tick_broadcast_enter();
926+
} else {
927+
tick = false;
929928
}
930929
}
931930

@@ -1555,7 +1554,7 @@ static int intel_idle_cpu_online(unsigned int cpu)
15551554
{
15561555
struct cpuidle_device *dev;
15571556

1558-
if (lapic_timer_reliable_states != LAPIC_TIMER_ALWAYS_RELIABLE)
1557+
if (!lapic_timer_always_reliable)
15591558
tick_broadcast_enable();
15601559

15611560
/*
@@ -1647,15 +1646,15 @@ static int __init intel_idle_init(void)
16471646
}
16481647

16491648
if (boot_cpu_has(X86_FEATURE_ARAT)) /* Always Reliable APIC Timer */
1650-
lapic_timer_reliable_states = LAPIC_TIMER_ALWAYS_RELIABLE;
1649+
lapic_timer_always_reliable = true;
16511650

16521651
retval = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "idle/intel:online",
16531652
intel_idle_cpu_online, NULL);
16541653
if (retval < 0)
16551654
goto hp_setup_fail;
16561655

1657-
pr_debug("lapic_timer_reliable_states 0x%x\n",
1658-
lapic_timer_reliable_states);
1656+
pr_debug("Local APIC timer is reliable in %s\n",
1657+
lapic_timer_always_reliable ? "all C-states" : "C1");
16591658

16601659
return 0;
16611660

0 commit comments

Comments
 (0)