Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp350861imn; Thu, 4 Aug 2022 08:22:53 -0700 (PDT) X-Google-Smtp-Source: AA6agR6vV3EkAMmSYRo+CzeVIy5ypntBPA/4LEcKR/4i256duGIbnGCbmabXi4Twv9jhFQjIweTF X-Received: by 2002:aa7:8286:0:b0:52b:5ccd:f6bb with SMTP id s6-20020aa78286000000b0052b5ccdf6bbmr2189909pfm.34.1659626573260; Thu, 04 Aug 2022 08:22:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659626573; cv=none; d=google.com; s=arc-20160816; b=mZsUasm6Ka/HxMHe1fC6Slz6MF9sDgTy7HYOZBsHQzQT7QNJHHspYpo/G4v4jCDurp 1Tp8qYr19bngFspUWmP4kS5o2Ry46MZmlj90VGl4MysXbUjY6mIF1O3w4SbxcS9NaL4J l+X+Twv7G6SXfC4TStlpUpoO3KZmqWbjTlVDzMSGN3nfBZ1NJwjeLPDC5BBjHGN+0efl vmW9tOU3h2VGhJ7fI0Q3cMzbBS5PooDEhzWHvsDfK0Xy23PDCNGSVOd3J7MhIwly/7zW x3kWt5L80IZLlHgUI22RJEFypy8DON0dX1EAxpLAYc0W4sMT0pu1hkEAB4brDu/QFNq1 xvsg== 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=L20eApIOmh5J2sBZIR9tBhGL7j9T1zTKskCacY3aqEY=; b=HR6x/DAEs5Cg2vSvQoATtyTj0NlfVjf81gAvmLNNy7u725cKSwA9YkKKKH6IC7X0PX v70+ISZthcNkRotCeGFBGYU4os2jqdBPY6YclE6ubLjZm+g5T0aBzEpOQc53l6HliqgJ xAQfcBmT1KcA3KCDYlAta8MJZG/zHwsh8at2lpXi7uNYPC6u4HUNauu3zHhU3H5SgeHQ jSMqG0ugm9U03pkaVy+gpZ7GDg78dHpdTZADi5jWE++ztLk4fLXVjsyHLxFAX4uUseCc g5rWB/uoqZEZtzJfuk4ueJdiWA9UOd0QJOnebYoIwtsKSw83PAGTVEYnc9ZLQvlpZZS9 lBJw== 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 h10-20020a056a00170a00b0052d7483e126si1300452pfc.292.2022.08.04.08.22.38; Thu, 04 Aug 2022 08:22:53 -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 S239893AbiHDOgv (ORCPT + 99 others); Thu, 4 Aug 2022 10:36:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239839AbiHDOgk (ORCPT ); Thu, 4 Aug 2022 10:36:40 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1D9684B48D for ; Thu, 4 Aug 2022 07:36:39 -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 6785B14BF; Thu, 4 Aug 2022 07:36:39 -0700 (PDT) Received: from localhost.localdomain (unknown [10.57.10.177]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 38DC93F73B; Thu, 4 Aug 2022 07:36:37 -0700 (PDT) From: Qais Yousef To: Ingo Molnar , "Peter Zijlstra (Intel)" , Vincent Guittot , Dietmar Eggemann Cc: linux-kernel@vger.kernel.org, Xuewen Yan , Lukasz Luba , Wei Wang , Jonathan JMChen , Hank , Qais Yousef Subject: [PATCH v2 2/9] sched/uclamp: Make task_fits_capacity() use util_fits_cpu() Date: Thu, 4 Aug 2022 15:36:02 +0100 Message-Id: <20220804143609.515789-3-qais.yousef@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220804143609.515789-1-qais.yousef@arm.com> References: <20220804143609.515789-1-qais.yousef@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 So that the new uclamp rules in regard to migration margin and capacity pressure are taken into account correctly. Fixes: a7008c07a568 ("sched/fair: Make task_fits_capacity() consider uclamp restrictions") Co-developed-by: Vincent Guittot Signed-off-by: Qais Yousef --- kernel/sched/fair.c | 26 ++++++++++++++++---------- kernel/sched/sched.h | 9 +++++++++ 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 00c2de800685..78feb9ca1e41 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -4377,10 +4377,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) @@ -4393,7 +4395,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; } @@ -8234,7 +8236,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; @@ -9239,6 +9241,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 = 1; + for_each_cpu(i, sched_group_span(group)) { struct rq *rq = cpu_rq(i); unsigned int local; @@ -9258,12 +9264,12 @@ 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 && + sgs->group_misfit_task_load && + task_fits_cpu(p, i)) + sgs->group_misfit_task_load = 0; - /* 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 3ccd35c22f0f..eec1cac3eef4 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -3047,6 +3047,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.25.1