Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp10048159rwr; Fri, 12 May 2023 03:06:05 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6pqdBBGx1sv0ZrGIJ7DrX00YuL2+NHfjo1I6NWgEYdwW+qfX9Jdlkq5ddnp/7USejSilvw X-Received: by 2002:a05:6a21:6d9a:b0:100:607:b997 with SMTP id wl26-20020a056a216d9a00b001000607b997mr25006241pzb.49.1683885965298; Fri, 12 May 2023 03:06:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683885965; cv=none; d=google.com; s=arc-20160816; b=z7Nta+7mMfDlEKG+EQvnyq4jHF7ncom7/tqakiDJLB3LLxpH3uf1S5WANTcDMiPcS8 V6/RHQgRssQ7xyJ9JED6eEdpjeYSOPtSR4BILtXwfFO0oXcEC993c3d0SfMSGCuKW0xp WtiuAy4OMbn6owHZtor/D7TSqnEWpUc0lGX+uaytk24vh0nRG9ZHrgZI2o9RCkw/SKkC Xf2TIqMw7IedxfwKmCBjgyuoG1+GKz76xZDsxW8j/ta2218qpBsZp49UjIuJXTIdCpRd MBO1kVhpPxN7xd99FNJMNZegx32ikrt9LDmGSMWCJBuEEUqoYdOk+OMSEjwllTcgCY1W g1Jw== 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=f+KgCUtCwGg99e7rscpptLTMzgTXvcKjtBRBQjqBUKM=; b=RecwGtORcv8jv6ngYgyKfYX5HjBULeqkQxXb+u+d5p6024fWAtW8SsteIgVZNEqxJO 8i0pt8uXTR4pidAKnNVc//yXGMKXC0ljvh1cwJujQ1BHnS0UDKs7BzNF33wKoOCumJx+ XFrLIDDl54C1gVPSyQlPvih1ey/hYZmbO5Cp8lVAvo1rG/QXnCsHd6BkFVyUFHYYurnn VbN+PCxcY5J+u8hMJT8t8Ooa/1ie23C2TKFCUpwZBzo+or9dSF4f+mUnhWNCKzMOumvN DpU8QHeOO1ZEA2s1Fy/cTC0TbUx38zblefnweA+kPiHtzPpFbUkx8jfypJu1PJoMlC95 jHFw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g67-20020a636b46000000b005030006a2desi8388786pgc.182.2023.05.12.03.05.51; Fri, 12 May 2023 03:06:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240614AbjELJ6w (ORCPT + 99 others); Fri, 12 May 2023 05:58:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239935AbjELJ6Y (ORCPT ); Fri, 12 May 2023 05:58:24 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D3ED611DAE; Fri, 12 May 2023 02:58:09 -0700 (PDT) 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 2B9F61684; Fri, 12 May 2023 02:58:54 -0700 (PDT) Received: from e123648.arm.com (unknown [10.57.22.28]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id E04DF3F5A1; Fri, 12 May 2023 02:58:06 -0700 (PDT) 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, Pierre.Gondois@arm.com, ionela.voinescu@arm.com, rostedt@goodmis.org, mhiramat@kernel.org Subject: [PATCH v2 04/17] PM: EM: Create a new function em_compute_costs() Date: Fri, 12 May 2023 10:57:30 +0100 Message-Id: <20230512095743.3393563-5-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230512095743.3393563-1-lukasz.luba@arm.com> References: <20230512095743.3393563-1-lukasz.luba@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Create a dedicated function which will be easier to maintain and re-use in future. The upcoming changes for the modifiable EM perf_state table will use it. Signed-off-by: Lukasz Luba --- kernel/power/energy_model.c | 72 ++++++++++++++++++++++--------------- 1 file changed, 43 insertions(+), 29 deletions(-) diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c index 85a70b7da023..fd1066dcf38b 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -103,14 +103,52 @@ static void em_debug_create_pd(struct device *dev) {} static void em_debug_remove_pd(struct device *dev) {} #endif +static int em_compute_costs(struct device *dev, struct em_perf_state *table, + struct em_data_callback *cb, int nr_states, + unsigned long flags) +{ + unsigned long prev_cost = ULONG_MAX; + u64 fmax; + int i, ret; + + /* Compute the cost of each performance state. */ + fmax = (u64) table[nr_states - 1].frequency; + for (i = nr_states - 1; i >= 0; i--) { + unsigned long power_res, cost; + + if (flags & EM_PERF_DOMAIN_ARTIFICIAL) { + ret = cb->get_cost(dev, table[i].frequency, &cost); + if (ret || !cost || cost > EM_MAX_POWER) { + dev_err(dev, "EM: invalid cost %lu %d\n", + cost, ret); + return -EINVAL; + } + } else { + power_res = table[i].power; + cost = div64_u64(fmax * power_res, table[i].frequency); + } + + table[i].cost = cost; + + if (table[i].cost >= prev_cost) { + table[i].flags = EM_PERF_STATE_INEFFICIENT; + dev_dbg(dev, "EM: OPP:%lu is inefficient\n", + table[i].frequency); + } else { + prev_cost = table[i].cost; + } + } + + return 0; +} + static int em_create_perf_table(struct device *dev, struct em_perf_domain *pd, int nr_states, struct em_data_callback *cb, unsigned long flags) { - unsigned long power, freq, prev_freq = 0, prev_cost = ULONG_MAX; + unsigned long power, freq, prev_freq = 0; struct em_perf_state *table; int i, ret; - u64 fmax; table = kcalloc(nr_states, sizeof(*table), GFP_KERNEL); if (!table) @@ -154,33 +192,9 @@ static int em_create_perf_table(struct device *dev, struct em_perf_domain *pd, table[i].frequency = prev_freq = freq; } - /* Compute the cost of each performance state. */ - fmax = (u64) table[nr_states - 1].frequency; - for (i = nr_states - 1; i >= 0; i--) { - unsigned long power_res, cost; - - if (flags & EM_PERF_DOMAIN_ARTIFICIAL) { - ret = cb->get_cost(dev, table[i].frequency, &cost); - if (ret || !cost || cost > EM_MAX_POWER) { - dev_err(dev, "EM: invalid cost %lu %d\n", - cost, ret); - goto free_ps_table; - } - } else { - power_res = table[i].power; - cost = div64_u64(fmax * power_res, table[i].frequency); - } - - table[i].cost = cost; - - if (table[i].cost >= prev_cost) { - table[i].flags = EM_PERF_STATE_INEFFICIENT; - dev_dbg(dev, "EM: OPP:%lu is inefficient\n", - table[i].frequency); - } else { - prev_cost = table[i].cost; - } - } + 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; -- 2.25.1