Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp4495374rdh; Wed, 29 Nov 2023 03:11:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IHVZFVYzdQXG7iiN0acGiCLRvfWwMuzGG4RerjGdckbYbtkWTIJB+ucddYEhIqFsk/tuVV2 X-Received: by 2002:a05:6808:21a2:b0:3b8:3ed6:c468 with SMTP id be34-20020a05680821a200b003b83ed6c468mr21457069oib.58.1701256283189; Wed, 29 Nov 2023 03:11:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701256283; cv=none; d=google.com; s=arc-20160816; b=oxFCT+0BNuTbNuStGcy4EnZau+RHpEyJJFZ6bjSXRVy6kLuMjVHVHlPZGqhc1yMpe8 nwPIL8z0GQ3R3OptBqEtryS1ewybSKP9mmtTzc7HGglxZ19UPdhtVagnoC/qt1Ehii0Q MpsEr8C12tZjJtQEdrUpoNFUCZLgKFP7SYdyeO+BinPuyH+L2pxwiKDN0FL//V7T85Za RQlb3s+xcnUfwdJ5yyTQ526X7mgI/mnnNOILEWTdDU6VQ/MxoAT7RW+soOdewCesr7Cr QRmer8g9cySz+gLWaI9X0Z94xKTnjuskTNaZmxHZSLeE5fvR2XQf1f4ixAjB/b+Dn7ZZ JoiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=1FYqQqQu3q83BdI+/Fq1nSNpS27wiWat/G6Lls1bqi8=; fh=jF+j1UEDAwnYbShW3HmO1TshMsWh36Jt7pSLTP62NeE=; b=E/L9M48kXCTxn+il+DpTaWCG7xUnVT0R33WeNWFG0kfLennDDke1c1AMKxznNH/IUC 1/+MzSClOnSLDUZFc8mXS7ItqROFjPUyjSLDrTRKL9ieVCfPVwp1WYtUIKHhhNj86jLU bcIzdgNlgD43vIHTX/QxGOHBEJy6tt6Adx2cpbew/0a8rslNxg5PU3eyq3ShI0/I+KyO DX5goS9XgxM74cH3/b1Bi2kAEknjuSuljwkmFQFOaak1K9CK2P1LL4/3SBi8qcBAyZDL O634pZ7WUyZ0rffPO0RGYqFhibNw60cpUwOnfYxBA38jPdMT+NsCcaiRrt/gKSiE+gg2 rtqw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id h6-20020a635746000000b005a0018ec785si14290987pgm.375.2023.11.29.03.11.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 03:11:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 109E8804485E; Wed, 29 Nov 2023 03:10:40 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232403AbjK2LKS (ORCPT + 99 others); Wed, 29 Nov 2023 06:10:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231954AbjK2LJh (ORCPT ); Wed, 29 Nov 2023 06:09:37 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 95E121FCE; Wed, 29 Nov 2023 03:08:50 -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 7D4CFC15; Wed, 29 Nov 2023 03:09:37 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.4.241]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id BA4E83F5A1; Wed, 29 Nov 2023 03:08:47 -0800 (PST) From: Lukasz Luba To: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, rafael@kernel.org Cc: lukasz.luba@arm.com, dietmar.eggemann@arm.com, rui.zhang@intel.com, amit.kucheria@verdurent.com, amit.kachhap@gmail.com, daniel.lezcano@linaro.org, viresh.kumar@linaro.org, len.brown@intel.com, pavel@ucw.cz, mhiramat@kernel.org, qyousef@layalina.io, wvw@google.com Subject: [PATCH v5 18/23] drivers/thermal/cpufreq_cooling: Use new Energy Model interface Date: Wed, 29 Nov 2023 11:08:48 +0000 Message-Id: <20231129110853.94344-19-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231129110853.94344-1-lukasz.luba@arm.com> References: <20231129110853.94344-1-lukasz.luba@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Wed, 29 Nov 2023 03:10:40 -0800 (PST) Energy Model framework support modifications at runtime of the power values. Use the new EM table API which is protected with RCU. Align the code so that this RCU read section is short. This change is not expected to alter the general functionality. Signed-off-by: Lukasz Luba --- drivers/thermal/cpufreq_cooling.c | 40 ++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/drivers/thermal/cpufreq_cooling.c b/drivers/thermal/cpufreq_cooling.c index e2cc7bd30862..c32d8dfa4fff 100644 --- a/drivers/thermal/cpufreq_cooling.c +++ b/drivers/thermal/cpufreq_cooling.c @@ -91,12 +91,15 @@ struct cpufreq_cooling_device { static unsigned long get_level(struct cpufreq_cooling_device *cpufreq_cdev, unsigned int freq) { + struct em_perf_state *table; int i; + table = em_get_table(cpufreq_cdev->em); for (i = cpufreq_cdev->max_level - 1; i >= 0; i--) { - if (freq > cpufreq_cdev->em->table[i].frequency) + if (freq > table[i].frequency) break; } + em_put_table(); return cpufreq_cdev->max_level - i - 1; } @@ -104,16 +107,19 @@ static unsigned long get_level(struct cpufreq_cooling_device *cpufreq_cdev, static u32 cpu_freq_to_power(struct cpufreq_cooling_device *cpufreq_cdev, u32 freq) { + struct em_perf_state *table; unsigned long power_mw; int i; + table = em_get_table(cpufreq_cdev->em); for (i = cpufreq_cdev->max_level - 1; i >= 0; i--) { - if (freq > cpufreq_cdev->em->table[i].frequency) + if (freq > table[i].frequency) break; } - power_mw = cpufreq_cdev->em->table[i + 1].power; + power_mw = table[i + 1].power; power_mw /= MICROWATT_PER_MILLIWATT; + em_put_table(); return power_mw; } @@ -121,18 +127,23 @@ static u32 cpu_freq_to_power(struct cpufreq_cooling_device *cpufreq_cdev, static u32 cpu_power_to_freq(struct cpufreq_cooling_device *cpufreq_cdev, u32 power) { + struct em_perf_state *table; unsigned long em_power_mw; + u32 freq; int i; + table = em_get_table(cpufreq_cdev->em); for (i = cpufreq_cdev->max_level; i > 0; i--) { /* Convert EM power to milli-Watts to make safe comparison */ - em_power_mw = cpufreq_cdev->em->table[i].power; + em_power_mw = table[i].power; em_power_mw /= MICROWATT_PER_MILLIWATT; if (power >= em_power_mw) break; } + freq = table[i].frequency; + em_put_table(); - return cpufreq_cdev->em->table[i].frequency; + return freq; } /** @@ -262,8 +273,9 @@ static int cpufreq_get_requested_power(struct thermal_cooling_device *cdev, static int cpufreq_state2power(struct thermal_cooling_device *cdev, unsigned long state, u32 *power) { - unsigned int freq, num_cpus, idx; struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata; + unsigned int freq, num_cpus, idx; + struct em_perf_state *table; /* Request state should be less than max_level */ if (state > cpufreq_cdev->max_level) @@ -272,7 +284,11 @@ static int cpufreq_state2power(struct thermal_cooling_device *cdev, num_cpus = cpumask_weight(cpufreq_cdev->policy->cpus); idx = cpufreq_cdev->max_level - state; - freq = cpufreq_cdev->em->table[idx].frequency; + + table = em_get_table(cpufreq_cdev->em); + freq = table[idx].frequency; + em_put_table(); + *power = cpu_freq_to_power(cpufreq_cdev, freq) * num_cpus; return 0; @@ -378,8 +394,16 @@ static unsigned int get_state_freq(struct cpufreq_cooling_device *cpufreq_cdev, #ifdef CONFIG_THERMAL_GOV_POWER_ALLOCATOR /* Use the Energy Model table if available */ if (cpufreq_cdev->em) { + struct em_perf_state *table; + unsigned int freq; + idx = cpufreq_cdev->max_level - state; - return cpufreq_cdev->em->table[idx].frequency; + + table = em_get_table(cpufreq_cdev->em); + freq = table[idx].frequency; + em_put_table(); + + return freq; } #endif -- 2.25.1