Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp218700rdb; Thu, 8 Feb 2024 04:11:57 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWa8GcZCwmWXLdTIwQ5ZG96lCIBrcHGibu3d8OhAOFGP1d2dCqwX25cH4NRnRe+Mz7Tt6POEJc6czAjz440SHhGzJEr1DOGYeUJFu39QQ== X-Google-Smtp-Source: AGHT+IEnupLVF0ZGctMRpxVbFFjp8h83gAULpOujudGllwLiIMsF/bnwYxPBQLig9HkIrW6eltDQ X-Received: by 2002:a17:906:f17:b0:a37:4d64:7c88 with SMTP id z23-20020a1709060f1700b00a374d647c88mr7688228eji.39.1707394317784; Thu, 08 Feb 2024 04:11:57 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707394317; cv=pass; d=google.com; s=arc-20160816; b=ahzVSdATZp0XxdW5iDml8VOhHOCTyIwyYyOCaVumCBw/is2T02sz9htBI9zUYy/knC 3IUig6+IQ8Uw4cUrOqoF0WgVXuqb2yV92eJ2WeaLAOvqZuPksXnBo1S85/DcQcoow+Z7 4lNWkT5fwPyYwaAr+aufe7aUDmhR7rnm+DSQ3ixpcEIT69MWlwdj/t94vdzNGhkc3J7l iAUnSGxCWR2k9sYYEsEeBCjHArqBI7hjBd5GrMj+rCe2NYZpdzu1tYQ95AQ2Ds1PvrnX u8qgVHdqymzM3ugkXnOv4tLFPp53T0xTAc3Chzxdouy1m561myaiGPH8Pbuh/c5Bw3Fe TnBw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=xQzoa8QciLbuu9teC8KFJQUK117fvdCm5FnO7lEtxus=; fh=1t6IoeyorpbAeX0GsTp3Uc7s1qP5S9UyHXIclqtDte8=; b=QXgrYdSoiJh07wJ5v/W9N9CTl4HtFhFm747CtJ6KEsqoN2m6OY0ZrrZylZaosQ/D0Q qdqx4ItWPuDLKsueQvEGKTHrk7p5b9aM4pMmG0yXnNRBazSWvo/x3wszxOv3YcsJ1IGw WIzufiU+32yiCt0bGPM3ObjkB1xo5ZPhRuB07EgeQ9jUE2WBlI5fKLs/zSbXhNLDR49o eK6HJzlhlnv/fVneNrpiOzwG60+S6NAOq+AMKcMgoUinwublnc1T05CWrQc9a985+7Zx DHRFfnFxxcpKD85K+rn+uxiJiR8mFSbDDl7+Kt3TxluhJ+atkkBhqMw2XwAWSPrqHklU wahQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-58012-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58012-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com X-Forwarded-Encrypted: i=2; AJvYcCUq4veZC/i3mPZLu7lp3cp0jahYeyejA0AouWJ/1fz8WHDSuvCvuVHX3d3ZbLIy8Ssb5anXxigAmSY1VUf9aOTiAgjVD0XdMZPg8djCnQ== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id i24-20020a170906251800b00a3832ee8b30si2047577ejb.429.2024.02.08.04.11.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 04:11:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58012-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-58012-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58012-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 4CAE11F2D068 for ; Thu, 8 Feb 2024 12:01:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 950F67E598; Thu, 8 Feb 2024 11:57:02 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 344F87E568; Thu, 8 Feb 2024 11:56:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707393422; cv=none; b=ijaxbsgvpG6m29QBj7BCwwLgEmOqdLEeAhXHUP9qMP7MUpPV2JOFbYHvbn/KzIKIk99ygNPghqQfMVjEmRsDj8icFc62u6L1ijohgkDjHvTBpNUOLd3MZZizHZwCNDqYwT+Qt9nd2lfTC+Um66FPzAsikGhFOWa/JeonLZ8Wm7I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707393422; c=relaxed/simple; bh=dnosOVP4e99Yo+cDanGIs3VtsbRgfhA+nmQCzHbYbTU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ZprnhXRwdacpqXhc375PvUuGhm7VAQ0gwn6GMAQ08yYNYdu4gcVcRPp15Xm6catG/bH/SDMMEBXaDnTXfi0uptE35580K/E69Ek4l32EupOZn+cL7Lve+Y8ArBfzls92neUrZY8aYNhhRDACrUwuo/+qYPMsKawhwlr3p3z6Ed4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com 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 C440D1FB; Thu, 8 Feb 2024 03:57:41 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.8.23]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id E57F63F5A1; Thu, 8 Feb 2024 03:56:56 -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, xuewen.yan94@gmail.com Subject: [PATCH v8 18/23] drivers/thermal/cpufreq_cooling: Use new Energy Model interface Date: Thu, 8 Feb 2024 11:55:52 +0000 Message-Id: <20240208115557.1273962-19-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240208115557.1273962-1-lukasz.luba@arm.com> References: <20240208115557.1273962-1-lukasz.luba@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Energy Model framework support modifications at runtime of the power values. Use the new EM table 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. Reviewed-by: Dietmar Eggemann Tested-by: Dietmar Eggemann Signed-off-by: Lukasz Luba --- drivers/thermal/cpufreq_cooling.c | 45 +++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/drivers/thermal/cpufreq_cooling.c b/drivers/thermal/cpufreq_cooling.c index e2cc7bd30862..9d1b1459700d 100644 --- a/drivers/thermal/cpufreq_cooling.c +++ b/drivers/thermal/cpufreq_cooling.c @@ -91,12 +91,16 @@ 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; + rcu_read_lock(); + table = em_perf_state_from_pd(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; } + rcu_read_unlock(); return cpufreq_cdev->max_level - i - 1; } @@ -104,16 +108,20 @@ 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; + rcu_read_lock(); + table = em_perf_state_from_pd(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; + rcu_read_unlock(); return power_mw; } @@ -121,18 +129,24 @@ 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; + rcu_read_lock(); + table = em_perf_state_from_pd(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; + rcu_read_unlock(); - return cpufreq_cdev->em->table[i].frequency; + return freq; } /** @@ -262,8 +276,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 +287,12 @@ 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; + + rcu_read_lock(); + table = em_perf_state_from_pd(cpufreq_cdev->em); + freq = table[idx].frequency; + rcu_read_unlock(); + *power = cpu_freq_to_power(cpufreq_cdev, freq) * num_cpus; return 0; @@ -378,8 +398,17 @@ 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; + + rcu_read_lock(); + table = em_perf_state_from_pd(cpufreq_cdev->em); + freq = table[idx].frequency; + rcu_read_unlock(); + + return freq; } #endif -- 2.25.1