Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp4494110rdh; Wed, 29 Nov 2023 03:09:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IG3DW63kpaf1vmoHiWzf0oDDOsJfeKeFYXkirYrypOVfMn2mKEBUVE+JiJ1yNIctI+okq85 X-Received: by 2002:a05:6a00:189d:b0:6cd:9033:b3d0 with SMTP id x29-20020a056a00189d00b006cd9033b3d0mr11211850pfh.28.1701256145596; Wed, 29 Nov 2023 03:09:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701256145; cv=none; d=google.com; s=arc-20160816; b=R5DCWgeHuGSgbZh+DRLEiyTbEmsyPKQF4zpv2+pCBSfdnyo5SctN0jTWFUCwo6/0q2 ig3cqaQn4WsfFppAep3rnwNtU8nD2NlWNZ9xkMKbYDOMm8IO6J9lSSD7vS9CcHnttNgi OpvV4dSORA34KJ5OtOZz3dIculoRN8hDhmSgXQh+6DnBAHP2eOi3OnHjqqqtkJXylaOg ZTNugcL+lPnSVQFvyNatr0CMGPmO19RzNXfCEDjTt1JkROrSi/uDiABbtNNSxCqSnnP0 BBgFI56arsC2LulsMKHo2vqP05UomFWcp6Qxc65os+GiFdgGuYgFw1xS3I4zzqRs//Ta kcvA== 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=wN28uzk/4zD0K3Rir9ePnJkCxMkfPw9SWPzBQwuGU1o=; fh=jF+j1UEDAwnYbShW3HmO1TshMsWh36Jt7pSLTP62NeE=; b=ew7MdB8D2L3kVetD1HNteJReJ8C3xPI4br8hQbu13p/NSH6i+S4ZEqWn+U4BpwW3a3 C+H56cJMMQflRxwdMcQuS8PQr8hiGoQ/88MsEbCEUqbGD2K0nMaNKjqu7HiAMAPHqAPO Ya7mi6yqVNuvabX/fSt5o0HbS3es1hxYaM+sidYjrX1R36G9uaqqvANyuOLc7bgRtM99 ED774UeDJEv/jrF886iro45NXJJ30cgNhVKw1Ira4RvHGuAFt0auUlJrFoqTGZiPdE2p /fyCeYC7cs5ulKPc9DoaVAoU1igFtkeUzZPJHWWHSpSbKNrNI3uteafb2AiuzOT8GLm7 UWyg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id 3-20020a631543000000b005b92a7d88e6si13988760pgv.823.2023.11.29.03.09.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 03:09:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (Postfix) with ESMTP id 1469A80914B9; Wed, 29 Nov 2023 03:09:03 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231470AbjK2LIn (ORCPT + 99 others); Wed, 29 Nov 2023 06:08:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232300AbjK2LI0 (ORCPT ); Wed, 29 Nov 2023 06:08:26 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 093E61FC3; Wed, 29 Nov 2023 03:08:21 -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 DF2262F4; Wed, 29 Nov 2023 03:09:07 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.4.241]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 506623F5A1; Wed, 29 Nov 2023 03:08:18 -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 07/23] PM: EM: Refactor how the EM table is allocated and populated Date: Wed, 29 Nov 2023 11:08:37 +0000 Message-Id: <20231129110853.94344-8-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 lipwig.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 (lipwig.vger.email [0.0.0.0]); Wed, 29 Nov 2023 03:09:03 -0800 (PST) Split the process of allocation and data initialization for the EM table. The upcoming changes for modifiable EM will use it. This change is not expected to alter the general functionality. Signed-off-by: Lukasz Luba --- kernel/power/energy_model.c | 52 ++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c index 3c8542443dd4..99426b5eedb6 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -142,18 +142,25 @@ static int em_compute_costs(struct device *dev, struct em_perf_state *table, return 0; } +static int em_allocate_perf_table(struct em_perf_domain *pd, + int nr_states) +{ + pd->table = kcalloc(nr_states, sizeof(struct em_perf_state), + GFP_KERNEL); + if (!pd->table) + return -ENOMEM; + + return 0; +} + static int em_create_perf_table(struct device *dev, struct em_perf_domain *pd, + struct em_perf_state *table, int nr_states, struct em_data_callback *cb, unsigned long flags) { unsigned long power, freq, prev_freq = 0; - struct em_perf_state *table; int i, ret; - table = kcalloc(nr_states, sizeof(*table), GFP_KERNEL); - if (!table) - return -ENOMEM; - /* Build the list of performance states for this performance domain */ for (i = 0, freq = 0; i < nr_states; i++, freq++) { /* @@ -165,7 +172,7 @@ static int em_create_perf_table(struct device *dev, struct em_perf_domain *pd, if (ret) { dev_err(dev, "EM: invalid perf. state: %d\n", ret); - goto free_ps_table; + return -EINVAL; } /* @@ -175,7 +182,7 @@ static int em_create_perf_table(struct device *dev, struct em_perf_domain *pd, if (freq <= prev_freq) { dev_err(dev, "EM: non-increasing freq: %lu\n", freq); - goto free_ps_table; + return -EINVAL; } /* @@ -185,7 +192,7 @@ static int em_create_perf_table(struct device *dev, struct em_perf_domain *pd, if (!power || power > EM_MAX_POWER) { dev_err(dev, "EM: invalid power: %lu\n", power); - goto free_ps_table; + return -EINVAL; } table[i].power = power; @@ -194,16 +201,9 @@ static int em_create_perf_table(struct device *dev, struct em_perf_domain *pd, ret = em_compute_costs(dev, table, cb, nr_states, flags); if (ret) - goto free_ps_table; - - pd->table = table; - pd->nr_perf_states = nr_states; + return -EINVAL; return 0; - -free_ps_table: - kfree(table); - return -EINVAL; } static int em_create_pd(struct device *dev, int nr_states, @@ -234,11 +234,15 @@ static int em_create_pd(struct device *dev, int nr_states, return -ENOMEM; } - ret = em_create_perf_table(dev, pd, nr_states, cb, flags); - if (ret) { - kfree(pd); - return ret; - } + pd->nr_perf_states = nr_states; + + ret = em_allocate_perf_table(pd, nr_states); + if (ret) + goto free_pd; + + ret = em_create_perf_table(dev, pd, pd->table, nr_states, cb, flags); + if (ret) + goto free_pd_table; if (_is_cpu_device(dev)) for_each_cpu(cpu, cpus) { @@ -249,6 +253,12 @@ static int em_create_pd(struct device *dev, int nr_states, dev->em_pd = pd; return 0; + +free_pd_table: + kfree(pd->table); +free_pd: + kfree(pd); + return -EINVAL; } static void -- 2.25.1