Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1251278rwb; Thu, 1 Dec 2022 14:42:01 -0800 (PST) X-Google-Smtp-Source: AA0mqf5R3/wdto6pXd4qAJnIZcUchSNoz5FRc0RAG+jlUA9ZiHjXW4B/CXrGlNI0EBwiUJIv/KAa X-Received: by 2002:a17:906:a40d:b0:7c0:b335:9157 with SMTP id l13-20020a170906a40d00b007c0b3359157mr3702542ejz.193.1669934521468; Thu, 01 Dec 2022 14:42:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669934521; cv=none; d=google.com; s=arc-20160816; b=Zcg36ITgxYILdx1WammyQ8Jm1OtEdyF7sAaIWx5iwRx2PgA5KjSmCSmywa2F67YMVe vZp04IvtZ5yXGTut5cfWtQpJ44Qv74dikDpT9utXG1jODfx7Imxn7sF322o4xgF/nlEe DrJKOtQ0NWdsoEGKBAv7jONyzAAtRbYKSjlq68ObBFklenKvpfnFXpDND3qohDyyQ63g khPR32aJb0NaVm1Yi7nqztj43clrIoXU9Rhf2fePZwRqZM2eVMARUFg95NZqTWKy42HI 2pdeNXbipegNBH1vVdaumRhxyb9aiz8ja3d+AVjeykW+sdBmMM/S+IPGUruWMVHQNKev Gadg== 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=eQ7qqkBFyKK4bmKVLq5wv0MP6GcwO38z4bUhNfBDvUo=; b=OEiOYfd0F8xohjg4eK96XYReNn8LSUcSVJmVr6FO1j05jHdOi23AFls5j9zCU7swuF 9Ivtk46HQ2e2VacZOAcTESF5nhpMmYb0ROr53lIHWzjTEJ/eHhv57nXEBzzI+VjFFlBo SViFTPX/A141U9rih8VEzhnGlSoQLkTGTeSMoa+F3S7DTrEag5wI4VjC8qCwhEzAxYjq or503z9W8ZsjIs/0RSQwWpfvO0kECppEro6pxRNR14BiRpjporrcCs9hO3KZfoczGiv3 Pc1dsAietOjWexAd6J7F6v48Zq94sG1Q9KiS5MfIda+/hlMT77uCCPiHCo9+MzbTjY6Z VrBA== 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 eb10-20020a0564020d0a00b00468ccfbba7asi4873547edb.387.2022.12.01.14.41.41; Thu, 01 Dec 2022 14:42:01 -0800 (PST) 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 S231338AbiLAWjK (ORCPT + 82 others); Thu, 1 Dec 2022 17:39:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230292AbiLAWjI (ORCPT ); Thu, 1 Dec 2022 17:39:08 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 22276BEC4A; Thu, 1 Dec 2022 14:39:06 -0800 (PST) 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 6156D2B; Thu, 1 Dec 2022 14:39:12 -0800 (PST) Received: from [192.168.178.6] (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8AE193F73D; Thu, 1 Dec 2022 14:39:03 -0800 (PST) Message-ID: <927e4ffc-8400-b615-2d58-9e88ee4bdc3c@arm.com> Date: Thu, 1 Dec 2022 23:38:37 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH 1/3] sched/uclamp: Fix a uninitialized variable warnings Content-Language: en-US To: Qais Yousef , Ingo Molnar , Peter Zijlstra , Vincent Guittot , "Rafael J. Wysocki" , Viresh Kumar Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Lukasz Luba , Wei Wang , Xuewen Yan , Hank , Jonathan JMChen , kernel test robot , Dan Carpenter References: <20221127141742.1644023-1-qyousef@layalina.io> <20221127141742.1644023-2-qyousef@layalina.io> From: Dietmar Eggemann In-Reply-To: <20221127141742.1644023-2-qyousef@layalina.io> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.5 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_MED,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 27/11/2022 15:17, Qais Yousef wrote: > Addresses the following warnings: > >> config: riscv-randconfig-m031-20221111 >> compiler: riscv64-linux-gcc (GCC) 12.1.0 >> >> smatch warnings: >> kernel/sched/fair.c:7263 find_energy_efficient_cpu() error: uninitialized symbol 'util_min'. >> kernel/sched/fair.c:7263 find_energy_efficient_cpu() error: uninitialized symbol 'util_max'. > > Fixes: 244226035a1f ("sched/uclamp: Fix fits_capacity() check in feec()") > Reported-by: kernel test robot > Reported-by: Dan Carpenter > Signed-off-by: Qais Yousef (Google) > --- > kernel/sched/fair.c | 7 ++----- > 1 file changed, 2 insertions(+), 5 deletions(-) > > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c > index 4cc56c91e06e..89dadaafc1ec 100644 > --- a/kernel/sched/fair.c > +++ b/kernel/sched/fair.c > @@ -7217,10 +7217,10 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu) > eenv_task_busy_time(&eenv, p, 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; > unsigned long rq_util_min, rq_util_max; > - unsigned long util_min, util_max; > unsigned long prev_spare_cap = 0; > int max_spare_cap_cpu = -1; > unsigned long base_energy; > @@ -7258,10 +7258,7 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu) > * aligned with sched_cpu_util(). > */ > if (uclamp_is_used()) { > - if (uclamp_rq_is_idle(cpu_rq(cpu))) { > - util_min = p_util_min; > - util_max = p_util_max; > - } else { > + if (!uclamp_rq_is_idle(cpu_rq(cpu))) { > /* > * Open code uclamp_rq_util_with() except for > * the clamp() part. Ie: apply max aggregation Can we use `struct rq *rq = cpu_rq(cpu)` to reduce nesting and comply with 80 columns line length? diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 89dadaafc1ec..6a2fc2ca5078 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -7239,6 +7239,8 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu) eenv.pd_cap = 0; for_each_cpu(cpu, cpus) { + struct rq *rq = cpu_rq(cpu); + eenv.pd_cap += cpu_thermal_cap; if (!cpumask_test_cpu(cpu, sched_domain_span(sd))) @@ -7257,21 +7259,19 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu) * much capacity we can get out of the CPU; this is * aligned with sched_cpu_util(). */ - if (uclamp_is_used()) { - if (!uclamp_rq_is_idle(cpu_rq(cpu))) { - /* - * Open code uclamp_rq_util_with() except for - * the clamp() part. Ie: apply max aggregation - * only. util_fits_cpu() logic requires to - * operate on non clamped util but must use the - * max-aggregated uclamp_{min, max}. - */ - rq_util_min = uclamp_rq_get(cpu_rq(cpu), UCLAMP_MIN); - rq_util_max = uclamp_rq_get(cpu_rq(cpu), UCLAMP_MAX); - - util_min = max(rq_util_min, p_util_min); - util_max = max(rq_util_max, p_util_max); - } + if (uclamp_is_used() && !uclamp_rq_is_idle(rq)) { + /* + * Open code uclamp_rq_util_with() except for + * the clamp() part. Ie: apply max aggregation + * only. util_fits_cpu() logic requires to + * operate on non clamped util but must use the + * max-aggregated uclamp_{min, max}. + */ + rq_util_min = uclamp_rq_get(rq, UCLAMP_MIN); + rq_util_max = uclamp_rq_get(rq, UCLAMP_MAX); + + util_min = max(rq_util_min, p_util_min); + util_max = max(rq_util_max, p_util_max); } if (!util_fits_cpu(util, util_min, util_max, cpu)) continue;