From patchwork Thu Feb 8 11:55:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 198347 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp113221dyd; Thu, 8 Feb 2024 04:02:40 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVXm96VFsZrOzI6sUzfW4LNndfIoLPo/QUk24L6vJOvgdSF8VB1kZGH0FOvXOgjuoDNCaegnEYHt9LNTBbA7Xq0inw/YA== X-Google-Smtp-Source: AGHT+IHJqV3MpAr8bgP1EPqP4uckzNieRqNPR1VWo+dsgGWHBlELeuEhCxTUiKfJfXgs3pqxHXg/ X-Received: by 2002:a05:620a:4d19:b0:783:e9ba:7d4c with SMTP id wa25-20020a05620a4d1900b00783e9ba7d4cmr9616412qkn.23.1707393760087; Thu, 08 Feb 2024 04:02:40 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707393760; cv=pass; d=google.com; s=arc-20160816; b=v8H+umDWn6n0rTpy6SaEXBRVEIxNmoR5b8jhavxnobd+gjefH5CfeBeaWFQlz7hLSi QE5KrFAQ+yUe6HWbjGhWHFxFhBkoDldOKfi9+/kFcMmGaVBJI8+K0WH0VamsUvTYWS2n gWbQ98PeYU+reQbX2ipxBDGFkDcPkTNXy7Q0AIOESy9yHy4K2v4NLmegWpZJ/VDBcBDs IpK0n+XB9ndbyseGLZZpKjA7v0ROfDFSScJROm1Sljnnxx1PDOoNLQPs9Ps75WE0fjHA kEAK85uKS6uys+o40HKU5Y1xV96thwo5kj+d6NvBHs67VOH4Z5dwc3qFpZHYv4EyyUrk P0ig== 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=M9xV9Fr+e7f6l0YF9FW+xsj3vZaJfVBxIMtTVYzVO/g=; fh=dg/VQKi2UieVX7/IQuZltGlGxhWXcV1zv/4NyBOTJO8=; b=U2ObeWpHaWdXNGyLFgJeRjkaaPNvL8BkI74/qqKcZgjQ99FkaTUYtxcQ98qTUmtiv5 8BuxlqA2ngP6krhGYC0EtS0cNpaFrTCvCm8fyBRVlK2NsvvzO2Awt0OvZBa/dHkkyBGL xdNc/NL9fDNF7d8iJ1wlnSbWVgz++l2fwyNC1E//jrmVkFCZ58ZNwp0785r92tN56Evn eYPqDLYFN+pF0eAnLgB11wpE1aI2MMkKYSjXHm73TjwugnezXe085nRAtXWj+HBAUyDa hXGIzqU0zSiBlzwzwaPf0iPfb/0fLkxbTpOrmLeZ65LxglPuGvBHoEWIqgWz+FFfI3IE ggIg==; 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-58010-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58010-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com X-Forwarded-Encrypted: i=2; AJvYcCWCrHW9xkkIr40NQOVPaEysBK2kg4XCiOAXSKNqqKE58ypNL7HuEVwKIi5kH05NQOEVZ+eo/UExx1WkD6oqLQ2xEvRc5A== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id wg10-20020a05620a568a00b007857d38b181si386156qkn.708.2024.02.08.04.02.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 04:02:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58010-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; 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-58010-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58010-ouuuleilei=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 515FD1C285FC for ; Thu, 8 Feb 2024 12:01:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E1EA87D406; Thu, 8 Feb 2024 11:56:57 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 47A547CF1E; Thu, 8 Feb 2024 11:56:54 +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=1707393416; cv=none; b=fW0B7D8iMNiJYHiiFa9Z9Laq8QiKLYS2pDtC2pl2PQyxkObnJuUVzbzJDIVfOpeQAYzAmCjWDqrMw5+yfjI8NDupqIIKYw+yeCHpT3x8TK7Jg5sAjy+feGgaWFDLCdXZbAQvj72FOkJyAQZ5S85hH3MKel9OCTeF96cEcy4jEsc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707393416; c=relaxed/simple; bh=8Gb0YkEvYUITCwedTOxqRk/oFDUD0wCdBVpfWbXqFYQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=pJy991IgPinO0F3sObMBuHJ2xuSNmlvN5wTILxGFyOqfaAkaHcTD20/lHsDxFw+VLSOYd5KYRE1qLx9VlmAKxxEL0y3TCpXeeDpnD5k4es+ZpG+WzImbx42y0wf7t0DirNKm+WQoM3yXcBsUxtltg2INYufEKOW4lllMhRb5hhI= 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 DE7231FB; Thu, 8 Feb 2024 03:57:35 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.8.23]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 0D1F73F5A1; Thu, 8 Feb 2024 03:56:50 -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 16/23] powercap/dtpm_cpu: Use new Energy Model interface to get table Date: Thu, 8 Feb 2024 11:55:50 +0000 Message-Id: <20240208115557.1273962-17-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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790332119148149709 X-GMAIL-MSGID: 1790332119148149709 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. Reviewed-by: Dietmar Eggemann Tested-by: Dietmar Eggemann Signed-off-by: Lukasz Luba --- drivers/powercap/dtpm_cpu.c | 39 +++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/drivers/powercap/dtpm_cpu.c b/drivers/powercap/dtpm_cpu.c index 9193c3b8edeb..ee0d1aa3e023 100644 --- a/drivers/powercap/dtpm_cpu.c +++ b/drivers/powercap/dtpm_cpu.c @@ -42,6 +42,7 @@ static u64 set_pd_power_limit(struct dtpm *dtpm, u64 power_limit) { struct dtpm_cpu *dtpm_cpu = to_dtpm_cpu(dtpm); struct em_perf_domain *pd = em_cpu_get(dtpm_cpu->cpu); + struct em_perf_state *table; struct cpumask cpus; unsigned long freq; u64 power; @@ -50,20 +51,22 @@ static u64 set_pd_power_limit(struct dtpm *dtpm, u64 power_limit) cpumask_and(&cpus, cpu_online_mask, to_cpumask(pd->cpus)); nr_cpus = cpumask_weight(&cpus); + rcu_read_lock(); + table = em_perf_state_from_pd(pd); for (i = 0; i < pd->nr_perf_states; i++) { - power = pd->table[i].power * nr_cpus; + power = table[i].power * nr_cpus; if (power > power_limit) break; } - freq = pd->table[i - 1].frequency; + freq = table[i - 1].frequency; + power_limit = table[i - 1].power * nr_cpus; + rcu_read_unlock(); freq_qos_update_request(&dtpm_cpu->qos_req, freq); - power_limit = pd->table[i - 1].power * nr_cpus; - return power_limit; } @@ -87,9 +90,11 @@ static u64 scale_pd_power_uw(struct cpumask *pd_mask, u64 power) static u64 get_pd_power_uw(struct dtpm *dtpm) { struct dtpm_cpu *dtpm_cpu = to_dtpm_cpu(dtpm); + struct em_perf_state *table; struct em_perf_domain *pd; struct cpumask *pd_mask; unsigned long freq; + u64 power = 0; int i; pd = em_cpu_get(dtpm_cpu->cpu); @@ -98,33 +103,43 @@ static u64 get_pd_power_uw(struct dtpm *dtpm) freq = cpufreq_quick_get(dtpm_cpu->cpu); + rcu_read_lock(); + table = em_perf_state_from_pd(pd); for (i = 0; i < pd->nr_perf_states; i++) { - if (pd->table[i].frequency < freq) + if (table[i].frequency < freq) continue; - return scale_pd_power_uw(pd_mask, pd->table[i].power); + power = scale_pd_power_uw(pd_mask, table[i].power); + break; } + rcu_read_unlock(); - return 0; + return power; } static int update_pd_power_uw(struct dtpm *dtpm) { struct dtpm_cpu *dtpm_cpu = to_dtpm_cpu(dtpm); struct em_perf_domain *em = em_cpu_get(dtpm_cpu->cpu); + struct em_perf_state *table; struct cpumask cpus; int nr_cpus; cpumask_and(&cpus, cpu_online_mask, to_cpumask(em->cpus)); nr_cpus = cpumask_weight(&cpus); - dtpm->power_min = em->table[0].power; + rcu_read_lock(); + table = em_perf_state_from_pd(em); + + dtpm->power_min = table[0].power; dtpm->power_min *= nr_cpus; - dtpm->power_max = em->table[em->nr_perf_states - 1].power; + dtpm->power_max = table[em->nr_perf_states - 1].power; dtpm->power_max *= nr_cpus; + rcu_read_unlock(); + return 0; } @@ -180,6 +195,7 @@ static int __dtpm_cpu_setup(int cpu, struct dtpm *parent) { struct dtpm_cpu *dtpm_cpu; struct cpufreq_policy *policy; + struct em_perf_state *table; struct em_perf_domain *pd; char name[CPUFREQ_NAME_LEN]; int ret = -ENOMEM; @@ -216,9 +232,12 @@ static int __dtpm_cpu_setup(int cpu, struct dtpm *parent) if (ret) goto out_kfree_dtpm_cpu; + rcu_read_lock(); + table = em_perf_state_from_pd(pd); ret = freq_qos_add_request(&policy->constraints, &dtpm_cpu->qos_req, FREQ_QOS_MAX, - pd->table[pd->nr_perf_states - 1].frequency); + table[pd->nr_perf_states - 1].frequency); + rcu_read_unlock(); if (ret) goto out_dtpm_unregister;