Skip to content

Commit 65e18e6

Browse files
committed
cpuidle: teo: Replace time_span_ns with a flag
After recent updates, the time_span_ns field in struct teo_cpu has become an indicator on whether or not the most recent wakeup has been "genuine" which may as well be indicated by a bool field without calling local_clock(), so update the code accordingly. No intentional functional impact. Signed-off-by: Rafael J. Wysocki <[email protected]> Reviewed-by: Christian Loehle <[email protected]> Tested-by: Aboorva Devarajan <[email protected]> Tested-by: Christian Loehle <[email protected]> Link: https://patch.msgid.link/[email protected]
1 parent ddcfa79 commit 65e18e6

File tree

1 file changed

+9
-18
lines changed
  • drivers/cpuidle/governors

1 file changed

+9
-18
lines changed

drivers/cpuidle/governors/teo.c

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -124,20 +124,20 @@ struct teo_bin {
124124

125125
/**
126126
* struct teo_cpu - CPU data used by the TEO cpuidle governor.
127-
* @time_span_ns: Time between idle state selection and post-wakeup update.
128127
* @sleep_length_ns: Time till the closest timer event (at the selection time).
129128
* @state_bins: Idle state data bins for this CPU.
130129
* @total: Grand total of the "intercepts" and "hits" metrics for all bins.
131130
* @tick_intercepts: "Intercepts" before TICK_NSEC.
132131
* @short_idles: Wakeups after short idle periods.
132+
* @artificial_wakeup: Set if the wakeup has been triggered by a safety net.
133133
*/
134134
struct teo_cpu {
135-
s64 time_span_ns;
136135
s64 sleep_length_ns;
137136
struct teo_bin state_bins[CPUIDLE_STATE_MAX];
138137
unsigned int total;
139138
unsigned int tick_intercepts;
140139
unsigned int short_idles;
140+
bool artificial_wakeup;
141141
};
142142

143143
static DEFINE_PER_CPU(struct teo_cpu, teo_cpus);
@@ -156,7 +156,7 @@ static void teo_update(struct cpuidle_driver *drv, struct cpuidle_device *dev)
156156

157157
cpu_data->short_idles -= cpu_data->short_idles >> DECAY_SHIFT;
158158

159-
if (cpu_data->time_span_ns < 0) {
159+
if (cpu_data->artificial_wakeup) {
160160
/*
161161
* If one of the safety nets has triggered, assume that this
162162
* might have been a long sleep.
@@ -165,13 +165,6 @@ static void teo_update(struct cpuidle_driver *drv, struct cpuidle_device *dev)
165165
} else {
166166
u64 lat_ns = drv->states[dev->last_state_idx].exit_latency_ns;
167167

168-
/*
169-
* The computations below are to determine whether or not the
170-
* (saved) time till the next timer event and the measured idle
171-
* duration fall into the same "bin", so use last_residency_ns
172-
* for that instead of time_span_ns which includes the cpuidle
173-
* overhead.
174-
*/
175168
measured_ns = dev->last_residency_ns;
176169
/*
177170
* The delay between the wakeup and the first instruction
@@ -286,7 +279,6 @@ static int teo_select(struct cpuidle_driver *drv, struct cpuidle_device *dev,
286279
dev->last_state_idx = -1;
287280
}
288281

289-
cpu_data->time_span_ns = local_clock();
290282
/*
291283
* Set the sleep length to infinity in case the invocation of
292284
* tick_nohz_get_sleep_length() below is skipped, in which case it won't
@@ -504,17 +496,16 @@ static void teo_reflect(struct cpuidle_device *dev, int state)
504496
struct teo_cpu *cpu_data = per_cpu_ptr(&teo_cpus, dev->cpu);
505497

506498
dev->last_state_idx = state;
507-
/*
508-
* If the wakeup was not "natural", but triggered by one of the safety
509-
* nets, assume that the CPU might have been idle for the entire sleep
510-
* length time.
511-
*/
512499
if (dev->poll_time_limit ||
513500
(tick_nohz_idle_got_tick() && cpu_data->sleep_length_ns > TICK_NSEC)) {
501+
/*
502+
* The wakeup was not "genuine", but triggered by one of the
503+
* safety nets.
504+
*/
514505
dev->poll_time_limit = false;
515-
cpu_data->time_span_ns = KTIME_MIN;
506+
cpu_data->artificial_wakeup = true;
516507
} else {
517-
cpu_data->time_span_ns = local_clock() - cpu_data->time_span_ns;
508+
cpu_data->artificial_wakeup = false;
518509
}
519510
}
520511

0 commit comments

Comments
 (0)