Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp2083291rdh; Tue, 26 Sep 2023 11:49:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFM3t7s0atiBxRjROzJWEHOPV2VLK7PrfE3KZjUnqtfKwyalCq/NNATJV4970EqmzReUU5G X-Received: by 2002:a05:6a00:3a03:b0:68b:e29c:b69 with SMTP id fj3-20020a056a003a0300b0068be29c0b69mr4648715pfb.9.1695754180773; Tue, 26 Sep 2023 11:49:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695754180; cv=none; d=google.com; s=arc-20160816; b=PFuIXKDLCLZHe/YSKqtNTyhQiyjS33U56GEVQgmUm+uWj3OvLxMagkpdY/K8TgsfcP noNiem6aqLkzVzZe6WlECxpH6hE39V4k+6hT2CjkjFbahm/xMsaxBNAfhVMSXyoePxau YNfV8dClAznyikMEiMCG7A0YIFeQLSxNhNB5BnXnysy3ULRJugSEX3cZGG56qPyeqj1H I/3JoMlMqPMcdrxLFyIOQVN2IyznM4UdDJJKo3Pj70R9YiS6ODx50zUX37Fjgp6G7rnZ 0ZmQHUExCycUkGxB4HQt+QIgTgi6HrrUbVS/ymKdUKPJAA65zhKOR34xAHrRLjupKTrP 1euQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version; bh=ZDP0k/czK5vlQlh2JbjTN3XO1zg8Wecl/DdzwW9XpFQ=; fh=O6YYF95gEoTquszwa1x1Mp3NZS9Am1klEUxdtkLeXmY=; b=qidZb5NoocXQT+d38iXBbdPklEnZbMrsZ2le7pHDu9FdQRlbsTHGx7OA4Iljnj3jJS cJaphqTrmwD2M1YpA9Hrp4lEODQMVKV7btt7X0kcCT9uNIGPF0weYuK7oGykRDOIW1Bn EWnX3zNGHWKrDruCjQ7FGgmze2OvEqqEq3PrxACre+jQKd8ba6Y3IrDXg+YEHqFZ1mpe atNeDbntiZl2PH+WmYzW7CdmcJD0HBW5Ybgcpuza/xcodbb7LHuy/GQVAeTPdrmU619M wrHsool3PzqF0F1s1d3nKYiswp7tYSkRZPcuOi3GdCU3YEH16B9xWmfolhVGtovbsVad MIBw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id e10-20020a056a001a8a00b0068fbbef790bsi13982773pfv.297.2023.09.26.11.49.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 11:49:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 911F58246949; Tue, 26 Sep 2023 11:40:07 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235449AbjIZSj7 convert rfc822-to-8bit (ORCPT + 99 others); Tue, 26 Sep 2023 14:39:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229674AbjIZSj6 (ORCPT ); Tue, 26 Sep 2023 14:39:58 -0400 Received: from mail-oo1-f43.google.com (mail-oo1-f43.google.com [209.85.161.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1495310A; Tue, 26 Sep 2023 11:39:52 -0700 (PDT) Received: by mail-oo1-f43.google.com with SMTP id 006d021491bc7-57bf04841ccso220722eaf.0; Tue, 26 Sep 2023 11:39:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695753591; x=1696358391; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lqH8J6lTpK2M+bzzcxGFMsEPF/8uShQKGeKMcDCVBbo=; b=GCDwT56KQJ8gxkSbpJjcqCK+K9MVhOyCHHfgx1pRZnOhPrXEoz4diubNc8Yln70QK3 ElnUVQjB5IIQcIlg5UlWrZlo4IdLflee39La9WLvQRPp743IJ0C5gJ6rx8MFgmOZ+nQ5 +3MKavXPEYUCRl2s3weL4h6N9xMDXdljqJo4KfwtF0L6YDysOwzsjvvTyaraPZe2Jye+ QrPUwbrHj6c7QMu0QjudVpuAn24+dLkqjPrH7f8nhpdz/KYz+6Gys0NFmPMefEpxvhBk 3nMBESVRcMDb0iVKEiJZttgjDO9KCjIXnkPfEQCVAQUWa9/CZGxWcth6YH115tBTh9pu d3XA== X-Gm-Message-State: AOJu0YwJBKLg6pFb9zjGbb8KOhKVZ9PcD1qVBOzFdek9Sb2xXiDpxqyS KAkGB0Ktge7JnybSxNs/M2erAAEcvLuxbrja138= X-Received: by 2002:a4a:de15:0:b0:57b:7804:9d72 with SMTP id y21-20020a4ade15000000b0057b78049d72mr9769263oot.1.1695753591340; Tue, 26 Sep 2023 11:39:51 -0700 (PDT) MIME-Version: 1.0 References: <20230925081139.1305766-1-lukasz.luba@arm.com> <20230925081139.1305766-6-lukasz.luba@arm.com> In-Reply-To: <20230925081139.1305766-6-lukasz.luba@arm.com> From: "Rafael J. Wysocki" Date: Tue, 26 Sep 2023 20:39:40 +0200 Message-ID: Subject: Re: [PATCH v4 05/18] PM: EM: Refactor a new function em_compute_costs() To: Lukasz Luba Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, rafael@kernel.org, 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS autolearn=no 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Tue, 26 Sep 2023 11:40:07 -0700 (PDT) On Mon, Sep 25, 2023 at 10:11 AM Lukasz Luba wrote: > > Refactor 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 (instead of duplicating the code). > > Signed-off-by: Lukasz Luba If I'm not mistaken, this patch by itself is not going to change the observable functionality in any way and it would be good to say that in the changelog. This also applies to some other patches in this series. > --- > 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 3dafdd7731c4..7ea882401833 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 >