From 96032468a8186b33f00d079716a741331fca978d Mon Sep 17 00:00:00 2001 From: Chris Redpath Date: Thu, 23 Nov 2017 14:05:05 +0000 Subject: [PATCH 1/4] ANDROID: trace/sched: Add tracepoint for sched_overutilized events Change-Id: Ieb46736cb21fe58024c434cd678af0abb8b0d249 Signed-off-by: Chris Redpath Git-commit: 7022c871dfc7215d32df21936876a4d9bafeaf50 Git-repo: https://android.googlesource.com/kernel/common/ [clingutla@codeaurora.org: Resolved trivial merge conflicts] Signed-off-by: Lingutla Chandrasekhar [satyap@codeaurora.org: port to 5.x and resolve trivial merge conflicts] Signed-off-by: Satya Durga Srinivasu Prabhala --- include/trace/events/sched.h | 28 ++++++++++++++++++++++++++++ kernel/sched/fair.c | 2 ++ 2 files changed, 30 insertions(+) diff --git a/include/trace/events/sched.h b/include/trace/events/sched.h index 0a1ec7cc06fd..9f0806599c80 100644 --- a/include/trace/events/sched.h +++ b/include/trace/events/sched.h @@ -1105,6 +1105,34 @@ TRACE_EVENT(sched_find_best_target, __entry->target, __entry->backup) ); +/* + * Tracepoint for system overutilized flag + */ +#ifdef CONFIG_SCHED_WALT +struct sched_domain; +TRACE_EVENT_CONDITION(sched_overutilized, + + TP_PROTO(struct sched_domain *sd, bool was_overutilized, bool overutilized), + + TP_ARGS(sd, was_overutilized, overutilized), + + TP_CONDITION(overutilized != was_overutilized), + + TP_STRUCT__entry( + __field( bool, overutilized ) + __array( char, cpulist , 32 ) + ), + + TP_fast_assign( + __entry->overutilized = overutilized; + scnprintf(__entry->cpulist, sizeof(__entry->cpulist), "%*pbl", cpumask_pr_args(sched_domain_span(sd))); + ), + + TP_printk("overutilized=%d sd_span=%s", + __entry->overutilized ? 1 : 0, __entry->cpulist) +); +#endif + TRACE_EVENT(sched_preempt_disable, TP_PROTO(u64 delta, bool irqs_disabled, diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 297c4b0242d7..9fbcb25e8b72 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -5305,11 +5305,13 @@ static bool sd_overutilized(struct sched_domain *sd) static void set_sd_overutilized(struct sched_domain *sd) { + trace_sched_overutilized(sd, sd->shared->overutilized, true); sd->shared->overutilized = true; } static void clear_sd_overutilized(struct sched_domain *sd) { + trace_sched_overutilized(sd, sd->shared->overutilized, false); sd->shared->overutilized = false; } #endif From 512a9f267aa64170855f9cf7915b1e6d29b50828 Mon Sep 17 00:00:00 2001 From: Chris Redpath Date: Sat, 28 Oct 2017 18:38:04 +0100 Subject: [PATCH 2/4] ANDROID: sched/fair: Reduce balance interval to 1 jiffy if we have a misfit task It is quite a common occurrence that we have a misfit task (a task running on a CPU which is close to the capacity limit of that CPU) in the system AND we have recently done a load balance operation. Normal load-balance rate limiting means we can leave those tasks on the restrictive CPU for a few hundred ms before we move them. Inspired by the work Leo Yan did on balancing misfits. This patch reduces the balance interval to one jiffy when there are such tasks running. There appears to be no impact on interactive performance from this patch. Change-Id: I71d74734d3bd6bca80476c0f466ba48914b7ac02 Signed-off-by: Chris Redpath Git-commit: 84c88fc37932db51b87af8df3cedc621cb5c6e97 Git-repo: https://android.googlesource.com/kernel/common [clingutla@codeaurora.org: Took only partial part from commit '84c88fc37932("ANDROID: Combined EAS Load Balance Tweaks")', and skip using 1 jiffy for busy balancing] Signed-off-by: Lingutla Chandrasekhar --- kernel/sched/fair.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 9fbcb25e8b72..b5dc0bee902d 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -10261,6 +10261,9 @@ static inline unsigned long get_sd_balance_interval(struct sched_domain *sd, int cpu_busy) { unsigned long interval = sd->balance_interval; +#ifdef CONFIG_SCHED_WALT + unsigned int cpu; +#endif if (cpu_busy) interval *= sd->busy_factor; @@ -10269,6 +10272,26 @@ get_sd_balance_interval(struct sched_domain *sd, int cpu_busy) interval = msecs_to_jiffies(interval); interval = clamp(interval, 1UL, max_load_balance_interval); + /* + * check if sched domain is marked as overutilized + * we ought to only do this on systems which have SD_ASYMCAPACITY + * but we want to do it for all sched domains in those systems + * So for now, just check if overutilized as a proxy. + */ + /* + * If we are overutilized and we have a misfit task, then + * we want to balance as soon as practically possible, so + * we return an interval of zero, except for busy balance. + */ +#ifdef CONFIG_SCHED_WALT + if (sd_overutilized(sd) && !cpu_busy) { + /* we know the root is overutilized, let's check for a misfit task */ + for_each_cpu(cpu, sched_domain_span(sd)) { + if (cpu_rq(cpu)->misfit_task_load) + return 1; + } + } +#endif return interval; } From de151d637fbe776598019f100201cbea50f199f0 Mon Sep 17 00:00:00 2001 From: Lingutla Chandrasekhar Date: Thu, 25 Apr 2019 17:02:46 +0530 Subject: [PATCH 3/4] sched: trace : Print current sched domain overutilization status Extend sched_load_balance trace event to print overutilization status of the current balancing sched domain. Change-Id: Iae14e580294a0ab38394b4e8d660d0c5dd14327d Signed-off-by: Lingutla Chandrasekhar --- include/trace/events/sched.h | 12 ++++++++---- kernel/sched/fair.c | 7 ++++++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/include/trace/events/sched.h b/include/trace/events/sched.h index 9f0806599c80..d1440b5a4ccf 100644 --- a/include/trace/events/sched.h +++ b/include/trace/events/sched.h @@ -275,11 +275,12 @@ TRACE_EVENT(sched_load_balance, TP_PROTO(int cpu, enum cpu_idle_type idle, int balance, unsigned long group_mask, int busiest_nr_running, unsigned long imbalance, unsigned int env_flags, int ld_moved, - unsigned int balance_interval, int active_balance), + unsigned int balance_interval, int active_balance, + int overutilized), TP_ARGS(cpu, idle, balance, group_mask, busiest_nr_running, imbalance, env_flags, ld_moved, balance_interval, - active_balance), + active_balance, overutilized), TP_STRUCT__entry( __field(int, cpu) @@ -292,6 +293,7 @@ TRACE_EVENT(sched_load_balance, __field(int, ld_moved) __field(unsigned int, balance_interval) __field(int, active_balance) + __field(int, overutilized) ), TP_fast_assign( @@ -305,16 +307,18 @@ TRACE_EVENT(sched_load_balance, __entry->ld_moved = ld_moved; __entry->balance_interval = balance_interval; __entry->active_balance = active_balance; + __entry->overutilized = overutilized; ), - TP_printk("cpu=%d state=%s balance=%d group=%#lx busy_nr=%d imbalance=%ld flags=%#x ld_moved=%d bal_int=%d active_balance=%d", + TP_printk("cpu=%d state=%s balance=%d group=%#lx busy_nr=%d imbalance=%ld flags=%#x ld_moved=%d bal_int=%d active_balance=%d sd_overutilized=%d", __entry->cpu, __entry->idle == CPU_IDLE ? "idle" : (__entry->idle == CPU_NEWLY_IDLE ? "newly_idle" : "busy"), __entry->balance, __entry->group_mask, __entry->busiest_nr_running, __entry->imbalance, __entry->env_flags, __entry->ld_moved, - __entry->balance_interval, __entry->active_balance) + __entry->balance_interval, __entry->active_balance, + __entry->overutilized) ); TRACE_EVENT(sched_load_balance_nohz_kick, diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index b5dc0bee902d..3a5e8ba90f3c 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -10253,7 +10253,12 @@ out: group ? group->cpumask[0] : 0, busiest ? busiest->nr_running : 0, env.imbalance, env.flags, ld_moved, - sd->balance_interval, active_balance); + sd->balance_interval, active_balance, +#ifdef CONFIG_SCHED_WALT + sd_overutilized(sd)); +#else + READ_ONCE(this_rq->rd->overutilized)); +#endif return ld_moved; } From 8a306ac79d4768c8654e5cd09e2c01da2381c88b Mon Sep 17 00:00:00 2001 From: Pavankumar Kondeti Date: Mon, 23 Sep 2019 14:38:35 +0530 Subject: [PATCH 4/4] PM / EM: Micro optimization in em_pd_energy If the sum of the utilization of CPUs in a power domain is zero, return the energy as 0 instead of doing any math. Change-Id: I9b1a83d210c30a8a86da26f94ac0c2f855d2ed10 Signed-off-by: Pavankumar Kondeti --- include/linux/energy_model.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/linux/energy_model.h b/include/linux/energy_model.h index 73f8c3cb9588..82cd68bbb8f5 100644 --- a/include/linux/energy_model.h +++ b/include/linux/energy_model.h @@ -83,6 +83,9 @@ static inline unsigned long em_pd_energy(struct em_perf_domain *pd, struct em_cap_state *cs; int i, cpu; + if (!sum_util) + return 0; + /* * In order to predict the capacity state, map the utilization of the * most utilized CPU of the performance domain to a requested frequency,