Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp212464rdb; Thu, 8 Feb 2024 04:02:04 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUItQyezXkggy8QfEhx180gJdQ/yA2VMFmW+IX97dt9e8HiufgxnLpGGhWfK79tt7Bh1ryJ04Xo/hLErjnePsPk7JbZYAdE8zSGIeMskw== X-Google-Smtp-Source: AGHT+IG/Dr9MWAoM/gg+TKEeM6lJVLpalsaYYfLVB106PgiP1tVrs7d5V4Sas3iTuUaYNYw27cIg X-Received: by 2002:a05:6a20:e607:b0:19c:7560:e7d6 with SMTP id my7-20020a056a20e60700b0019c7560e7d6mr6921959pzb.1.1707393724451; Thu, 08 Feb 2024 04:02:04 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707393724; cv=pass; d=google.com; s=arc-20160816; b=LS1V6pt5gutOk0DwT7QhCSqs+tPb5C5AdQ9+8wz1aooF9XvZgYQTN7k3oP9HF/KG2T /S/SrsmyoO1AZA1jrstnhqEdEACLIm1Q0wtWoZsq00FC2mQpB8pTXsDF4ZiKGq2Sr6Gh eCnpCVWingr6IiY6lDLG8rxsvdUcm7iS6vBwLhGb6+tDho0am0GouN6/3Km/GoEYyD1Z wd0e6tPlgit1WvVz0u8/f7sPAjyKx2dXjWFoqNF16VkjsZPVu3ToAfbNGxXfG4/ff4AV +/YR4K4CWWBhWCYyoCDiK7jQZze4D0e1ge57eotxBMgTyDc0LODLdaP0C3zUpRw+O0DC R7Uw== 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=rCbxpVu9mo4ZgSOlXH4MmsDhAi1ov9jvstLlQZrkozQ=; fh=jLmvRHUlWLn7/7jyXBdj+NbNh8qstJZykIsHFVsgwN0=; b=G7UHu1Np3lYoSo7BMaWLIUxUsgP26Kah3OwxX/ICdGsKiLbuUrrFVFOfxvKWrQwWe0 uYhVA1TWLdwtFA7rH9KVWq6lmOyNFS7YmInO9gzH/+sE1Up1IBWc9YHrvu7hYYTYapY6 KSIQD4rfpeN45IYJAY3N3DVGYgnFDdptYbHqW5TVit+SBKzDLjxbi3Z5XnptT0ppGboR XOgjkHnPnbLcfwgPwSDtQ2yx/jjMHDF561+YkITl+zkSWkzniaGrmYnlCFHauaQmU8lF 42nFDQavpsgGsnLPnj/UehHeCZ2qlUsLd6zZaGQLA32h7c+MvHY/z7bqXXWF/RJAvKVm 17aQ==; 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-58013-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58013-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; AJvYcCVoI8LOfNLwsydvveXfhYm2PVgglkvLsonXoTLva+9TaauRimWZCmHjv617EzsJRZLIt1KnxDzN9OKT+/eC+TfSTKG1h0knBaX0YTk1Hg== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id z3-20020aa79e43000000b006e0385d7185si3777167pfq.229.2024.02.08.04.02.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 04:02:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58013-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; 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-58013-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58013-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 1FC8B282094 for ; Thu, 8 Feb 2024 12:02:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 47AAF7EEF1; Thu, 8 Feb 2024 11:57:05 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CC2F07E761; Thu, 8 Feb 2024 11:57:02 +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=1707393424; cv=none; b=NYGGLXOPm6jOIZv5aMIQOlLZ8gYa4xUWWLS6KF4Lc/kCwsl99mXvbfl7uLLThpcrHzsSzR20iEP6dmrWIKY5E7CwOTWPYlsusEEhhpvlomEVkXnnvzlw8sW3DUCRTXpudvGLhmPyoZL7qQfC+EHcnDZFuyK8/lQbQsUNIztREl8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707393424; c=relaxed/simple; bh=wkTlNeA3yVySpfdCDKAwYbrsIV5UQmUrBVPxFwqVSSo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=LbhQ/wMVVff/bLlrpsEwbOmBTXh/XMx21ZH4cQyaKHvtposSQmPLuvR4oLMjOwcJ3S0Q9PS3lDsRVGo8/FdvQgHe921GdAf08npJV/boAwLE5MJDWvH9doBo1HGSQ/WmDq9yr8O7K7aj6Q9pczN0SB18Q/s8un4YcaaAj2vmk6k= 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 B5D031FB; Thu, 8 Feb 2024 03:57:44 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.8.23]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id D750A3F5A1; Thu, 8 Feb 2024 03:56:59 -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 19/23] drivers/thermal/devfreq_cooling: Use new Energy Model interface Date: Thu, 8 Feb 2024 11:55:53 +0000 Message-Id: <20240208115557.1273962-20-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/devfreq_cooling.c | 49 +++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 9 deletions(-) diff --git a/drivers/thermal/devfreq_cooling.c b/drivers/thermal/devfreq_cooling.c index 262e62ab6cf2..50dec24e967a 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,11 @@ 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; + + rcu_read_lock(); + table = em_perf_state_from_pd(dfc->em_pd); + freq = table[perf_idx].frequency * 1000; + rcu_read_unlock(); } else { freq = dfc->freq_table[state]; } @@ -123,14 +128,21 @@ 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; + rcu_read_lock(); + table = em_perf_state_from_pd(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; } + rcu_read_unlock(); - return -EINVAL; + return idx; } static unsigned long get_voltage(struct devfreq *df, unsigned long freq) @@ -181,6 +193,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 +217,11 @@ 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; + rcu_read_lock(); + table = em_perf_state_from_pd(dfc->em_pd); + dfc->res_util = table[state].power; + rcu_read_unlock(); + dfc->res_util /= MICROWATT_PER_MILLIWATT; dfc->res_util *= SCALE_ERROR_MITIGATION; @@ -225,7 +242,11 @@ 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; + rcu_read_lock(); + table = em_perf_state_from_pd(dfc->em_pd); + *power = table[perf_idx].power; + rcu_read_unlock(); + *power /= MICROWATT_PER_MILLIWATT; /* Scale power for utilization */ *power *= status.busy_time; @@ -245,13 +266,19 @@ 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; + + rcu_read_lock(); + table = em_perf_state_from_pd(dfc->em_pd); + *power = table[perf_idx].power; + rcu_read_unlock(); + *power /= MICROWATT_PER_MILLIWATT; return 0; @@ -264,6 +291,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 +316,16 @@ 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. */ + rcu_read_lock(); + table = em_perf_state_from_pd(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; } + rcu_read_unlock(); *state = dfc->max_state - i; dfc->capped_state = *state; -- 2.25.1