summaryrefslogtreecommitdiffstats
path: root/drivers/cpuidle
diff options
context:
space:
mode:
authorMarcelo Tosatti <mtosatti@redhat.com>2019-07-03 19:51:27 -0400
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2019-07-30 11:27:37 -0400
commit7d4daeedd575bbc3c40c87fc6708a8b88c50fe7e (patch)
tree6d7dc0087f66e09fe2a7d1752ab657b56ee9d075 /drivers/cpuidle
parent259231a045616c4101d023a8f4dcc8379af265a6 (diff)
governors: unify last_state_idx
Since this field is shared by all governors, move it to cpuidle device structure. Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Diffstat (limited to 'drivers/cpuidle')
-rw-r--r--drivers/cpuidle/governors/ladder.c21
-rw-r--r--drivers/cpuidle/governors/menu.c5
-rw-r--r--drivers/cpuidle/governors/teo.c12
3 files changed, 18 insertions, 20 deletions
diff --git a/drivers/cpuidle/governors/ladder.c b/drivers/cpuidle/governors/ladder.c
index f0dddc66af26..428eeb832fe7 100644
--- a/drivers/cpuidle/governors/ladder.c
+++ b/drivers/cpuidle/governors/ladder.c
@@ -38,7 +38,6 @@ struct ladder_device_state {
38 38
39struct ladder_device { 39struct ladder_device {
40 struct ladder_device_state states[CPUIDLE_STATE_MAX]; 40 struct ladder_device_state states[CPUIDLE_STATE_MAX];
41 int last_state_idx;
42}; 41};
43 42
44static DEFINE_PER_CPU(struct ladder_device, ladder_devices); 43static DEFINE_PER_CPU(struct ladder_device, ladder_devices);
@@ -49,12 +48,13 @@ static DEFINE_PER_CPU(struct ladder_device, ladder_devices);
49 * @old_idx: the current state index 48 * @old_idx: the current state index
50 * @new_idx: the new target state index 49 * @new_idx: the new target state index
51 */ 50 */
52static inline void ladder_do_selection(struct ladder_device *ldev, 51static inline void ladder_do_selection(struct cpuidle_device *dev,
52 struct ladder_device *ldev,
53 int old_idx, int new_idx) 53 int old_idx, int new_idx)
54{ 54{
55 ldev->states[old_idx].stats.promotion_count = 0; 55 ldev->states[old_idx].stats.promotion_count = 0;
56 ldev->states[old_idx].stats.demotion_count = 0; 56 ldev->states[old_idx].stats.demotion_count = 0;
57 ldev->last_state_idx = new_idx; 57 dev->last_state_idx = new_idx;
58} 58}
59 59
60/** 60/**
@@ -68,13 +68,13 @@ static int ladder_select_state(struct cpuidle_driver *drv,
68{ 68{
69 struct ladder_device *ldev = this_cpu_ptr(&ladder_devices); 69 struct ladder_device *ldev = this_cpu_ptr(&ladder_devices);
70 struct ladder_device_state *last_state; 70 struct ladder_device_state *last_state;
71 int last_residency, last_idx = ldev->last_state_idx; 71 int last_residency, last_idx = dev->last_state_idx;
72 int first_idx = drv->states[0].flags & CPUIDLE_FLAG_POLLING ? 1 : 0; 72 int first_idx = drv->states[0].flags & CPUIDLE_FLAG_POLLING ? 1 : 0;
73 int latency_req = cpuidle_governor_latency_req(dev->cpu); 73 int latency_req = cpuidle_governor_latency_req(dev->cpu);
74 74
75 /* Special case when user has set very strict latency requirement */ 75 /* Special case when user has set very strict latency requirement */
76 if (unlikely(latency_req == 0)) { 76 if (unlikely(latency_req == 0)) {
77 ladder_do_selection(ldev, last_idx, 0); 77 ladder_do_selection(dev, ldev, last_idx, 0);
78 return 0; 78 return 0;
79 } 79 }
80 80
@@ -91,7 +91,7 @@ static int ladder_select_state(struct cpuidle_driver *drv,
91 last_state->stats.promotion_count++; 91 last_state->stats.promotion_count++;
92 last_state->stats.demotion_count = 0; 92 last_state->stats.demotion_count = 0;
93 if (last_state->stats.promotion_count >= last_state->threshold.promotion_count) { 93 if (last_state->stats.promotion_count >= last_state->threshold.promotion_count) {
94 ladder_do_selection(ldev, last_idx, last_idx + 1); 94 ladder_do_selection(dev, ldev, last_idx, last_idx + 1);
95 return last_idx + 1; 95 return last_idx + 1;
96 } 96 }
97 } 97 }
@@ -107,7 +107,7 @@ static int ladder_select_state(struct cpuidle_driver *drv,
107 if (drv->states[i].exit_latency <= latency_req) 107 if (drv->states[i].exit_latency <= latency_req)
108 break; 108 break;
109 } 109 }
110 ladder_do_selection(ldev, last_idx, i); 110 ladder_do_selection(dev, ldev, last_idx, i);
111 return i; 111 return i;
112 } 112 }
113 113
@@ -116,7 +116,7 @@ static int ladder_select_state(struct cpuidle_driver *drv,
116 last_state->stats.demotion_count++; 116 last_state->stats.demotion_count++;
117 last_state->stats.promotion_count = 0; 117 last_state->stats.promotion_count = 0;
118 if (last_state->stats.demotion_count >= last_state->threshold.demotion_count) { 118 if (last_state->stats.demotion_count >= last_state->threshold.demotion_count) {
119 ladder_do_selection(ldev, last_idx, last_idx - 1); 119 ladder_do_selection(dev, ldev, last_idx, last_idx - 1);
120 return last_idx - 1; 120 return last_idx - 1;
121 } 121 }
122 } 122 }
@@ -139,7 +139,7 @@ static int ladder_enable_device(struct cpuidle_driver *drv,
139 struct ladder_device_state *lstate; 139 struct ladder_device_state *lstate;
140 struct cpuidle_state *state; 140 struct cpuidle_state *state;
141 141
142 ldev->last_state_idx = first_idx; 142 dev->last_state_idx = first_idx;
143 143
144 for (i = first_idx; i < drv->state_count; i++) { 144 for (i = first_idx; i < drv->state_count; i++) {
145 state = &drv->states[i]; 145 state = &drv->states[i];
@@ -167,9 +167,8 @@ static int ladder_enable_device(struct cpuidle_driver *drv,
167 */ 167 */
168static void ladder_reflect(struct cpuidle_device *dev, int index) 168static void ladder_reflect(struct cpuidle_device *dev, int index)
169{ 169{
170 struct ladder_device *ldev = this_cpu_ptr(&ladder_devices);
171 if (index > 0) 170 if (index > 0)
172 ldev->last_state_idx = index; 171 dev->last_state_idx = index;
173} 172}
174 173
175static struct cpuidle_governor ladder_governor = { 174static struct cpuidle_governor ladder_governor = {
diff --git a/drivers/cpuidle/governors/menu.c b/drivers/cpuidle/governors/menu.c
index e9a28c7846d6..dace4c7f830c 100644
--- a/drivers/cpuidle/governors/menu.c
+++ b/drivers/cpuidle/governors/menu.c
@@ -117,7 +117,6 @@
117 */ 117 */
118 118
119struct menu_device { 119struct menu_device {
120 int last_state_idx;
121 int needs_update; 120 int needs_update;
122 int tick_wakeup; 121 int tick_wakeup;
123 122
@@ -455,7 +454,7 @@ static void menu_reflect(struct cpuidle_device *dev, int index)
455{ 454{
456 struct menu_device *data = this_cpu_ptr(&menu_devices); 455 struct menu_device *data = this_cpu_ptr(&menu_devices);
457 456
458 data->last_state_idx = index; 457 dev->last_state_idx = index;
459 data->needs_update = 1; 458 data->needs_update = 1;
460 data->tick_wakeup = tick_nohz_idle_got_tick(); 459 data->tick_wakeup = tick_nohz_idle_got_tick();
461} 460}
@@ -468,7 +467,7 @@ static void menu_reflect(struct cpuidle_device *dev, int index)
468static void menu_update(struct cpuidle_driver *drv, struct cpuidle_device *dev) 467static void menu_update(struct cpuidle_driver *drv, struct cpuidle_device *dev)
469{ 468{
470 struct menu_device *data = this_cpu_ptr(&menu_devices); 469 struct menu_device *data = this_cpu_ptr(&menu_devices);
471 int last_idx = data->last_state_idx; 470 int last_idx = dev->last_state_idx;
472 struct cpuidle_state *target = &drv->states[last_idx]; 471 struct cpuidle_state *target = &drv->states[last_idx];
473 unsigned int measured_us; 472 unsigned int measured_us;
474 unsigned int new_factor; 473 unsigned int new_factor;
diff --git a/drivers/cpuidle/governors/teo.c b/drivers/cpuidle/governors/teo.c
index 7d05efdbd3c6..a2fd81067a13 100644
--- a/drivers/cpuidle/governors/teo.c
+++ b/drivers/cpuidle/governors/teo.c
@@ -96,7 +96,6 @@ struct teo_idle_state {
96 * @time_span_ns: Time between idle state selection and post-wakeup update. 96 * @time_span_ns: Time between idle state selection and post-wakeup update.
97 * @sleep_length_ns: Time till the closest timer event (at the selection time). 97 * @sleep_length_ns: Time till the closest timer event (at the selection time).
98 * @states: Idle states data corresponding to this CPU. 98 * @states: Idle states data corresponding to this CPU.
99 * @last_state: Idle state entered by the CPU last time.
100 * @interval_idx: Index of the most recent saved idle interval. 99 * @interval_idx: Index of the most recent saved idle interval.
101 * @intervals: Saved idle duration values. 100 * @intervals: Saved idle duration values.
102 */ 101 */
@@ -104,7 +103,6 @@ struct teo_cpu {
104 u64 time_span_ns; 103 u64 time_span_ns;
105 u64 sleep_length_ns; 104 u64 sleep_length_ns;
106 struct teo_idle_state states[CPUIDLE_STATE_MAX]; 105 struct teo_idle_state states[CPUIDLE_STATE_MAX];
107 int last_state;
108 int interval_idx; 106 int interval_idx;
109 unsigned int intervals[INTERVALS]; 107 unsigned int intervals[INTERVALS];
110}; 108};
@@ -130,7 +128,9 @@ static void teo_update(struct cpuidle_driver *drv, struct cpuidle_device *dev)
130 */ 128 */
131 measured_us = sleep_length_us; 129 measured_us = sleep_length_us;
132 } else { 130 } else {
133 unsigned int lat = drv->states[cpu_data->last_state].exit_latency; 131 unsigned int lat;
132
133 lat = drv->states[dev->last_state_idx].exit_latency;
134 134
135 measured_us = ktime_to_us(cpu_data->time_span_ns); 135 measured_us = ktime_to_us(cpu_data->time_span_ns);
136 /* 136 /*
@@ -245,9 +245,9 @@ static int teo_select(struct cpuidle_driver *drv, struct cpuidle_device *dev,
245 int max_early_idx, idx, i; 245 int max_early_idx, idx, i;
246 ktime_t delta_tick; 246 ktime_t delta_tick;
247 247
248 if (cpu_data->last_state >= 0) { 248 if (dev->last_state_idx >= 0) {
249 teo_update(drv, dev); 249 teo_update(drv, dev);
250 cpu_data->last_state = -1; 250 dev->last_state_idx = -1;
251 } 251 }
252 252
253 cpu_data->time_span_ns = local_clock(); 253 cpu_data->time_span_ns = local_clock();
@@ -394,7 +394,7 @@ static void teo_reflect(struct cpuidle_device *dev, int state)
394{ 394{
395 struct teo_cpu *cpu_data = per_cpu_ptr(&teo_cpus, dev->cpu); 395 struct teo_cpu *cpu_data = per_cpu_ptr(&teo_cpus, dev->cpu);
396 396
397 cpu_data->last_state = state; 397 dev->last_state_idx = state;
398 /* 398 /*
399 * If the wakeup was not "natural", but triggered by one of the safety 399 * If the wakeup was not "natural", but triggered by one of the safety
400 * nets, assume that the CPU might have been idle for the entire sleep 400 * nets, assume that the CPU might have been idle for the entire sleep