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

Commit 1f31b828 authored by Patrick Bellasi's avatar Patrick Bellasi Committed by Satya Durga Srinivasu Prabhala
Browse files

ANDROID: sched/fair: Cleanup cpu_util{_wake}()



The current implementation of cpu_util and cpu_util_wake makes more
difficult the backporting of mainline patches and it also has some
features not longer required by the current EAS code, e.g. delta
utilization in __cpu_util().

Let's clean up these functions definitions to:
1. get rid of the not longer required __cpu_util(cpu, delta)
   This function is now only called with delta=0 and thus we can refold
   its implementation into the original wrapper function cpu_util(cpu)
2. optimize for the WALT path on CONFIG_SCHED_WALT builds
   Currently indeed we execute some not necessary PELT related code even
   when WALT signals are required.
   Let's change this by assuming that on CONFIG_SCHED_WALT build we are
   likely using WALT signals. While on !CONFIG_SCHED_WALT we still have
   just the PELT signals with a code structure which matches mainline
3. move the definitions from sched/sched.h into sched/fair.c
   This is the only module using these functions and it also better
   align with the mainline location for these functions
4. get rid of the walt_util macro
   That macro has a function-like signature but it's modifying a
   parameter (passed by value) which makes it a bit confusing.
   Moreover, the usage of the min_t() macro to cap signals with
   capacity_orig_of() it makes not more required the explicit type cast
   used by that macro to support both 32 and 63 bits targets.
5. remove forward declarations
   Which are not required once the definition is moved at the top of
   fair.c, since they don't have other local dependencies.

Signed-off-by: default avatarPatrick Bellasi <patrick.bellasi@arm.com>
Change-Id: I61c9b7b8a0a34b494527c5aa76218c64543c16d2
Git-commit: 2bd47d3f
Git-repo: https://android.googlesource.com/kernel/common/


[satyap@codeaurora.org:
1. Update cpu_util() and cpu_util_freq() as needed and keep the
   functionality in kernel/sched/sched.h instead of moving to
   kernel/sched/fair.c
2. Replace cpu_util_freq_pelt() with cpu_util()
]
Signed-off-by: default avatarSatya Durga Srinivasu Prabhala <satyap@codeaurora.org>
parent b4f436ae
Loading
Loading
Loading
Loading
+43 −34
Original line number Diff line number Diff line
@@ -5004,8 +5004,6 @@ static inline void hrtick_update(struct rq *rq)
#endif

#ifdef CONFIG_SMP
static unsigned long cpu_util(int cpu);

static bool sd_overutilized(struct sched_domain *sd)
{
	return sd->shared->overutilized;
@@ -5551,8 +5549,6 @@ bool sched_is_energy_aware(void)
	return energy_aware();
}

static int cpu_util_wake(int cpu, struct task_struct *p);

/*
 * __cpu_norm_util() returns the cpu util relative to a specific capacity,
 * i.e. it's busy ratio, in the range [0..SCHED_CAPACITY_SCALE] which is useful
@@ -5717,7 +5713,49 @@ struct energy_env {
	struct sched_group	*sg;
};

static int cpu_util_wake(int cpu, struct task_struct *p);
/*
 * cpu_util_wake: Compute CPU utilization with any contributions from
 * the waking task p removed.
 */
static unsigned long cpu_util_wake(int cpu, struct task_struct *p)
{
	unsigned int util;

#ifdef CONFIG_SCHED_WALT
	/*
	 * WALT does not decay idle tasks in the same manner
	 * as PELT, so it makes little sense to subtract task
	 * utilization from cpu utilization. Instead just use
	 * cpu_util for this case.
	 */
	if (likely(!walt_disabled && sysctl_sched_use_walt_cpu_util) &&
						p->state == TASK_WAKING)
		return cpu_util(cpu);
#endif

	/* Task has no contribution or is new */
	if (cpu != task_cpu(p) || !READ_ONCE(p->se.avg.last_update_time))
		return cpu_util(cpu);

#ifdef CONFIG_SCHED_WALT
	util = max_t(long, cpu_util(cpu) - task_util(p), 0);
#else
	struct cfs_rq *cfs_rq;

	cfs_rq = &cpu_rq(cpu)->cfs;
	util = READ_ONCE(cfs_rq->avg.util_avg);

	/* Discount task's blocked util from CPU's util */
	util -= min_t(unsigned int, util, task_util(p));
#endif

	/*
	 * Utilization (estimated) can exceed the CPU capacity, thus let's
	 * clamp to the maximum CPU capacity to ensure consistency with
	 * the cpu_util call.
	 */
	return min_t(unsigned long, util, capacity_orig_of(cpu));
}

static unsigned long group_max_util(struct energy_env *eenv, int cpu_idx)
{
@@ -6975,35 +7013,6 @@ static int select_idle_sibling(struct task_struct *p, int prev, int target)
	return select_idle_sibling_cstate_aware(p, prev, target);
}

/*
 * cpu_util_wake: Compute cpu utilization with any contributions from
 * the waking task p removed.
 */
static int cpu_util_wake(int cpu, struct task_struct *p)
{
	unsigned long util, capacity;

#ifdef CONFIG_SCHED_WALT
	/*
	 * WALT does not decay idle tasks in the same manner
	 * as PELT, so it makes little sense to subtract task
	 * utilization from cpu utilization. Instead just use
	 * cpu_util for this case.
	 */
	if (!walt_disabled && sysctl_sched_use_walt_cpu_util &&
					p->state == TASK_WAKING)
		return cpu_util(cpu);
#endif
	/* Task has no contribution or is new */
	if (cpu != task_cpu(p) || !p->se.avg.last_update_time)
		return cpu_util(cpu);

	capacity = capacity_orig_of(cpu);
	util = max_t(long, cpu_util(cpu) - task_util(p), 0);

	return (util >= capacity) ? capacity : util;
}

static inline bool task_fits_capacity(struct task_struct *p,
					long capacity,
					int cpu)
+19 −34
Original line number Diff line number Diff line
@@ -1921,28 +1921,28 @@ static inline unsigned long task_util(struct task_struct *p)
 * capacity_orig) as it useful for predicting the capacity required after task
 * migrations (scheduler-driven DVFS).
 */
static inline unsigned long __cpu_util(int cpu, int delta)
static inline unsigned long cpu_util(int cpu)
{
	u64 util = cpu_rq(cpu)->cfs.avg.util_avg;
	unsigned long capacity = capacity_orig_of(cpu);
	struct cfs_rq *cfs_rq;
	unsigned int util;

#ifdef CONFIG_SCHED_WALT
	if (!walt_disabled && sysctl_sched_use_walt_cpu_util) {
		util = cpu_rq(cpu)->walt_stats.cumulative_runnable_avg;
		util = div64_u64(util,
				 sched_ravg_window >> SCHED_CAPACITY_SHIFT);
	if (likely(!walt_disabled && sysctl_sched_use_walt_cpu_util)) {
		u64 walt_cpu_util =
				cpu_rq(cpu)->walt_stats.cumulative_runnable_avg;

		walt_cpu_util <<= SCHED_CAPACITY_SHIFT;
		do_div(walt_cpu_util, sched_ravg_window);

		return min_t(unsigned long, walt_cpu_util,
				capacity_orig_of(cpu));
	}
#endif
	delta += util;
	if (delta < 0)
		return 0;

	return (delta >= capacity) ? capacity : delta;
}
	cfs_rq = &cpu_rq(cpu)->cfs;
	util = READ_ONCE(cfs_rq->avg.util_avg);

static inline unsigned long cpu_util(int cpu)
{
	return __cpu_util(cpu, 0);
	return min_t(unsigned long, util, capacity_orig_of(cpu));
}

struct sched_walt_cpu_load {
@@ -1974,22 +1974,7 @@ static inline unsigned long cpu_util_cum(int cpu, int delta)

#ifdef CONFIG_SCHED_WALT
u64 freq_policy_load(struct rq *rq);
#endif

static inline unsigned long
cpu_util_freq_pelt(int cpu)
{
	struct rq *rq = cpu_rq(cpu);
	u64 util = rq->cfs.avg.util_avg;
	unsigned long capacity = capacity_orig_of(cpu);

	util *= (100 + per_cpu(sched_load_boost, cpu));
	do_div(util, 100);

	return (util >= capacity) ? capacity : util;
}

#ifdef CONFIG_SCHED_WALT
extern u64 walt_load_reported_window;

static inline unsigned long
@@ -2000,8 +1985,8 @@ cpu_util_freq_walt(int cpu, struct sched_walt_cpu_load *walt_load)
	unsigned long capacity = capacity_orig_of(cpu);
	int boost;

	if (walt_disabled || !sysctl_sched_use_walt_cpu_util)
		return cpu_util_freq_pelt(cpu);
	if (unlikely(walt_disabled || !sysctl_sched_use_walt_cpu_util))
		return cpu_util(cpu);

	boost = per_cpu(sched_load_boost, cpu);
	util_unboosted = util = freq_policy_load(rq);
@@ -2045,7 +2030,7 @@ cpu_util_freq(int cpu, struct sched_walt_cpu_load *walt_load)
static inline unsigned long
cpu_util_freq(int cpu, struct sched_walt_cpu_load *walt_load)
{
	return cpu_util_freq_pelt(cpu);
	return cpu_util(cpu);
}

#define sched_ravg_window TICK_NSEC
@@ -2067,7 +2052,7 @@ add_capacity_margin(unsigned long cpu_capacity, int cpu)
	return cpu_capacity;
}

#endif
#endif /* CONFIG_SMP */

static inline void sched_rt_avg_update(struct rq *rq, u64 rt_delta)
{