Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp7845865rdb; Thu, 4 Jan 2024 09:21:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IEVghUj8FLZxWsDo9bm339138vJrKbSIyjRbZF6FHssaYvrglwgw9PAEiNA2LnGO1+EgFvw X-Received: by 2002:a17:902:bd95:b0:1d4:6274:b4fb with SMTP id q21-20020a170902bd9500b001d46274b4fbmr675316pls.20.1704388903148; Thu, 04 Jan 2024 09:21:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704388903; cv=none; d=google.com; s=arc-20160816; b=j1fB0dyTMpPJ16XJG40YYvLl6ECjvGQjFau5ml/3yuN9DwSbi2yx/ZxF8deFdArFZE WyjSrO6ZDXvGb9Q0CoAEaNF8n3KN5gqh6n3uAp7YqEVf70u5fZkdDU67lQsp1Tn1FWhI WYSsxvIFtlIn4RvW4JPP1oNPb/p7lKQrHuBoHrdagbPiWyhhxaPObBQC5YAYtRIlgozj Rd1dyI0EERtv/D2CignFRkyJM0nb7pZ660fJjxWF7apDd/q9/wL8frqJ+G1xVfbnj53S Cf+BXsw7zQDIw9ZsrBsZB4h+4D6KTnDfaU06oUg0J8Z71ezXUAmu1b0WbV0+xhlmE+mr dpmg== ARC-Message-Signature: i=1; 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=i0ORcFjhY9ErutLfdoO+q/reWzicYmf5BjlsVGijKAs=; fh=jF+j1UEDAwnYbShW3HmO1TshMsWh36Jt7pSLTP62NeE=; b=vFtCLVltKRS0o786oSzXHomAZ8e9tL0IlYhrLbx3jAtYwxKHcyDz98vjq72eu6cl6l qJPZIZPz0YoIa3Y3dnfCxuUQP7EFj2mybpTDb9sWl5g2h9x94iPThGtz0QPDUorr31qo 1eVl8EgP1mze7i1DK4a0ACMkP+bFZQbD0yTkwpGPBepN1aiOnnEkFgv/doe7ecfH5gzM XRArUl379qqC1fuIXwvjfSB1iwbPu9kFr7nOJk+vaDHkKyFrU0etrz5pIr9PQOnIqXJ7 bXfNuA3dKLNYRxXon3pEkbBXGHWKd7tCSe2LQSYnGAF1i7wMtkr5gDU3p2FSRMpvayyW RK2Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-17023-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17023-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id z8-20020a170903018800b001d3eaa05025si15028234plg.553.2024.01.04.09.21.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 09:21:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-17023-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-17023-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17023-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id CAF5E280DCD for ; Thu, 4 Jan 2024 17:21:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0587E328DA; Thu, 4 Jan 2024 17:15:45 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 24AAF328CA; Thu, 4 Jan 2024 17:15:43 +0000 (UTC) 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 B86DC153B; Thu, 4 Jan 2024 09:16:28 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.88.128]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 4D5393F64C; Thu, 4 Jan 2024 09:15:40 -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 v6 19/23] drivers/thermal/devfreq_cooling: Use new Energy Model interface Date: Thu, 4 Jan 2024 17:15:49 +0000 Message-Id: <20240104171553.2080674-20-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240104171553.2080674-1-lukasz.luba@arm.com> References: <20240104171553.2080674-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 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/devfreq_cooling.c | 43 ++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/drivers/thermal/devfreq_cooling.c b/drivers/thermal/devfreq_cooling.c index 262e62ab6cf2..b7aed5a3810e 100644 --- a/drivers/thermal/devfreq_cooling.c +++ b/drivers/thermal/devfreq_cooling.c @@ -87,6 +87,7 @@ static int devfreq_cooling_set_cur_state(struct thermal_cooling_device *cdev, struct devfreq_cooling_device *dfc = cdev->devdata; struct devfreq *df = dfc->devfreq; struct device *dev = df->dev.parent; + struct em_perf_state *table; unsigned long freq; int perf_idx; @@ -100,7 +101,10 @@ static int devfreq_cooling_set_cur_state(struct thermal_cooling_device *cdev, if (dfc->em_pd) { perf_idx = dfc->max_state - state; - freq = dfc->em_pd->table[perf_idx].frequency * 1000; + + table = em_get_table(dfc->em_pd); + freq = table[perf_idx].frequency * 1000; + em_put_table(); } else { freq = dfc->freq_table[state]; } @@ -123,14 +127,20 @@ static int devfreq_cooling_set_cur_state(struct thermal_cooling_device *cdev, */ static int get_perf_idx(struct em_perf_domain *em_pd, unsigned long freq) { - int i; + struct em_perf_state *table; + int i, idx = -EINVAL; + table = em_get_table(em_pd); for (i = 0; i < em_pd->nr_perf_states; i++) { - if (em_pd->table[i].frequency == freq) - return i; + if (table[i].frequency != freq) + continue; + + idx = i; + break; } + em_put_table(); - return -EINVAL; + return idx; } static unsigned long get_voltage(struct devfreq *df, unsigned long freq) @@ -181,6 +191,7 @@ static int devfreq_cooling_get_requested_power(struct thermal_cooling_device *cd struct devfreq_cooling_device *dfc = cdev->devdata; struct devfreq *df = dfc->devfreq; struct devfreq_dev_status status; + struct em_perf_state *table; unsigned long state; unsigned long freq; unsigned long voltage; @@ -204,7 +215,10 @@ static int devfreq_cooling_get_requested_power(struct thermal_cooling_device *cd state = dfc->capped_state; /* Convert EM power into milli-Watts first */ - dfc->res_util = dfc->em_pd->table[state].power; + table = em_get_table(dfc->em_pd); + dfc->res_util = table[state].power; + em_put_table(); + dfc->res_util /= MICROWATT_PER_MILLIWATT; dfc->res_util *= SCALE_ERROR_MITIGATION; @@ -225,7 +239,10 @@ static int devfreq_cooling_get_requested_power(struct thermal_cooling_device *cd _normalize_load(&status); /* Convert EM power into milli-Watts first */ - *power = dfc->em_pd->table[perf_idx].power; + table = em_get_table(dfc->em_pd); + *power = table[perf_idx].power; + em_put_table(); + *power /= MICROWATT_PER_MILLIWATT; /* Scale power for utilization */ *power *= status.busy_time; @@ -245,13 +262,18 @@ static int devfreq_cooling_state2power(struct thermal_cooling_device *cdev, unsigned long state, u32 *power) { struct devfreq_cooling_device *dfc = cdev->devdata; + struct em_perf_state *table; int perf_idx; if (state > dfc->max_state) return -EINVAL; perf_idx = dfc->max_state - state; - *power = dfc->em_pd->table[perf_idx].power; + + table = em_get_table(dfc->em_pd); + *power = table[perf_idx].power; + em_put_table(); + *power /= MICROWATT_PER_MILLIWATT; return 0; @@ -264,6 +286,7 @@ static int devfreq_cooling_power2state(struct thermal_cooling_device *cdev, struct devfreq *df = dfc->devfreq; struct devfreq_dev_status status; unsigned long freq, em_power_mw; + struct em_perf_state *table; s32 est_power; int i; @@ -288,13 +311,15 @@ static int devfreq_cooling_power2state(struct thermal_cooling_device *cdev, * Find the first cooling state that is within the power * budget. The EM power table is sorted ascending. */ + table = em_get_table(dfc->em_pd); for (i = dfc->max_state; i > 0; i--) { /* Convert EM power to milli-Watts to make safe comparison */ - em_power_mw = dfc->em_pd->table[i].power; + em_power_mw = table[i].power; em_power_mw /= MICROWATT_PER_MILLIWATT; if (est_power >= em_power_mw) break; } + em_put_table(); *state = dfc->max_state - i; dfc->capped_state = *state; -- 2.25.1