Received: by 2002:ac0:e34a:0:0:0:0:0 with SMTP id g10csp406089imn; Wed, 27 Jul 2022 09:22:57 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tHzZmPvHueba0BwfRQ8lMj+tuOf7+C3uA9Ra/7IeuWSW4LjqGEaTJyAKL/oJD/NFYymAxY X-Received: by 2002:a05:6402:b7b:b0:43c:90c0:86cc with SMTP id cb27-20020a0564020b7b00b0043c90c086ccmr6081990edb.247.1658938977376; Wed, 27 Jul 2022 09:22:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658938977; cv=none; d=google.com; s=arc-20160816; b=QVLDerdshu0JSizkitjUePBDQoLU8Y17+IU3PXVtySI4E9qaqqVhlmahwx8BAQ93vQ 7bcxNcVSNQuTIv/Q+TZ8NEVjILPj4LcGXQ4LKgGRfGkCUpb1xgROmYNKEbr5WhMcEyx+ wb/e/1R9m6pZ/pcDmkU1X83rkqrq9yLAD60J2LEJds1sWk/APlYgMotziJG4GBRTS7Ix Qpy06/juEoUi+nTIg1jgaQbU1MH/cN17Wrbeh4q5r9dCMCxiB2OD4IT9K8VHU7fP+5Kk mi1ljY/lHufmgn9Jno96Nxy2BoLwt5B4xEClflAa8MA72cliVr/kpYzLvI2FbPAZVRDq ZzqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=hCbGZ9+jHkqCkVF0PrPv1NyH6pZ13kuxzaQ6sjyriek=; b=jrIthKrWUMCKZ9jDgH9p7p8YgzCw2uvA6EYd3TP9Z6wwm6lit7aCUq/geZB307FSP5 ZThWD65b6Gqi3lC3zn+oLtAgt2qe+L9ItjiBbeH9LAIJ3dz+msfMxXhkJ5D+O55lHvt6 m3NKPdDx52wE+3zLDDkywH4t58RX+eTYbvAi3MEm/VMxuByJRtYdSZUGpMpMcrS7wSSG af7G/wRiK8ApGO4QgNhrsrXaoZ9AS46CHWVbtK5+mFa0wb0qWOVIR+zHmi4KtFn/JwXy +PtDuLSeFIFnMhvXrl+5vLDxrqNfLH7oUwHw4152WVH83ppwmIc16ooPc0W2ZKtN5HSA Oe+w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ds12-20020a170907724c00b006f3c6ceb0efsi20946409ejc.51.2022.07.27.09.22.32; Wed, 27 Jul 2022 09:22:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234369AbiG0QFH (ORCPT + 99 others); Wed, 27 Jul 2022 12:05:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233421AbiG0QFG (ORCPT ); Wed, 27 Jul 2022 12:05:06 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 76B554AD78 for ; Wed, 27 Jul 2022 09:05:04 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id CF9EF113E; Wed, 27 Jul 2022 09:05:04 -0700 (PDT) Received: from wubuntu (unknown [10.57.12.122]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id F376D3F73B; Wed, 27 Jul 2022 09:05:02 -0700 (PDT) Date: Wed, 27 Jul 2022 17:05:01 +0100 From: Qais Yousef To: Vincent Guittot Cc: Ingo Molnar , "Peter Zijlstra (Intel)" , Dietmar Eggemann , linux-kernel@vger.kernel.org, Xuewen Yan , Wei Wang , Jonathan JMChen , Hank Subject: Re: [PATCH 2/7] sched/uclamp: Make task_fits_capacity() use util_fits_cpu() Message-ID: <20220727160501.m4omtncl5nvqoh3p@wubuntu> References: <20220629194632.1117723-1-qais.yousef@arm.com> <20220629194632.1117723-3-qais.yousef@arm.com> <20220712104843.frbtkgkiftaovcon@wubuntu> <20220721142949.fqmabrjwylkuoltw@wubuntu> <20220722081913.GA6045@vingu-book> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20220722081913.GA6045@vingu-book> X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Vincent On 07/22/22 10:19, Vincent Guittot wrote: > Le jeudi 21 juil. 2022 � 15:29:49 (+0100), Qais Yousef a �crit : > > On 07/12/22 11:48, Qais Yousef wrote: > > > On 07/11/22 15:09, Vincent Guittot wrote: > > > > On Wed, 29 Jun 2022 at 21:48, Qais Yousef wrote: > > > > > [...] > > > > > > @@ -9108,7 +9125,7 @@ static inline void update_sg_wakeup_stats(struct sched_domain *sd, > > > > > > > > > > /* Check if task fits in the group */ > > > > > if (sd->flags & SD_ASYM_CPUCAPACITY && > > > > > - !task_fits_capacity(p, group->sgc->max_capacity)) { > > > > > + !task_fits_cpu(p, group->sgc->max_capacity_cpu)) { > > > > > > > > All the changes and added complexity above for this line. Can't you > > > > find another way ? > > > > > > You're right, I might have got carried away trying to keep the logic the same. > > > > > > Can we use group->asym_prefer_cpu or pick a cpu from group->sgc->cpumask > > > instead? > > > > > > I'll dig more into it anyway and try to come up with simpler alternative. > > > > Actually we can't. > > > > I can keep the current {max,min}_capacity field and just add the new > > {max,min}_capacity_cpu and use them where needed. Should address your concerns > > this way? That was actually the first version of the code, but then it seemed > > redundant to keep both {max,min}_capacity and {max,min}_capacity_cpu. > > > > OR > > > > I can add a new function to search for max spare capacity cpu in the group. > > > > Preference? > > > > Isn't the below enough and much simpler ? Thanks for that! > > [PATCH] sched/uclamp: Make task_fits_capacity() use util_fits_cpu() > > So that the new uclamp rules in regard to migration margin and capacity > pressure are taken into account correctly. > --- > kernel/sched/fair.c | 25 +++++++++++++++---------- > kernel/sched/sched.h | 9 +++++++++ > 2 files changed, 24 insertions(+), 10 deletions(-) > > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c > index 5eecae32a0f6..3e0c7cc490be 100644 > --- a/kernel/sched/fair.c > +++ b/kernel/sched/fair.c > @@ -4317,10 +4317,12 @@ static inline int util_fits_cpu(unsigned long util, > return fits; > } > > -static inline int task_fits_capacity(struct task_struct *p, > - unsigned long capacity) > +static inline int task_fits_cpu(struct task_struct *p, int cpu) > { > - return fits_capacity(uclamp_task_util(p), capacity); > + unsigned long uclamp_min = uclamp_eff_value(p, UCLAMP_MIN); > + unsigned long uclamp_max = uclamp_eff_value(p, UCLAMP_MAX); > + unsigned long util = task_util_est(p); > + return util_fits_cpu(util, uclamp_min, uclamp_max, cpu); > } > > static inline void update_misfit_status(struct task_struct *p, struct rq *rq) > @@ -4333,7 +4335,7 @@ static inline void update_misfit_status(struct task_struct *p, struct rq *rq) > return; > } > > - if (task_fits_capacity(p, capacity_of(cpu_of(rq)))) { > + if (task_fits_cpu(p, cpu_of(rq))) { > rq->misfit_task_load = 0; > return; > } > @@ -8104,7 +8106,7 @@ static int detach_tasks(struct lb_env *env) > > case migrate_misfit: > /* This is not a misfit task */ > - if (task_fits_capacity(p, capacity_of(env->src_cpu))) > + if (task_fits_cpu(p, env->src_cpu)) > goto next; > > env->imbalance = 0; > @@ -9085,6 +9087,10 @@ static inline void update_sg_wakeup_stats(struct sched_domain *sd, > > memset(sgs, 0, sizeof(*sgs)); > > + /* Assume that task can't fit any CPU of the group */ > + if (sd->flags & SD_ASYM_CPUCAPACITY) > + sgs->group_misfit_task_load = 0; Should this be sgs->group_misfit_task_load = 1 to indicate it doesn't fit? > + > for_each_cpu(i, sched_group_span(group)) { > struct rq *rq = cpu_rq(i); > unsigned int local; > @@ -9104,12 +9110,11 @@ static inline void update_sg_wakeup_stats(struct sched_domain *sd, > if (!nr_running && idle_cpu_without(i, p)) > sgs->idle_cpus++; > > - } > + /* Check if task fits in the CPU */ > + if (sd->flags & SD_ASYM_CPUCAPACITY && > + task_fits_cpu(p, i)) > + sgs->group_misfit_task_load = 0; So we clear the flag if there's any cpu that fits, I think that should work, yes and much better too. I got tunneled visioned and didn't take a step back to look at the big picture. Thanks for the suggestion :-) I think we can make it more efficient by checking if sgs->group_misfit_task_load is set /* Check if task fits in the CPU */ if (sd->flags & SD_ASYM_CPUCAPACITY && sgs->group_misfit_task_load && task_fits_cpu(p, i)) sgs->group_misfit_task_load = 0; which will avoid calling task_fits_cpu() repeatedly if we got a hit already. Thanks! -- Qais Yousef > > - /* Check if task fits in the group */ > - if (sd->flags & SD_ASYM_CPUCAPACITY && > - !task_fits_capacity(p, group->sgc->max_capacity)) { > - sgs->group_misfit_task_load = 1; > } > > sgs->group_capacity = group->sgc->capacity; > diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h > index 02c970501295..3292ad2db4ac 100644 > --- a/kernel/sched/sched.h > +++ b/kernel/sched/sched.h > @@ -2988,6 +2988,15 @@ static inline bool uclamp_is_used(void) > return static_branch_likely(&sched_uclamp_used); > } > #else /* CONFIG_UCLAMP_TASK */ > +static inline unsigned long uclamp_eff_value(struct task_struct *p, > + enum uclamp_id clamp_id) > +{ > + if (clamp_id == UCLAMP_MIN) > + return 0; > + > + return SCHED_CAPACITY_SCALE; > +} > + > static inline > unsigned long uclamp_rq_util_with(struct rq *rq, unsigned long util, > struct task_struct *p) > -- > 2.17.1 > > > > > Thanks! > > > > -- > > Qais Yousef