Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp2337121rwl; Thu, 6 Apr 2023 08:53:12 -0700 (PDT) X-Google-Smtp-Source: AKy350akQdrmX+ixN1f4AuX0zl6cBjroZzUyvKrTeWl2GUz9Dd4jxYRqUG04LRDyYFWxedhrVnE7 X-Received: by 2002:a17:902:e5c8:b0:1a1:a146:f6d7 with SMTP id u8-20020a170902e5c800b001a1a146f6d7mr12350783plf.4.1680796392335; Thu, 06 Apr 2023 08:53:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680796392; cv=none; d=google.com; s=arc-20160816; b=J+wF9xcZAVHAbvG7TvaJp82x4ETRMCvNlCQ/ENZRDmtUq/9TP62dYqt/4UJDjuBMUk 1ss7usLC00lPvv4Kn+Ca2+TEDmx/aU1s0oGGUjVBoCmJc08znQ9buT5VapK+ji4VedYA Wc3P+IBGTr/zlBAWjSl8EIeec1xNxp/HJgnsXFa9tXFjBn3057S7DYNl3bhEMEGaxsIn y64rXl6+jqUCTAXTIqhhCXPyvbgLq8pe6hm8rBSE6PWhYmaeOINPWvnOU5Fd5XRszQvl EaXWLtD8gu2Jxn+UoyP+xTp4JwAEJrkM1aYM/ZoLkl6ioflhBIVjWM6kXBQgrK8IDMNt 5SUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=wk7CjqAzAN71oXnyuqecD9Eyqj1S4TwJEUtw3JZSy6w=; b=uMkDjtB8CDL/4rBUw9XfIOkj/W2SMbhwqqqNDW1c2mUHwjMBKDwe1klbcnxH+Ebk4a tNIsOuU7+Cxl4nZjnQRIjZ+ajZWCDW4dmXEYy6wvWDvJ2U46E0tQNhECDG9xzRWX1YrE urmR5wRvBRukusnUW/SaMPvsNw9dvLdt9egoTZfrcyzJe888sKyTG7Sjl+lp9c3WDDsE xIpfks0aQPDltWtMb3egqDk4d0HCj1BFMRQ/NQFlp/UL6oS/2fJoW26cSGCfwS0BQiyN ++H9uc1G4fRPAh47lAcmcksQ0j3XuB39N+RcFjWRPLvQA8ZUNGMi7T9JVA0BbeTXcWCp fxpg== 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 m2-20020a170902db0200b001a5089fe47fsi672631plx.326.2023.04.06.08.52.58; Thu, 06 Apr 2023 08:53:12 -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 S239095AbjDFPux (ORCPT + 99 others); Thu, 6 Apr 2023 11:50:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238972AbjDFPuu (ORCPT ); Thu, 6 Apr 2023 11:50:50 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7A4739750 for ; Thu, 6 Apr 2023 08:50:46 -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 5FE5A1C0A; Thu, 6 Apr 2023 08:51:30 -0700 (PDT) Received: from e125579.fritz.box (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 9EA3F3F6C4; Thu, 6 Apr 2023 08:50:44 -0700 (PDT) From: Dietmar Eggemann To: Ingo Molnar , Peter Zijlstra , Vincent Guittot Cc: Qais Yousef , Kajetan Puchalski , Morten Rasmussen , Vincent Donnefort , Quentin Perret , Abhijeet Dharmapurikar , linux-kernel@vger.kernel.org Subject: [PATCH 1/1] sched: Consider CPU contention in frequency & load-balance busiest CPU selection Date: Thu, 6 Apr 2023 17:50:30 +0200 Message-Id: <20230406155030.1989554-2-dietmar.eggemann@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230406155030.1989554-1-dietmar.eggemann@arm.com> References: <20230406155030.1989554-1-dietmar.eggemann@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.3 required=5.0 tests=RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=unavailable 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 Use new cpu_boosted_util_cfs() instead of cpu_util_cfs(). The former returns max(util_avg, runnable_avg) capped by max CPU capacity. CPU contention is thereby considered through runnable_avg. The change in load-balance only affects migration type `migrate_util`. Suggested-by: Vincent Guittot Signed-off-by: Dietmar Eggemann --- kernel/sched/cpufreq_schedutil.c | 3 ++- kernel/sched/fair.c | 2 +- kernel/sched/sched.h | 19 +++++++++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c index e3211455b203..728b186cd367 100644 --- a/kernel/sched/cpufreq_schedutil.c +++ b/kernel/sched/cpufreq_schedutil.c @@ -158,7 +158,8 @@ static void sugov_get_util(struct sugov_cpu *sg_cpu) struct rq *rq = cpu_rq(sg_cpu->cpu); sg_cpu->bw_dl = cpu_bw_dl(rq); - sg_cpu->util = effective_cpu_util(sg_cpu->cpu, cpu_util_cfs(sg_cpu->cpu), + sg_cpu->util = effective_cpu_util(sg_cpu->cpu, + cpu_boosted_util_cfs(sg_cpu->cpu), FREQUENCY_UTIL, NULL); } diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index bc358dc4faeb..5ae36224a1c2 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -10481,7 +10481,7 @@ static struct rq *find_busiest_queue(struct lb_env *env, break; case migrate_util: - util = cpu_util_cfs(i); + util = cpu_boosted_util_cfs(i); /* * Don't try to pull utilization from a CPU with one diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index 060616944d7a..f42c859579d9 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -2994,6 +2994,25 @@ static inline unsigned long cpu_util_cfs(int cpu) return min(util, capacity_orig_of(cpu)); } +/* + * cpu_boosted_util_cfs() - Estimates the amount of CPU capacity used by + * CFS tasks. + * + * Similar to cpu_util_cfs() but also take possible CPU contention into + * consideration. + */ +static inline unsigned long cpu_boosted_util_cfs(int cpu) +{ + unsigned long runnable; + struct cfs_rq *cfs_rq; + + cfs_rq = &cpu_rq(cpu)->cfs; + runnable = READ_ONCE(cfs_rq->avg.runnable_avg); + runnable = min(runnable, capacity_orig_of(cpu)); + + return max(cpu_util_cfs(cpu), runnable); +} + static inline unsigned long cpu_util_rt(struct rq *rq) { return READ_ONCE(rq->avg_rt.util_avg); -- 2.25.1