Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp1468943rdb; Sat, 10 Feb 2024 03:36:56 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWKxlU0ktG1bwT/kx3e0H6PvWF4VC9o6zR75T9Za8HN1l/zpeLorb65Om556gEJcERecjvPt/RxKvSvnb0rRb9PwEeIk0XbOkJ7SUSeoA== X-Google-Smtp-Source: AGHT+IH6j+93RfpHFHbmqsqgyS9wZbILDd4MPgMJQzxHX5IR26FijCnCrgO+P4iohAIaOM6HNd+W X-Received: by 2002:a17:90b:1187:b0:296:94cb:4d02 with SMTP id gk7-20020a17090b118700b0029694cb4d02mr2522249pjb.1.1707565016218; Sat, 10 Feb 2024 03:36:56 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707565016; cv=pass; d=google.com; s=arc-20160816; b=LAkzyafa9o/Z5vE3N5ZBYhvGmDwaAgLq89RwZx6MOqEVNRFEoaQW1gfaSdqmkzYN/r YF1dRA+pPTsjhsKPfCn11EQ/JQcHCi9hz6UwSZXX4E60oO2vg7gB1IA8n5UIrGUxt2FW 36cTk2IvOlcpP7RPLVN+YX8wNz2dJZlMHp3PzrBxntq416yy15zHMy3e6PbmUSbxJt/i DuFiFy2Fe3eDEwBoAnq+llEO7BX3UxqSkjFLXpqsycb6D+34y3ziRaPiT3fuTAtGvZlO vwS4IWwmoUdNW+PxPkTCB2u5EHrhtoSCm+FFD+uL1AZERVt50nQV0ESGr2ThjqzqkvXW XVRg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=/Y5BxNWmnqPQPSpwm3SzHBMMx6j6jGLWJCiJIYLr7ko=; fh=CJSc+8EevuAz/UgvWwCAiiYmmMHJkkPsiVq03JP0QKQ=; b=bMnxxWrjEUfcDPhcGatQR9AGJc4vOBbRpLI0x/2qmXlvCDQYqohAeEvxrze6pbuffL jyK4oIc6zox1I9n0tGlO5Wkr4tlyJ+uNQe0G3oaWS7VyxUYXQCKOUX2zHDsZlb6Gg4IW 6aI2XWC5L+w+Qt1Al6+9E4zg2S2U7cr6/WXNU7/ZCwxetARkmUTp4AsBiWJwBX0NJ6// TbC/TK4XxatIJDLV32OPXRrojz5Mm7swuxac+baJQ8VyIAzTiRO+NncwD7oXRDlcrsWW RzSygTxBIY43rSTL8nl4vGjST+/pD0DXe3uTXP6SSfk0uV1Zgyb2imt9n1pXIpMEcccQ EKNw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=RPTNgJJJ; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-60380-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60380-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=2; AJvYcCXsChvoI75G9dR3/RpBuVUwcNoL9rFzy3NJWeNk0/Hti6YjfjoqU37OUdd5KqTfY68cwpYHdkB3MRGX0WCJfgXEEm/Dd2DW5WA17U28Zg== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id ch4-20020a056a0208c400b005dc50694bb3si3435277pgb.718.2024.02.10.03.36.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Feb 2024 03:36:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-60380-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=RPTNgJJJ; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-60380-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60380-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id D99B22871D3 for ; Sat, 10 Feb 2024 11:36:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D97BA3D965; Sat, 10 Feb 2024 11:36:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="RPTNgJJJ" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 06C053D57A for ; Sat, 10 Feb 2024 11:36:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707564990; cv=none; b=SOoyJ+HsN63GZjwpUtiN3C/dy13AeIaOP9TipS53N1Zut2z3hRTyaiHEbQg19rihPTjXYMS1C44eJz/LFmP7frg23FPo80hbyNnLPz5OmaZpXpgTrjVb14fWvDoKuHGYXoWahuo6DITeAeVECPILgOAirf9eg9iAS6Bfe8Z1d1k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707564990; c=relaxed/simple; bh=1Prw9eKOLc7XnYIr5gRAob0S2UL6jacinMD8Gm2WYdQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Egjk2/N/xMLrjjBokei8igllw3P9auSDbz8+azQTYGuYE1Le8mQLYjJ9pDwRIB5Kugwk8UarUoYDGiU3PVdFUk1LPyH4BwSkigGBcOPEiVbbgA266yrZHG308LLh/yOH+v3l4aXQsMSnNWGx6pChuZ7j28bqK5xSf5ZcgjNXINs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=RPTNgJJJ; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8D997C433F1; Sat, 10 Feb 2024 11:36:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707564989; bh=1Prw9eKOLc7XnYIr5gRAob0S2UL6jacinMD8Gm2WYdQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RPTNgJJJoqWOzrheU6wrV978/BrI/9/YQgRtoUDpe+kkI44Qmu6JZjehpwCk8I+oz dgjxfEjpAJM01R8qbsg3zPGoLAsaaVSVrzkvo9T1NuMNEjquY+KhPVo/EvBAcAlVQR kohn5lPFJz9UKh5TFmDnSy1YFsDB5k2ttBwNJSrwOqgWtNn5GFrxOJD14L6Yg6fufv ewvEJdXpYaAAcDZuHH82WDgSZ0lLK9BdlS6PstLRI7PgtMxVRHiEWQt4aj8ZUKEJwY Kd3eE/YHkO/TGPnC2YuwGrlNMxs3kNT7JLUMlkqsD1CxPe0N9lvD0UU+OXgQV1YJIT KZ/NoNZMlhnAg== From: alexs@kernel.org To: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , linux-kernel@vger.kernel.org (open list:SCHEDULER) Cc: Alex Shi , Ricardo Neri Subject: [PATCH v5 3/5] sched/fair: Rework sched_use_asym_prio() and sched_asym_prefer() Date: Sat, 10 Feb 2024 19:39:21 +0800 Message-ID: <20240210113924.1130448-3-alexs@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240210113924.1130448-1-alexs@kernel.org> References: <20240210113924.1130448-1-alexs@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Alex Shi sched_use_asym_prio() and sched_asym_prefer() are used together in various places. Consolidate them into a single function sched_asym(). The existing sched_group_asym() is only used when collecting statistics of a scheduling group. Rename it as sched_group_asym(), and remove the obsolete function description. This makes the code easier to read. No functional changes. Tested-by: Ricardo Neri Signed-off-by: Alex Shi Cc: Ricardo Neri Cc: Valentin Schneider Cc: Vincent Guittot Cc: Peter Zijlstra Cc: Ingo Molnar Reviewed-by: Ricardo Neri --- kernel/sched/fair.c | 45 ++++++++++++++++++++------------------------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 607dc310b355..426eda9eda57 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -9746,8 +9746,18 @@ static bool sched_use_asym_prio(struct sched_domain *sd, int cpu) return sd->flags & SD_SHARE_CPUCAPACITY || is_core_idle(cpu); } +static inline bool sched_asym(struct sched_domain *sd, int dst_cpu, int src_cpu) +{ + /* + * First check if @dst_cpu can do asym_packing load balance. Only do it + * if it has higher priority than @src_cpu. + */ + return sched_use_asym_prio(sd, dst_cpu) && + sched_asym_prefer(dst_cpu, src_cpu); +} + /** - * sched_asym - Check if the destination CPU can do asym_packing load balance + * sched_group_asym - Check if the destination CPU can do asym_packing balance * @env: The load balancing environment * @sgs: Load-balancing statistics of the candidate busiest group * @group: The candidate busiest group @@ -9755,34 +9765,21 @@ static bool sched_use_asym_prio(struct sched_domain *sd, int cpu) * @env::dst_cpu can do asym_packing if it has higher priority than the * preferred CPU of @group. * - * SMT is a special case. If we are balancing load between cores, @env::dst_cpu - * can do asym_packing balance only if all its SMT siblings are idle. Also, it - * can only do it if @group is an SMT group and has exactly on busy CPU. Larger - * imbalances in the number of CPUS are dealt with in find_busiest_group(). - * - * If we are balancing load within an SMT core, or at PKG domain level, always - * proceed. - * * Return: true if @env::dst_cpu can do with asym_packing load balance. False * otherwise. */ static inline bool -sched_asym(struct lb_env *env, struct sg_lb_stats *sgs, struct sched_group *group) +sched_group_asym(struct lb_env *env, struct sg_lb_stats *sgs, struct sched_group *group) { - /* Ensure that the whole local core is idle, if applicable. */ - if (!sched_use_asym_prio(env->sd, env->dst_cpu)) - return false; - /* - * CPU priorities does not make sense for SMT cores with more than one + * CPU priorities do not make sense for SMT cores with more than one * busy sibling. */ - if (group->flags & SD_SHARE_CPUCAPACITY) { - if (sgs->group_weight - sgs->idle_cpus != 1) - return false; - } + if ((group->flags & SD_SHARE_CPUCAPACITY) && + (sgs->group_weight - sgs->idle_cpus != 1)) + return false; - return sched_asym_prefer(env->dst_cpu, group->asym_prefer_cpu); + return sched_asym(env->sd, env->dst_cpu, group->asym_prefer_cpu); } /* One group has more than one SMT CPU while the other group does not */ @@ -9938,7 +9935,7 @@ static inline void update_sg_lb_stats(struct lb_env *env, /* Check if dst CPU is idle and preferred to this group */ if (!local_group && env->sd->flags & SD_ASYM_PACKING && env->idle != CPU_NOT_IDLE && sgs->sum_h_nr_running && - sched_asym(env, sgs, group)) { + sched_group_asym(env, sgs, group)) { sgs->group_asym_packing = 1; } @@ -11037,8 +11034,7 @@ static struct rq *find_busiest_queue(struct lb_env *env, * SMT cores with more than one busy sibling. */ if ((env->sd->flags & SD_ASYM_PACKING) && - sched_use_asym_prio(env->sd, i) && - sched_asym_prefer(i, env->dst_cpu) && + sched_asym(env->sd, i, env->dst_cpu) && nr_running == 1) continue; @@ -11908,8 +11904,7 @@ static void nohz_balancer_kick(struct rq *rq) * preferred CPU must be idle. */ for_each_cpu_and(i, sched_domain_span(sd), nohz.idle_cpus_mask) { - if (sched_use_asym_prio(sd, i) && - sched_asym_prefer(i, cpu)) { + if (sched_asym(sd, i, cpu)) { flags = NOHZ_STATS_KICK | NOHZ_BALANCE_KICK; goto unlock; } -- 2.43.0