Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a6f81a0b authored by Pavankumar Kondeti's avatar Pavankumar Kondeti
Browse files

sched/walt: Improve the scheduler



This change is for general scheduler improvement.

Change-Id: I2735e374c0c78b89d0f722aa6346deb7022ed9b3
Signed-off-by: default avatarPavankumar Kondeti <pkondeti@codeaurora.org>
parent f7de9ee5
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -674,7 +674,6 @@ do { \
	P(cpu_capacity);
#endif
#ifdef CONFIG_SCHED_WALT
	P(cluster->load_scale_factor);
	P(cluster->max_possible_capacity);
	P(cluster->efficiency);
	P(cluster->cur_freq);
+0 −79
Original line number Diff line number Diff line
@@ -131,7 +131,6 @@ struct sched_cluster {
	int min_power_cost;
	int max_possible_capacity;
	int efficiency; /* Differentiate cpus with different IPC capability */
	int load_scale_factor;
	unsigned int exec_scale_factor;
	/*
	 * max_freq = user maximum
@@ -2789,11 +2788,6 @@ static inline int cpu_max_possible_capacity(int cpu)
	return cpu_rq(cpu)->cluster->max_possible_capacity;
}

static inline int cpu_load_scale_factor(int cpu)
{
	return cpu_rq(cpu)->cluster->load_scale_factor;
}

static inline unsigned int cluster_max_freq(struct sched_cluster *cluster)
{
	/*
@@ -2814,47 +2808,6 @@ static inline unsigned int cpu_max_possible_freq(int cpu)
	return cpu_rq(cpu)->cluster->max_possible_freq;
}

/*
 * Return load_scale_factor of a cpu in reference to "most" efficient cpu, so
 * that "most" efficient cpu gets a load_scale_factor of 1
 */
static inline unsigned long
load_scale_cpu_efficiency(struct sched_cluster *cluster)
{
	return DIV_ROUND_UP(1024 * max_possible_efficiency,
			    cluster->efficiency);
}

/*
 * Return load_scale_factor of a cpu in reference to cpu with best max_freq
 * (max_possible_freq), so that one with best max_freq gets a load_scale_factor
 * of 1.
 */
static inline unsigned long load_scale_cpu_freq(struct sched_cluster *cluster)
{
	return DIV_ROUND_UP(1024 * max_possible_freq,
			   cluster_max_freq(cluster));
}

static inline int compute_load_scale_factor(struct sched_cluster *cluster)
{
	int load_scale = 1024;

	/*
	 * load_scale_factor accounts for the fact that task load
	 * is in reference to "best" performing cpu. Task's load will need to be
	 * scaled (up) by a factor to determine suitability to be placed on a
	 * (little) cpu.
	 */
	load_scale *= load_scale_cpu_efficiency(cluster);
	load_scale >>= 10;

	load_scale *= load_scale_cpu_freq(cluster);
	load_scale >>= 10;

	return load_scale;
}

static inline bool hmp_capable(void)
{
	return max_possible_capacity != min_max_possible_capacity;
@@ -2870,23 +2823,6 @@ static inline bool is_min_capacity_cpu(int cpu)
	return cpu_max_possible_capacity(cpu) == min_max_possible_capacity;
}

/*
 * 'load' is in reference to "best cpu" at its best frequency.
 * Scale that in reference to a given cpu, accounting for how bad it is
 * in reference to "best cpu".
 */
static inline u64 scale_load_to_cpu(u64 task_load, int cpu)
{
	u64 lsf = cpu_load_scale_factor(cpu);

	if (lsf != 1024) {
		task_load *= lsf;
		task_load /= 1024;
	}

	return task_load;
}

static inline unsigned int task_load(struct task_struct *p)
{
	return p->ravg.demand;
@@ -2897,12 +2833,6 @@ static inline unsigned int task_pl(struct task_struct *p)
	return p->ravg.pred_demand;
}

#define pct_to_real(tunable)	\
		(div64_u64((u64)tunable * (u64)max_task_load(), 100))

#define real_to_pct(tunable)	\
		(div64_u64((u64)tunable * (u64)100, (u64)max_task_load()))

static inline bool task_in_related_thread_group(struct task_struct *p)
{
	return !!(rcu_access_pointer(p->grp) != NULL);
@@ -3023,8 +2953,6 @@ static inline void walt_fixup_cum_window_demand(struct rq *rq, s64 scaled_delta)
		rq->cum_window_demand_scaled = 0;
}

extern void update_cpu_cluster_capacity(const cpumask_t *cpus);

extern unsigned long thermal_cap(int cpu);

extern void clear_walt_request(int cpu);
@@ -3134,11 +3062,6 @@ static inline struct sched_cluster *rq_cluster(struct rq *rq)

static inline int asym_cap_siblings(int cpu1, int cpu2) { return 0; }

static inline u64 scale_load_to_cpu(u64 load, int cpu)
{
	return load;
}

static inline void set_preferred_cluster(struct related_thread_group *grp) { }

static inline bool task_in_related_thread_group(struct task_struct *p)
@@ -3174,8 +3097,6 @@ static inline int alloc_related_thread_groups(void) { return 0; }
static inline void walt_fixup_cum_window_demand(struct rq *rq,
						s64 scaled_delta) { }

static inline void update_cpu_cluster_capacity(const cpumask_t *cpus) { }

#ifdef CONFIG_SMP
static inline unsigned long thermal_cap(int cpu)
{
+20 −30
Original line number Diff line number Diff line
@@ -2071,8 +2071,11 @@ void mark_task_starting(struct task_struct *p)
}

#define pct_to_min_scaled(tunable) \
		div64_u64(((u64)sched_ravg_window * tunable) << 10, \
			   (u64)sched_cluster[0]->load_scale_factor * 100)
		div64_u64(((u64)sched_ravg_window * tunable *	\
			  cluster_max_freq(sched_cluster[0]) *	\
			  sched_cluster[0]->efficiency),	\
			  ((u64)max_possible_freq *		\
			  max_possible_efficiency * 100))

static inline void walt_update_group_thresholds(void)
{
@@ -2082,6 +2085,19 @@ static inline void walt_update_group_thresholds(void)
			pct_to_min_scaled(sysctl_sched_group_downmigrate_pct);
}

static void walt_cpus_capacity_changed(const cpumask_t *cpus)
{
	unsigned long flags;

	acquire_rq_locks_irqsave(cpu_possible_mask, &flags);

	if (cpumask_intersects(cpus, &sched_cluster[0]->cpus))
		walt_update_group_thresholds();

	release_rq_locks_irqrestore(cpu_possible_mask, &flags);
}


static cpumask_t all_cluster_cpus = CPU_MASK_NONE;
DECLARE_BITMAP(all_cluster_ids, NR_CPUS);
struct sched_cluster *sched_cluster[NR_CPUS];
@@ -2120,7 +2136,6 @@ static struct sched_cluster *alloc_new_cluster(const struct cpumask *cpus)
	cluster->min_power_cost		=	1;
	cluster->max_possible_capacity	=	1024;
	cluster->efficiency		=	1;
	cluster->load_scale_factor	=	1024;
	cluster->cur_freq		=	1;
	cluster->max_freq		=	1;
	cluster->max_mitigated_freq	=	UINT_MAX;
@@ -2238,7 +2253,6 @@ static void update_all_clusters_stats(void)

		mpc = cluster->max_possible_capacity =
			compute_max_possible_capacity(cluster);
		cluster->load_scale_factor = compute_load_scale_factor(cluster);

		cluster->exec_scale_factor =
			DIV_ROUND_UP(cluster->efficiency * 1024,
@@ -2301,7 +2315,6 @@ struct sched_cluster init_cluster = {
	.min_power_cost		=	1,
	.max_possible_capacity	=	1024,
	.efficiency		=	1,
	.load_scale_factor	=	1024,
	.cur_freq		=	1,
	.max_freq		=	1,
	.max_mitigated_freq	=	UINT_MAX,
@@ -2373,7 +2386,7 @@ static int cpufreq_notifier_policy(struct notifier_block *nb,
	}

	if (update_capacity)
		update_cpu_cluster_capacity(policy->related_cpus);
		walt_cpus_capacity_changed(policy->related_cpus);

	return 0;
}
@@ -2850,29 +2863,6 @@ int sync_cgroup_colocation(struct task_struct *p, bool insert)
}
#endif

void update_cpu_cluster_capacity(const cpumask_t *cpus)
{
	int i;
	struct sched_cluster *cluster;
	struct cpumask cpumask;
	unsigned long flags;

	cpumask_copy(&cpumask, cpus);
	acquire_rq_locks_irqsave(cpu_possible_mask, &flags);

	for_each_cpu(i, &cpumask) {
		cluster = cpu_rq(i)->cluster;
		cpumask_andnot(&cpumask, &cpumask, &cluster->cpus);

		cluster->load_scale_factor = compute_load_scale_factor(cluster);
	}

	if (cpumask_intersects(cpus, &sched_cluster[0]->cpus))
		walt_update_group_thresholds();

	release_rq_locks_irqrestore(cpu_possible_mask, &flags);
}

static unsigned long max_cap[NR_CPUS];
static unsigned long thermal_cap_cpu[NR_CPUS];

@@ -2938,7 +2928,7 @@ void sched_update_cpu_freq_min_max(const cpumask_t *cpus, u32 fmin, u32 fmax)
	spin_unlock_irqrestore(&cpu_freq_min_max_lock, flags);

	if (update_capacity)
		update_cpu_cluster_capacity(cpus);
		walt_cpus_capacity_changed(cpus);
}

void note_task_waking(struct task_struct *p, u64 wallclock)