Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp2926211rwb; Mon, 15 Aug 2022 14:11:21 -0700 (PDT) X-Google-Smtp-Source: AA6agR4MGNsD9CvFj6/vMRDCSGQwRlny6xMJtsUj3v5XoOS2R3q6DaSpoScqrxCOtVd/lkie3VHg X-Received: by 2002:a17:907:16ab:b0:731:55c0:e7a1 with SMTP id hc43-20020a17090716ab00b0073155c0e7a1mr11583205ejc.154.1660597881160; Mon, 15 Aug 2022 14:11:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660597881; cv=none; d=google.com; s=arc-20160816; b=qbG+dt0DokZH0PtAegH98+ce9nXt/IIO7KT7yMYXh7MeiVlswh+nxx7wms4+tAkhnk /AV45lRztAPA4S0ohQdR9Vc6QQZNvx9gTDFrrJVoTjohtgoC9NZazQdpPK+Sfi7o03kJ L2YzoWJ1AWcCfvEY8mgifuIo3RqxVxukjqmI01qwP2Aaeu0gRd7nF3x8oks2M+le+FCN Xi7wZTQH45139bUqm85c4O5AtFSjzeCjq41SWhdj3OUloCxza6VNGUz+YOp9QX8KLNYt MCxmcx2z17VzLUgDFW1A+i0rvCfJm6wFjl028jRWqcc5Fbikj25esTngQbwuDF2j4yKx 9CJQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=/X8uO9BmshEJzRdk/K6JafD1+r+MH3UphmRdxnT9aRo=; b=I9+aByPpkXEjrWA0r9eaOocCMGrxcpL+PgZUuouwqhdYutGI6LbgnpTl4w4N1aOYDN NEKLczbcZDnq9RwoHZFdanMNYHAi2dVeUVTLC1gNLYGwamNYwmJqH1tWfAMwTXSI7dQu 4H5qYwvBM7N8jQVEKB2hY91r6zfQetg2HkNdnZrh+haKmetC1sfUw/ajYXKjnZ+E5KRf /YKLO+x9VxEPHs2sOx8/OXkBZepTLfgMvsnv4XYOwKJOjZ8qv/HkcRvFORLq2raU5eVB azKPTSwu/JBakMK6Dm0AC1jV35AdKD6OW5i4247v1dqWmyFlNvfS24oY7AG5yIJxf4c+ k1Qw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=dwID2QjV; 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=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ft16-20020a170907801000b0072ed0d06c0csi7065975ejc.411.2022.08.15.14.10.56; Mon, 15 Aug 2022 14:11:21 -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=@linuxfoundation.org header.s=korg header.b=dwID2QjV; 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=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347964AbiHOU1A (ORCPT + 99 others); Mon, 15 Aug 2022 16:27:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347203AbiHOUWD (ORCPT ); Mon, 15 Aug 2022 16:22:03 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BFCD14AD7E; Mon, 15 Aug 2022 12:01:23 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 02E1461211; Mon, 15 Aug 2022 19:01:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 04A7CC433C1; Mon, 15 Aug 2022 19:01:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660590082; bh=Us5azn9z/bhsRcCBR8T73DvmbNO0Qh6ELubzdyA/PTc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dwID2QjVAtXv6De1QMr+StyzBtw5Scrq8snO1i0JkaFklodqpg01808lpE9HlwNFD dAiVrK5GTR2J0i9d2ojhUQw8KO8EoEbTj6jKFrpAqFI7AHy9M+i2+Lj07Z9n+je8ep 45YBR31ugOwqrowr5YgX+iCPifdQMuU2a+h1u6uU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, David Chen , Zhang Qiao , Vincent Guittot , "Peter Zijlstra (Intel)" , Sasha Levin Subject: [PATCH 5.18 0146/1095] sched/fair: fix case with reduced capacity CPU Date: Mon, 15 Aug 2022 19:52:25 +0200 Message-Id: <20220815180435.632793897@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180429.240518113@linuxfoundation.org> References: <20220815180429.240518113@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 From: Vincent Guittot [ Upstream commit c82a69629c53eda5233f13fc11c3c01585ef48a2 ] 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 Signed-off-by: Sasha Levin --- 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 ef2d8690fe18..46f6674a0979 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -7628,8 +7628,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, /* @@ -8712,6 +8712,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. @@ -8734,8 +8747,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; @@ -8765,11 +8779,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; } } @@ -8822,7 +8842,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; @@ -9443,9 +9464,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; } -- 2.35.1