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

Commit 449182f6 authored by Joonwoo Park's avatar Joonwoo Park
Browse files

sched: fix energy diff calculation when sync = 1



Make energy_diff() aware of sync flag and waker CPU in order to discount
energy cost of placing wakee task on the waker's CPU.

Change-Id: Ic9fa136167550307e2920fb1ea5ea340fe1b782d
Signed-off-by: default avatarJoonwoo Park <joonwoop@codeaurora.org>
parent 2d215218
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -699,9 +699,9 @@ TRACE_EVENT(sched_freq_alert,
#ifdef CONFIG_SMP
TRACE_EVENT(sched_cpu_util,

	TP_PROTO(struct task_struct *p, int cpu, int task_util, long spare_cap, int sync),
	TP_PROTO(struct task_struct *p, int cpu, int task_util, unsigned long curr_util, int sync),

	TP_ARGS(p, cpu, task_util, spare_cap, sync),
	TP_ARGS(p, cpu, task_util, curr_util, sync),

	TP_STRUCT__entry(
		__array(char, comm, TASK_COMM_LEN	)
@@ -712,7 +712,7 @@ TRACE_EVENT(sched_cpu_util,
		__field(long, cpu_util			)
		__field(unsigned int, capacity_curr		)
		__field(unsigned int, capacity			)
		__field(long, spare_cap				)
		__field(unsigned long, curr_util		)
		__field(int, sync				)
		__field(int, idle_state				)
	),
@@ -726,13 +726,13 @@ TRACE_EVENT(sched_cpu_util,
		__entry->cpu_util		= cpu_util(cpu);
		__entry->capacity_curr		= capacity_curr_of(cpu);
		__entry->capacity		= capacity_of(cpu);
		__entry->spare_cap		= spare_cap;
		__entry->curr_util		= curr_util;
		__entry->sync			= sync;
		__entry->idle_state		= idle_get_state_idx(cpu_rq(cpu));
	),

	TP_printk("comm=%s pid=%d cpu=%d task_util=%d nr_running=%d cpu_util=%ld capacity_curr=%u capacity=%u spare_capacity=%ld sync=%d idle_state=%d",
		__entry->comm, __entry->pid, __entry->cpu, __entry->task_util, __entry->nr_running, __entry->cpu_util, __entry->capacity_curr, __entry->capacity, __entry->spare_cap, __entry->sync, __entry->idle_state)
	TP_printk("comm=%s pid=%d cpu=%d task_util=%d nr_running=%d cpu_util=%ld capacity_curr=%u capacity=%u curr_util=%ld sync=%d idle_state=%d",
		__entry->comm, __entry->pid, __entry->cpu, __entry->task_util, __entry->nr_running, __entry->cpu_util, __entry->capacity_curr, __entry->capacity, __entry->curr_util, __entry->sync, __entry->idle_state)
);

DECLARE_EVENT_CLASS(sched_task_util,
+14 −10
Original line number Diff line number Diff line
@@ -5348,6 +5348,8 @@ struct energy_env {
	int			dst_cpu;
	int			energy;
	int			payoff;
	int			sync_cpu;
	unsigned long		curr_util;
	struct task_struct	*task;
	struct {
		int before;
@@ -5450,6 +5452,9 @@ unsigned long group_max_util(struct energy_env *eenv)

	for_each_cpu(i, sched_group_cpus(eenv->sg_cap)) {
		delta = calc_util_delta(eenv, i);
		/* substract sync_cpu's rq->curr util to discount its cost */
		if (eenv->sync_cpu == i)
			delta -= eenv->curr_util;
		max_util = max(max_util, __cpu_util(i, delta));
	}

@@ -5474,6 +5479,9 @@ long group_norm_util(struct energy_env *eenv, struct sched_group *sg)

	for_each_cpu(i, sched_group_cpus(sg)) {
		delta = calc_util_delta(eenv, i);
		/* substract sync_cpu's rq->curr util to discount its cost */
		if (eenv->sync_cpu == i)
			delta -= eenv->curr_util;
		util_sum += __cpu_norm_util(i, capacity, delta);
	}

@@ -5654,6 +5662,7 @@ static inline int __energy_diff(struct energy_env *eenv)
		.nrg		= { 0, 0, 0, 0},
		.cap		= { 0, 0, 0 },
		.task		= eenv->task,
		.sync_cpu       = eenv->sync_cpu,
	};

	if (eenv->src_cpu == eenv->dst_cpu)
@@ -6601,7 +6610,6 @@ static int energy_aware_wake_cpu(struct task_struct *p, int target, int sync)
	sg_target = sg;

	sync = sync && sysctl_sched_sync_hint_enable;
	if (sync)
	curr_util = boosted_task_util(cpu_rq(cpu)->curr);

	if (sysctl_sched_is_big_little) {
@@ -6645,7 +6653,8 @@ static int energy_aware_wake_cpu(struct task_struct *p, int target, int sync)
			if (sync && i == cpu)
				new_util -= curr_util;

			trace_sched_cpu_util(p, i, task_util_boosted, 0, sync);
			trace_sched_cpu_util(p, i, task_util_boosted,
					     curr_util, sync);

			/*
			 * Ensure minimum capacity to grant the required boost.
@@ -6725,15 +6734,10 @@ static int energy_aware_wake_cpu(struct task_struct *p, int target, int sync)
			.src_cpu	= task_cpu(p),
			.dst_cpu	= target_cpu,
			.task		= p,
			.sync_cpu	= sync ? smp_processor_id() : -1,
			.curr_util	= curr_util,
		};

		if (sync) {
			if (eenv.dst_cpu == cpu)
				eenv.util_delta -= curr_util;
			else if (eenv.src_cpu == cpu)
				eenv.util_delta += curr_util;
		}

#ifdef CONFIG_SCHED_WALT
		if (walt_disabled || !sysctl_sched_use_walt_cpu_util)
			task_util_boosted = 0;