8000 cpuidle: Fix last_residency division · bsd-unix/linux@dbd1b8e · GitHub
[go: up one dir, main page]

Skip to content

Commit dbd1b8e

Browse files
shreyasbprafaeljw
authored andcommitted
cpuidle: Fix last_residency division
Snooze is a poll idle state in powernv and pseries platforms. Snooze has a timeout so that if a CPU stays in snooze for more than target residency of the next available idle state, then it would exit thereby giving chance to the cpuidle governor to re-evaluate and promote the CPU to a deeper idle state. Therefore whenever snooze exits due to this timeout, its last_residency will be target_residency of the next deeper state. Commit e93e59c "cpuidle: Replace ktime_get() with local_clock()" changed the math around last_residency calculation. Specifically, while converting last_residency value from nano- to microseconds, it carries out right shift by 10. Because of that, in snooze timeout exit scenarios last_residency calculated is roughly 2.3% less than target_residency of the next available state. This pattern is picked up by get_typical_interval() in the menu governor and therefore expected_interval in menu_select() is frequently less than the target_residency of any state other than snooze. Due to this we are entering snooze at a higher rate, thereby affecting the single thread performance. Fix this by using more precise division via ktime_us_delta(). Fixes: e93e59c "cpuidle: Replace ktime_get() with local_clock()" Reported-by: Anton Blanchard <anton@samba.org> Bisected-by: Shilpasri G Bhat <shilpa.bhat@linux.vnet.ibm.com> Signed-off-by: Shreyas B. Prabhu <shreyas@linux.vnet.ibm.com> Acked-by: Daniel Lezcano <daniel.lezcano@linaro.org> Acked-by: Balbir Singh <bsingharora@gmail.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 4c2e07c commit dbd1b8e

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

drivers/cpuidle/cpuidle.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ int cpuidle_enter_state(struct cpuidle_device *dev, struct cpuidle_driver *drv,
173173

174174
struct cpuidle_state *target_state = &drv->states[index];
175175
bool broadcast = !!(target_state->flags & CPUIDLE_FLAG_TIMER_STOP);
176-
u64 time_start, time_end;
176+
ktime_t time_start, time_end;
177177
s64 diff;
178178

179179
/*
@@ -195,13 +195,13 @@ int cpuidle_enter_state(struct cpuidle_device *dev, struct cpuidle_driver *drv,
195195
sched_idle_set_state(target_state);
196196

197197
trace_cpu_idle_rcuidle(index, dev->cpu);
198-
time_start = local_clock();
198+
time_start = ns_to_ktime(local_clock());
199199

200200
stop_critical_timings();
201201
entered_state = target_state->enter(dev, drv, index);
202202
start_critical_timings();
203203

204-
time_end = local_clock();
204+
time_end = ns_to_ktime(local_clock());
205205
trace_cpu_idle_rcuidle(PWR_EVENT_EXIT, dev->cpu);
206206

207207
/* The cpu is no longer idle or about to enter idle. */
@@ -217,11 +217,7 @@ int cpuidle_enter_state(struct cpuidle_device *dev, struct cpuidle_driver *drv,
217217
if (!cpuidle_state_is_coupled(drv, index))
218218
local_irq_enable();
219219

220-
/*
221-
* local_clock() returns the time in nanosecond, let's shift
222-
* by 10 (divide by 1024) to have microsecond based time.
223-
*/
224-
diff = (time_end - time_start) >> 10;
220+
diff = ktime_us_delta(time_end, time_start);
225221
if (diff > INT_MAX)
226222
diff = INT_MAX;
227223

0 commit comments

Comments
 (0)
0