sched/walt: Remove avg_cap check in packing CPU feature

The current scheduler code uses avg_cap that is calculated by waltgov.
This is stored in a private structure wg_policy in waltgov.

The problem with this is wg_policy could be freed when the governor
changes or all the CPUs in the policy get offlined. This leads to a
use-after-free access of wg_policy->avg_cap. Besides, WALT introduced
checks between avg_cap and cur_freq to identify if scheduler guided
frequency is overridden by CPU frequency min/max limits. However, avg_cap
doesn't reflect the scheduler guided frequency and instead represents
the frequency from min/max limits. IOW, cur_freq will always be
equal to avg_cap when CPU frequency limits are active, rendering the
check useless and thus allowing packing.

Remove the code that retrieves and checks avg_cap.

Change-Id: I9b32c6798fb209d63d688ed89dc17674a7859475
Signed-off-by: Sai Harshini Nimmala <quic_snimmala@quicinc.com>
This commit is contained in:
Sai Harshini Nimmala 2022-06-21 19:50:52 -07:00 committed by Rishabh Bhatnagar
parent 84bb530ed3
commit ca90b4c36e
4 changed files with 0 additions and 52 deletions

View File

@ -188,25 +188,6 @@ static void waltgov_calc_avg_cap(struct waltgov_policy *wg_policy, u64 curr_ws,
wg_policy->last_ws = curr_ws;
}
/*
* if waltgov is initialized, return the avg_cap seen
* over the last window. return 0 otherwise.
*/
unsigned int waltgov_get_avg_cap(unsigned int cpu)
{
struct waltgov_cpu *wg_cpu = &per_cpu(waltgov_cpu, cpu);
struct waltgov_policy *wg_policy = wg_cpu->wg_policy;
/* if the policy is not initialized, or the callback
* is not initialized. callback is initialized on
* start of waltgov, erased on stop of waltgov.
*/
if (!wg_policy || !wg_cpu->cb.func)
return 0;
return wg_policy->avg_cap;
}
static void waltgov_fast_switch(struct waltgov_policy *wg_policy, u64 time,
unsigned int next_freq)
{

View File

@ -56,16 +56,6 @@ unsigned int sched_get_cluster_util_pct(struct walt_sched_cluster *cluster)
return cluster_util_pct;
}
unsigned int sched_get_cpu_avg_cap(int cpu)
{
unsigned int cpu_avg_cap = 0;
if (cpu < WALT_NR_CPUS)
cpu_avg_cap = stats[cpu].avg_cap;
return cpu_avg_cap;
}
/**
* sched_get_nr_running_avg
* @return: Average nr_running, iowait and nr_big_tasks value since last poll.
@ -119,7 +109,6 @@ struct sched_avg_stats *sched_get_nr_running_avg(void)
NR_THRESHOLD_PCT), 100);
stats[cpu].nr_max = per_cpu(nr_max, cpu);
stats[cpu].nr_scaled = tmp_nr;
stats[cpu].avg_cap = waltgov_get_avg_cap(cpu);
trace_sched_get_nr_running_avg(cpu, stats[cpu].nr,
stats[cpu].nr_misfit, stats[cpu].nr_max,

View File

@ -345,21 +345,6 @@ static void fixup_walt_sched_stats_common(struct rq *rq, struct task_struct *p,
static void rollover_cpu_window(struct rq *rq, bool full_window);
static void rollover_top_tasks(struct rq *rq, bool full_window);
/*
* if last window's average capacity is less than or
* equal to the current capacity, return true.
*/
static inline bool is_cpufreq_avg_or_higher(int cpu)
{
unsigned int avg_cap = sched_get_cpu_avg_cap(cpu);
unsigned int cur_cap = capacity_curr_of(cpu);
if (cur_cap >= avg_cap && avg_cap != 0)
return true;
return false;
}
/* walt_find_cluster_packing_cpu - Return a packing_cpu choice common for this cluster.
* @start_cpu: The cpu from the cluster to choose from
*
@ -429,10 +414,6 @@ bool walt_choose_packing_cpu(int packing_cpu, struct task_struct *p)
if (task_util(p) >= sysctl_sched_idle_enough)
return false;
/* if cpufreq is lower than the previous window */
if (!is_cpufreq_avg_or_higher(packing_cpu))
return false;
/* the packing cpu can be used, so pack! */
return true;
}

View File

@ -349,7 +349,6 @@ struct sched_avg_stats {
int nr_misfit;
int nr_max;
int nr_scaled;
u32 avg_cap;
};
struct waltgov_callback {
@ -791,8 +790,6 @@ static inline bool task_fits_max(struct task_struct *p, int cpu)
extern struct sched_avg_stats *sched_get_nr_running_avg(void);
extern unsigned int sched_get_cluster_util_pct(struct walt_sched_cluster *cluster);
extern unsigned int sched_get_cpu_avg_cap(int cpu);
extern unsigned int waltgov_get_avg_cap(unsigned int cpu);
extern void sched_update_hyst_times(void);
extern void walt_rt_init(void);