From patchwork Wed Feb 7 03:47:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: alexs@kernel.org X-Patchwork-Id: 197722 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1981338dyb; Tue, 6 Feb 2024 19:44:59 -0800 (PST) X-Google-Smtp-Source: AGHT+IGK/Sho8wHsGT+6JyetI1nOqd1wUPVfq++6A8sjDqChmbotnzZJOjJzhlWu899fkiCuMyI4 X-Received: by 2002:ac8:554a:0:b0:42b:f0aa:3b2f with SMTP id o10-20020ac8554a000000b0042bf0aa3b2fmr4426682qtr.42.1707277499772; Tue, 06 Feb 2024 19:44:59 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707277499; cv=pass; d=google.com; s=arc-20160816; b=KYLSZV1XxrOLmDK7LJuQ1VI0X5EAEDQPKJTrYeZFASRbrxoe1j+DS0Z9/4bFuU75Nj 7bnLhEIgY/WMikhgwTbShBJoMiHnk5seU0AZzEyUg7qobdbflUCEib3u6CbFyEGs2Fu6 XFzZ7nLyIQYjGLoiEdhw0YfICmkTEYrq+P/TEwEyqZDzO/aiH2W5ou+icBRd1C4H1mFv CRD0uo3M1vvdsTygRZctDR2oVi5m7nX16mXXnyySGce9Sd43IxzzMN6u3j989iykoQfg tPpLjAS/bkSD/DHJ45l82OV7HNmNxp4Q20t3rmze721WEu4qOzly5tldp/WynubVt3gI C1MQ== 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=hoLgI6tgVplVDKK3BnwI+V8rgXQ9re+fu3yG12BK0Pg=; fh=NBpwoF15zOm/VJQPRd0MQ/6rlkXq13LFJWeB5txr0mg=; b=C0+hWgNlFkykjjc9dwBzPerODftNzmDMELR0gcTU+DmT3qU0l8Q4bd36WyqDCl7CjX uNtNdZkrUWerBBOsVG7wmqT8Uv7knEYKncjeoZ/moYEGczHTJvi3s0KoUm7PrwgUQ19n 9qjR6t2pgB+IaAOsKTghym/JG+C8YY2HQgcd2d5LFH9OcGRBXh67RxpLkDSPxlv0H+Cx hDNxE/RwSZI9+zGXS7NAmH3njhbZRlaVVyTreDT0llAoKB5Wv+Qj6XmFjljW9ZGfOwwy cvRUSVDuS/kCSpcXyx59Qlz7KgSp9cBmLwvW9/livZbm5fx4K6KOfgJS9xoI5WJFgq7e 5Iwg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=tSWUTl5M; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-55907-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55907-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=2; AJvYcCUSL1ay0po9voi4oI4CnCUjjHmjcshn9ZJ2d+3Yf1uFXKqenuBGx2eYSTx0JKVSODp4XFR0TiivP11swLzxQNxPdhwXuA== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id f20-20020a05620a12f400b0078564385e39si340576qkl.372.2024.02.06.19.44.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 19:44:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-55907-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=tSWUTl5M; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-55907-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55907-ouuuleilei=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 820651C24A7E for ; Wed, 7 Feb 2024 03:44:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B73271CD3B; Wed, 7 Feb 2024 03:44:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="tSWUTl5M" 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 E28AF1C694 for ; Wed, 7 Feb 2024 03:44:17 +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=1707277458; cv=none; b=nnjTJCf3epIqzGhG685VMDY5zNBwOF/n/vq9KDS8qRIB4eQNG6rk/soP1VZb9aVef4qXs6VZyUpLnoGtoR4/r/QcdSkIAWd0IzOCW+fZKI89B4Z50Z08Tp4JJvI79lWFmLEBDQOJjKWmzUIrRz//gGcdeU13bCdUc1GEsm2UXb4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707277458; c=relaxed/simple; bh=ZBWabr/sl4BLAglGWdQysfp0ZTpL5iL55T/CdtsmPuA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KSs/rvFp8VYsn62nmeFgY4eEVAjKYN0oU9ZVRthPIlPC5zUPteTR7BGP17ysPHhoV2j/3W1OQv5HotN5yPzOAUIxDRIJwSXOQmGsI732Hq0Za5dkoP2sMPVEQ0NtG8T8R3MzcSqeGVNWEWstHlYwe2ALYcmlI0n18U1c0hbPFso= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=tSWUTl5M; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 59F2DC433F1; Wed, 7 Feb 2024 03:44:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707277457; bh=ZBWabr/sl4BLAglGWdQysfp0ZTpL5iL55T/CdtsmPuA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tSWUTl5MrVR3aRqaLNPAk0UvumXyYjyTudHP0DvKUQpEUu8DiZdBWzjLL3F7C8MED JcjrVw3T/pkkEP/V/FSUU/hlGHNoNKKDoqC5ay/0S8uu8PGzom6PTfAzDgsq5PQN/X BmFs3agVrqKEKfVS7TAVYDB2KztXTTEgQSTc1EA3hjRWZVOZeXGi21cr+Hi9bKlsjL 1NhuATAg6EMERrch94F3xAUivLqTF9dCXFOn9eRs8idRL+0uvdkQouBqL5mtghLeQa CFYJo3eAVYuLP57L1h7rUcMlVMhqliBsYDtQfGEnLeFm46k1E53Ihf54MUq/VVPf+v LvD1Obi8r8odA== From: alexs@kernel.org To: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Daniel Bristot de Oliveira , Valentin Schneider , linux-kernel@vger.kernel.org, ricardo.neri-calderon@linux.intel.com, yangyicong@hisilicon.com Cc: Alex Shi Subject: [PATCH v4 3/4] sched/fair: Rework sched_use_asym_prio() and sched_asym_prefer() Date: Wed, 7 Feb 2024 11:47:03 +0800 Message-ID: <20240207034704.935774-3-alexs@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240207034704.935774-1-alexs@kernel.org> References: <20240207034704.935774-1-alexs@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790210211610530825 X-GMAIL-MSGID: 1790210211610530825 From: Alex Shi sched_use_asym_prio() 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(). This makes the code easier to read. No functional changes. Signed-off-by: Alex Shi To: Ricardo Neri To: Valentin Schneider To: Vincent Guittot To: Peter Zijlstra To: Ingo Molnar Reviewed-by: Ricardo Neri Tested-by: Ricardo Neri --- kernel/sched/fair.c | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 607dc310b355..942b6358f683 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 @@ -9767,22 +9777,17 @@ static bool sched_use_asym_prio(struct sched_domain *sd, int cpu) * 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 +9943,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 +11042,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 +11912,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; }