From patchwork Tue Mar 14 10:33:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 69477 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1678334wrd; Tue, 14 Mar 2023 03:38:09 -0700 (PDT) X-Google-Smtp-Source: AK7set9IzOqRzvxNpsRMuKHIZulbJ+JJP0t4eYOAmAny7ABBHsCv+B83INuRWUTX5kPXrfNAqV5N X-Received: by 2002:a17:90a:2c2:b0:234:ac93:d715 with SMTP id d2-20020a17090a02c200b00234ac93d715mr38708013pjd.45.1678790288748; Tue, 14 Mar 2023 03:38:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678790288; cv=none; d=google.com; s=arc-20160816; b=sPWwKDtLkg6IzaF6la6Os73KEmEQ9JJ/g58qeNBx77F99SQetN5GAkEv231XHgbz0D 163iP50eukmT8nMipTslPamk0CCUpRCEBm2wQFlwgvL5wAP74UW6qPymPGLfRKLp93Wx YXhvM2uJaJzNWQi0fKbM2jaGqteXZK1nyokggza2VfApEg8NatHUVNvFIDeboKafI0Df GrX4ZmeIXYSQUisPclVSknDRIGWnl6EbwIbSkY5vpZMJ7+H1ePcL/fYu5j2i0s4QzbUq 0/w5sHRtzWG/9Nauxn7n/xVgZOc8WdG3kLu/lE7kI8TRrJFKdNfeYdXvpkmv9V0XkYFB OsRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=Ueb4Nnd44zcCGj1+yqsSLROzel10a4lIjdgwj+oK658=; b=GyOxIHLOXQOb05tcm0q12HEbZv4fHa4376tpaWngJeSg331PH2vbt37fqBLifA78p4 JxaJQpiZDva+8jemZ2OCsMNd0KUFwByfoOPd26kCXS6BIHGvSjkOtuM9uyWjTqRgpvb5 ZNYVSc11qF8valBxGCydynVAvRsYe5X6UNeFHATqB8CJo98RkJuACSwbgWCt/ddg9GwK ggQeTa+5Mh5scIXHYNfsQ/e9nVw2F69c6oEPGz8BSM33WWSzVMfY8LzRjq5vEOcGg2iy oLShT5bxMCZyHTt6g2aoXb4Nu/+UPVuTCCvXBmU1Fz9G/umo6Pq8WOqZ3uuA7fV9mZeN Ifgw== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c5-20020a17090a8d0500b0023750b6960csi2094595pjo.156.2023.03.14.03.37.55; Tue, 14 Mar 2023 03:38:08 -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 S229734AbjCNKfZ (ORCPT + 99 others); Tue, 14 Mar 2023 06:35:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231382AbjCNKfJ (ORCPT ); Tue, 14 Mar 2023 06:35:09 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0926A8A3B2; Tue, 14 Mar 2023 03:34:32 -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 5A33F1042; Tue, 14 Mar 2023 03:35:00 -0700 (PDT) Received: from e123648.arm.com (unknown [10.57.19.101]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id D46943F71A; Tue, 14 Mar 2023 03:34:13 -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 01/17] PM: EM: Refactor em_cpufreq_update_efficiencies() arguments Date: Tue, 14 Mar 2023 10:33:41 +0000 Message-Id: <20230314103357.26010-2-lukasz.luba@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230314103357.26010-1-lukasz.luba@arm.com> References: <20230314103357.26010-1-lukasz.luba@arm.com> X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760339205693415007?= X-GMAIL-MSGID: =?utf-8?q?1760339205693415007?= In order to prepare the code for the modifiable EM perf_state table, refactor existing function em_cpufreq_update_efficiencies(). Signed-off-by: Lukasz Luba --- kernel/power/energy_model.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c index f82111837b8d..265d51a948d4 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -240,10 +240,10 @@ static int em_create_pd(struct device *dev, int nr_states, return 0; } -static void em_cpufreq_update_efficiencies(struct device *dev) +static void +em_cpufreq_update_efficiencies(struct device *dev, struct em_perf_state *table) { struct em_perf_domain *pd = dev->em_pd; - struct em_perf_state *table; struct cpufreq_policy *policy; int found = 0; int i; @@ -257,8 +257,6 @@ static void em_cpufreq_update_efficiencies(struct device *dev) return; } - table = pd->table; - for (i = 0; i < pd->nr_perf_states; i++) { if (!(table[i].flags & EM_PERF_STATE_INEFFICIENT)) continue; @@ -400,7 +398,7 @@ int em_dev_register_perf_domain(struct device *dev, unsigned int nr_states, dev->em_pd->flags |= flags; - em_cpufreq_update_efficiencies(dev); + em_cpufreq_update_efficiencies(dev, dev->em_pd->table); em_debug_create_pd(dev); dev_info(dev, "EM: created perf domain\n"); From patchwork Tue Mar 14 10:33:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 69492 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1680275wrd; Tue, 14 Mar 2023 03:43:27 -0700 (PDT) X-Google-Smtp-Source: AK7set85b3M0kuyAvljojX72I+oD22RtPjRdSgaDHzdhSl1InPacTY/qw/W7c7xKMooZuS6qGg88 X-Received: by 2002:a17:90b:4a52:b0:237:373e:9dfa with SMTP id lb18-20020a17090b4a5200b00237373e9dfamr37003078pjb.20.1678790607616; Tue, 14 Mar 2023 03:43:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678790607; cv=none; d=google.com; s=arc-20160816; b=rMX8qgdg+0WGVEAmulkkypvr8vkrRYNzhlVmt94I0xksV560SCQVhVsrV/lnMeq2Sh WMSkm/E5U9vAA/SqNaTex/tvQwGBcCCYpuQdKRKnwYSnDyl8SH62hlnyN+qvPloUGuOv p7kON8M3NzmhtErIs61oxsOJ1IvXu+N30zZx4ynppwlyuQ1DBF7izD0MkrA7LSNaSxQr IbUtrtk4ORPvRRe4XOtMP6//E+mA5Zn5cMVKKPN1xVO3+9azajOIKKtpjh3bUlYABhwx lfv9oFi9hjuRmMHy28pUgq+NOfhsMQXCYHj6as6VSgb1CQFGVlHcMV0Nq2PhqqjDw+4L B07Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=hvD2XkLV7Y/oKAumhN6Ti/NUoV2ZDD0HgZwfT/MlgeU=; b=m4O/vHGrhL1cGNET8KLbspDJHm7X+5LWFQtJdVqRKAW8YIErMt4KBuRochaAHZXkoM JmWJmvhrkyS/JoM18w4u2dMuLkNioYzzj9li0LiCdG1U7OVggEhKT/v3U1R0Czyi2MLb eKZVI1TilsluL/s9PmiDa0E0ajJYatoIm8qLCnuFY/j9O5uwUVO2LvP+rUeWlYzfhe5y IfrShYlIjdIYmgWra/srxtkEdMRIz+9vYHRxSaK777ZKgnIQOR0cVdGMd5aqaJxMssqi BOfxlBE+CRspqXthMJNVwT1TaNAw5jOkNHTJcwZdKXu2Ry91aMz4txVxhV75w610yjqx sr0Q== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 24-20020a631658000000b004df75c35e02si1923606pgw.492.2023.03.14.03.43.12; Tue, 14 Mar 2023 03:43:27 -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 S229886AbjCNKfd (ORCPT + 99 others); Tue, 14 Mar 2023 06:35:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52854 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231395AbjCNKfK (ORCPT ); Tue, 14 Mar 2023 06:35:10 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 11D0E95BE0; Tue, 14 Mar 2023 03:34:37 -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 872F81063; Tue, 14 Mar 2023 03:35:03 -0700 (PDT) Received: from e123648.arm.com (unknown [10.57.19.101]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 05FC23F71A; Tue, 14 Mar 2023 03:34:16 -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 02/17] PM: EM: Find first CPU online while updating OPP efficiency Date: Tue, 14 Mar 2023 10:33:42 +0000 Message-Id: <20230314103357.26010-3-lukasz.luba@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230314103357.26010-1-lukasz.luba@arm.com> References: <20230314103357.26010-1-lukasz.luba@arm.com> X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760339539952597023?= X-GMAIL-MSGID: =?utf-8?q?1760339539952597023?= The Energy Model might be updated at runtime and the energy efficiency for each OPP may change. Thus, there is a need to update also the cpufreq framework and make it aligned to the new values. In order to do that, use a first online CPU from the Performance Domain. Signed-off-by: Lukasz Luba --- kernel/power/energy_model.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c index 265d51a948d4..3d8d1fad00ac 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -246,12 +246,19 @@ em_cpufreq_update_efficiencies(struct device *dev, struct em_perf_state *table) struct em_perf_domain *pd = dev->em_pd; struct cpufreq_policy *policy; int found = 0; - int i; + int i, cpu; if (!_is_cpu_device(dev) || !pd) return; - policy = cpufreq_cpu_get(cpumask_first(em_span_cpus(pd))); + /* Try to get a CPU which is online and in this PD */ + cpu = cpumask_first_and(em_span_cpus(pd), cpu_active_mask); + if (cpu >= nr_cpu_ids) { + dev_warn(dev, "EM: No online CPU for CPUFreq policy\n"); + return; + } + + policy = cpufreq_cpu_get(cpu); if (!policy) { dev_warn(dev, "EM: Access to CPUFreq policy failed"); return; From patchwork Tue Mar 14 10:33:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 69478 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1678360wrd; Tue, 14 Mar 2023 03:38:13 -0700 (PDT) X-Google-Smtp-Source: AK7set+2tv6ItVetK0b14HVOiqxQDTsqCqPVGNTtJrn/a+vLFxlRRkjSIiTZt630kc5vE5uPfW5J X-Received: by 2002:a17:902:ab82:b0:19b:da8:1ce6 with SMTP id f2-20020a170902ab8200b0019b0da81ce6mr30195952plr.55.1678790293244; Tue, 14 Mar 2023 03:38:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678790293; cv=none; d=google.com; s=arc-20160816; b=t35HzT3CNVOq5p6As61gu8i0m6r4fRBsPDjhnvdZM6YD3klYjZikF6+ccyGm8rcGzF YvwiWKol3QcO/9tVHtBcbZAXktQCc9aghoaaHcfWzDQQe8IeEnnCa3o8Pt21n023tDfy Tv4T8y4A/V/rTOuQuwoPKawNgH4vJkllH5iKAUaDNRs/l7B8T/nBYUSs3MwS3DeC7KnP MRuH8k+Iig7b3TsSS8z1BUhpWMWhN7Sm855kvokCLB3gBDs5ufDzziBJYDC3kQNl0qKj kClcyDNIiIN0Sm/gIIhMXhFaIANrLh577tpfGrm7RMmKDKzcAv7ZmfiNlJdp6sZtQDZa 3ulw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=4RoofPA592oFIYtUUp0PNd4H+b9XUctQukmAJ5tZNt0=; b=dC6Hu1Nx4Cj/jKwQ2k36MaYThzpBBExeYQaGj11OBdM3ZIC1sBNA2vmJu5WO+sSFy0 scVymIIKhbSPFmZNSzy9fsUoQPacq7pw20IfXO/AaevtOrc1+a4QzmpwUFW6q9WfkkLZ Evs05iaEYSIpc5YIe+phdytRJL+yduQ43B5mJ9A+gjNdEj3sI2FP2vMDhBRhtFO90Jjk E9jX6AOmo6hCqMUI6hN74VOBlZpq9Fo/61Bo14Q0yHfxeZZxfk0J/Bm7wcqjlmdjEtkc f066GjOfdfbOI36KvXW25pTs9ji2Bhtc8Yv0ze+Pb5DycBqVOzC+DHVe1zSzxkiverhb 7xZQ== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f30-20020a17090a702100b00233e561533dsi2093628pjk.61.2023.03.14.03.38.00; Tue, 14 Mar 2023 03:38:13 -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 S229810AbjCNKf3 (ORCPT + 99 others); Tue, 14 Mar 2023 06:35:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52926 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231421AbjCNKfN (ORCPT ); Tue, 14 Mar 2023 06:35:13 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 729AD10430; Tue, 14 Mar 2023 03:34:43 -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 AA2D21474; Tue, 14 Mar 2023 03:35:06 -0700 (PDT) Received: from e123648.arm.com (unknown [10.57.19.101]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 3333A3F71A; Tue, 14 Mar 2023 03:34:20 -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 03/17] PM: EM: Refactor em_pd_get_efficient_state() to be more flexible Date: Tue, 14 Mar 2023 10:33:43 +0000 Message-Id: <20230314103357.26010-4-lukasz.luba@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230314103357.26010-1-lukasz.luba@arm.com> References: <20230314103357.26010-1-lukasz.luba@arm.com> X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760339210683939504?= X-GMAIL-MSGID: =?utf-8?q?1760339210683939504?= Prepare em_pd_get_efficient_state() for the upcoming changes and make it possible to re-use. Return an index for the best performance state. The function arguments that are introduced should allow to work on different performance state arrays. The caller of em_pd_get_efficient_state() should be able to use the index either on the default or the modifiable EM table. Signed-off-by: Lukasz Luba --- include/linux/energy_model.h | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/include/linux/energy_model.h b/include/linux/energy_model.h index b9caa01dfac4..8069f526c9d8 100644 --- a/include/linux/energy_model.h +++ b/include/linux/energy_model.h @@ -175,33 +175,35 @@ void em_dev_unregister_perf_domain(struct device *dev); /** * em_pd_get_efficient_state() - Get an efficient performance state from the EM - * @pd : Performance domain for which we want an efficient frequency - * @freq : Frequency to map with the EM + * @state: List of performance states, in ascending order + * @nr_perf_states: Number of performance states + * @freq: Frequency to map with the EM + * @pd_flags: Performance Domain flags * * It is called from the scheduler code quite frequently and as a consequence * doesn't implement any check. * - * Return: An efficient performance state, high enough to meet @freq + * Return: An efficient performance state id, high enough to meet @freq * requirement. */ -static inline -struct em_perf_state *em_pd_get_efficient_state(struct em_perf_domain *pd, - unsigned long freq) +static inline int +em_pd_get_efficient_state(struct em_perf_state *table, int nr_perf_states, + unsigned long freq, unsigned long pd_flags) { struct em_perf_state *ps; int i; - for (i = 0; i < pd->nr_perf_states; i++) { - ps = &pd->table[i]; + for (i = 0; i < nr_perf_states; i++) { + ps = &table[i]; if (ps->frequency >= freq) { - if (pd->flags & EM_PERF_DOMAIN_SKIP_INEFFICIENCIES && + if (pd_flags & EM_PERF_DOMAIN_SKIP_INEFFICIENCIES && ps->flags & EM_PERF_STATE_INEFFICIENT) continue; - break; + return i; } } - return ps; + return nr_perf_states - 1; } /** @@ -226,7 +228,7 @@ static inline unsigned long em_cpu_energy(struct em_perf_domain *pd, { unsigned long freq, scale_cpu; struct em_perf_state *ps; - int cpu; + int cpu, i; if (!sum_util) return 0; @@ -251,7 +253,9 @@ static inline unsigned long em_cpu_energy(struct em_perf_domain *pd, * Find the lowest performance state of the Energy Model above the * requested frequency. */ - ps = em_pd_get_efficient_state(pd, freq); + i = em_pd_get_efficient_state(pd->table, pd->nr_perf_states, freq, + pd->flags); + ps = &pd->table[i]; /* * The capacity of a CPU in the domain at the performance state (ps) From patchwork Tue Mar 14 10:33:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 69479 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1678383wrd; Tue, 14 Mar 2023 03:38:17 -0700 (PDT) X-Google-Smtp-Source: AK7set9px8EM0GUcaDiU4VaYEmPR84AGRNHwbl2ZTvK8DRynW2rIOHNGIOVWkJGIA7kydRCGW0gk X-Received: by 2002:a62:5210:0:b0:5d9:f3a6:a925 with SMTP id g16-20020a625210000000b005d9f3a6a925mr27418503pfb.24.1678790297391; Tue, 14 Mar 2023 03:38:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678790297; cv=none; d=google.com; s=arc-20160816; b=UqTKlYKtMKvpst3B2HSIsGIliNHjQxYTpXTYK0wl9RFocKhHFiaiGDP0FWg43veQZ0 fk7Cx5vvHD64vaF1KxC+hiKoNnWCEs96EclMAfDhvBQxwXf1/VuxZEf6a7YaXdWugw6v H9CTmr0ZhmE5ZcKmk+zcQ/Mk/Ynn7s643VmG4lxpTzCdwi5ZJy03TENHvUkzOEkUZlM3 EOO6vCgaylNuHso54nlRaQq4V5pSGR3hVro41VXam7FmT19FJ4vCcGX9FaBgqULHCyL0 dm0N800eymma8gOTWcNwkbqqzQUK0nRmzUos7CFt5oLsBHMQXpe8vWGXRcQ+J61/djEa K+Og== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=LAP9+eD7KGqFRfTA7HOLU3ch3JfNxEfblVEZWhm70vE=; b=po7PwqznnUIIvYMHn7gDuQtamoZrgvl7w7lW2EO+hmIox9CGeuh4aFdW4NXi/Nb7Vm d+YiDI1CzREN6zsnqXSBJPYTt+GBTfisplnZpQj2uauoxTRAEmJ5oz8RrIR6E+VC+BG9 poEfND3EFKO+Qt5vXMplG/iHRlEdA+7vlfa1pySmb1DFLxYBga03V3OvgCR3s9vq5oU5 tVUk7ztmUAkiusj8xF37rIVvl8xmRfiSm6K17NWARqWzG3bs3SSy9mwmU7UZxqxy3qFs +lq47gyhM/TAAE0nfmqDURcZt8Jv604h2F7cbW5b4HDTmo/kbZyPbjsBaE/eYsPf4AaL gUwQ== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b3-20020aa78ec3000000b005a81866ff8csi1899807pfr.319.2023.03.14.03.38.05; Tue, 14 Mar 2023 03:38:17 -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 S230240AbjCNKfo (ORCPT + 99 others); Tue, 14 Mar 2023 06:35:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231469AbjCNKfS (ORCPT ); Tue, 14 Mar 2023 06:35:18 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 098BD911C6; Tue, 14 Mar 2023 03:34:52 -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 D118B150C; Tue, 14 Mar 2023 03:35:09 -0700 (PDT) Received: from e123648.arm.com (unknown [10.57.19.101]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 56C5E3F71A; Tue, 14 Mar 2023 03:34:23 -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 04/17] PM: EM: Create a new function em_compute_costs() Date: Tue, 14 Mar 2023 10:33:44 +0000 Message-Id: <20230314103357.26010-5-lukasz.luba@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230314103357.26010-1-lukasz.luba@arm.com> References: <20230314103357.26010-1-lukasz.luba@arm.com> X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760339215069793625?= X-GMAIL-MSGID: =?utf-8?q?1760339215069793625?= 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 3d8d1fad00ac..937e98a71ed5 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -106,14 +106,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) @@ -157,33 +195,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; From patchwork Tue Mar 14 10:33:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 69481 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1678503wrd; Tue, 14 Mar 2023 03:38:34 -0700 (PDT) X-Google-Smtp-Source: AK7set9/6h2qesoi97wb13lnkRy7rxbycnFJ5euy29gRZYKrKi8TrwDQvA5/E7zgr6ZVzxXaW293 X-Received: by 2002:aa7:9568:0:b0:623:258:1446 with SMTP id x8-20020aa79568000000b0062302581446mr7568446pfq.15.1678790314084; Tue, 14 Mar 2023 03:38:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678790314; cv=none; d=google.com; s=arc-20160816; b=NiAkK7fEiUyU9e+9tD6nrbQmrwO8kyQThmsEwgSqIEItmxGMZruBEUXuqmyEjwyXiY TOLpjJtCZDenEOOJ8YqI0Fig5IX4KYadwsNjMF2CB5GoXj73HljFlBwHyXgVC3adEzKy OOn5/Fz1LADpdow8zOew+r9YmwUurTcA+wgNID6v8knUaUYwIPFQMlZNIfyv+L+5U78F C4ycoaQ2bshDnQwgGSuCUtH+dNZJKr3s0SYgEZFcwhBDS3XwE7hJCMiDLSaH/E1exFOz TCEqrsNKwCPnNZpQ8DZBe8Jt6fJ3A7ZHuWAbYjK0nCr2GqBNc8cU9ygAf25v+cm+qR2O SEww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=3Hxdglakj/pkjvCiB/TJmaUxHXFhjzMtR3aFxtOehqM=; b=fz1JYEXekHcy8c3Nv+v21HwnaB8fderabK8d083+hPWHAJvLB8xwom5bnKV5MyFQBS radJws9Vb/3eC4CNLcrKuXdXzCNzjdJfMrMldp6u3JkPHxdoHlMuwc6i15bjWB+qT+i5 J4rXrhtOVCZAjJ//U1yyTTLrv7oTXG2xWEmi4KdX7afJ9l0gktjWMT5bhgWCqzC/OjpD NEeNnjR2CyzIFMgQHS9DKWedPnRns6rPBANtHKIeVhQaNopch3tL0tJ1edB+5Baffv6H lHav5AoyaGUL30YEuf0TI61NMzwPhkAhgZnv2qOh4BN2CXxkOJjdsr9e9WVkIJhlRJ17 b6wg== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x8-20020aa79568000000b00624de0ad130si1892502pfq.276.2023.03.14.03.38.21; Tue, 14 Mar 2023 03:38:34 -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 S231207AbjCNKgR (ORCPT + 99 others); Tue, 14 Mar 2023 06:36:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53648 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229977AbjCNKfw (ORCPT ); Tue, 14 Mar 2023 06:35:52 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3F00C1B3; Tue, 14 Mar 2023 03:35:14 -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 F1EF5168F; Tue, 14 Mar 2023 03:35:12 -0700 (PDT) Received: from e123648.arm.com (unknown [10.57.19.101]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 7C7E33F71A; Tue, 14 Mar 2023 03:34:26 -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 05/17] trace: energy_model: Add trace event for EM runtime modifications Date: Tue, 14 Mar 2023 10:33:45 +0000 Message-Id: <20230314103357.26010-6-lukasz.luba@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230314103357.26010-1-lukasz.luba@arm.com> References: <20230314103357.26010-1-lukasz.luba@arm.com> X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760339232440894597?= X-GMAIL-MSGID: =?utf-8?q?1760339232440894597?= The Energy Model (EM) supports runtime modifications. Track the changes in order to do post-processing analysis. Don't use arrays in the trace event, since they are not properly supported by the tools. Instead use simple "unroll" with emitting the trace event for each EM array entry with proper ID information. The older debugging mechanism which was the simple debugfs which dumping the EM content won't be sufficient for the modifiable EM purpose. This trace event mechanism would address the needs. Signed-off-by: Lukasz Luba --- include/trace/events/energy_model.h | 46 +++++++++++++++++++++++++++++ kernel/power/energy_model.c | 3 ++ 2 files changed, 49 insertions(+) create mode 100644 include/trace/events/energy_model.h diff --git a/include/trace/events/energy_model.h b/include/trace/events/energy_model.h new file mode 100644 index 000000000000..f70babeb5dde --- /dev/null +++ b/include/trace/events/energy_model.h @@ -0,0 +1,46 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#undef TRACE_SYSTEM +#define TRACE_SYSTEM energy_model + +#if !defined(_TRACE_ENERGY_MODEL_H) || defined(TRACE_HEADER_MULTI_READ) +#define _TRACE_ENERGY_MODEL_H + +#include + +TRACE_EVENT(em_perf_state, + TP_PROTO(const char *dev_name, int nr_perf_states, int state, + unsigned long ps_frequency, unsigned long ps_power, + unsigned long ps_cost, unsigned long ps_flags), + + TP_ARGS(dev_name, nr_perf_states, state, ps_frequency, ps_power, ps_cost, + ps_flags), + + TP_STRUCT__entry( + __string(name, dev_name) + __field(int, num_states) + __field(int, state) + __field(unsigned long, frequency) + __field(unsigned long, power) + __field(unsigned long, cost) + __field(unsigned long, flags) + ), + + TP_fast_assign( + __assign_str(name, dev_name); + __entry->num_states = nr_perf_states; + __entry->state = state; + __entry->frequency = ps_frequency; + __entry->power = ps_power; + __entry->cost = ps_cost; + __entry->flags = ps_flags; + ), + + TP_printk("dev_name=%s nr_perf_states=%d state=%d frequency=%lu power=%lu cost=%lu flags=%lu", + __get_str(name), __entry->num_states, __entry->state, + __entry->frequency, __entry->power, __entry->cost, + __entry->flags) +); +#endif /* _TRACE_ENERGY_MODEL_H */ + +/* This part must be outside protection */ +#include diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c index 937e98a71ed5..3b778743ba89 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -17,6 +17,9 @@ #include #include +#define CREATE_TRACE_POINTS +#include + /* * Mutex serializing the registrations of performance domains and letting * callbacks defined by drivers sleep. From patchwork Tue Mar 14 10:33:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 69482 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1678506wrd; Tue, 14 Mar 2023 03:38:34 -0700 (PDT) X-Google-Smtp-Source: AK7set9Egi5R3Cx44Iq4rgJzEsQgZKjXNXCxfJyPQSNocfLJpgRY+Cja8tRyloCUfvzEUxTH3ZnK X-Received: by 2002:a17:90b:3e8e:b0:236:99c4:6096 with SMTP id rj14-20020a17090b3e8e00b0023699c46096mr38053817pjb.35.1678790314265; Tue, 14 Mar 2023 03:38:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678790314; cv=none; d=google.com; s=arc-20160816; b=kLsH6kRqSI2SaoSoP6Zyz2L6aXa7217LcjCLjj6eJILCszJrTzjLdRMA68VfDXH555 SORWTYtJ6jb3PfJSi+mbOIsjYgERqPVbj3cFheKWKvi3HjC3hg2QwsTDeftNWOeb/fcC gSAWkpPN5cR031AJqn852VpSWpeOiSEtGS6wxrOEI8FdQQ+mvqLvGWr1zW3U1/TRQyZP N2X66W/Us4ENjf7cr0QIIgSdZy90tNDlHKPJBWqYF1o55l3keoQ6QQj8iQPpI4tT3yxI ixPIGRoXwrim6s1VQb3SfyqRnuU40t9+vxh866Y1zxySu6jtZ24w8AeIO+g4Wm7oZVeU tFGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=XIypkIjcAejwcG3WZLPbyT/liSdoUcoLYHoVe/VsbmQ=; b=HrqhYvB1r4RLXZziKjxi9xUcVR28Vq3cofcALIsixZO61l4HB1zQOSWTyRuIJR9LzG rVMkLkieMf/ww51zXtP/QqUvI+qOWiUj7H12B4ckUeizqKptS9AfihC9gk00uXYSttGC FEuUQK+kkBMeI6vUcZm5U7WQmAScPqhJb0qhzskd6/NRtpvdKym0Xlm/rzl4wVH+bEIz 6wkm5BugpHmWUpN1V36bBnDb8TcjNSZo768FJKPzfCieMyNTH1lqlWgypfyHUaCYtri3 aR4X0aRX65fOFfA9b0cEIdOM2gbX/a5O+l9CUHEoHJRdb74SGweIn0qoi7i7ZZ9WflmY JjNQ== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i8-20020a17090ad34800b00234ba949302si2262244pjx.91.2023.03.14.03.38.21; Tue, 14 Mar 2023 03:38:34 -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 S231384AbjCNKgU (ORCPT + 99 others); Tue, 14 Mar 2023 06:36:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230297AbjCNKfw (ORCPT ); Tue, 14 Mar 2023 06:35:52 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 45977F947; Tue, 14 Mar 2023 03:35:14 -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 210B2169C; Tue, 14 Mar 2023 03:35:16 -0700 (PDT) Received: from e123648.arm.com (unknown [10.57.19.101]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 9EED33F71A; Tue, 14 Mar 2023 03:34:29 -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 06/17] PM: EM: Add update_power() callback for runtime modifications Date: Tue, 14 Mar 2023 10:33:46 +0000 Message-Id: <20230314103357.26010-7-lukasz.luba@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230314103357.26010-1-lukasz.luba@arm.com> References: <20230314103357.26010-1-lukasz.luba@arm.com> X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760339232442813193?= X-GMAIL-MSGID: =?utf-8?q?1760339232442813193?= The Energy Model (EM) is going to support runtime modifications. This new callback would be used in the upcoming EM changes. The drivers or frameworks which want to modify the EM have to implement the update_power() callback and provide it via EM API em_dev_update_perf_domain(). The callback is then used by the EM framework to get new power values for each frequency in existing EM. Signed-off-by: Lukasz Luba --- include/linux/energy_model.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/include/linux/energy_model.h b/include/linux/energy_model.h index 8069f526c9d8..cc2bf607191e 100644 --- a/include/linux/energy_model.h +++ b/include/linux/energy_model.h @@ -158,6 +158,26 @@ struct em_data_callback { */ int (*get_cost)(struct device *dev, unsigned long freq, unsigned long *cost); + + /** + * update_power() - Provide new power at the given performance state of + * a device + * @dev : Device for which we do this operation (can be a CPU) + * @freq : Frequency at the performance state in kHz + * @power : New power value at the performance state + * (modified) + * @priv : Pointer to private data useful for tracking context + * during run-time modifications of EM. + * + * The update_power() is used by run-time modifiable EM. It aims to + * provide updated power value for a given frequency, which is stored + * in the performance state. The power value provided by this callback + * should fit in the [0, EM_MAX_POWER] range. + * + * Return 0 on success, or appropriate error value in case of failure. + */ + int (*update_power)(struct device *dev, unsigned long freq, + unsigned long *power, void *priv); }; #define EM_SET_ACTIVE_POWER_CB(em_cb, cb) ((em_cb).active_power = cb) #define EM_ADV_DATA_CB(_active_power_cb, _cost_cb) \ @@ -165,6 +185,7 @@ struct em_data_callback { .get_cost = _cost_cb } #define EM_DATA_CB(_active_power_cb) \ EM_ADV_DATA_CB(_active_power_cb, NULL) +#define EM_UPDATE_CB(_update_power_cb) { .update_power = &_update_power_cb } struct em_perf_domain *em_cpu_get(int cpu); struct em_perf_domain *em_pd_get(struct device *dev); From patchwork Tue Mar 14 10:33:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 69484 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1678765wrd; Tue, 14 Mar 2023 03:39:17 -0700 (PDT) X-Google-Smtp-Source: AK7set+Pe+sLqWbfBffiVYbknRylTA4GR6VAhfA5e+fCQs6Ipaxhi/ZpdnhvDa4SdNbcqU+ykgeu X-Received: by 2002:a05:6a20:258a:b0:c7:8644:a9ff with SMTP id k10-20020a056a20258a00b000c78644a9ffmr35076404pzd.57.1678790356897; Tue, 14 Mar 2023 03:39:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678790356; cv=none; d=google.com; s=arc-20160816; b=g5ySFsnrVugYJVmQby5NJyIGFsj1PFUHml3S9qQ90qJIyNVtSKllhmPxBC3L0oaCkn xGdyYNqyiQZTr5U+/nHcTEQOuMTd5TK88PqBv8uBswT5O47qCeBRDlJsy7W9u1jbb/pL WrPQKMsdSlqrdxpeoMDEZlCgHWoQ0S7tLqUd2URoRsFphyMfJAIJ6KTcU8M17JZ4df/Z SvtnAPBOUhbi5AnuZGhgV+fvM6rSXvG0zmZL0P0sgXtx5DPqjW3wBQOXn7485qkTHmAK DJ00jEMcxiWvfPv7cOVwXk78rX0pN1bNur4EpZaWQOscZRwHrNoHiWvjF5n/e4yfJchw QUxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=pMO4BIB/uqaiZaCrCdK2gXIr5nWUyYwrvynEi1I1Ca8=; b=DTk7mPEJXX+iiIdZ/WeYiHKZChldpid7FllMeLbyxG5sGbzI1AqrEThVoFq7NTrTqg OFzsGrZbVVblvb7BMEdvcceTXI3ZueClLNyejGnhZ8mcQSWgBbhbuQ/d4aa2n/xKfQug 1Aka4opIt6XoF7z9Wmbo/1BIX8kJh02oKLujOZUIsyXi3sRXB33Q599eN4hzjroicAE6 c/KLSeLBk4I4cHT1GxgRh7vUjoUrmmGgVElEsQWwZhH8u2cVlsKVIRx+tjR+8aJLYUng 3FG9/7WXXLNV9eTR0pJBzikoN5s24p8QTApWop/sqUh7y2aiY+Y0g2YjcZZm9eiA0n9l 1Xrg== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bm18-20020a656e92000000b004fb97a4c536si1868574pgb.873.2023.03.14.03.39.03; Tue, 14 Mar 2023 03:39:16 -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 S231400AbjCNKgW (ORCPT + 99 others); Tue, 14 Mar 2023 06:36:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231226AbjCNKgH (ORCPT ); Tue, 14 Mar 2023 06:36:07 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9512830B20; Tue, 14 Mar 2023 03:35:18 -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 4C119169E; Tue, 14 Mar 2023 03:35:19 -0700 (PDT) Received: from e123648.arm.com (unknown [10.57.19.101]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id C03C63F71A; Tue, 14 Mar 2023 03:34:32 -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 07/17] PM: EM: Check if the get_cost() callback is present in em_compute_costs() Date: Tue, 14 Mar 2023 10:33:47 +0000 Message-Id: <20230314103357.26010-8-lukasz.luba@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230314103357.26010-1-lukasz.luba@arm.com> References: <20230314103357.26010-1-lukasz.luba@arm.com> X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760339276939121282?= X-GMAIL-MSGID: =?utf-8?q?1760339276939121282?= The em_compute_cost() is going to be re-used in runtime modified EM code path. Thus, make sure that this common code is safe and won't try to use the NULL pointer. The former em_compute_cost() didn't have to care about runtime modification code path. The upcoming changes introduce such option, but with different callback. Those two paths which use get_cost() (during first EM registration) or update_power() (during runtime modification) need to be safely handled in em_compute_costs(). Signed-off-by: Lukasz Luba --- kernel/power/energy_model.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c index 3b778743ba89..230310709e2a 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -122,7 +122,7 @@ static int em_compute_costs(struct device *dev, struct em_perf_state *table, for (i = nr_states - 1; i >= 0; i--) { unsigned long power_res, cost; - if (flags & EM_PERF_DOMAIN_ARTIFICIAL) { + if (flags & EM_PERF_DOMAIN_ARTIFICIAL && cb->get_cost) { 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", From patchwork Tue Mar 14 10:33:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 69483 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1678697wrd; Tue, 14 Mar 2023 03:39:04 -0700 (PDT) X-Google-Smtp-Source: AK7set+SUsPM6fgftJxLpgLwWQd2cxkUeQ0ftGI0zjtala9rW8f1PNDGWNVkrJZ1FJqSh3DIFH8r X-Received: by 2002:a17:90a:7:b0:23a:6be8:9446 with SMTP id 7-20020a17090a000700b0023a6be89446mr38384105pja.48.1678790343718; Tue, 14 Mar 2023 03:39:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678790343; cv=none; d=google.com; s=arc-20160816; b=oH6V0jySoGMYYQf/66+Z/0ZFCV399+EtYfKAGngNfQxnlyKl6vRdjtcQktbHe/LWgh 1dl/V8tH72BgZrV8G7unrmGaIWuM6GfsvWGM1c6NrOWcMdTOqJqL7GOawVqj3dvI0pjV UlNN8okzW+Il05R4l0Cg3Okyi230vToxxerlfjN7X5iJfKPVoWv1540QFhoCNf/9SVKL woNRLPDQwKO53F4wO6t3p+QLOVE805lMVNWdrLfjtnDgeD6hOGgJGznznFR4GQ5YOvPK n596dbUTGpKUh/hLwWXpHH5utdY7lodfm8WiMp7x1TOtWTZM6L5hH1F4ff6Ogie5kGVk e65Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=9HTY519uUT/EzkNiAd5nVwJTh/egS95z+ziD7vq3fs8=; b=kjwM9XwzsazHf6a20+h2q6NZwFJli7tHEnpQsB/mgcs1NNttIWNbyhGjkE1IXRXBt5 OVVQ8uChI+vEWMllbMetH4HM0LJHo33HWoY+wxSNDup0g+Ie2ncXT6XKbTtLp7+woHHm nayoX44CaELTfr2mgtYy3wpbMrA1+yXj+NGX3S+vRj+PHRNnSRopQmD55CTQQSlvhJgf n/ZTyPSnW05kmhB24YOMDFT68JBv3wXNiSWES1gN803WOekQRzf6qjs5d8NH2Zivm87B Tl6aYQdGMM7Ef3fxGmgpsr70K5M4OjaCMK8AAo1fdwJnJ9ukllCD4eNv/1LyQs8D3X1k dwqA== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id om16-20020a17090b3a9000b002342e691837si2271241pjb.21.2023.03.14.03.38.51; Tue, 14 Mar 2023 03:39:03 -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 S230075AbjCNKgZ (ORCPT + 99 others); Tue, 14 Mar 2023 06:36:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231224AbjCNKgH (ORCPT ); Tue, 14 Mar 2023 06:36:07 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 94F8A30184; Tue, 14 Mar 2023 03:35:18 -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 7089B16A3; Tue, 14 Mar 2023 03:35:22 -0700 (PDT) Received: from e123648.arm.com (unknown [10.57.19.101]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id EB0CA3F71A; Tue, 14 Mar 2023 03:34:35 -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 08/17] PM: EM: Introduce runtime modifiable table Date: Tue, 14 Mar 2023 10:33:48 +0000 Message-Id: <20230314103357.26010-9-lukasz.luba@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230314103357.26010-1-lukasz.luba@arm.com> References: <20230314103357.26010-1-lukasz.luba@arm.com> X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760339263471307961?= X-GMAIL-MSGID: =?utf-8?q?1760339263471307961?= This patch introduces the new feature: modifiable EM perf_state table. The new runtime table would be populated with a new power data to better reflect the actual power. The power can vary over time e.g. due to the SoC temperature change. Higher temperature can increase power values. For longer running scenarios, such as game or camera, when also other devices are used (e.g. GPU, ISP) the CPU power can change. The new EM framework is able to addresses this issue and change the data at runtime safely. The runtime modifiable EM data is used by the Energy Aware Scheduler (EAS) for the task placement. Signed-off-by: Lukasz Luba --- include/linux/energy_model.h | 13 +++++++++++++ kernel/power/energy_model.c | 24 ++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/include/linux/energy_model.h b/include/linux/energy_model.h index cc2bf607191e..a616006a8130 100644 --- a/include/linux/energy_model.h +++ b/include/linux/energy_model.h @@ -36,9 +36,21 @@ struct em_perf_state { */ #define EM_PERF_STATE_INEFFICIENT BIT(0) +/** + * struct em_perf_table - Performance states table, which can be + * runtime modifiable and protected with RCU + * @state: List of performance states, in ascending order + * @rcu: RCU used for safe access and destruction + */ +struct em_perf_table { + struct em_perf_state *state; + struct rcu_head rcu; +}; + /** * struct em_perf_domain - Performance domain * @table: List of performance states, in ascending order + * @runtime_table: Pointer to the runtime modified em_perf_table * @nr_perf_states: Number of performance states * @flags: See "em_perf_domain flags" * @cpus: Cpumask covering the CPUs of the domain. It's here @@ -54,6 +66,7 @@ struct em_perf_state { */ struct em_perf_domain { struct em_perf_state *table; + struct em_perf_table __rcu *runtime_table; int nr_perf_states; unsigned long flags; unsigned long cpus[]; diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c index 230310709e2a..500b9cf26ba8 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -216,6 +216,7 @@ static int em_create_pd(struct device *dev, int nr_states, struct em_data_callback *cb, cpumask_t *cpus, unsigned long flags) { + struct em_perf_table *runtime_table; struct em_perf_domain *pd; struct device *cpu_dev; int cpu, ret, num_cpus; @@ -240,12 +241,23 @@ static int em_create_pd(struct device *dev, int nr_states, return -ENOMEM; } + runtime_table = kzalloc(sizeof(*runtime_table), GFP_KERNEL); + if (!runtime_table) { + kfree(pd); + return -ENOMEM; + } + ret = em_create_perf_table(dev, pd, nr_states, cb, flags); if (ret) { kfree(pd); + kfree(runtime_table); return ret; } + /* Re-use temporally (till 1st modification) the memory */ + runtime_table->state = pd->table; + rcu_assign_pointer(pd->runtime_table, runtime_table); + if (_is_cpu_device(dev)) for_each_cpu(cpu, cpus) { cpu_dev = get_cpu_device(cpu); @@ -441,20 +453,32 @@ EXPORT_SYMBOL_GPL(em_dev_register_perf_domain); */ void em_dev_unregister_perf_domain(struct device *dev) { + struct em_perf_domain *pd; + struct em_perf_table *tmp; + if (IS_ERR_OR_NULL(dev) || !dev->em_pd) return; if (_is_cpu_device(dev)) return; + pd = dev->em_pd; /* * The mutex separates all register/unregister requests and protects * from potential clean-up/setup issues in the debugfs directories. * The debugfs directory name is the same as device's name. */ mutex_lock(&em_pd_mutex); + em_debug_remove_pd(dev); + tmp = pd->runtime_table; + + rcu_assign_pointer(pd->runtime_table, NULL); + synchronize_rcu(); + + kfree(tmp); + kfree(dev->em_pd->table); kfree(dev->em_pd); dev->em_pd = NULL; From patchwork Tue Mar 14 10:33:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 69487 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1679062wrd; Tue, 14 Mar 2023 03:40:06 -0700 (PDT) X-Google-Smtp-Source: AK7set+/fhvjBKEhvuzpqGX90s4riN2V8PVTQuvahFbKgq6+Z0IKY60w9B6mfNdb/kz3m8eOTcWq X-Received: by 2002:a05:6a21:6da0:b0:d4:ca6d:2ac2 with SMTP id wl32-20020a056a216da000b000d4ca6d2ac2mr4604541pzb.42.1678790405820; Tue, 14 Mar 2023 03:40:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678790405; cv=none; d=google.com; s=arc-20160816; b=APOGBVwRU85nWGgyNGntamiOIzwHIRdHrA8aG/flGv6BZjOZ1Gn4EAIfmX4fWt9J/h 1/LXN7TIQX6R1EOO5xynbkDz93LONpKHLaKe4ab+zFkUMPF8H5mdSSNjbrPI0fMfMyc3 UHc9arGtet4PLRTE5yC8ArLD4NczAfDvFvk29QfDI6Cy0yBCGwDnvr1bRfqHwYNDWxcJ QEqIUViO/Q/N1u7AbaFTjpJPNaC2RxSEK8ghyR+9j7zFR0z2iNTmL2GTK44wnECc6Pmg 6Xf2B//43cNB+cPXdEQuCxqcpP+E8zhScrx0YVlNs3sFqA0KP8SbPjC8I0EX/gwSoGeg eW/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=Ct/TM6a5VqLH/WjTWEt35LsDWNcDPvbaS4qvscpoeu8=; b=wj6xAunSOwQZ49q9pXss6sgg2xwJaViiii58UkkM9FycXpSTxRIqjVGWipzAdlZp12 NF9gYMZWDpRXX4322uso99YKGr9jVCCG//qBea0XXYzxIO835R6xngo/Q2f0ZG2+Rn5O 7onxwthQPkvOrJPvHHjoh7HmVNymnzjpFEoIm/4g6I+unLCKIo8O1syf7uQoJf5VF+JA 8MRi0C6EZaZ+7ZNueLU05/CKGnQQ81eCIRA6SxgzfMkQCF7fgkQEpRNitFL1JqcqAgDt TdszCOtaUxWrD90ZN/HQgrDMn1Gf5SlJgbGoenYCt+8lnO6R+54N1dR33wwEp8pcAO11 hJNw== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a5-20020aa794a5000000b005939fff6d47si1839883pfl.326.2023.03.14.03.39.53; Tue, 14 Mar 2023 03:40: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 S230451AbjCNKg2 (ORCPT + 99 others); Tue, 14 Mar 2023 06:36:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54520 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231254AbjCNKgH (ORCPT ); Tue, 14 Mar 2023 06:36:07 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4AD0B85B2D; Tue, 14 Mar 2023 03:35:19 -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 9243316F2; Tue, 14 Mar 2023 03:35:25 -0700 (PDT) Received: from e123648.arm.com (unknown [10.57.19.101]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 1B8A23F71A; Tue, 14 Mar 2023 03:34:38 -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 09/17] PM: EM: Add RCU mechanism which safely cleans the old data Date: Tue, 14 Mar 2023 10:33:49 +0000 Message-Id: <20230314103357.26010-10-lukasz.luba@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230314103357.26010-1-lukasz.luba@arm.com> References: <20230314103357.26010-1-lukasz.luba@arm.com> X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760339328481884473?= X-GMAIL-MSGID: =?utf-8?q?1760339328481884473?= The EM is going to support runtime modifications of the power data. In order to achieve that prepare the internal mechanism. This patch introduces RCU safe mechanism to clean up the old allocated EM data. It also adds a mutex for the EM structure to serialize the modifiers. Signed-off-by: Lukasz Luba --- kernel/power/energy_model.c | 57 +++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c index 500b9cf26ba8..87962b877376 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -26,6 +26,9 @@ */ static DEFINE_MUTEX(em_pd_mutex); +static void em_cpufreq_update_efficiencies(struct device *dev, + struct em_perf_state *table); + static bool _is_cpu_device(struct device *dev) { return (dev->bus == &cpu_subsys); @@ -109,6 +112,60 @@ static void em_debug_create_pd(struct device *dev) {} static void em_debug_remove_pd(struct device *dev) {} #endif +static void em_destroy_rt_table_rcu(struct rcu_head *rp) +{ + struct em_perf_table *runtime_table; + + runtime_table = container_of(rp, struct em_perf_table, rcu); + kfree(runtime_table->state); + kfree(runtime_table); +} + +static void em_destroy_tmp_setup_rcu(struct rcu_head *rp) +{ + struct em_perf_table *runtime_table; + + runtime_table = container_of(rp, struct em_perf_table, rcu); + kfree(runtime_table); +} + +static void em_perf_runtime_table_set(struct device *dev, + struct em_perf_table *runtime_table) +{ + struct em_perf_domain *pd = dev->em_pd; + struct em_perf_table *tmp; + + tmp = pd->runtime_table; + + rcu_assign_pointer(pd->runtime_table, runtime_table); + + em_cpufreq_update_efficiencies(dev, runtime_table->state); + + if (trace_em_perf_state_enabled()) { + unsigned long freq, power, cost, flags; + int i; + + for (i = 0; i < pd->nr_perf_states; i++) { + freq = runtime_table->state[i].frequency; + power = runtime_table->state[i].power; + cost = runtime_table->state[i].cost; + flags = runtime_table->state[i].flags; + + trace_em_perf_state(dev_name(dev), pd->nr_perf_states, + i, freq, power, cost, flags); + } + } + + /* + * Check if the 'state' array is not actually the one from setup. + * If it is then don't free it. + */ + if (tmp->state == pd->table) + call_rcu(&tmp->rcu, em_destroy_tmp_setup_rcu); + else + call_rcu(&tmp->rcu, em_destroy_rt_table_rcu); +} + static int em_compute_costs(struct device *dev, struct em_perf_state *table, struct em_data_callback *cb, int nr_states, unsigned long flags) From patchwork Tue Mar 14 10:33:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 69489 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1679064wrd; Tue, 14 Mar 2023 03:40:06 -0700 (PDT) X-Google-Smtp-Source: AK7set+u5nqxIrf7yk41/dpGeO7qI3l+ycZ8Cd0eExwP1bhaFGK9c+36n+m+GgHHlCmI/Hjyr9PJ X-Received: by 2002:a62:1b92:0:b0:5a8:b07b:82dc with SMTP id b140-20020a621b92000000b005a8b07b82dcmr28561708pfb.0.1678790405828; Tue, 14 Mar 2023 03:40:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678790405; cv=none; d=google.com; s=arc-20160816; b=G/xevCHYrq+4hzSPwm1gVJx4wcQatdp15CbSEAQZ70kEQFMTq1j1iZ+5D+G+fHXJik Rxx2eZlaqBIfuW8LtIs5uHsZEfHqUpPnA/pvW9Jk3vRbtyxcGk0c4YGJdx76LHwZwAoU dcc5iQiDOi7o3VHEmjbewQulADiAYLFRX29MbLvAF5FC01fdy2bQ5w/TPzC3USw1js+s kpOue4/sHwPX7s6grPmqYZU/XWyPN0Z+LgbrZZAce2MKIaEVE0cW5BFja/W317DFZ/8N fPEo1qXGlV8Z1Njo/IqRGPm9FKHUyAPWPFD8VOYxOSdw9j1fJBCVZhICNlHHhMekgMQh oROQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=9OfEonDQQGCr1J0cnega4/ZT3eOosGIqZQVvZTEbymA=; b=ef3yRLTMLLJHaVx2/ccX6smvqh5/gqIWeVcyk11CxUTMUxczK/LftjCGjIJYVhHmif dSgTgcVF3WTobqCFYBVKVFwNRyHZyEro52qm8g4Fr8KPzdTv7tmmg1PvutJAXeMp9GNL eUQ5Uv3y/8FIHqXqa8TpzQ2ATkYwlVJJzuk59FszPn4LbZT362y/Wh/eH1Bbix1N8q8m XygPIfyJaoYPxpUFrXgK5B+HKg1RgGnDkBCxDbYUWnf1oQxOCToGNrpBGh4/RfFVe1cE 4od2XS20PXddtgCQO6HUNkZdLaTCZxmOd8oMqPQ+QTGlHQSL4Sunez6tEpnXckYWNVl1 gUFA== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y5-20020a63fa05000000b00502e4103888si1943937pgh.801.2023.03.14.03.39.53; Tue, 14 Mar 2023 03:40: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 S230457AbjCNKgb (ORCPT + 99 others); Tue, 14 Mar 2023 06:36:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229868AbjCNKgH (ORCPT ); Tue, 14 Mar 2023 06:36:07 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7E85487D95; Tue, 14 Mar 2023 03:35:19 -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 B6A0816F3; Tue, 14 Mar 2023 03:35:28 -0700 (PDT) Received: from e123648.arm.com (unknown [10.57.19.101]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 3E6CF3F71A; Tue, 14 Mar 2023 03:34:42 -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 10/17] PM: EM: Add runtime update interface to modify EM power Date: Tue, 14 Mar 2023 10:33:50 +0000 Message-Id: <20230314103357.26010-11-lukasz.luba@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230314103357.26010-1-lukasz.luba@arm.com> References: <20230314103357.26010-1-lukasz.luba@arm.com> X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760339328502528616?= X-GMAIL-MSGID: =?utf-8?q?1760339328502528616?= Add an interface which allows to modify EM power data at runtime. The new power information is populated by the provided callback, which is called for each performance state. The CPU frequencies' efficiency is re-calculated since that might be affected as well. The old EM memory is going to be freed later using RCU mechanism. Signed-off-by: Lukasz Luba --- include/linux/energy_model.h | 8 +++ kernel/power/energy_model.c | 109 +++++++++++++++++++++++++++++++++++ 2 files changed, 117 insertions(+) diff --git a/include/linux/energy_model.h b/include/linux/energy_model.h index a616006a8130..e1772aa6c843 100644 --- a/include/linux/energy_model.h +++ b/include/linux/energy_model.h @@ -202,6 +202,8 @@ struct em_data_callback { struct em_perf_domain *em_cpu_get(int cpu); struct em_perf_domain *em_pd_get(struct device *dev); +int em_dev_update_perf_domain(struct device *dev, struct em_data_callback *cb, + void *priv); int em_dev_register_perf_domain(struct device *dev, unsigned int nr_states, struct em_data_callback *cb, cpumask_t *span, bool microwatts); @@ -382,6 +384,12 @@ static inline int em_pd_nr_perf_states(struct em_perf_domain *pd) { return 0; } +static inline +int em_dev_update_perf_domain(struct device *dev, struct em_data_callback *cb, + void *priv) +{ + return -EINVAL; +} #endif #endif diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c index 87962b877376..e0e8fba3d02b 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -205,6 +205,101 @@ static int em_compute_costs(struct device *dev, struct em_perf_state *table, return 0; } +/** + * em_dev_update_perf_domain() - Update run-time EM table for a device + * @dev : Device for which the EM is to be updated + * @cb : Callback function providing the power data for the EM + * @priv : Pointer to private data useful for passing context + * which might be required while calling @cb + * + * Update EM run-time modifiable table for a @dev using the callback + * defined in @cb. The EM new power values are then used for calculating + * the em_perf_state::cost for associated performance state. + * + * This function uses mutex to serialize writers, so it must not be called + * from non-sleeping context. + * + * Return 0 on success or a proper error in case of failure. + */ +int em_dev_update_perf_domain(struct device *dev, struct em_data_callback *cb, + void *priv) +{ + struct em_perf_table *runtime_table; + unsigned long power, freq; + struct em_perf_domain *pd; + int ret, i; + + if (!cb || !cb->update_power) + return -EINVAL; + + /* + * The lock serializes update and unregister code paths. When the + * EM has been unregistered in the meantime, we should capture that + * when entering this critical section. It also makes sure that + * two concurrent updates will be serialized. + */ + mutex_lock(&em_pd_mutex); + + if (!dev || !dev->em_pd) { + ret = -EINVAL; + goto unlock_em; + } + + pd = dev->em_pd; + + runtime_table = kzalloc(sizeof(*runtime_table), GFP_KERNEL); + if (!runtime_table) { + ret = -ENOMEM; + goto unlock_em; + } + + runtime_table->state = kcalloc(pd->nr_perf_states, + sizeof(struct em_perf_state), + GFP_KERNEL); + if (!runtime_table->state) { + ret = -ENOMEM; + goto free_runtime_table; + } + + /* Populate runtime table with updated values using driver callback */ + for (i = 0; i < pd->nr_perf_states; i++) { + freq = pd->table[i].frequency; + runtime_table->state[i].frequency = freq; + + /* + * Call driver callback to get a new power value for + * a given frequency. + */ + ret = cb->update_power(dev, freq, &power, priv); + if (ret) { + dev_dbg(dev, "EM: run-time update error: %d\n", ret); + goto free_runtime_state_table; + } + + runtime_table->state[i].power = power; + } + + ret = em_compute_costs(dev, runtime_table->state, cb, + pd->nr_perf_states, pd->flags); + if (ret) + goto free_runtime_state_table; + + em_perf_runtime_table_set(dev, runtime_table); + + mutex_unlock(&em_pd_mutex); + return 0; + +free_runtime_state_table: + kfree(runtime_table->state); +free_runtime_table: + kfree(runtime_table); +unlock_em: + mutex_unlock(&em_pd_mutex); + + return -EINVAL; +} +EXPORT_SYMBOL_GPL(em_dev_update_perf_domain); + 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) @@ -524,6 +619,8 @@ void em_dev_unregister_perf_domain(struct device *dev) * The mutex separates all register/unregister requests and protects * from potential clean-up/setup issues in the debugfs directories. * The debugfs directory name is the same as device's name. + * The lock also protects the updater of the runtime modifiable + * EM and this remover. */ mutex_lock(&em_pd_mutex); @@ -531,9 +628,21 @@ void em_dev_unregister_perf_domain(struct device *dev) tmp = pd->runtime_table; + /* + * Safely destroy runtime modifiable EM. By using the call + * synchronize_rcu() we make sure we don't progress till last user + * finished the RCU section and our update got applied. + */ rcu_assign_pointer(pd->runtime_table, NULL); synchronize_rcu(); + /* + * After the sync no updates will be in-flight, so free the old + * memory. + */ + if (tmp->state != pd->table) + kfree(tmp->state); + kfree(tmp); kfree(dev->em_pd->table); From patchwork Tue Mar 14 10:33:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 69488 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1679063wrd; Tue, 14 Mar 2023 03:40:06 -0700 (PDT) X-Google-Smtp-Source: AK7set89I0dGKWGCLJW7r7o5BLsAit3Ou2I88FytMCvbtI32vX13sjFrPNH0e6AiY33sGu8p11bY X-Received: by 2002:a05:6a20:3d02:b0:bc:42f9:6b21 with SMTP id y2-20020a056a203d0200b000bc42f96b21mr46067949pzi.15.1678790405818; Tue, 14 Mar 2023 03:40:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678790405; cv=none; d=google.com; s=arc-20160816; b=D11atGxHvcvvSgU4EdHeflGtn+5SsCS8T+tFdNu6L4bdf/wYA28xGeUKhOFa+SN2TW NhskwNjVS51ohrC3zApN/7moG0YHDNqlf3DUZK2COXtKwplE0PBOyvk2q1aUtA37IAj0 HbN/HIc6nKyrWDJYOCp+scSOKQasQdEhOlZ8MYDyn22BVZedlgz5Lgp3eljIf4Zf9DZW lBJncfIxIsvuvOu7aLW6e9LCNXBdICeSIhgasgYTCDnF1VOXVMRHdBqVbAxVAyfmhZLN FLGeQaXhW64XFPIMN1cky/E65mkUybQp4xJBgLQJSJ2IAPAXn73jJx9h22RX+iGyauhF dxug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=Q5/hMggK5nUzVk4QLCay3SnYKebNETeA9wwkxbhdego=; b=LFBbrnXKUb5/zW2SdBYlYy9+gtB1TeH8EGkfntMaR9CzcH3JlJOGJINAhUVq3Pudp0 fGUROclZPCYuAHU8Zn2G3qfK4u6gbzORs0i3YdVNxZN8qHult51eytI07tH+AMDZbo96 oZrbnIiImzR17S8WcwuV5cqiFszrGI2EArhxE1ZgAXmDDob/KmFPODqfTnpAv45PB6il Q5TyO5CyNE84AxAHCnMg22merX2uaI2ZoJNLNOusj6dMPy5XCLCF+fwMRvZwyIfLAvtd 5kaZnpldm2PHDoEQiX6ICW7aQRadPmMSiPWGMRSKmhNc5OoMDSKjtN+o3O9F3awUPqZB 2lxQ== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q14-20020aa7982e000000b006222f47503dsi1985421pfl.39.2023.03.14.03.39.53; Tue, 14 Mar 2023 03:40: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 S231145AbjCNKgf (ORCPT + 99 others); Tue, 14 Mar 2023 06:36:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54528 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231267AbjCNKgH (ORCPT ); Tue, 14 Mar 2023 06:36:07 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id EE69494A6B; Tue, 14 Mar 2023 03:35:19 -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 D928C16F8; Tue, 14 Mar 2023 03:35:31 -0700 (PDT) Received: from e123648.arm.com (unknown [10.57.19.101]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 61CC23F71A; Tue, 14 Mar 2023 03:34:45 -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 11/17] PM: EM: Use runtime modified EM for CPUs energy estimation in EAS Date: Tue, 14 Mar 2023 10:33:51 +0000 Message-Id: <20230314103357.26010-12-lukasz.luba@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230314103357.26010-1-lukasz.luba@arm.com> References: <20230314103357.26010-1-lukasz.luba@arm.com> X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760339328720433099?= X-GMAIL-MSGID: =?utf-8?q?1760339328720433099?= The new Energy Model (EM) supports runtime modification of the performance state table to better model the power used by the SoC. Use this new feature to improve energy estimation and therefore task placement in Energy Aware Scheduler (EAS). Signed-off-by: Lukasz Luba --- include/linux/energy_model.h | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/include/linux/energy_model.h b/include/linux/energy_model.h index e1772aa6c843..8e3fa2b6bf28 100644 --- a/include/linux/energy_model.h +++ b/include/linux/energy_model.h @@ -262,6 +262,7 @@ static inline unsigned long em_cpu_energy(struct em_perf_domain *pd, unsigned long max_util, unsigned long sum_util, unsigned long allowed_cpu_cap) { + struct em_perf_table *runtime_table; unsigned long freq, scale_cpu; struct em_perf_state *ps; int cpu, i; @@ -279,7 +280,14 @@ static inline unsigned long em_cpu_energy(struct em_perf_domain *pd, */ cpu = cpumask_first(to_cpumask(pd->cpus)); scale_cpu = arch_scale_cpu_capacity(cpu); - ps = &pd->table[pd->nr_perf_states - 1]; + + /* + * No rcu_read_lock() since it's already called by task scheduler. + * The runtime_table is always there for CPUs, so we don't check. + */ + runtime_table = rcu_dereference(pd->runtime_table); + + ps = &runtime_table->state[pd->nr_perf_states - 1]; max_util = map_util_perf(max_util); max_util = min(max_util, allowed_cpu_cap); @@ -289,9 +297,9 @@ static inline unsigned long em_cpu_energy(struct em_perf_domain *pd, * Find the lowest performance state of the Energy Model above the * requested frequency. */ - i = em_pd_get_efficient_state(pd->table, pd->nr_perf_states, freq, - pd->flags); - ps = &pd->table[i]; + i = em_pd_get_efficient_state(runtime_table->state, pd->nr_perf_states, + freq, pd->flags); + ps = &runtime_table->state[i]; /* * The capacity of a CPU in the domain at the performance state (ps) From patchwork Tue Mar 14 10:33:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 69493 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1680420wrd; Tue, 14 Mar 2023 03:43:52 -0700 (PDT) X-Google-Smtp-Source: AK7set9a7lW6U3L8x+1LXA2YCl0zxzEzFpt7Ir8PJ+f4lMDpuErsElFXm3rsjBOE/plpCllYof5w X-Received: by 2002:a62:6414:0:b0:622:676e:5e8e with SMTP id y20-20020a626414000000b00622676e5e8emr7828117pfb.21.1678790632679; Tue, 14 Mar 2023 03:43:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678790632; cv=none; d=google.com; s=arc-20160816; b=E7ush760sodBn44gZh6Zh+sTV8xGImzk6cZgH/VDTcPRIQ2O8zHW70sYwn+EaBvF5L UQcovGhRsed5W6o0K0EbYDgSLvk8shtcg+wEjpTlQYcp2/wA7OxqaVbDzxAAO3LRBdhk Ey0oZBVH41yyIlqZbe9sBPxwZd+TbLKp7c86rNg+TBFJ7ejwAZ474AY/PowORnAFxfpp aHc8eqKX3ec4lmmbojzWSEx5FDEVftWq6NzqqqnQkQyzsrlROrtH43HTjv+GE23xsT0B 9+3MEz+ZTGVdDAxAXQ57NjcXcJKX8uLREU5d3+NO2vUefTmIrlFY+W+XAH3nkl69GtTM ylcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=nop/RlBWrxEW5OlysN+fd+ZOmOG5n6DE/lxD5vpPl+k=; b=b/y2canVO0FGiR3fYArCGcxSRfOZqsTGiipdeQnt8jKrubBWLNYAmK3KPjQrVgDbr7 C39sZrDKUxDhKlzBGIpXwe82gxNZkLksHfoPjSChtCf+i0FsN3gx/4uZPGeHPs9Wrswu MtrNbUT2PIW+iZQAcKIQHCX+lBWtyfXTFgw7EaBQp0YsChR80tO+UHTF4dWk5wARqR+z fbDSTsU9p+yEUqSjv+TZ9L/gJmhromC7GAoTMZdBbCdBi2C3p1HCwQzZpa1jXr8iLF47 MdGipFaGx5Wy+JsxQlretJzAuOZpMI8+CBi0rFgHDPeE655HAbjOJ2n6xF1TKBJ7RzoG hfpQ== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a5-20020aa794a5000000b005939fff6d47si1839883pfl.326.2023.03.14.03.43.40; Tue, 14 Mar 2023 03:43:52 -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 S231424AbjCNKgl (ORCPT + 99 others); Tue, 14 Mar 2023 06:36:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230280AbjCNKgI (ORCPT ); Tue, 14 Mar 2023 06:36:08 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id F00AB95BD2; Tue, 14 Mar 2023 03:35:19 -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 068F01713; Tue, 14 Mar 2023 03:35:35 -0700 (PDT) Received: from e123648.arm.com (unknown [10.57.19.101]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 841C03F71A; Tue, 14 Mar 2023 03:34:48 -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 12/17] PM: EM: Add argument to get_cost() for runtime modification Date: Tue, 14 Mar 2023 10:33:52 +0000 Message-Id: <20230314103357.26010-13-lukasz.luba@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230314103357.26010-1-lukasz.luba@arm.com> References: <20230314103357.26010-1-lukasz.luba@arm.com> X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760339566698354399?= X-GMAIL-MSGID: =?utf-8?q?1760339566698354399?= The Energy Model (EM) supports runtime modifications. Let also the artificial EM use this new feature and allow to update the 'cost' values at runtime. When the artificial EM is used there is a need to provide two callbacks: get_cost() and update_power(), not only the last one. Update also CPPC driver code, since the new argument is needed there to compile properly and register EM. Signed-off-by: Lukasz Luba --- drivers/cpufreq/cppc_cpufreq.c | 2 +- include/linux/energy_model.h | 7 ++++++- kernel/power/energy_model.c | 9 +++++---- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/drivers/cpufreq/cppc_cpufreq.c b/drivers/cpufreq/cppc_cpufreq.c index 432dfb4e8027..bfbfb7b134ac 100644 --- a/drivers/cpufreq/cppc_cpufreq.c +++ b/drivers/cpufreq/cppc_cpufreq.c @@ -573,7 +573,7 @@ static int cppc_get_cpu_power(struct device *cpu_dev, } static int cppc_get_cpu_cost(struct device *cpu_dev, unsigned long KHz, - unsigned long *cost) + unsigned long *cost, void *priv) { unsigned long perf_step, perf_prev; struct cppc_perf_caps *perf_caps; diff --git a/include/linux/energy_model.h b/include/linux/energy_model.h index 8e3fa2b6bf28..b8506df9af2d 100644 --- a/include/linux/energy_model.h +++ b/include/linux/energy_model.h @@ -162,6 +162,8 @@ struct em_data_callback { * @freq : Frequency at the performance state in kHz * @cost : The cost value for the performance state * (modified) + * @priv : Pointer to private data useful for tracking context + * during run-time modifications of EM. * * In case of CPUs, the cost is the one of a single CPU in the domain. * It is expected to fit in the [0, EM_MAX_POWER] range due to internal @@ -170,7 +172,7 @@ struct em_data_callback { * Return 0 on success, or appropriate error value in case of failure. */ int (*get_cost)(struct device *dev, unsigned long freq, - unsigned long *cost); + unsigned long *cost, void *priv); /** * update_power() - Provide new power at the given performance state of @@ -199,6 +201,9 @@ struct em_data_callback { #define EM_DATA_CB(_active_power_cb) \ EM_ADV_DATA_CB(_active_power_cb, NULL) #define EM_UPDATE_CB(_update_power_cb) { .update_power = &_update_power_cb } +#define EM_ADV_UPDATE_CB(_update_power_cb, _cost_cb) \ + { .update_power = &_update_power_cb, \ + .get_cost = _cost_cb } struct em_perf_domain *em_cpu_get(int cpu); struct em_perf_domain *em_pd_get(struct device *dev); diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c index e0e8fba3d02b..4fcc3b9d63e0 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -168,7 +168,7 @@ static void em_perf_runtime_table_set(struct device *dev, 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 flags, void *priv) { unsigned long prev_cost = ULONG_MAX; u64 fmax; @@ -180,7 +180,8 @@ static int em_compute_costs(struct device *dev, struct em_perf_state *table, unsigned long power_res, cost; if (flags & EM_PERF_DOMAIN_ARTIFICIAL && cb->get_cost) { - ret = cb->get_cost(dev, table[i].frequency, &cost); + ret = cb->get_cost(dev, table[i].frequency, &cost, + priv); if (ret || !cost || cost > EM_MAX_POWER) { dev_err(dev, "EM: invalid cost %lu %d\n", cost, ret); @@ -280,7 +281,7 @@ int em_dev_update_perf_domain(struct device *dev, struct em_data_callback *cb, } ret = em_compute_costs(dev, runtime_table->state, cb, - pd->nr_perf_states, pd->flags); + pd->nr_perf_states, pd->flags, priv); if (ret) goto free_runtime_state_table; @@ -350,7 +351,7 @@ static int em_create_perf_table(struct device *dev, struct em_perf_domain *pd, table[i].frequency = prev_freq = freq; } - ret = em_compute_costs(dev, table, cb, nr_states, flags); + ret = em_compute_costs(dev, table, cb, nr_states, flags, NULL); if (ret) goto free_ps_table; From patchwork Tue Mar 14 10:33:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 69491 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1680096wrd; Tue, 14 Mar 2023 03:42:56 -0700 (PDT) X-Google-Smtp-Source: AK7set8rhmGjthURn0zhEqdlO8ufjGDOkNQhjyjNk0cy3gexgxFJnx76G/4IzDZ2Om+Gk7h3A0PY X-Received: by 2002:a05:6a20:4289:b0:d5:58df:fb5f with SMTP id o9-20020a056a20428900b000d558dffb5fmr2344155pzj.23.1678790576163; Tue, 14 Mar 2023 03:42:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678790576; cv=none; d=google.com; s=arc-20160816; b=A9GhYCaPNYZlzWXloguEZMItt2vV0+jUz3ziQkj41ebRDA+LRHAxftZRq/1lwozVY/ w6sqFtn7dPStUGmSY8UVZo/DAt5rkf/4Eci6+5jSCBuHT8iLjW4ThYuJeBJYGFPkQdJr fCCK+s97VReweBhRbT3D2ter49tBInDip7bOquC94vyByqXc6khhYIsEhEtZKpsJrxmP wiu8tVtlcUj/y1L0ooaPyTKbzAKio7rXcuYelCpiv7Pag/H6A9FxKuncTJzbB5KU8uM2 /qNSMNVeqh5vXaS6GFKQXjaMC9O+0fOkNofN+c/JyvYvNP17a2j2skn4Eq8BzxqkLqFb EeEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=GeIP+DKazG9hgS+NXLYf3zuKXQkc64NeOyikxeKHsfw=; b=OvNUlkv/Zn4aoA0bKa8aJkpx//95AZL2qFBH+VqGT1GkHepKG+6QO4j2UXOs7lKJ1A aP8O2Wyx0uawudOQJ3/emvrBe956aCX0eIQlANVLXR90gy2LmmoxFK9Y9PmZZSHnmNUk EP0bXdaLEsRvSVp7qTYwmmp7NpIevFrx7eQ5MxFicFH1NoQE88MJ0aks/aASJDw/ZLVU rH2nTeG+f/94CxxXvJJowa7K5P3R11HATRgqsZCY7YarVE3el3zlr6SGJdKys8q3I8D6 ftc09GwHj8ncIXWxEsJSgYAxhgec6IH8lhEfZgOmaM4V5MF09sPc4PNae52b17AQDwtq GQ1g== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y5-20020a63fa05000000b00502e4103888si1943937pgh.801.2023.03.14.03.42.42; Tue, 14 Mar 2023 03:42:56 -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 S230428AbjCNKgu (ORCPT + 99 others); Tue, 14 Mar 2023 06:36:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53472 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230447AbjCNKgJ (ORCPT ); Tue, 14 Mar 2023 06:36:09 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4DDDA9884C; Tue, 14 Mar 2023 03:35:20 -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 560D11AED; Tue, 14 Mar 2023 03:35:38 -0700 (PDT) Received: from e123648.arm.com (unknown [10.57.19.101]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id A7B403F71A; Tue, 14 Mar 2023 03:34:51 -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 13/17] PM: EM: Refactor struct em_perf_domain and add default_table Date: Tue, 14 Mar 2023 10:33:53 +0000 Message-Id: <20230314103357.26010-14-lukasz.luba@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230314103357.26010-1-lukasz.luba@arm.com> References: <20230314103357.26010-1-lukasz.luba@arm.com> X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760339507585656940?= X-GMAIL-MSGID: =?utf-8?q?1760339507585656940?= The Energy Model support runtime modifications. Refactor old implementation which accessed struct em_perf_state and introduce em_perf_domain::default_table to clean up the design. This new field is better aligned with em_perf_domain::runtime_table and helps to distinguish them better. Update all drivers or frameworks which used the old field: em_perf_domain::table and now should use em_perf_domain::default_table. Signed-off-by: Lukasz Luba --- drivers/powercap/dtpm_cpu.c | 27 ++++++++++++++++++-------- drivers/powercap/dtpm_devfreq.c | 23 +++++++++++++++------- drivers/thermal/cpufreq_cooling.c | 23 ++++++++++++++-------- drivers/thermal/devfreq_cooling.c | 23 ++++++++++++++++------ include/linux/energy_model.h | 4 ++-- kernel/power/energy_model.c | 32 ++++++++++++++++++++++--------- 6 files changed, 92 insertions(+), 40 deletions(-) diff --git a/drivers/powercap/dtpm_cpu.c b/drivers/powercap/dtpm_cpu.c index 2ff7717530bf..743a0ac8ecdf 100644 --- a/drivers/powercap/dtpm_cpu.c +++ b/drivers/powercap/dtpm_cpu.c @@ -43,6 +43,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; @@ -51,19 +52,21 @@ 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); + table = pd->default_table->state; + 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; freq_qos_update_request(&dtpm_cpu->qos_req, freq); - power_limit = pd->table[i - 1].power * nr_cpus; + power_limit = table[i - 1].power * nr_cpus; return power_limit; } @@ -88,12 +91,14 @@ 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; int i; pd = em_cpu_get(dtpm_cpu->cpu); + table = pd->default_table->state; pd_mask = em_span_cpus(pd); @@ -101,10 +106,10 @@ static u64 get_pd_power_uw(struct dtpm *dtpm) 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 * + return scale_pd_power_uw(pd_mask, table[i].power * MICROWATT_PER_MILLIWATT); } @@ -115,17 +120,20 @@ 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; + table = em->default_table->state; + + dtpm->power_min = table[0].power; dtpm->power_min *= MICROWATT_PER_MILLIWATT; 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 *= MICROWATT_PER_MILLIWATT; dtpm->power_max *= nr_cpus; @@ -182,6 +190,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; @@ -198,6 +207,8 @@ static int __dtpm_cpu_setup(int cpu, struct dtpm *parent) if (!pd || em_is_artificial(pd)) return -EINVAL; + table = pd->default_table->state; + dtpm_cpu = kzalloc(sizeof(*dtpm_cpu), GFP_KERNEL); if (!dtpm_cpu) return -ENOMEM; @@ -216,7 +227,7 @@ static int __dtpm_cpu_setup(int cpu, struct dtpm *parent) 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); if (ret) goto out_dtpm_unregister; diff --git a/drivers/powercap/dtpm_devfreq.c b/drivers/powercap/dtpm_devfreq.c index 91276761a31d..6ef0f2b4a683 100644 --- a/drivers/powercap/dtpm_devfreq.c +++ b/drivers/powercap/dtpm_devfreq.c @@ -37,11 +37,14 @@ static int update_pd_power_uw(struct dtpm *dtpm) struct devfreq *devfreq = dtpm_devfreq->devfreq; struct device *dev = devfreq->dev.parent; struct em_perf_domain *pd = em_pd_get(dev); + struct em_perf_state *table; - dtpm->power_min = pd->table[0].power; + table = pd->default_table->state; + + dtpm->power_min = table[0].power; dtpm->power_min *= MICROWATT_PER_MILLIWATT; - dtpm->power_max = pd->table[pd->nr_perf_states - 1].power; + dtpm->power_max = table[pd->nr_perf_states - 1].power; dtpm->power_max *= MICROWATT_PER_MILLIWATT; return 0; @@ -53,22 +56,25 @@ static u64 set_pd_power_limit(struct dtpm *dtpm, u64 power_limit) struct devfreq *devfreq = dtpm_devfreq->devfreq; struct device *dev = devfreq->dev.parent; struct em_perf_domain *pd = em_pd_get(dev); + struct em_perf_state *table; unsigned long freq; u64 power; int i; + table = pd->default_table->state; + for (i = 0; i < pd->nr_perf_states; i++) { - power = pd->table[i].power * MICROWATT_PER_MILLIWATT; + power = table[i].power * MICROWATT_PER_MILLIWATT; if (power > power_limit) break; } - freq = pd->table[i - 1].frequency; + freq = table[i - 1].frequency; dev_pm_qos_update_request(&dtpm_devfreq->qos_req, freq); - power_limit = pd->table[i - 1].power * MICROWATT_PER_MILLIWATT; + power_limit = table[i - 1].power * MICROWATT_PER_MILLIWATT; return power_limit; } @@ -94,6 +100,7 @@ static u64 get_pd_power_uw(struct dtpm *dtpm) struct device *dev = devfreq->dev.parent; struct em_perf_domain *pd = em_pd_get(dev); struct devfreq_dev_status status; + struct em_perf_state *table; unsigned long freq; u64 power; int i; @@ -102,15 +109,17 @@ static u64 get_pd_power_uw(struct dtpm *dtpm) status = devfreq->last_status; mutex_unlock(&devfreq->lock); + table = pd->default_table->state; + freq = DIV_ROUND_UP(status.current_frequency, HZ_PER_KHZ); _normalize_load(&status); for (i = 0; i < pd->nr_perf_states; i++) { - if (pd->table[i].frequency < freq) + if (table[i].frequency < freq) continue; - power = pd->table[i].power * MICROWATT_PER_MILLIWATT; + power = table[i].power * MICROWATT_PER_MILLIWATT; power *= status.busy_time; power >>= 10; diff --git a/drivers/thermal/cpufreq_cooling.c b/drivers/thermal/cpufreq_cooling.c index 9f8b438fcf8f..012ebaf6ea96 100644 --- a/drivers/thermal/cpufreq_cooling.c +++ b/drivers/thermal/cpufreq_cooling.c @@ -91,10 +91,11 @@ struct cpufreq_cooling_device { static unsigned long get_level(struct cpufreq_cooling_device *cpufreq_cdev, unsigned int freq) { + struct em_perf_state *table = cpufreq_cdev->em->default_table->state; int i; for (i = cpufreq_cdev->max_level - 1; i >= 0; i--) { - if (freq > cpufreq_cdev->em->table[i].frequency) + if (freq > table[i].frequency) break; } @@ -104,15 +105,16 @@ static unsigned long get_level(struct cpufreq_cooling_device *cpufreq_cdev, static u32 cpu_freq_to_power(struct cpufreq_cooling_device *cpufreq_cdev, u32 freq) { + struct em_perf_state *table = cpufreq_cdev->em->default_table->state; unsigned long power_mw; int i; for (i = cpufreq_cdev->max_level - 1; i >= 0; i--) { - if (freq > cpufreq_cdev->em->table[i].frequency) + if (freq > table[i].frequency) break; } - power_mw = cpufreq_cdev->em->table[i + 1].power; + power_mw = table[i + 1].power; power_mw /= MICROWATT_PER_MILLIWATT; return power_mw; @@ -121,18 +123,19 @@ static u32 cpu_freq_to_power(struct cpufreq_cooling_device *cpufreq_cdev, static u32 cpu_power_to_freq(struct cpufreq_cooling_device *cpufreq_cdev, u32 power) { + struct em_perf_state *table = cpufreq_cdev->em->default_table->state; unsigned long em_power_mw; int i; for (i = cpufreq_cdev->max_level; i > 0; i--) { /* Convert EM power to milli-Watts to make safe comparison */ - em_power_mw = cpufreq_cdev->em->table[i].power; + em_power_mw = table[i].power; em_power_mw /= MICROWATT_PER_MILLIWATT; if (power >= em_power_mw) break; } - return cpufreq_cdev->em->table[i].frequency; + return table[i].frequency; } /** @@ -262,8 +265,9 @@ static int cpufreq_get_requested_power(struct thermal_cooling_device *cdev, static int cpufreq_state2power(struct thermal_cooling_device *cdev, unsigned long state, u32 *power) { - unsigned int freq, num_cpus, idx; struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata; + unsigned int freq, num_cpus, idx; + struct em_perf_state *table; /* Request state should be less than max_level */ if (state > cpufreq_cdev->max_level) @@ -271,8 +275,9 @@ static int cpufreq_state2power(struct thermal_cooling_device *cdev, num_cpus = cpumask_weight(cpufreq_cdev->policy->cpus); + table = cpufreq_cdev->em->default_table->state; idx = cpufreq_cdev->max_level - state; - freq = cpufreq_cdev->em->table[idx].frequency; + freq = table[idx].frequency; *power = cpu_freq_to_power(cpufreq_cdev, freq) * num_cpus; return 0; @@ -373,13 +378,15 @@ static unsigned int get_state_freq(struct cpufreq_cooling_device *cpufreq_cdev, unsigned long state) { struct cpufreq_policy *policy; + struct em_perf_state *table; unsigned long idx; #ifdef CONFIG_THERMAL_GOV_POWER_ALLOCATOR /* Use the Energy Model table if available */ if (cpufreq_cdev->em) { + table = cpufreq_cdev->em->default_table->state; idx = cpufreq_cdev->max_level - state; - return cpufreq_cdev->em->table[idx].frequency; + return table[idx].frequency; } #endif diff --git a/drivers/thermal/devfreq_cooling.c b/drivers/thermal/devfreq_cooling.c index 24b474925cd6..01187a5848ac 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; @@ -99,8 +100,9 @@ static int devfreq_cooling_set_cur_state(struct thermal_cooling_device *cdev, return -EINVAL; if (dfc->em_pd) { + table = dfc->em_pd->default_table->state; perf_idx = dfc->max_state - state; - freq = dfc->em_pd->table[perf_idx].frequency * 1000; + freq = table[perf_idx].frequency * 1000; } else { freq = dfc->freq_table[state]; } @@ -123,10 +125,11 @@ 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) { + struct em_perf_state *table = em_pd->default_table->state; int i; for (i = 0; i < em_pd->nr_perf_states; i++) { - if (em_pd->table[i].frequency == freq) + if (table[i].frequency == freq) return i; } @@ -181,6 +184,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; @@ -192,6 +196,8 @@ static int devfreq_cooling_get_requested_power(struct thermal_cooling_device *cd freq = status.current_frequency; + table = dfc->em_pd->default_table->state; + if (dfc->power_ops && dfc->power_ops->get_real_power) { voltage = get_voltage(df, freq); if (voltage == 0) { @@ -204,7 +210,7 @@ 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; + dfc->res_util = table[state].power; dfc->res_util /= MICROWATT_PER_MILLIWATT; dfc->res_util *= SCALE_ERROR_MITIGATION; @@ -225,7 +231,7 @@ 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; + *power = table[perf_idx].power; *power /= MICROWATT_PER_MILLIWATT; /* Scale power for utilization */ *power *= status.busy_time; @@ -245,13 +251,15 @@ 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; + table = dfc->em_pd->default_table->state; perf_idx = dfc->max_state - state; - *power = dfc->em_pd->table[perf_idx].power; + *power = table[perf_idx].power; *power /= MICROWATT_PER_MILLIWATT; return 0; @@ -264,6 +272,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; @@ -273,6 +282,8 @@ static int devfreq_cooling_power2state(struct thermal_cooling_device *cdev, freq = status.current_frequency; + table = dfc->em_pd->default_table->state; + if (dfc->power_ops && dfc->power_ops->get_real_power) { /* Scale for resource utilization */ est_power = power * dfc->res_util; @@ -290,7 +301,7 @@ static int devfreq_cooling_power2state(struct thermal_cooling_device *cdev, */ 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; diff --git a/include/linux/energy_model.h b/include/linux/energy_model.h index b8506df9af2d..eb28920b1b2c 100644 --- a/include/linux/energy_model.h +++ b/include/linux/energy_model.h @@ -49,7 +49,7 @@ struct em_perf_table { /** * struct em_perf_domain - Performance domain - * @table: List of performance states, in ascending order + * @default_table: Pointer to the default em_perf_table * @runtime_table: Pointer to the runtime modified em_perf_table * @nr_perf_states: Number of performance states * @flags: See "em_perf_domain flags" @@ -65,7 +65,7 @@ struct em_perf_table { * field is unused. */ struct em_perf_domain { - struct em_perf_state *table; + struct em_perf_table *default_table; struct em_perf_table __rcu *runtime_table; int nr_perf_states; unsigned long flags; diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c index 4fcc3b9d63e0..e981be27d2d4 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -72,6 +72,7 @@ DEFINE_SHOW_ATTRIBUTE(em_debug_flags); static void em_debug_create_pd(struct device *dev) { + struct em_perf_table *table = dev->em_pd->default_table; struct dentry *d; int i; @@ -87,7 +88,7 @@ static void em_debug_create_pd(struct device *dev) /* Create a sub-directory for each performance state */ for (i = 0; i < dev->em_pd->nr_perf_states; i++) - em_debug_create_ps(&dev->em_pd->table[i], d); + em_debug_create_ps(&table->state[i], d); } @@ -160,7 +161,7 @@ static void em_perf_runtime_table_set(struct device *dev, * Check if the 'state' array is not actually the one from setup. * If it is then don't free it. */ - if (tmp->state == pd->table) + if (tmp->state == pd->default_table->state) call_rcu(&tmp->rcu, em_destroy_tmp_setup_rcu); else call_rcu(&tmp->rcu, em_destroy_rt_table_rcu); @@ -264,7 +265,7 @@ int em_dev_update_perf_domain(struct device *dev, struct em_data_callback *cb, /* Populate runtime table with updated values using driver callback */ for (i = 0; i < pd->nr_perf_states; i++) { - freq = pd->table[i].frequency; + freq = pd->default_table->state[i].frequency; runtime_table->state[i].frequency = freq; /* @@ -355,7 +356,7 @@ static int em_create_perf_table(struct device *dev, struct em_perf_domain *pd, if (ret) goto free_ps_table; - pd->table = table; + pd->default_table->state = table; pd->nr_perf_states = nr_states; return 0; @@ -369,7 +370,7 @@ static int em_create_pd(struct device *dev, int nr_states, struct em_data_callback *cb, cpumask_t *cpus, unsigned long flags) { - struct em_perf_table *runtime_table; + struct em_perf_table *default_table, *runtime_table; struct em_perf_domain *pd; struct device *cpu_dev; int cpu, ret, num_cpus; @@ -394,21 +395,31 @@ static int em_create_pd(struct device *dev, int nr_states, return -ENOMEM; } + default_table = kzalloc(sizeof(*default_table), GFP_KERNEL); + if (!default_table) { + kfree(pd); + return -ENOMEM; + } + runtime_table = kzalloc(sizeof(*runtime_table), GFP_KERNEL); if (!runtime_table) { kfree(pd); + kfree(default_table); return -ENOMEM; } + pd->default_table = default_table; + ret = em_create_perf_table(dev, pd, nr_states, cb, flags); if (ret) { kfree(pd); + kfree(default_table); kfree(runtime_table); return ret; } /* Re-use temporally (till 1st modification) the memory */ - runtime_table->state = pd->table; + runtime_table->state = pd->default_table->state; rcu_assign_pointer(pd->runtime_table, runtime_table); if (_is_cpu_device(dev)) @@ -529,6 +540,7 @@ int em_dev_register_perf_domain(struct device *dev, unsigned int nr_states, bool microwatts) { unsigned long cap, prev_cap = 0; + struct em_perf_state *table; unsigned long flags = 0; int cpu, ret; @@ -587,7 +599,8 @@ int em_dev_register_perf_domain(struct device *dev, unsigned int nr_states, dev->em_pd->flags |= flags; - em_cpufreq_update_efficiencies(dev, dev->em_pd->table); + table = dev->em_pd->default_table->state; + em_cpufreq_update_efficiencies(dev, table); em_debug_create_pd(dev); dev_info(dev, "EM: created perf domain\n"); @@ -641,12 +654,13 @@ void em_dev_unregister_perf_domain(struct device *dev) * After the sync no updates will be in-flight, so free the old * memory. */ - if (tmp->state != pd->table) + if (tmp->state != pd->default_table->state) kfree(tmp->state); kfree(tmp); - kfree(dev->em_pd->table); + kfree(pd->default_table->state); + kfree(pd->default_table); kfree(dev->em_pd); dev->em_pd = NULL; mutex_unlock(&em_pd_mutex); From patchwork Tue Mar 14 10:33:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 69490 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1679078wrd; Tue, 14 Mar 2023 03:40:08 -0700 (PDT) X-Google-Smtp-Source: AK7set+jL2TgXhSgGreTCwKE8pETD2nloKihyIwQlZBi+9Vfvw8ye35/vRRpN4ZQoKh22Oe58Z6D X-Received: by 2002:a05:6a20:7f9c:b0:cc:aa7b:84e1 with SMTP id d28-20020a056a207f9c00b000ccaa7b84e1mr49385876pzj.21.1678790407991; Tue, 14 Mar 2023 03:40:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678790407; cv=none; d=google.com; s=arc-20160816; b=nzXQfPMALJQmmmpwcZct0bQFdW4lLFaJH0xnLRjQBQxI+wVVq/GoHzPg0gKbgNWoBH sihzUYAFb72he5kbydQJ3yOOXwoDMqZOG+Gw1XG74KCsMQXKl/39gnY3mrc9CdoQP97z LcKFCwoM651N5jNg9BkGB0VpX7H3pWd5qxI9hQ3B8KDpH73xvq/wghiF7luo2mI9I9ss iaP2q491WjgHX5XKb+7CQIpGlnNyQuH2Dyqe08uaR3jvFrc0rDiZA8UvRq725p3H70Gc Mf/qZXxN/gGVazB5qB19vnfdPPFUy04lQ+kNS5gIJj2aKX/TGFrlO2vyTXWlbgnsfmhF unRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=8Jl9GUqrpGJG7ViAe4w39oMHaSGc3UT6rMtUFf/gsVY=; b=bM0fLjvEKjv5tZqkATOn0IxXz52jD5wRYBtCKj1j4i70WF/AdUEEdRBts8x0xb6/6N 10xlCoDWJQodMxWOCz9lmIheacyIjf3pyOE+ZYf+Dx+gVsQrG2E5wFisK8MDEkcY6Tta MsOqEz2e+V9xoZ24Z1SmH6xMFW0N+rjrKM0c2GhZlzbyHTodU7SC4XIq6Ka6mISrqqxr tYscXs9KNbUxoLaWmgjJCmUaCQz5068WDPhh0R50unYfuG2CwOUP4gSgAkfjVxOLKH32 1Z9DRIMUcuYK6Jd0SGqQxUgR8C3BANbYTQS1SaQrY8nPYk/FqdDxXnjkFOW3ofC4r0p+ FoiA== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y15-20020a63494f000000b0050bd14260adsi566347pgk.235.2023.03.14.03.39.55; Tue, 14 Mar 2023 03:40:07 -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 S231420AbjCNKgi (ORCPT + 99 others); Tue, 14 Mar 2023 06:36:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54538 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230270AbjCNKgH (ORCPT ); Tue, 14 Mar 2023 06:36:07 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5AF449884D; Tue, 14 Mar 2023 03:35:20 -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 7A6901BA8; Tue, 14 Mar 2023 03:35:41 -0700 (PDT) Received: from e123648.arm.com (unknown [10.57.19.101]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 012C33F71A; Tue, 14 Mar 2023 03:34:54 -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 14/17] Documentation: EM: Add a new section about the design Date: Tue, 14 Mar 2023 10:33:54 +0000 Message-Id: <20230314103357.26010-15-lukasz.luba@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230314103357.26010-1-lukasz.luba@arm.com> References: <20230314103357.26010-1-lukasz.luba@arm.com> X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760339330621438961?= X-GMAIL-MSGID: =?utf-8?q?1760339330621438961?= Add a new section 'Design' which covers the information about Energy Model. It contains the design decisions, describes models and how they reflect the reality. Add description of the basic const. EM. Change the other section IDs. Signed-off-by: Lukasz Luba --- Documentation/power/energy-model.rst | 36 +++++++++++++++++++++------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/Documentation/power/energy-model.rst b/Documentation/power/energy-model.rst index ef341be2882b..e97c7f18d8bd 100644 --- a/Documentation/power/energy-model.rst +++ b/Documentation/power/energy-model.rst @@ -72,16 +72,34 @@ required to have the same micro-architecture. CPUs in different performance domains can have different micro-architectures. -2. Core APIs +2. Design +----------------- + +2.1 Basic EM +^^^^^^^^^^^^ + +The basic EM is built around const. power information for each performance +state. This model can be derived based on power measurements of the device +e.g. CPU while running some benchmark. The benchmark might be integer heavy +or floating point computation with a data set fitting into the CPU cache or +registers. Bare in mind that this model might not be covering all possible +workloads running on CPUs. Thus, please run a few different benchmarks and +verify with some real workloads your power model values. The power variation +due to the workload instruction mix and data set is not modeled. +Also static power which can change during runtime due to variation of SOC +temperature is not modeled in EM. + + +3. Core APIs ------------ -2.1 Config options +3.1 Config options ^^^^^^^^^^^^^^^^^^ CONFIG_ENERGY_MODEL must be enabled to use the EM framework. -2.2 Registration of performance domains +3.2 Registration of performance domains ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Registration of 'advanced' EM @@ -110,8 +128,8 @@ The last argument 'microwatts' is important to set with correct value. Kernel subsystems which use EM might rely on this flag to check if all EM devices use the same scale. If there are different scales, these subsystems might decide to return warning/error, stop working or panic. -See Section 3. for an example of driver implementing this -callback, or Section 2.4 for further documentation on this API +See Section 4. for an example of driver implementing this +callback, or Section 3.4 for further documentation on this API Registration of EM using DT ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -156,7 +174,7 @@ The EM which is registered using this method might not reflect correctly the physics of a real device, e.g. when static power (leakage) is important. -2.3 Accessing performance domains +3.3 Accessing performance domains ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ There are two API functions which provide the access to the energy model: @@ -175,10 +193,10 @@ CPUfreq governor is in use in case of CPU device. Currently this calculation is not provided for other type of devices. More details about the above APIs can be found in ```` -or in Section 2.4 +or in Section 3.4 -2.4 Description details of this API +3.4 Description details of this API ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. kernel-doc:: include/linux/energy_model.h :internal: @@ -187,7 +205,7 @@ or in Section 2.4 :export: -3. Example driver +4. Example driver ----------------- The CPUFreq framework supports dedicated callback for registering From patchwork Tue Mar 14 10:33:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 69485 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1678783wrd; Tue, 14 Mar 2023 03:39:20 -0700 (PDT) X-Google-Smtp-Source: AK7set8kKcDbfVU1Qau7qnmR4usJY3Ef3xU4Ot6iq6kPazlV5DoqcJNXIgl5zjZxfQQtlMLOnPkX X-Received: by 2002:a62:65c1:0:b0:5cd:d766:8a2b with SMTP id z184-20020a6265c1000000b005cdd7668a2bmr32285341pfb.6.1678790359883; Tue, 14 Mar 2023 03:39:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678790359; cv=none; d=google.com; s=arc-20160816; b=I+XLsstPR+bigy+mkjYwvoB8lYAlfqPo0b8lLKWAoHbpBWFMwE6wrAzjdGo2sog9Pj kEuGDXRFBwzEnzCHNOyMd9xtYF29V6h9vWSpU0LFOSK6V8SyPuyRFWqKJJWEnx3zeHoz XcHWoJfxrwG9yuIgOxDYixeqsBdn2cQK8Pf7ooRsHdGf8hqpq/SZd1YW3MQqUDhv4bqQ g3cFqL/YFWOL7bKDVX5msqDtwhdoUjbmWFSgtYEToVZUU4ogzgMl1/JL0IhGx2yEXUzC JSrshvAGlu94pF9plTkwJpnjkoMelzaVaz35PDdh+YgLVyBTUNe3fT/lJ1CCipSfAwIL gxhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=/pI+6YHizuK8PF4WBPmJXI3lbbqx1UD6jHpGpgCzdM8=; b=G5z6Mxlu1ExnLMdimvVsl/1VvzirWTE0uLE/24YUl2ZUQp459nNFET39hSbjcKvrPz aKqV+FT9hEYQSk2nX2gjT0beBNkAKPwZj89rPzRU7kLx0DiXHr5HXWfg1rW0LC2UhadM zwO+zbGvQwus27tTUym0XGGNB4V7phKyWTWPQXBarREUnD5Y0ZfrjdGrzzel/Gpxj/57 hUREJYqj+SR3P2TM1eO2e52OtOskpnVZ4mQA+tVDLMcbzP9qhnekj2ZTFlrj77DvYVgt 613x3JGqMJlv+NtycOEDppU0Ry+EQcKttghji2g3kIrbsDkY9UODCfGb7HR5hN7FJsY6 Oi9Q== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v15-20020aa799cf000000b006257a5672afsi389744pfi.380.2023.03.14.03.39.07; Tue, 14 Mar 2023 03:39:19 -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 S230212AbjCNKhK (ORCPT + 99 others); Tue, 14 Mar 2023 06:37:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231366AbjCNKgT (ORCPT ); Tue, 14 Mar 2023 06:36:19 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 968019BE3C; Tue, 14 Mar 2023 03:35:49 -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 9D4D21BB0; Tue, 14 Mar 2023 03:35:44 -0700 (PDT) Received: from e123648.arm.com (unknown [10.57.19.101]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 26CC23F71A; Tue, 14 Mar 2023 03:34:57 -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 15/17] Documentation: EM: Add a runtime modifiable EM design description Date: Tue, 14 Mar 2023 10:33:55 +0000 Message-Id: <20230314103357.26010-16-lukasz.luba@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230314103357.26010-1-lukasz.luba@arm.com> References: <20230314103357.26010-1-lukasz.luba@arm.com> X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760339280169986661?= X-GMAIL-MSGID: =?utf-8?q?1760339280169986661?= Document the new runtime modifiable EM design and how it can be used. Change the last section layout and allow to provide another example how to use this new API in a driver code. Signed-off-by: Lukasz Luba --- Documentation/power/energy-model.rst | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Documentation/power/energy-model.rst b/Documentation/power/energy-model.rst index e97c7f18d8bd..64c2462dc9a6 100644 --- a/Documentation/power/energy-model.rst +++ b/Documentation/power/energy-model.rst @@ -89,6 +89,26 @@ due to the workload instruction mix and data set is not modeled. Also static power which can change during runtime due to variation of SOC temperature is not modeled in EM. +2.2 Runtime modifiable EM +^^^^^^^^^^^^^^^^^^^^^^^^^ + +To better reflect power variation due to static power (leakage) the EM +supports runtime modifications of the power values. The mechanism relies on +RCU to free the modifiable EM perf_state table memory. Its user, the task +scheduler, also uses RCU to access this memory. The EM framework is +responsible for allocating the new memory for the modifiable EM perf_state +table. The old memory is freed automatically using RCU callback mechanism. +This design decision is made based on task scheduler using that data and +to prevent wrong usage of kernel modules if they would be responsible for the +memory management. +The drivers which want to modify the EM values are protected from concurrent +access using a mutex. Therefore, the drivers must use sleeping context when +they want to modify the EM. The runtime modifiable EM might also be used for +better reflecting real workload scenarios, e.g. when they pop-up on the screen +and will run for longer period, such as: games, video recoding or playing, +video calls, etc. It is up to the platform engineers to experiment and choose +the right approach for their device. + 3. Core APIs ------------ From patchwork Tue Mar 14 10:33:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 69497 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1685335wrd; Tue, 14 Mar 2023 03:58:46 -0700 (PDT) X-Google-Smtp-Source: AK7set/5uTkQvqcayo/E7waa16OfwSYpr/7lNCtio/vAEfdqdOmj+OtoBPUrvgDBUyl5aNuMMK/4 X-Received: by 2002:a17:902:a9c6:b0:19e:872b:e844 with SMTP id b6-20020a170902a9c600b0019e872be844mr30561807plr.40.1678791526552; Tue, 14 Mar 2023 03:58:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678791526; cv=none; d=google.com; s=arc-20160816; b=Ab1y4Z5KKP0QDDRvc+u7ak7iijWQesoBcdRIm9SMII24fEGPEP+agujKpJtK/e2d8t o5uwBWam+KWGFWrWnWwwTl3t4Tq9MUofTHn0JjlATjXwMjoPGRtZbXh+Ejwz+2z69J1J ht3aVGfmLhO4Cjp5QDmdFky4VcDSjeK0BHmuufGNGoWYfWgk1zQ0GNTHGVzCj/X54XdP r6EybVsSYlWMjgN3PZd0Nl+TAbIX3dZ56SZ6hEwEOOskiNtKtqbDuO9CmrjShblsHuP/ u0F7YOO4UvzCNRU6fZ2856uzz/wpe3QYPhaQuQUuRnshsPWZ+ccDDacLR3kRO/UGTh73 i9iQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=1/YZw9uRU8pmvcEDbehdXDRdIQathzsGcQXMxfOJFt0=; b=SjSsONnqHxk3NOMUIuzdIMcjQk9J+0LZEAz24bPsMRU2tOMDu7JGG+eKzSJ8RScdWc 7fmo53l2hmKGKLvdb8bbn7FAl01XvQAXiLKiV8XBqrcoiGqmVBRytXprkcIsgmloQZBh uz5ORFlJZtXOHfxzZzh1uZEDBSVf1uhaZpyobrmSAH6wv8F9DsRkLm8kCH24orsluWZK KaOS0rSgl7MLbqVNuygkruqaxTmDpNOL89ny/fzLOqrwEJqmHN/TA/FQZ+WiKlJ4wlfO f02eit46lshVCQeax0gzRnc32UmVnDD4O2Wqer9vW2uqI23M9UvJA5mibTuvic+xhEPB /WIg== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q32-20020a631f60000000b004fd51160160si1867849pgm.130.2023.03.14.03.58.33; Tue, 14 Mar 2023 03:58:46 -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 S229749AbjCNKnD (ORCPT + 99 others); Tue, 14 Mar 2023 06:43:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41246 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229793AbjCNKmi (ORCPT ); Tue, 14 Mar 2023 06:42:38 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 61B05170A; Tue, 14 Mar 2023 03:42:04 -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 C32C64B3; Tue, 14 Mar 2023 03:35:47 -0700 (PDT) Received: from e123648.arm.com (unknown [10.57.19.101]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 4B88B3F71A; Tue, 14 Mar 2023 03:35:01 -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 16/17] Documentation: EM: Add example with driver modifying the EM Date: Tue, 14 Mar 2023 10:33:56 +0000 Message-Id: <20230314103357.26010-17-lukasz.luba@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230314103357.26010-1-lukasz.luba@arm.com> References: <20230314103357.26010-1-lukasz.luba@arm.com> X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760340503775489086?= X-GMAIL-MSGID: =?utf-8?q?1760340503775489086?= The Energy Model (EM) support runtime modifications. Add description with example driver code which updates EM. Signed-off-by: Lukasz Luba --- Documentation/power/energy-model.rst | 53 ++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/Documentation/power/energy-model.rst b/Documentation/power/energy-model.rst index 64c2462dc9a6..a6ceeeb72868 100644 --- a/Documentation/power/energy-model.rst +++ b/Documentation/power/energy-model.rst @@ -225,8 +225,11 @@ or in Section 3.4 :export: -4. Example driver ------------------ +4. Examples +----------- + +4.1 Example driver with EM registration +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ The CPUFreq framework supports dedicated callback for registering the EM for a given CPU(s) 'policy' object: cpufreq_driver::register_em(). @@ -280,3 +283,49 @@ EM framework:: 39 static struct cpufreq_driver foo_cpufreq_driver = { 40 .register_em = foo_cpufreq_register_em, 41 }; + + +4.2 Example driver with EM modification +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +This section provides a simple example of a thermal driver modifying the EM. +The driver implements a foo_mod_power() function to be provided to the +EM framework. The driver is woken up periodically to check the temperature +and modify the EM data if needed:: + + -> drivers/thermal/foo_thermal.c + + 01 static int foo_mod_power(struct device *dev, unsigned long freq, + 02 unsigned long *power, void *priv) + 03 { + 04 struct foo_context *ctx = priv; + 05 + 06 /* Estimate power for the given frequency and temperature */ + 07 *power = foo_estimate_power(dev, freq, ctx->temperature); + 08 if (*power >= EM_MAX_POWER); + 09 return -EINVAL; + 10 + 11 return 0; + 12 } + 13 + 14 /* + 15 * Function called periodically to check the temperature and + 16 * update the EM if needed + 17 */ + 18 static void foo_thermal_em_update(struct foo_context *ctx) + 19 { + 20 struct em_data_callback em_cb = EM_UPDATE_CB(mod_power); + 21 struct cpufreq_policy *policy = ctx->policy; + 22 struct device *cpu_dev; + 23 + 24 cpu_dev = get_cpu_device(cpumask_first(policy->cpus)); + 25 + 26 ctx->temperature = foo_get_temp(cpu_dev, ctx); + 27 if (ctx->temperature < FOO_EM_UPDATE_TEMP_THRESHOLD) + 28 return; + 29 + 30 /* Update EM for the CPUs' performance domain */ + 31 ret = em_dev_update_perf_domain(cpu_dev, &em_cb, ctx); + 32 if (ret) + 33 pr_warn("foo_thermal: EM update failed\n"); + 34 } From patchwork Tue Mar 14 10:33:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 69486 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1678835wrd; Tue, 14 Mar 2023 03:39:28 -0700 (PDT) X-Google-Smtp-Source: AK7set8rqGUDelYsCrn+NRJd8J1TRQ5aS96ee3gzwFcQZ6N1jpZ1FUT9cflkTPV2/bil00/IqCOW X-Received: by 2002:a17:90b:3881:b0:234:b082:48a2 with SMTP id mu1-20020a17090b388100b00234b08248a2mr38799503pjb.28.1678790368718; Tue, 14 Mar 2023 03:39:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678790368; cv=none; d=google.com; s=arc-20160816; b=n1AddBHqSoIFqccqzMMeZbLZiATnbVdlIcFvxTUTiTDIAqrpoq50wnBrp8ILu5KtAe itvnJiV6qe47Uq9mYxVe2vE+L6atcgCp6udnLHD9QZuOjRLHm9xBuqebs6FDNmFD84Eb t7btIO55+GyaS+L1NoMFHOkDXawAD9mQO/8Jy16g16hivV+DRZ2D/08bwECbgjBaatQ5 GZugQBqWVCF7agV3rzxYgP2UgOoxbFZlaN6YBVa/ihaGkHgTdjmNja0iHEjI8cHbyXen fvVFGOidWfg+SJ4+U4w67E6GGony5MZh5jLbJ0UDIGU+yjMxtiRPa1GGwuGsmspFmO1v Rd8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=mkQ0Vzv4K08WTljXAtqXXMEGMsKQdPZsNZYBMjKkoSE=; b=a7CgrUt7viGbbc/Bj5D9Vw77u2zDHbC5M5FGQQ7mZcootkaZCMOUlzQSInQRtmYse3 YMdpnc0E84Lf1+FakWW27PA7/3w1j8tfePN96+/4iyRcmsoF9sV3YTs8GileHM627Lhw 3WH+WXj4j/DGjPB7R5FK22s4s3ar+22jfCeIBSz8kVL/6i5+hac81STLmp9oeaEgsbtr eC1x0/lwagUh30NQ4iDzPJK8GL2/f17w+j7YVInfSTBrxrd1DXHVn/f5G3pyYfuHitxK m15zALrxMjig/PI1fBm6spOXUBY+3QSgX08mKR05zn+3ugtWIk2TtdVET+5UO1hvRf0n eIwg== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ci18-20020a17090afc9200b00228e80888c9si2183558pjb.14.2023.03.14.03.39.16; Tue, 14 Mar 2023 03:39:28 -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 S231382AbjCNKhM (ORCPT + 99 others); Tue, 14 Mar 2023 06:37:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231365AbjCNKgT (ORCPT ); Tue, 14 Mar 2023 06:36:19 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A4A169C9B1; Tue, 14 Mar 2023 03:35:50 -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 01CFD1BB2; Tue, 14 Mar 2023 03:35:51 -0700 (PDT) Received: from e123648.arm.com (unknown [10.57.19.101]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 719423F71A; Tue, 14 Mar 2023 03:35:04 -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 17/17] Documentation: EM: Describe the API of runtime modifications Date: Tue, 14 Mar 2023 10:33:57 +0000 Message-Id: <20230314103357.26010-18-lukasz.luba@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230314103357.26010-1-lukasz.luba@arm.com> References: <20230314103357.26010-1-lukasz.luba@arm.com> X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760339289349445174?= X-GMAIL-MSGID: =?utf-8?q?1760339289349445174?= Describe the Energy Model runtime modification API and how it can be used. Signed-off-by: Lukasz Luba --- Documentation/power/energy-model.rst | 31 ++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/Documentation/power/energy-model.rst b/Documentation/power/energy-model.rst index a6ceeeb72868..2fd6e82a8124 100644 --- a/Documentation/power/energy-model.rst +++ b/Documentation/power/energy-model.rst @@ -213,10 +213,37 @@ CPUfreq governor is in use in case of CPU device. Currently this calculation is not provided for other type of devices. More details about the above APIs can be found in ```` -or in Section 3.4 +or in Section 3.5 -3.4 Description details of this API +3.4 Runtime modifications +^^^^^^^^^^^^^^^^^^^^^^^^^ + +Drivers willing to modify the EM at runtime should use the following API:: + + + int em_dev_update_perf_domain(struct device *dev, + struct em_data_callback *cb, void *priv); + +Drivers must provide a callback .update_power() returning power value for each +performance state. The callback function provided by the driver is free +to fetch data from any relevant location (DT, firmware, ...) or sensor. +The .update_power() callback is called by the EM for each performance state to +provide new power value. In the Section 4.2 there is an example driver +which shows simple implementation of this mechanism. The callback can be +declared with EM_UPDATE_CB() macro. The caller of that callback also passes +a private void pointer back to the driver which tries to update EM. +It is useful and helps to maintain the consistent context for all performance +state calls for a given EM. +The artificial EM also supports runtime modifications. For this type of EM +there is a need to provide one more callback: .get_cost(). The .get_cost() +returns the cost value for each performance state, which better reflects the +efficiency of the CPUs which use artificial EM. Those two callbacks: +.update_power() and get .get_cost() can be declared with one macro +EM_ADV_UPDATE_CB() and then passed to the em_dev_update_perf_domain(). + + +3.5 Description details of this API ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. kernel-doc:: include/linux/energy_model.h :internal: