From nobody Fri Sep 19 07:00:36 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A3849C43217 for ; Mon, 28 Nov 2022 13:14:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231804AbiK1NOI (ORCPT ); Mon, 28 Nov 2022 08:14:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40078 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231657AbiK1NNi (ORCPT ); Mon, 28 Nov 2022 08:13:38 -0500 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80F671D676; Mon, 28 Nov 2022 05:13:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1669641217; x=1701177217; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=2uPfNNplw7xOwTi269F+VNr3fJJfs2c0TJ+7Nw/WlL4=; b=W2mD71dOmlZY9WM53EkJ/Uy9G7hyZOgGnRJ14qwTAHhYW/RLkVjqhltN CuKkQs3ExkJPIt4eO0JvXCYhXHVkpoh8vBDkouHeSKDrzRmO7F0LsX0Wb dWiEwUb+UKsNOXNloc8CSUTIgZ7pJ3PhTtdrM+NN8opTVzbjye6aTVkSe BqnP71iOS6AFuL8v2jSc4DfLB8ghR6Gk6683P3ZRFRl6O+DEUNEuQOQus ZVLNyI/m+NjIJYpbHlHas1VJMAcNnSUh90JrqcnmR0Ojh6Skyq+1sFrOy TPec0XhDsegeMrYxVUnlaLsXWsyKFILWR3RTCHS4kocgHVMRrEiAt2vWL g==; X-IronPort-AV: E=McAfee;i="6500,9779,10544"; a="401117115" X-IronPort-AV: E=Sophos;i="5.96,200,1665471600"; d="scan'208";a="401117115" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Nov 2022 05:13:33 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10544"; a="749381345" X-IronPort-AV: E=Sophos;i="5.96,200,1665471600"; d="scan'208";a="749381345" Received: from ranerica-svr.sc.intel.com ([172.25.110.23]) by fmsmga002.fm.intel.com with ESMTP; 28 Nov 2022 05:13:32 -0800 From: Ricardo Neri To: "Peter Zijlstra (Intel)" , Juri Lelli , Vincent Guittot Cc: Ricardo Neri , "Ravi V. Shankar" , Ben Segall , Daniel Bristot de Oliveira , Dietmar Eggemann , Len Brown , Mel Gorman , "Rafael J. Wysocki" , Srinivas Pandruvada , Steven Rostedt , Tim Chen , Valentin Schneider , x86@kernel.org, "Joel Fernandes (Google)" , linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Ricardo Neri , "Tim C . Chen" Subject: [PATCH v2 07/22] sched/fair: Compute IPC class scores for load balancing Date: Mon, 28 Nov 2022 05:20:45 -0800 Message-Id: <20221128132100.30253-8-ricardo.neri-calderon@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221128132100.30253-1-ricardo.neri-calderon@linux.intel.com> References: <20221128132100.30253-1-ricardo.neri-calderon@linux.intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Compute the joint total (both current and prospective) IPC class score of a scheduling group and the local scheduling group. These IPCC statistics are used during asym_packing load balancing. It implies that the candidate sched group will have one fewer busy CPU after load balancing. This observation is important for physical cores with SMT support. The IPCC score of scheduling groups composed of SMT siblings needs to consider that the siblings share CPU resources. When computing the total IPCC score of the scheduling group, divide score from each sibilng by the number of busy siblings. Cc: Ben Segall Cc: Daniel Bristot de Oliveira Cc: Dietmar Eggemann Cc: Joel Fernandes (Google) Cc: Len Brown Cc: Mel Gorman Cc: Rafael J. Wysocki Cc: Srinivas Pandruvada Cc: Steven Rostedt Cc: Tim C. Chen Cc: Valentin Schneider Cc: x86@kernel.org Cc: linux-pm@vger.kernel.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Ricardo Neri --- Changes since v1: * Implemented cleanups and reworks from PeterZ. I took all his suggestions, except the computation of the IPC score before and after load balancing. We are computing not the average score, but the *total*. * Check for the SD_SHARE_CPUCAPACITY to compute the throughput of the SMT siblings of a physical core. * Used the new interface names. * Reworded commit message for clarity. --- kernel/sched/fair.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 3a1d6c50a19b..e333f9623b3a 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -8766,6 +8766,10 @@ struct sg_lb_stats { unsigned int nr_numa_running; unsigned int nr_preferred_running; #endif +#ifdef CONFIG_IPC_CLASSES + long ipcc_score_after; /* Prospective IPCC score after load balancing */ + long ipcc_score_before; /* IPCC score before load balancing */ +#endif }; =20 /* @@ -9140,6 +9144,38 @@ static void update_sg_lb_ipcc_stats(struct sg_lb_ipc= c_stats *sgcs, } } =20 +static void update_sg_lb_stats_scores(struct sg_lb_ipcc_stats *sgcs, + struct sg_lb_stats *sgs, + struct sched_group *sg, + int dst_cpu) +{ + int busy_cpus, score_on_dst_cpu; + long before, after; + + if (!sched_ipcc_enabled()) + return; + + busy_cpus =3D sgs->group_weight - sgs->idle_cpus; + /* No busy CPUs in the group. No tasks to move. */ + if (!busy_cpus) + return; + + score_on_dst_cpu =3D arch_get_ipcc_score(sgcs->min_ipcc, dst_cpu); + + before =3D sgcs->sum_score; + after =3D before - sgcs->min_score; + + /* SMT siblings share throughput. */ + if (busy_cpus > 1 && sg->flags & SD_SHARE_CPUCAPACITY) { + before /=3D busy_cpus; + /* One sibling will become idle after load balance. */ + after /=3D busy_cpus - 1; + } + + sgs->ipcc_score_after =3D after + score_on_dst_cpu; + sgs->ipcc_score_before =3D before; +} + #else /* CONFIG_IPC_CLASSES */ static void update_sg_lb_ipcc_stats(struct sg_lb_ipcc_stats *sgcs, struct rq *rq) @@ -9149,6 +9185,14 @@ static void update_sg_lb_ipcc_stats(struct sg_lb_ipc= c_stats *sgcs, static void init_rq_ipcc_stats(struct sg_lb_ipcc_stats *class_sgs) { } + +static void update_sg_lb_stats_scores(struct sg_lb_ipcc_stats *sgcs, + struct sg_lb_stats *sgs, + struct sched_group *sg, + int dst_cpu) +{ +} + #endif /* CONFIG_IPC_CLASSES */ =20 /** @@ -9329,6 +9373,7 @@ static inline void update_sg_lb_stats(struct lb_env *= env, if (!local_group && env->sd->flags & SD_ASYM_PACKING && env->idle !=3D CPU_NOT_IDLE && sgs->sum_h_nr_running && sched_asym(env, sds, sgs, group)) { + update_sg_lb_stats_scores(&sgcs, sgs, group, env->dst_cpu); sgs->group_asym_packing =3D 1; } =20 --=20 2.25.1