From f970f604f2d18eea66194b8d5f7465ff9cfbc326 Mon Sep 17 00:00:00 2001 From: Abhijeet Dharmapurikar Date: Mon, 8 Aug 2022 15:05:35 -0700 Subject: [PATCH] sched/walt: use sched_idle_enough to skip packing When sysctl_sched_idle_enough is not set, the current code still finds a pakcing cpu only to reject it later. Fix this i.e. don't even bother finding a packing cpu when idle_enough is zero. Change-Id: I5cdce5e06072eee75593aa1e36953a2946e20efa Signed-off-by: Abhijeet Dharmapurikar --- kernel/sched/walt/walt.c | 73 ------------------------------------ kernel/sched/walt/walt.h | 68 +++++++++++++++++++++++++++++++++ kernel/sched/walt/walt_cfs.c | 4 +- kernel/sched/walt/walt_rt.c | 8 ++-- 4 files changed, 74 insertions(+), 79 deletions(-) diff --git a/kernel/sched/walt/walt.c b/kernel/sched/walt/walt.c index af6c8fda9339..cfedcae2de1d 100644 --- a/kernel/sched/walt/walt.c +++ b/kernel/sched/walt/walt.c @@ -354,79 +354,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); -/* walt_find_cluster_packing_cpu - Return a packing_cpu choice common for this cluster. - * @start_cpu: The cpu from the cluster to choose from - * - * If the cluster has a 32bit capable cpu return it regardless - * of whether it is halted or not. - * - * If the cluster does not have a 32 bit capable cpu, find the - * first unhalted, active cpu in this cluster. - */ -int walt_find_cluster_packing_cpu(int start_cpu) -{ - struct rq *rq = cpu_rq(start_cpu); - struct walt_rq *wrq = (struct walt_rq *)rq->android_vendor_data1; - struct walt_sched_cluster *cluster = wrq->cluster; - cpumask_t unhalted_cpus; - cpumask_t cluster_32bit_cpus; - - /* find all 32 bit capable cpus in this cluster */ - cpumask_and(&cluster_32bit_cpus, &cluster->cpus, system_32bit_el0_cpumask()); - - /* pack 32 bit and 64 bit tasks on the same cpu, if possible */ - if (cpumask_weight(&cluster_32bit_cpus) > 0) - return cpumask_first(&cluster_32bit_cpus); - - /* find all unhalted active cpus */ - cpumask_andnot(&unhalted_cpus, cpu_active_mask, cpu_halt_mask); - - /* find all unhalted active cpus in this cluster */ - cpumask_and(&unhalted_cpus, &unhalted_cpus, &cluster->cpus); - - /* return the first found unhalted, active cpu, in this cluster */ - return cpumask_first(&unhalted_cpus); -} - -/* for cfs and rt, determine if packing_cpu should be used */ -bool walt_choose_packing_cpu(int packing_cpu, struct task_struct *p) -{ - struct rq *rq; - struct walt_rq *wrq; - struct walt_sched_cluster *cluster; - - /* packing cpu must be a valid cpu for runqueue lookup */ - if (packing_cpu >= nr_cpu_ids) - return false; - - rq = cpu_rq(packing_cpu); - wrq = (struct walt_rq *)rq->android_vendor_data1; - cluster = wrq->cluster; - - /* if idle_enough feature is not enabled */ - if (!sysctl_sched_idle_enough) - return false; - - /* if cpu is not allowed for this task */ - if (!cpumask_test_cpu(packing_cpu, p->cpus_ptr)) - return false; - - /* if cluster util is high */ - if (sched_get_cluster_util_pct(cluster) >= sysctl_sched_cluster_util_thres_pct) - return false; - - /* if cpu utilization is high */ - if (cpu_util(packing_cpu) >= sysctl_sched_idle_enough) - return false; - - /* don't pack big tasks */ - if (task_util(p) >= sysctl_sched_idle_enough) - return false; - - /* the packing cpu can be used, so pack! */ - return true; -} - /* * Demand aggregation for frequency purpose: * diff --git a/kernel/sched/walt/walt.h b/kernel/sched/walt/walt.h index e5bfef031dc5..203ca9798fa1 100644 --- a/kernel/sched/walt/walt.h +++ b/kernel/sched/walt/walt.h @@ -962,6 +962,74 @@ extern struct cpumask __cpu_halt_mask; #define cpu_halt_mask ((struct cpumask *)&__cpu_halt_mask) #define cpu_halted(cpu) cpumask_test_cpu((cpu), cpu_halt_mask) +/* walt_find_and_choose_cluster_packing_cpu - Return a packing_cpu choice common for this cluster. + * @start_cpu: The cpu from the cluster to choose from + * + * If the cluster has a 32bit capable cpu return it regardless + * of whether it is halted or not. + * + * If the cluster does not have a 32 bit capable cpu, find the + * first unhalted, active cpu in this cluster. + * + * Returns -1 if packing_cpu if not found or is unsuitable to be packed on to + * Returns a valid cpu number if packing_cpu is found and is usable + */ +static inline int walt_find_and_choose_cluster_packing_cpu(int start_cpu, struct task_struct *p) +{ + struct rq *rq = cpu_rq(start_cpu); + struct walt_rq *wrq = (struct walt_rq *)rq->android_vendor_data1; + struct walt_sched_cluster *cluster = wrq->cluster; + cpumask_t unhalted_cpus; + cpumask_t cluster_32bit_cpus; + int packing_cpu; + + /* if idle_enough feature is not enabled */ + if (!sysctl_sched_idle_enough) + return -1; + if (!sysctl_sched_cluster_util_thres_pct) + return -1; + + /* find all 32 bit capable cpus in this cluster */ + cpumask_and(&cluster_32bit_cpus, &cluster->cpus, system_32bit_el0_cpumask()); + + /* pack 32 bit and 64 bit tasks on the same cpu, if possible */ + if (cpumask_weight(&cluster_32bit_cpus) > 0) { + packing_cpu = cpumask_first(&cluster_32bit_cpus); + } else { + /* find all unhalted active cpus */ + cpumask_andnot(&unhalted_cpus, cpu_active_mask, cpu_halt_mask); + + /* find all unhalted active cpus in this cluster */ + cpumask_and(&unhalted_cpus, &unhalted_cpus, &cluster->cpus); + + /* return the first found unhalted, active cpu, in this cluster */ + packing_cpu = cpumask_first(&unhalted_cpus); + } + + /* packing cpu must be a valid cpu for runqueue lookup */ + if (packing_cpu >= nr_cpu_ids) + return -1; + + /* if cpu is not allowed for this task */ + if (!cpumask_test_cpu(packing_cpu, p->cpus_ptr)) + return -1; + + /* if cluster util is high */ + if (sched_get_cluster_util_pct(cluster) >= sysctl_sched_cluster_util_thres_pct) + return -1; + + /* if cpu utilization is high */ + if (cpu_util(packing_cpu) >= sysctl_sched_idle_enough) + return -1; + + /* don't pack big tasks */ + if (task_util(p) >= sysctl_sched_idle_enough) + return -1; + + /* the packing cpu can be used, so pack! */ + return packing_cpu; +} + extern void walt_task_dump(struct task_struct *p); extern void walt_rq_dump(int cpu); extern void walt_dump(void); diff --git a/kernel/sched/walt/walt_cfs.c b/kernel/sched/walt/walt_cfs.c index ec5e03e34c92..18543e113aad 100644 --- a/kernel/sched/walt/walt_cfs.c +++ b/kernel/sched/walt/walt_cfs.c @@ -281,8 +281,8 @@ static void walt_find_best_target(struct sched_domain *sd, } /* fast path for packing_cpu */ - packing_cpu = walt_find_cluster_packing_cpu(start_cpu); - if (walt_choose_packing_cpu(packing_cpu, p)) { + packing_cpu = walt_find_and_choose_cluster_packing_cpu(start_cpu, p); + if (packing_cpu >= 0) { fbt_env->fastpath = CLUSTER_PACKING_FASTPATH; cpumask_set_cpu(packing_cpu, candidates); goto out; diff --git a/kernel/sched/walt/walt_rt.c b/kernel/sched/walt/walt_rt.c index e69fe2a9e9de..3265be5ba664 100644 --- a/kernel/sched/walt/walt_rt.c +++ b/kernel/sched/walt/walt_rt.c @@ -290,8 +290,8 @@ static void walt_select_task_rq_rt(void *unused, struct task_struct *task, int c lowest_mask, walt_rt_task_fits_capacity); /* create a fastpath for finding a packing cpu */ - packing_cpu = walt_find_cluster_packing_cpu(task_cpu(task)); - if (walt_choose_packing_cpu(packing_cpu, task)) { + packing_cpu = walt_find_and_choose_cluster_packing_cpu(task_cpu(task), task); + if (packing_cpu >= 0) { *new_cpu = packing_cpu; goto unlock; } @@ -333,8 +333,8 @@ static void walt_rt_find_lowest_rq(void *unused, struct task_struct *task, return; /* create a fastpath for finding a packing cpu */ - packing_cpu = walt_find_cluster_packing_cpu(task_cpu(task)); - if (walt_choose_packing_cpu(packing_cpu, task)) { + packing_cpu = walt_find_and_choose_cluster_packing_cpu(task_cpu(task), task); + if (packing_cpu >= 0) { *best_cpu = packing_cpu; return; }