提交 dc59f8b0 编写于 作者: M Marcelo Tosatti 提交者: Shile Zhang

governors: unify last_state_idx

commit 7d4daeedd575bbc3c40c87fc6708a8b88c50fe7e upstream

Since this field is shared by all governors, move it to
cpuidle device structure.
Signed-off-by: NMarcelo Tosatti <mtosatti@redhat.com>
Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: NYihao Wu <wuyihao@linux.alibaba.com>
Acked-by: NMichael Wang <yun.wang@linux.alibaba.com>
上级 5e083c5c
...@@ -38,7 +38,6 @@ struct ladder_device_state { ...@@ -38,7 +38,6 @@ struct ladder_device_state {
struct ladder_device { struct ladder_device {
struct ladder_device_state states[CPUIDLE_STATE_MAX]; struct ladder_device_state states[CPUIDLE_STATE_MAX];
int last_state_idx;
}; };
static DEFINE_PER_CPU(struct ladder_device, ladder_devices); static DEFINE_PER_CPU(struct ladder_device, ladder_devices);
...@@ -49,12 +48,13 @@ static DEFINE_PER_CPU(struct ladder_device, ladder_devices); ...@@ -49,12 +48,13 @@ static DEFINE_PER_CPU(struct ladder_device, ladder_devices);
* @old_idx: the current state index * @old_idx: the current state index
* @new_idx: the new target state index * @new_idx: the new target state index
*/ */
static inline void ladder_do_selection(struct ladder_device *ldev, static inline void ladder_do_selection(struct cpuidle_device *dev,
struct ladder_device *ldev,
int old_idx, int new_idx) int old_idx, int new_idx)
{ {
ldev->states[old_idx].stats.promotion_count = 0; ldev->states[old_idx].stats.promotion_count = 0;
ldev->states[old_idx].stats.demotion_count = 0; ldev->states[old_idx].stats.demotion_count = 0;
ldev->last_state_idx = new_idx; dev->last_state_idx = new_idx;
} }
/** /**
...@@ -68,13 +68,13 @@ static int ladder_select_state(struct cpuidle_driver *drv, ...@@ -68,13 +68,13 @@ static int ladder_select_state(struct cpuidle_driver *drv,
{ {
struct ladder_device *ldev = this_cpu_ptr(&ladder_devices); struct ladder_device *ldev = this_cpu_ptr(&ladder_devices);
struct ladder_device_state *last_state; struct ladder_device_state *last_state;
int last_residency, last_idx = ldev->last_state_idx; int last_residency, last_idx = dev->last_state_idx;
int first_idx = drv->states[0].flags & CPUIDLE_FLAG_POLLING ? 1 : 0; int first_idx = drv->states[0].flags & CPUIDLE_FLAG_POLLING ? 1 : 0;
int latency_req = cpuidle_governor_latency_req(dev->cpu); int latency_req = cpuidle_governor_latency_req(dev->cpu);
/* Special case when user has set very strict latency requirement */ /* Special case when user has set very strict latency requirement */
if (unlikely(latency_req == 0)) { if (unlikely(latency_req == 0)) {
ladder_do_selection(ldev, last_idx, 0); ladder_do_selection(dev, ldev, last_idx, 0);
return 0; return 0;
} }
...@@ -91,7 +91,7 @@ static int ladder_select_state(struct cpuidle_driver *drv, ...@@ -91,7 +91,7 @@ static int ladder_select_state(struct cpuidle_driver *drv,
last_state->stats.promotion_count++; last_state->stats.promotion_count++;
last_state->stats.demotion_count = 0; last_state->stats.demotion_count = 0;
if (last_state->stats.promotion_count >= last_state->threshold.promotion_count) { if (last_state->stats.promotion_count >= last_state->threshold.promotion_count) {
ladder_do_selection(ldev, last_idx, last_idx + 1); ladder_do_selection(dev, ldev, last_idx, last_idx + 1);
return last_idx + 1; return last_idx + 1;
} }
} }
...@@ -107,7 +107,7 @@ static int ladder_select_state(struct cpuidle_driver *drv, ...@@ -107,7 +107,7 @@ static int ladder_select_state(struct cpuidle_driver *drv,
if (drv->states[i].exit_latency <= latency_req) if (drv->states[i].exit_latency <= latency_req)
break; break;
} }
ladder_do_selection(ldev, last_idx, i); ladder_do_selection(dev, ldev, last_idx, i);
return i; return i;
} }
...@@ -116,7 +116,7 @@ static int ladder_select_state(struct cpuidle_driver *drv, ...@@ -116,7 +116,7 @@ static int ladder_select_state(struct cpuidle_driver *drv,
last_state->stats.demotion_count++; last_state->stats.demotion_count++;
last_state->stats.promotion_count = 0; last_state->stats.promotion_count = 0;
if (last_state->stats.demotion_count >= last_state->threshold.demotion_count) { if (last_state->stats.demotion_count >= last_state->threshold.demotion_count) {
ladder_do_selection(ldev, last_idx, last_idx - 1); ladder_do_selection(dev, ldev, last_idx, last_idx - 1);
return last_idx - 1; return last_idx - 1;
} }
} }
...@@ -139,7 +139,7 @@ static int ladder_enable_device(struct cpuidle_driver *drv, ...@@ -139,7 +139,7 @@ static int ladder_enable_device(struct cpuidle_driver *drv,
struct ladder_device_state *lstate; struct ladder_device_state *lstate;
struct cpuidle_state *state; struct cpuidle_state *state;
ldev->last_state_idx = first_idx; dev->last_state_idx = first_idx;
for (i = first_idx; i < drv->state_count; i++) { for (i = first_idx; i < drv->state_count; i++) {
state = &drv->states[i]; state = &drv->states[i];
...@@ -167,9 +167,8 @@ static int ladder_enable_device(struct cpuidle_driver *drv, ...@@ -167,9 +167,8 @@ static int ladder_enable_device(struct cpuidle_driver *drv,
*/ */
static void ladder_reflect(struct cpuidle_device *dev, int index) static void ladder_reflect(struct cpuidle_device *dev, int index)
{ {
struct ladder_device *ldev = this_cpu_ptr(&ladder_devices);
if (index > 0) if (index > 0)
ldev->last_state_idx = index; dev->last_state_idx = index;
} }
static struct cpuidle_governor ladder_governor = { static struct cpuidle_governor ladder_governor = {
......
...@@ -119,7 +119,6 @@ ...@@ -119,7 +119,6 @@
*/ */
struct menu_device { struct menu_device {
int last_state_idx;
int needs_update; int needs_update;
int tick_wakeup; int tick_wakeup;
...@@ -461,7 +460,7 @@ static void menu_reflect(struct cpuidle_device *dev, int index) ...@@ -461,7 +460,7 @@ static void menu_reflect(struct cpuidle_device *dev, int index)
{ {
struct menu_device *data = this_cpu_ptr(&menu_devices); struct menu_device *data = this_cpu_ptr(&menu_devices);
data->last_state_idx = index; dev->last_state_idx = index;
data->needs_update = 1; data->needs_update = 1;
data->tick_wakeup = tick_nohz_idle_got_tick(); data->tick_wakeup = tick_nohz_idle_got_tick();
} }
...@@ -474,7 +473,7 @@ static void menu_reflect(struct cpuidle_device *dev, int index) ...@@ -474,7 +473,7 @@ static void menu_reflect(struct cpuidle_device *dev, int index)
static void menu_update(struct cpuidle_driver *drv, struct cpuidle_device *dev) static void menu_update(struct cpuidle_driver *drv, struct cpuidle_device *dev)
{ {
struct menu_device *data = this_cpu_ptr(&menu_devices); struct menu_device *data = this_cpu_ptr(&menu_devices);
int last_idx = data->last_state_idx; int last_idx = dev->last_state_idx;
struct cpuidle_state *target = &drv->states[last_idx]; struct cpuidle_state *target = &drv->states[last_idx];
unsigned int measured_us; unsigned int measured_us;
unsigned int new_factor; unsigned int new_factor;
......
...@@ -84,6 +84,7 @@ struct cpuidle_device { ...@@ -84,6 +84,7 @@ struct cpuidle_device {
unsigned int poll_time_limit:1; unsigned int poll_time_limit:1;
unsigned int cpu; unsigned int cpu;
int last_state_idx;
int last_residency; int last_residency;
u64 poll_limit_ns; u64 poll_limit_ns;
struct cpuidle_state_usage states_usage[CPUIDLE_STATE_MAX]; struct cpuidle_state_usage states_usage[CPUIDLE_STATE_MAX];
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册