15 #include <linux/kernel.h>
18 #include <linux/module.h>
22 #include <asm/uaccess.h>
24 #define PROMOTION_COUNT 4
25 #define DEMOTION_COUNT 1
53 static inline void ladder_do_selection(
struct ladder_device *ldev,
54 int old_idx,
int new_idx)
56 ldev->
states[old_idx].stats.promotion_count = 0;
57 ldev->
states[old_idx].stats.demotion_count = 0;
76 ladder_do_selection(ldev, last_idx, 0);
80 last_state = &ldev->
states[last_idx];
83 last_residency = cpuidle_get_last_residency(dev) - \
84 drv->states[last_idx].exit_latency;
87 last_residency = last_state->
threshold.promotion_time + 1;
90 if (last_idx < drv->state_count - 1 &&
91 !drv->
states[last_idx + 1].disabled &&
93 last_residency > last_state->
threshold.promotion_time &&
94 drv->
states[last_idx + 1].exit_latency <= latency_req) {
95 last_state->
stats.promotion_count++;
96 last_state->
stats.demotion_count = 0;
97 if (last_state->
stats.promotion_count >= last_state->
threshold.promotion_count) {
98 ladder_do_selection(ldev, last_idx, last_idx + 1);
105 (drv->
states[last_idx].disabled ||
107 drv->
states[last_idx].exit_latency > latency_req)) {
111 if (drv->
states[i].exit_latency <= latency_req)
114 ladder_do_selection(ldev, last_idx, i);
118 if (last_idx > CPUIDLE_DRIVER_STATE_START &&
119 last_residency < last_state->
threshold.demotion_time) {
120 last_state->
stats.demotion_count++;
121 last_state->
stats.promotion_count = 0;
122 if (last_state->
stats.demotion_count >= last_state->
threshold.demotion_count) {
123 ladder_do_selection(ldev, last_idx, last_idx - 1);
151 lstate->
stats.promotion_count = 0;
152 lstate->
stats.demotion_count = 0;
157 if (i < drv->state_count - 1)
181 .enable = ladder_enable_device,
182 .select = ladder_select_state,
183 .reflect = ladder_reflect,
190 static int __init init_ladder(
void)
198 static void __exit exit_ladder(
void)