Received: by 2002:a05:7412:1492:b0:e2:908c:2ebd with SMTP id s18csp798142rdh; Wed, 23 Aug 2023 15:44:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF4ifVBSDzJ6WDY6SB56r5KCuLbcq+QzxHYthROVQENXtO3D7gHq6j/W6j8MoMqwBnnbhbT X-Received: by 2002:a17:907:a063:b0:9a1:eb4f:56f with SMTP id ia3-20020a170907a06300b009a1eb4f056fmr2568007ejc.13.1692830680107; Wed, 23 Aug 2023 15:44:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692830680; cv=none; d=google.com; s=arc-20160816; b=ysUhSeRejunbdGX5vFe2zOFrxx9XOPXIcZEjDg4bGyfWzvsyjfB0+/gKWa6h5L6McT 2sIc4IKSMWn6oBvVIeXyk0yozTB+n4xg8FMrU93NXe58Z7S0MKvVpZO2XG9HqFzhlozl GcqYFSnoFagbo72Qsckvy7Jf2NaayNipgY4wc67MQEHqL9MMR9fBYFUUEN6KhFo0v6sb so0dYszgQ9a0GAGeeTGLFESMSmzW4kIjei85FQ+jAacJDGkeg30yWIST85iixeshpqag DGUwvOyzuuFt5OsUKB6bM9v2RaoIrG2bMXpdhTTYvD3G+XSpv+X6sxdTAKjQzTS+yT9b WYBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=0rZK9F6OdjuKdmcvti7uVTMdJiSuYiZTFBwHIOipUaM=; fh=LGu5VMV+yRoTIsAs/UHNtHY3hOppEGiGXKtnpQIj/EA=; b=PkUlWjTN0EQRy2JL6FSs5xoo9dMzYg8XWHj5VKg0QlLCrY9hk5oSuOx0hnkGKyKh7B yGfFodXZgR87GNe9BdJbwzzjZXfF1df7tQIZVeaa/80JLNo/lwv0+yci42aGggjpZvnG rUJHL4NuLH/TddR0bLtiV5hCmTGlEnssK6swYaf66AE52SeHTq4BQxE+F3sKjn64ByFL BUV2MtJmDy4tIl11UfNJB50uzIKgMGwoKUADPI6RplC8JQu1BCT7UHVGdDSmNNy6eibK 4oXkKSVCiueftbiHRcoRoQgB8AXnn0t1THYR/GaxcSoGQv0QkkiwUKcD0ccxsDvjpPXZ vvwQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h25-20020a170906399900b0099e03fb797fsi9512308eje.671.2023.08.23.15.44.15; Wed, 23 Aug 2023 15:44:40 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232793AbjHWKaN (ORCPT + 99 others); Wed, 23 Aug 2023 06:30:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55334 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230414AbjHWKaN (ORCPT ); Wed, 23 Aug 2023 06:30:13 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 98AACFB for ; Wed, 23 Aug 2023 03:30:10 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id CE34F1042; Wed, 23 Aug 2023 03:30:50 -0700 (PDT) Received: from [192.168.178.6] (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 81B093F64C; Wed, 23 Aug 2023 03:30:08 -0700 (PDT) Message-ID: Date: Wed, 23 Aug 2023 12:30:07 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: [PATCH v4 1/3] sched/uclamp: Set max_spare_cap_cpu even if max_spare_cap is 0 Content-Language: en-US To: Qais Yousef , Ingo Molnar , Peter Zijlstra , Vincent Guittot Cc: linux-kernel@vger.kernel.org, Lukasz Luba , Wei Wang , Xuewen Yan , Hank , Jonathan JMChen , Hongyan Xia References: <20230821224504.710576-1-qyousef@layalina.io> <20230821224504.710576-2-qyousef@layalina.io> From: Dietmar Eggemann In-Reply-To: <20230821224504.710576-2-qyousef@layalina.io> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.6 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE 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 22/08/2023 00:45, Qais Yousef wrote: > When uclamp_max is being used, the util of the task could be higher than > the spare capacity of the CPU, but due to uclamp_max value we force fit > it there. > > The way the condition for checking for max_spare_cap in > find_energy_efficient_cpu() was constructed; it ignored any CPU that has > its spare_cap less than or _equal_ to max_spare_cap. Since we initialize > max_spare_cap to 0; this lead to never setting max_spare_cap_cpu and > hence ending up never performing compute_energy() for this cluster and > missing an opportunity for a better energy efficient placement to honour > uclamp_max setting. > > max_spare_cap = 0; > cpu_cap = capacity_of(cpu) - task_util(p); // 0 if task_util(p) is high Nitpick: s/task_util(p)/cpu_util(cpu, p, cpu, ...) which is max(cpu_util + task_util, cpu_util_est + task_util_est) > > ... > > util_fits_cpu(...); // will return true if uclamp_max forces it to fit > > ... > > // this logic will fail to update max_spare_cap_cpu if cpu_cap is 0 > if (cpu_cap > max_spare_cap) { > max_spare_cap = cpu_cap; > max_spare_cap_cpu = cpu; > } > > prev_spare_cap suffers from a similar problem. > > Fix the logic by converting the variables into long and treating -1 > value as 'not populated' instead of 0 which is a viable and correct > spare capacity value. We need to be careful signed comparison is used > when comparing with cpu_cap in one of the conditions. > > Fixes: 1d42509e475c ("sched/fair: Make EAS wakeup placement consider uclamp restrictions") > Reviewed-by: Vincent Guittot > Signed-off-by: Qais Yousef (Google) > --- > kernel/sched/fair.c | 11 +++++------ > 1 file changed, 5 insertions(+), 6 deletions(-) > > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c > index 0b7445cd5af9..5da6538ed220 100644 > --- a/kernel/sched/fair.c > +++ b/kernel/sched/fair.c > @@ -7707,11 +7707,10 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu) > for (; pd; pd = pd->next) { > unsigned long util_min = p_util_min, util_max = p_util_max; > unsigned long cpu_cap, cpu_thermal_cap, util; > - unsigned long cur_delta, max_spare_cap = 0; > + long prev_spare_cap = -1, max_spare_cap = -1; > unsigned long rq_util_min, rq_util_max; > - unsigned long prev_spare_cap = 0; > + unsigned long cur_delta, base_energy; > int max_spare_cap_cpu = -1; > - unsigned long base_energy; > int fits, max_fits = -1; > > cpumask_and(cpus, perf_domain_span(pd), cpu_online_mask); > @@ -7774,7 +7773,7 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu) > prev_spare_cap = cpu_cap; > prev_fits = fits; > } else if ((fits > max_fits) || > - ((fits == max_fits) && (cpu_cap > max_spare_cap))) { > + ((fits == max_fits) && ((long)cpu_cap > max_spare_cap))) { > /* > * Find the CPU with the maximum spare capacity > * among the remaining CPUs in the performance > @@ -7786,7 +7785,7 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu) > } > } > > - if (max_spare_cap_cpu < 0 && prev_spare_cap == 0) > + if (max_spare_cap_cpu < 0 && prev_spare_cap < 0) > continue; > > eenv_pd_busy_time(&eenv, cpus, p); > @@ -7794,7 +7793,7 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu) > base_energy = compute_energy(&eenv, pd, cpus, p, -1); > > /* Evaluate the energy impact of using prev_cpu. */ > - if (prev_spare_cap > 0) { > + if (prev_spare_cap > -1) { > prev_delta = compute_energy(&eenv, pd, cpus, p, > prev_cpu); > /* CPU utilization has changed */ We still need a solution to deal with situations in which `pd + task contribution` > `pd_capacity`: compute_energy() if (dst_cpu >= 0) busy_time = min(pd_capacity, pd_busy_time + task_busy_time); ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ pd + task contribution busy_time is based on util (ENERGY_UTIL), not on the uclamp values (FREQUENCY_UTIL) we try to fit into a PD (and finally onto a CPU). With that as a reminder for us and the change in the cover letter: Reviewed-by: Dietmar Eggemann