Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp15247928rwd; Sun, 25 Jun 2023 13:25:03 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6ct1sCVhQQLc37JKKTt0M4xa1/jxuUGdQX8C+3zMhcRPk6k2D4A+Gu8XoCY4Cp0oSb59Gy X-Received: by 2002:aa7:c1d9:0:b0:51b:c714:a296 with SMTP id d25-20020aa7c1d9000000b0051bc714a296mr12332967edp.13.1687724703310; Sun, 25 Jun 2023 13:25:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687724703; cv=none; d=google.com; s=arc-20160816; b=LAIX8tZKQowjDEKae7nzHwxrmC3pc+tspShf5fz87eW+1VzXpM7zeghf9PmQcaciL5 tZMjlqmvpnUnuLPz55JaGV4k/LLAhBswd7VuYYpENlRXQhF5BE0aK/PXVMOZug9CEDyZ 9Azn1HGMZuUyZYoFwnM0UkPcNc1kEn5RWX9eQ+EP4aaxBprw8e09d5X1KxRMUuPtxl0K 3o9Pat2v4/jXrJo7ywmascUjISsBdWVW7uEY9CzDo2JBC1xLKJiPuMPUaj43pIA/a/d0 xYAa1MxNuqJjMw0TvWptb9wFDpoUwWWQn14ovH3duSBXzwkWfULgB9d5Xdq1LXfNDUfe +z/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=Qh40X8DYi6kiUXs4/yFCRDU0ZB9hrGa6QmORXGP03V0=; fh=KZBoJFENbWds9sQunSX/agCJrI12aqY4Wb24oOnZYEI=; b=Woem1rzo2gh6B0QCDLid83uc/obsdFJSyOpBFnv3K7HRfltWHULC1YZHERkxWYtSlO Z1Y+dVLoM6KjR4rD4LwTXIx5dKBoXNO0z6ShnFwPRZBm+QrXe0Acb9GcGcTUS34Ftitu PnhmoY1Gr6YyQ9SRU7lJiDTXm3UWCssKZLGNe95o/b+VjgbcdkJOrMAYjVnZq4Y03E05 3utGeAJC3xS+ukwgdCNW9Nx7oak3G3R5tCeGCx6SmyHzfwVUiYW/jWOeMO7eFd7d4wRW 2BH9XXGmfWfHwkvqYh9k6tH7UXR75vmIrdZN8MlHSUi1wIh2VRfl6dSID48MiETB1Ljz GgXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=K6EALgwI; 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=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a15-20020aa7cf0f000000b005169ffc81acsi1982277edy.111.2023.06.25.13.24.38; Sun, 25 Jun 2023 13:25:03 -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=@intel.com header.s=Intel header.b=K6EALgwI; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229723AbjFYUJO (ORCPT + 99 others); Sun, 25 Jun 2023 16:09:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229447AbjFYUJN (ORCPT ); Sun, 25 Jun 2023 16:09:13 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 615BB12B; Sun, 25 Jun 2023 13:09:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1687723751; x=1719259751; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=8vbFi8C3UhrauUoUcMrhi5Q92b4US4VObe9G4fZZdKQ=; b=K6EALgwIjPMgtbBgFhRGMIa0oBvmoGkbvHhZ8TyxhoRNdVnf3nCB2TDo GXm9jptqkTA2+mTAa2T44opc1VXlHTrZONNHzOlKSKaCuDncFACY7+fss SR7qscCNuJlAbx+qPZVNktpHci34pONt7FukRc/Vws/bvuPwYL+evGTsn VPm7dRXReSRXZtVuQGJwF0OX9FIHKxX7OsGnzBlgUiR6At8GXT2sCWhIX TUpXmYUxcqYJNPtkVyJiY+VXoJK6AcS4yDfsGQzahWbcKeInbUvBN02UI vJ7AkGF+i1HVrX7wQlx4qABR7KyYdnLXP5fN8oGNfwj8u4Zp6PdmH/bHn A==; X-IronPort-AV: E=McAfee;i="6600,9927,10752"; a="361148668" X-IronPort-AV: E=Sophos;i="6.01,158,1684825200"; d="scan'208";a="361148668" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jun 2023 13:09:10 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10752"; a="693245280" X-IronPort-AV: E=Sophos;i="6.01,158,1684825200"; d="scan'208";a="693245280" Received: from ranerica-svr.sc.intel.com ([172.25.110.23]) by orsmga006.jf.intel.com with ESMTP; 25 Jun 2023 13:09:08 -0700 Date: Sun, 25 Jun 2023 13:11:55 -0700 From: Ricardo Neri To: Ionela Voinescu Cc: "Peter Zijlstra (Intel)" , Juri Lelli , Vincent Guittot , 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 , Lukasz Luba , Zhao Liu , "Yuan, Perry" , x86@kernel.org, "Joel Fernandes (Google)" , linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, "Tim C . Chen" , Zhao Liu Subject: Re: [PATCH v4 07/24] sched/fair: Compute IPC class scores for load balancing Message-ID: <20230625201155.GA3902@ranerica-svr.sc.intel.com> References: <20230613042422.5344-1-ricardo.neri-calderon@linux.intel.com> <20230613042422.5344-8-ricardo.neri-calderon@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,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 On Thu, Jun 22, 2023 at 10:02:44AM +0100, Ionela Voinescu wrote: > On Monday 12 Jun 2023 at 21:24:05 (-0700), Ricardo Neri wrote: > > When using IPCC scores to break ties between two scheduling groups, it is > > necessary to consider both the current score and the score that would > > result after load balancing. > > > > Compute the combined IPC class score of a scheduling group and the local > > scheduling group. Compute both the current score and the prospective score. > > > > Collect IPCC statistics only for asym_packing and fully_busy scheduling > > groups. These are the only cases that use IPCC scores. > > > > These IPCC statistics are used during idle load balancing. The candidate > > scheduling group will have one fewer busy CPU after load balancing. This > > observation is important for 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 the score of each sibling by > > the number of busy siblings. > > > > Cc: Ben Segall > > Cc: Daniel Bristot de Oliveira > > Cc: Dietmar Eggemann > > Cc: Ionela Voinescu > > Cc: Joel Fernandes (Google) > > Cc: Len Brown > > Cc: Lukasz Luba > > Cc: Mel Gorman > > Cc: Perry Yuan > > Cc: Rafael J. Wysocki > > Cc: Srinivas Pandruvada > > Cc: Steven Rostedt > > Cc: Tim C. Chen > > Cc: Valentin Schneider > > Cc: Zhao Liu > > Cc: x86@kernel.org > > Cc: linux-pm@vger.kernel.org > > Cc: linux-kernel@vger.kernel.org > > Signed-off-by: Ricardo Neri > > --- > > Changes since v3: > > * None > > > > Changes since v2: > > * Also collect IPCC stats for fully_busy sched groups. > > * Restrict use of IPCC stats to SD_ASYM_PACKING. (Ionela) > > * Handle errors of arch_get_ipcc_score(). (Ionela) > > > > 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 | 68 +++++++++++++++++++++++++++++++++++++++++++++ > > 1 file changed, 68 insertions(+) > > > > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c > > index c0cab5e501b6..a51c65c9335f 100644 > > --- a/kernel/sched/fair.c > > +++ b/kernel/sched/fair.c > > @@ -9114,6 +9114,8 @@ struct sg_lb_stats { > > unsigned long min_score; /* Min(score(rq->curr->ipcc)) */ > > unsigned short min_ipcc; /* Class of the task with the minimum IPCC score in the rq */ > > unsigned long sum_score; /* Sum(score(rq->curr->ipcc)) */ > > + long ipcc_score_after; /* Prospective IPCC score after load balancing */ > > + unsigned long ipcc_score_before; /* IPCC score before load balancing */ > > #endif > > }; > > > > @@ -9452,6 +9454,62 @@ static void update_sg_lb_ipcc_stats(int dst_cpu, struct sg_lb_stats *sgs, > > } > > } > > > > +static void update_sg_lb_stats_scores(struct sg_lb_stats *sgs, > > + struct sched_group *sg, > > + struct lb_env *env) > > +{ > > + unsigned long score_on_dst_cpu, before; > > + int busy_cpus; > > + long after; > > + > > + if (!sched_ipcc_enabled()) > > + return; > > + > > + /* > > + * IPCC scores are only useful during idle load balancing. For now, > > + * only asym_packing uses IPCC scores. > > + */ > > + if (!(env->sd->flags & SD_ASYM_PACKING) || > > + env->idle == CPU_NOT_IDLE) > > + return; > > + > > + /* > > + * IPCC scores are used to break ties only between these types of > > + * groups. > > + */ > > + if (sgs->group_type != group_fully_busy && > > + sgs->group_type != group_asym_packing) > > + return; > > + > > + busy_cpus = sgs->group_weight - sgs->idle_cpus; > > + > > + /* No busy CPUs in the group. No tasks to move. */ > > + if (!busy_cpus) > > + return; > > + > > + score_on_dst_cpu = arch_get_ipcc_score(sgs->min_ipcc, env->dst_cpu); > > + > > + /* > > + * Do not use IPC scores. sgs::ipcc_score_{after, before} will be zero > > + * and not used. > > + */ > > + if (IS_ERR_VALUE(score_on_dst_cpu)) > > + return; > > + > > + before = sgs->sum_score; > > + after = before - sgs->min_score; > > I don't believe this can end up being negative as the sum of all > scores should be higher or equal to the min score, right? Yes, I agree. `after` cannot be negative. > > I'm just wondering if ipcc_score_after can be made unsigned long as well, > just for consistency. Sure. I can make it of type unsigned long as well. > > > + > > + /* SMT siblings share throughput. */ > > + if (busy_cpus > 1 && sg->flags & SD_SHARE_CPUCAPACITY) { > > + before /= busy_cpus; > > + /* One sibling will become idle after load balance. */ > > + after /= busy_cpus - 1; > > + } > > + > > + sgs->ipcc_score_after = after + score_on_dst_cpu; > > + sgs->ipcc_score_before = before; > > Shouldn't the score_on_dst_cpu be added to "after" before being divided > between the SMT siblings? No, because ipcc_score_after represents the joint score of the busiest core and the destination core after load balance has taken place. The destination core was previously idle and now contributes to the joint score. Thanks and BR, Ricardo