Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp6885921rwr; Wed, 10 May 2023 00:17:59 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6IHdJEASs1YuQP3OVNzGL0rnzTsG+Es3v/fh83Qux2FNmGBznGPDAU9dKfep8uSbA4QTwT X-Received: by 2002:a17:902:7290:b0:1a9:7c6d:abb with SMTP id d16-20020a170902729000b001a97c6d0abbmr15247462pll.29.1683703079667; Wed, 10 May 2023 00:17:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683703079; cv=none; d=google.com; s=arc-20160816; b=xe8w80+MJRBsbNrZDAIR9kyfZYzu0ubDCR5qRG4D1FmDTUFlwAoho7jDK/aPFQkvp1 3q+psTTaVHilAP8YPmmVHs0Z+Uw4HYMw+DD19VgyEpDO250+61X8wlF3hkauxh9gDHUY qIsmlACPUDp0okhEj/RWyn9Y/Fl9CjRVWn3AXeUJmisb0gbA7MS3bSeJW1sXl+DK+kl+ osdXODLk1bGq3nph65qP143U8/eHLAVwrJIrARGCIoCBKzyk3qrsJOeIEJ6mvP7+1fX7 OWjAe/TxXP3TYVcpyvDZQnn9Z1A2xUjy3OKZPcXr0cOjGG5MbFYq6+y5Sm/b7agAOB8K thcQ== 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=wHIYyrpClgjZy4lJ9Jx3YAnRClrAaR29Eb7jqZzgsgs=; b=gPkFZENs3aLofZ06us08d7/UX0lsJhErWXdZYV996ErXG9bOBpIhAM6hw+5Vgce961 Sbpp10fS1ysiA9qRzrSIIVAE3fOWfKZlPLeFF1345p08skkxGX5UnEo9EVVN7sk7iF4D UmSDxm4Od6Vi0PvSQgDoQZdDq2p9C/dRIYU4/oNFCk7WIEaWpPeX3RZEq6+VQRox1Man VuTifDHo8IX77VVMnIxKPSji2fjOU+b6YqqCtRQDyFAV6no72pujQvksy2EcHS+ROu/S 5WfxsDdSgkACMplhQ2czqXzo9Q213JYg7y1neN16AbLL4z5/MhJawF2D2Z44mYiKtOWd 8MPg== 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 d10-20020a170903230a00b001a979141a25si3631718plh.243.2023.05.10.00.17.45; Wed, 10 May 2023 00:17:59 -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 S236430AbjEJHIV (ORCPT + 99 others); Wed, 10 May 2023 03:08:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39520 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236416AbjEJHIO (ORCPT ); Wed, 10 May 2023 03:08:14 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 06A785B80; Wed, 10 May 2023 00:08:06 -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 254D21063; Wed, 10 May 2023 00:08:50 -0700 (PDT) Received: from [10.57.22.157] (unknown [10.57.22.157]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 2A0BE3F663; Wed, 10 May 2023 00:08:03 -0700 (PDT) Message-ID: <0cda1fc9-2e99-66a2-b833-fe5be676d815@arm.com> Date: Wed, 10 May 2023 08:08:03 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: Re: [PATCH 02/17] PM: EM: Find first CPU online while updating OPP efficiency Content-Language: en-US To: Pierre Gondois Cc: dietmar.eggemann@arm.com, rui.zhang@intel.com, rafael@kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, amit.kucheria@verdurent.com, amit.kachhap@gmail.com, daniel.lezcano@linaro.org, viresh.kumar@linaro.org, len.brown@intel.com, pavel@ucw.cz, ionela.voinescu@arm.com, rostedt@goodmis.org, mhiramat@kernel.org References: <20230314103357.26010-1-lukasz.luba@arm.com> <20230314103357.26010-3-lukasz.luba@arm.com> From: Lukasz Luba In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.6 required=5.0 tests=BAYES_00,NICE_REPLY_A, 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 4/11/23 16:40, Pierre Gondois wrote: > Hello Lukasz, > > On 3/14/23 11:33, Lukasz Luba wrote: >> The Energy Model might be updated at runtime and the energy efficiency >> for each OPP may change. Thus, there is a need to update also the >> cpufreq framework and make it aligned to the new values. In order to >> do that, use a first online CPU from the Performance Domain. >> >> Signed-off-by: Lukasz Luba >> --- >>   kernel/power/energy_model.c | 11 +++++++++-- >>   1 file changed, 9 insertions(+), 2 deletions(-) >> >> diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c >> index 265d51a948d4..3d8d1fad00ac 100644 >> --- a/kernel/power/energy_model.c >> +++ b/kernel/power/energy_model.c >> @@ -246,12 +246,19 @@ em_cpufreq_update_efficiencies(struct device >> *dev, struct em_perf_state *table) >>       struct em_perf_domain *pd = dev->em_pd; >>       struct cpufreq_policy *policy; >>       int found = 0; >> -    int i; >> +    int i, cpu; >>       if (!_is_cpu_device(dev) || !pd) >>           return; > > Since dev is a CPU, I think it shouldn be possible to get the cpu id via > 'dev->id'. > If so the code below should not be necessary anymore. When you look at the code it does two things. It tries to get the CPU id - this might be similar to what you have proposed with the 'dev->id' but it's also looking at CPUs which are 'active'. The 'dev' that we have might come from some place, e.g. thermal cooling, which had a first CPU in the domain stored somewhere. That CPU might be sometimes not active, but the rest of the CPUs in the domain might be running. We have to find an active CPU id and then we get the 'policy'. > >> -    policy = cpufreq_cpu_get(cpumask_first(em_span_cpus(pd))); >> +    /* Try to get a CPU which is online and in this PD */ >> +    cpu = cpumask_first_and(em_span_cpus(pd), cpu_active_mask); >> +    if (cpu >= nr_cpu_ids) { >> +        dev_warn(dev, "EM: No online CPU for CPUFreq policy\n"); >> +        return; >> +    } >> + >> +    policy = cpufreq_cpu_get(cpu); >>       if (!policy) { >>           dev_warn(dev, "EM: Access to CPUFreq policy failed"); >>           return; > > Regards, > Pierre