cpuidle: governors: qcom-lpm: Move start of prediction

Currently first prediction is done and then checks like PM QoS and
idle state is enabled or not are happening. Swap this. Now predict
only if checks like PM QoS latency and idle state not disabled are
passed which will make WFI entry latency reduced.

While at this also do below misc optimizations and clean up.

1. Update check_cpu_active() function to be inline.
2. Move cancelling bias and pred timer to lpm_idle_exit().
3. Do not check for state0 (WFI) disabled as its default choice of
   selection.
4. Use NSEC_PER_USEC to convert duration to usec instead of 1000
   number.
5. Correct spacing in arithmetic operations.
6. Make goto label fail name consistent.
7. Declare suspend_disabled as static.

Change-Id: I8825b423e6939559bd395801b365a610c6de82c7
Signed-off-by: Maulik Shah <mkshah@codeaurora.org>
This commit is contained in:
Maulik Shah 2021-09-02 22:52:11 +05:30 committed by Tushar Nimkar
parent 51877d2426
commit 286f84a887
2 changed files with 17 additions and 20 deletions

View File

@ -40,13 +40,13 @@
bool prediction_disabled;
bool sleep_disabled = true;
bool suspend_disabled;
static bool suspend_disabled;
static bool traces_registered;
static struct cluster_governor *cluster_gov_ops;
DEFINE_PER_CPU(struct lpm_cpu, lpm_cpu_data);
static bool check_cpu_isactive(int cpu)
static inline bool check_cpu_isactive(int cpu)
{
return cpu_active(cpu);
}
@ -341,7 +341,7 @@ static void update_cpu_history(struct lpm_cpu *cpu_gov)
u64 measured_us = ktime_to_us(cpu_gov->dev->last_residency_ns);
struct cpuidle_state *target;
if (prediction_disabled || idx < 0 || idx > cpu_gov->drv->state_count-1)
if (prediction_disabled || idx < 0 || idx > cpu_gov->drv->state_count - 1)
return;
target = &cpu_gov->drv->states[idx];
@ -351,7 +351,7 @@ static void update_cpu_history(struct lpm_cpu *cpu_gov)
if (cpu_gov->htmr_wkup) {
if (!lpm_history->samples_idx)
lpm_history->samples_idx = MAXSAMPLES-1;
lpm_history->samples_idx = MAXSAMPLES - 1;
else
lpm_history->samples_idx--;
@ -546,22 +546,18 @@ static int lpm_select(struct cpuidle_driver *drv, struct cpuidle_device *dev,
do_div(latency_req, NSEC_PER_USEC);
cpu_gov->predicted = 0;
cpu_gov->predict_started = false;
cpu_gov->now = ktime_get();
histtimer_cancel();
biastimer_cancel();
duration_ns = tick_nohz_get_sleep_length(&delta_tick);
update_cpu_history(cpu_gov);
if (lpm_disallowed(duration_ns, dev->cpu))
goto done;
if (check_cpu_isactive(dev->cpu))
cpu_predict(cpu_gov, duration_ns);
for (i = drv->state_count - 1; i > 0; i--) {
struct cpuidle_state *s = &drv->states[i];
if (dev->states_usage[i].disable) {
if (!i && dev->states_usage[i].disable) {
reason |= UPDATE_REASON(i, LPM_SELECT_STATE_DISABLED);
continue;
}
@ -577,6 +573,11 @@ static int lpm_select(struct cpuidle_driver *drv, struct cpuidle_device *dev,
continue;
}
if (check_cpu_isactive(dev->cpu) && !cpu_gov->predict_started) {
cpu_predict(cpu_gov, duration_ns);
cpu_gov->predict_started = true;
}
if (cpu_gov->predicted)
if (s->target_residency > cpu_gov->predicted) {
reason |= UPDATE_REASON(i,
@ -586,7 +587,7 @@ static int lpm_select(struct cpuidle_driver *drv, struct cpuidle_device *dev,
break;
}
do_div(duration_ns, 1000);
do_div(duration_ns, NSEC_PER_USEC);
cpu_gov->last_idx = i;
cpu_gov->next_wakeup = ktime_add_us(cpu_gov->now, duration_ns);
htime = start_prediction_timer(cpu_gov, duration_ns);
@ -614,12 +615,7 @@ static int lpm_select(struct cpuidle_driver *drv, struct cpuidle_device *dev,
*/
static void lpm_reflect(struct cpuidle_device *dev, int state)
{
struct lpm_cpu *cpu_gov = per_cpu_ptr(&lpm_cpu_data, dev->cpu);
if (cpu_gov->enable) {
histtimer_cancel();
biastimer_cancel();
}
}
/**
@ -649,7 +645,8 @@ static void lpm_idle_enter(void *unused, int *state, struct cpuidle_device *dev)
*/
static void lpm_idle_exit(void *unused, int state, struct cpuidle_device *dev)
{
histtimer_cancel();
biastimer_cancel();
}
/**
@ -798,18 +795,17 @@ static int __init qcom_lpm_governor_init(void)
ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "qcom-cpu-lpm",
lpm_online_cpu, lpm_offline_cpu);
if (ret < 0)
goto cpuhp_setup_failed;
goto cpuhp_setup_fail;
return 0;
cpuhp_setup_failed:
cpuhp_setup_fail:
unregister_trace_suspend_resume(qcom_lpm_suspend_trace, NULL);
cpuidle_reg_fail:
qcom_cluster_lpm_governor_deinit();
cluster_init_fail:
remove_global_sysfs_nodes();
sysfs_fail:
return ret;
}
module_init(qcom_lpm_governor_init);

View File

@ -49,6 +49,7 @@ struct lpm_cpu {
ktime_t next_wakeup;
uint64_t predicted;
uint32_t history_invalid;
bool predict_started;
bool htmr_wkup;
struct hrtimer histtimer;
struct hrtimer biastimer;