Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp491084imw; Thu, 14 Jul 2022 05:27:28 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uhXB6fM34NJ9p3T+ikUdENYWFRihM8q9aizDbmfrRYuFmFL3XzlSqwKqcQCigP4Qs+jd7f X-Received: by 2002:a17:907:6e12:b0:72e:6774:cb80 with SMTP id sd18-20020a1709076e1200b0072e6774cb80mr5441091ejc.504.1657801647883; Thu, 14 Jul 2022 05:27:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657801647; cv=none; d=google.com; s=arc-20160816; b=kPUED0SJzH/3dSfhKYlGm0g+1EiqFD42nQ/Sndm6wpvPOeaYuw2uXwAZoX9q4VoYYR Tj9l1geRcJK7B/KWp7+/wTkBZRMYv1SQZVax010ongj/XnCSyFJC1VyxS/9NcloRLoKB Iri4gkG1MDV3wceesdyuQ7tUJ4Oy5HaIzkJnOk88C/WWz/p0jCnAVQRTDcZyXpkDbr/A ZBx6+0/Z0jSgzHU55Gh/4J4GjofyhtktQ/6808fW2ZYGDGQ6zRgWzeA6UaYbwFLH0drO RgC50gaa/ZhIcQeClZq2G2OYBF0qTe2/6drA2J4UumDnYadfyloeNpmtw/Z0pFjyH0GR Rn8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=up1HiDpQLpyxuWkd7NU5c0wZC/w3JzgDQG83OzRQZVI=; b=W+RBKr/+HR1mDi2SICYNrHPcbEfQsDAbniqumAw4PsdvbbbiaNsqN2vBpOsfZpX43R 4cJtOQ4qBbEjk1vCkA3I2xFV77QlIkatGaHEpnmB+5PeX+Yf7vUUFVkfzs37Q00kn5gA iFkkMZygRm/0UZtLFZfNDb74BOBaLTPQodK58f7kdPNciIE+j/cR6G+w2vcpjBiGqE5U zXpzkvGAfBJBypGxwRuZzYuQtf61KeNEDBr3DOot+famWVE52QOd+f8klc0hqcUA81Nv ioKXf61HwhM/kV7ffGP6Fq2C4b+V/WJsHbj+yid0KkBGZnv3WXi73oGJ5wFb4+tcbbp1 d/sw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=2ZmN54dy; dkim=neutral (no key) header.i=@linutronix.de; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g16-20020a170906521000b00711ca15cd48si1211176ejm.939.2022.07.14.05.27.03; Thu, 14 Jul 2022 05:27:27 -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; dkim=pass header.i=@linutronix.de header.s=2020 header.b=2ZmN54dy; dkim=neutral (no key) header.i=@linutronix.de; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238985AbiGNLfl (ORCPT + 99 others); Thu, 14 Jul 2022 07:35:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238968AbiGNLfg (ORCPT ); Thu, 14 Jul 2022 07:35:36 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B9A55927B; Thu, 14 Jul 2022 04:35:34 -0700 (PDT) Date: Thu, 14 Jul 2022 11:35:32 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1657798533; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=up1HiDpQLpyxuWkd7NU5c0wZC/w3JzgDQG83OzRQZVI=; b=2ZmN54dyc+f45Pa6htYKBQ6fl623K4PNtyoayJ29R1USW1SG/uAPyCZH1vX4ob9DMf8XCH FhuIDo/DAcXYXaEUKc5ivJejOurSrgN8P7dtNoW2aLIA1+lPZWqD86E3ff5g3PiyJWm59v GfB9rwf7trMs9qAGKpIIy7nigB9X57d/wR7Vf8CRXeqzpmjvjy1P5qUiT8oSNwSGUTY9jB 3csjQ3KbnftkqEIAypcaolT1l1M45rEIGID/fa4OIg1XKInp3vtTZmN/GNuJL3i1jURQuy qVkKouA8Lm4ZO51XKdsxF7vfuXmlNM8v7kH/LVTGB0NU+tr8caxGWvO35ExeKw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1657798533; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=up1HiDpQLpyxuWkd7NU5c0wZC/w3JzgDQG83OzRQZVI=; b=2vFt1QmPebt8jAZTS30/YO1jJo094Zcw3Z5mou2bakT6qr7Jx/Iq/AWMtOmGByqfy/jmGU BxU7oU/QqD87LyBw== From: "tip-bot2 for Vincent Guittot" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: sched/core] sched/fair: fix case with reduced capacity CPU Cc: David Chen , Zhang Qiao , Vincent Guittot , "Peter Zijlstra (Intel)" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20220708154401.21411-1-vincent.guittot@linaro.org> References: <20220708154401.21411-1-vincent.guittot@linaro.org> MIME-Version: 1.0 Message-ID: <165779853202.15455.11200413501635211610.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE 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 The following commit has been merged into the sched/core branch of tip: Commit-ID: c82a69629c53eda5233f13fc11c3c01585ef48a2 Gitweb: https://git.kernel.org/tip/c82a69629c53eda5233f13fc11c3c01585ef48a2 Author: Vincent Guittot AuthorDate: Fri, 08 Jul 2022 17:44:01 +02:00 Committer: Peter Zijlstra CommitterDate: Wed, 13 Jul 2022 11:29:17 +02:00 sched/fair: fix case with reduced capacity CPU The capacity of the CPU available for CFS tasks can be reduced because of other activities running on the latter. In such case, it's worth trying to move CFS tasks on a CPU with more available capacity. The rework of the load balance has filtered the case when the CPU is classified to be fully busy but its capacity is reduced. Check if CPU's capacity is reduced while gathering load balance statistic and classify it group_misfit_task instead of group_fully_busy so we can try to move the load on another CPU. Reported-by: David Chen Reported-by: Zhang Qiao Signed-off-by: Vincent Guittot Signed-off-by: Peter Zijlstra (Intel) Tested-by: David Chen Tested-by: Zhang Qiao Link: https://lkml.kernel.org/r/20220708154401.21411-1-vincent.guittot@linaro.org --- kernel/sched/fair.c | 54 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 42 insertions(+), 12 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index a78d2e3..914096c 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -7711,8 +7711,8 @@ enum group_type { */ group_fully_busy, /* - * SD_ASYM_CPUCAPACITY only: One task doesn't fit with CPU's capacity - * and must be migrated to a more powerful CPU. + * One task doesn't fit with CPU's capacity and must be migrated to a + * more powerful CPU. */ group_misfit_task, /* @@ -8798,6 +8798,19 @@ sched_asym(struct lb_env *env, struct sd_lb_stats *sds, struct sg_lb_stats *sgs return sched_asym_prefer(env->dst_cpu, group->asym_prefer_cpu); } +static inline bool +sched_reduced_capacity(struct rq *rq, struct sched_domain *sd) +{ + /* + * When there is more than 1 task, the group_overloaded case already + * takes care of cpu with reduced capacity + */ + if (rq->cfs.h_nr_running != 1) + return false; + + return check_cpu_capacity(rq, sd); +} + /** * update_sg_lb_stats - Update sched_group's statistics for load balancing. * @env: The load balancing environment. @@ -8820,8 +8833,9 @@ static inline void update_sg_lb_stats(struct lb_env *env, for_each_cpu_and(i, sched_group_span(group), env->cpus) { struct rq *rq = cpu_rq(i); + unsigned long load = cpu_load(rq); - sgs->group_load += cpu_load(rq); + sgs->group_load += load; sgs->group_util += cpu_util_cfs(i); sgs->group_runnable += cpu_runnable(rq); sgs->sum_h_nr_running += rq->cfs.h_nr_running; @@ -8851,11 +8865,17 @@ static inline void update_sg_lb_stats(struct lb_env *env, if (local_group) continue; - /* Check for a misfit task on the cpu */ - if (env->sd->flags & SD_ASYM_CPUCAPACITY && - sgs->group_misfit_task_load < rq->misfit_task_load) { - sgs->group_misfit_task_load = rq->misfit_task_load; - *sg_status |= SG_OVERLOAD; + if (env->sd->flags & SD_ASYM_CPUCAPACITY) { + /* Check for a misfit task on the cpu */ + if (sgs->group_misfit_task_load < rq->misfit_task_load) { + sgs->group_misfit_task_load = rq->misfit_task_load; + *sg_status |= SG_OVERLOAD; + } + } else if ((env->idle != CPU_NOT_IDLE) && + sched_reduced_capacity(rq, env->sd)) { + /* Check for a task running on a CPU with reduced capacity */ + if (sgs->group_misfit_task_load < load) + sgs->group_misfit_task_load = load; } } @@ -8908,7 +8928,8 @@ static bool update_sd_pick_busiest(struct lb_env *env, * CPUs in the group should either be possible to resolve * internally or be covered by avg_load imbalance (eventually). */ - if (sgs->group_type == group_misfit_task && + if ((env->sd->flags & SD_ASYM_CPUCAPACITY) && + (sgs->group_type == group_misfit_task) && (!capacity_greater(capacity_of(env->dst_cpu), sg->sgc->max_capacity) || sds->local_stat.group_type != group_has_spare)) return false; @@ -9517,9 +9538,18 @@ static inline void calculate_imbalance(struct lb_env *env, struct sd_lb_stats *s busiest = &sds->busiest_stat; if (busiest->group_type == group_misfit_task) { - /* Set imbalance to allow misfit tasks to be balanced. */ - env->migration_type = migrate_misfit; - env->imbalance = 1; + if (env->sd->flags & SD_ASYM_CPUCAPACITY) { + /* Set imbalance to allow misfit tasks to be balanced. */ + env->migration_type = migrate_misfit; + env->imbalance = 1; + } else { + /* + * Set load imbalance to allow moving task from cpu + * with reduced capacity. + */ + env->migration_type = migrate_load; + env->imbalance = busiest->group_misfit_task_load; + } return; }