From patchwork Fri May 12 09:57:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 93068 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp4976086vqo; Fri, 12 May 2023 02:59:52 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4RICYoZdSe/mNHl3hhIgy++8RSkDdCYaC0/P16agvQF3BcPtSjxwFUPmRf6l+LIVRCtq69 X-Received: by 2002:a17:902:e550:b0:1a6:e564:6044 with SMTP id n16-20020a170902e55000b001a6e5646044mr30978794plf.7.1683885592070; Fri, 12 May 2023 02:59:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683885592; cv=none; d=google.com; s=arc-20160816; b=GTQLRAUhWIDKHhvKiXsRsTf96H4ZtbscPQy42rmkGZG5MhrkqpI/T+wpGN8e7VoXAs VUrWAWFwVXeyUMIYAZFei2qBRrOKH0g39lkGY/rU/2JDIJmtSO430vld0Pmx15XI94am aPw1K10Jv8wUnhfBt8b17hqjXFgOlHPDcD92VvlkVG6O6wkID4wZh3z+tEE6ALXbuM3l 78vO1wp+9o9wxpUCCIitBn7+lPaTWon4YKFNjZueoz6Scoea611IiGe/CYlG3fOYEGtw cc0PZsqcCH01vnv4ZG8XUdyOZlwsgTi6KlBlyHmg4MJso9cdkgNJEL5LRydnx2Lq+5ww Ob/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=dJ4oD4oEqAaOOiVxKkQkMsMLazgas2uscx+WInoc7Bw=; b=jPJSUZlVDHdFBhlcUrRBkQBMATIvJ8RCyDmI1JiFzjwVd0QQ6g42fF4Z1NZxu0E8/A 4x4HiYh7yFGcnbfyCBf8uAuX7WSoQrmQnlaaoe4YKzACcdXY1GYIbkA6nVeIOTaNrIr7 JgUVnB4GWqS/dH1Fly7Rz2SBgbOgFLRTxHIhpSi5/wZ7K/TTjrTZrVZxQXhxAB8HmdTi jJO1QPFcYZCuO2egl3HQ6RzlS5H5ElZ4cDk5P5d0IubIDzCqYRdKDLCbXZC9t+Ua9fEm 0RndNIlvUtfsp8FdQ5plp1fwuUFfCSFpqWQmT04RWOqpqjpl9VKxaW0YuZDFDdoA7SgI GBwA== 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 r7-20020a1709028bc700b0019a730571dfsi8495847plo.394.2023.05.12.02.59.37; Fri, 12 May 2023 02:59: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 S240437AbjELJ61 (ORCPT + 99 others); Fri, 12 May 2023 05:58:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240591AbjELJ6R (ORCPT ); Fri, 12 May 2023 05:58:17 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id ED11811626; Fri, 12 May 2023 02:58:00 -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 23F401063; Fri, 12 May 2023 02:58:45 -0700 (PDT) Received: from e123648.arm.com (unknown [10.57.22.28]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id C9C1C3F5A1; Fri, 12 May 2023 02:57: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 v2 01/17] PM: EM: Refactor em_cpufreq_update_efficiencies() arguments Date: Fri, 12 May 2023 10:57:27 +0100 Message-Id: <20230512095743.3393563-2-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230512095743.3393563-1-lukasz.luba@arm.com> References: <20230512095743.3393563-1-lukasz.luba@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765682018082333640?= X-GMAIL-MSGID: =?utf-8?q?1765682018082333640?= 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 7b44f5b89fa1..0d037f3c4e58 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -237,10 +237,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; @@ -254,8 +254,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; @@ -397,7 +395,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 Fri May 12 09:57:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 93074 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp4980273vqo; Fri, 12 May 2023 03:05:57 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5NeewM/fKItEU57KeNZndJkzXYadsUQyFPJ4Uljq37EEeupUGhp5n5I4VTXRiHfnG6BBPC X-Received: by 2002:a05:6a20:8405:b0:ff:8640:4c2e with SMTP id c5-20020a056a20840500b000ff86404c2emr22642233pzd.17.1683885957561; Fri, 12 May 2023 03:05:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683885957; cv=none; d=google.com; s=arc-20160816; b=x71ptAEqHw1L/u47c9Ve+ZjBMm0Et/diLT/SKEBUHxLbfJ7fii0XZxV6AyG9NfeNWI 3m1nTABaaCtlrOnYORgoKRxKf9E6hb1yCgXXYQhGiNJRDHmkk3bKtTc2w/8nE7B4U3LH 3Rq/Bafv+S1BC6ge7DhMOtP1FwG1TiBSf0MsW3TqFT7b12ZIPEPyn+dh1R9cxlGm8tes wxDV1GzwVfXthP6sN6GD+PCQP/Pje8LI3omqmcfBaaz6xUts8Bztqig6HxLc/8Vi0Kqq QDbP5TfQj6M4sp11YOVJGTzgLNKk7NxU6qjnbcaG7J98+GxSUZC3Gd8u9aZlWhVDH4Jw wlvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=0f7A+J7qoAVqGJHnUSp7JB5CygJ8bFgjrXQY5hOqp8g=; b=ub/8cGq8sHmtQ2HD6FSXUpnO3i1Lka11DUi4fdidq/D+3ZkJ3ti7kdslWhokkS0X4k sUz0y/XjNxV4xrwYKUDe7bAVyCkmAbpOssNDBUQ2x+3XL0euMYJV5liU9lefJ+k8zK8B TB/wG8LWE4k5vYSUAzQj3SMqojCuZAq11xucQ1/LOuBMQmycNiVp8ldH5BT1SVxl+iIC 7V2mDvDoX466TrU9AE+w6GEEcs9fpQeN/PJClFDiUcmlVnaqcH7/MLRLupmPexiWD7Lj aOeHp9vfDIXd23mEoA7J5JG/cGcb4nTqf2mjhLdyySq0IJ2wNQiz9XsPluUzaI2jWnQ5 WvYw== 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 g4-20020a633744000000b00530725b58a1si4022846pgn.24.2023.05.12.03.05.44; Fri, 12 May 2023 03:05:57 -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 S240644AbjELJ6h (ORCPT + 99 others); Fri, 12 May 2023 05:58:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240655AbjELJ6U (ORCPT ); Fri, 12 May 2023 05:58:20 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D9CA410E6E; Fri, 12 May 2023 02:58:03 -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 2E27C139F; Fri, 12 May 2023 02:58:48 -0700 (PDT) Received: from e123648.arm.com (unknown [10.57.22.28]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id D9E8A3F5A1; Fri, 12 May 2023 02:58:00 -0700 (PDT) From: Lukasz Luba To: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, rafael@kernel.org Cc: lukasz.luba@arm.com, dietmar.eggemann@arm.com, rui.zhang@intel.com, amit.kucheria@verdurent.com, amit.kachhap@gmail.com, daniel.lezcano@linaro.org, viresh.kumar@linaro.org, len.brown@intel.com, pavel@ucw.cz, Pierre.Gondois@arm.com, ionela.voinescu@arm.com, rostedt@goodmis.org, mhiramat@kernel.org Subject: [PATCH v2 02/17] PM: EM: Find first CPU online while updating OPP efficiency Date: Fri, 12 May 2023 10:57:28 +0100 Message-Id: <20230512095743.3393563-3-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230512095743.3393563-1-lukasz.luba@arm.com> References: <20230512095743.3393563-1-lukasz.luba@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765682401693008431?= X-GMAIL-MSGID: =?utf-8?q?1765682401693008431?= 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 0d037f3c4e58..85a70b7da023 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -243,12 +243,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 Fri May 12 09:57:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 93086 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp4981923vqo; Fri, 12 May 2023 03:08:33 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4dtMCzNN3yafo+UEa4v0aDdwPGUfBN6Bgf++geIkx9j4ZE5Ri+39pFrLTcJv3W++bSkU0T X-Received: by 2002:a05:6a20:160a:b0:103:7b79:1506 with SMTP id l10-20020a056a20160a00b001037b791506mr10408428pzj.24.1683886113525; Fri, 12 May 2023 03:08:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683886113; cv=none; d=google.com; s=arc-20160816; b=YGvr3fUlTSXoWgudCSJ9MWuDZC17Hxg5r4jr6rSZ18Gxy2yce+YKFsVrGyU+QrFgOK A5nhmx5m79sAJPKPrRfZVkX7fF+6ca4HpdVWLpkyiDrvIgkxTl9/nbQyRn+y/FVXnoTC SFdexQv0m52LPWo8jVYaZcgaxmhiSVkrkGWTtF2vwW5RyfdcHn9P+dn/nr+9GcJHpSpM ogiRT+qpu5zki7OC/NyQY/HdyPEsL2oCytzb4/Aq4AtHuYwdrKbzliT4DsdzvTsieLvK LQQL3rRXPXcwdVQH/ssrEtse5WrzgHtANqaKCyYPtAE56zR/t/RJT6OCjlWDt8whd9T5 8z+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=gu9yvEAWYXJF0qW9SJFTVh5HhfGeAgRh+7RvF/01tVg=; b=wA28ypcFmmLsaMCjezuUdoC/X7UF906lQ0K8C+Y8tmja6zBSGtITBTXFd1kxVd2jdx vWcbRKIEm0bOjqBJLhWcHYAKV4jUuYhfWtl1EDv+/r4KLGAlZxPGt4WXZhcxTE7X6bht fTVhhzFkwe4mG5LFUHdUzgWA2zp9ZIz7qZf6SmT0hbP0SV7tZTNzddBNOc+Vfctvb868 IN1rpQ7fBWa2g30OIVnfbbk5RrNZxTeUjWqwaCBO9HPX42qulrAn8qh3PjYGIAXNYBED 5SHgL4u4VE6cyGaPMVvhrgDQGN16mVnNvkYu8grF4YaYyToMoa/xtW5ASISuXCd/AtPJ d+LQ== 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 j13-20020a63cf0d000000b005139e5df68asi8803524pgg.433.2023.05.12.03.08.18; Fri, 12 May 2023 03:08:33 -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 S240670AbjELJ6l (ORCPT + 99 others); Fri, 12 May 2023 05:58:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52588 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240657AbjELJ6U (ORCPT ); Fri, 12 May 2023 05:58:20 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E323D120A8; Fri, 12 May 2023 02:58:06 -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 2B22B165C; Fri, 12 May 2023 02:58:51 -0700 (PDT) Received: from e123648.arm.com (unknown [10.57.22.28]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id DFC8F3F5A1; Fri, 12 May 2023 02:58:03 -0700 (PDT) From: Lukasz Luba To: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, rafael@kernel.org Cc: lukasz.luba@arm.com, dietmar.eggemann@arm.com, rui.zhang@intel.com, amit.kucheria@verdurent.com, amit.kachhap@gmail.com, daniel.lezcano@linaro.org, viresh.kumar@linaro.org, len.brown@intel.com, pavel@ucw.cz, Pierre.Gondois@arm.com, ionela.voinescu@arm.com, rostedt@goodmis.org, mhiramat@kernel.org Subject: [PATCH v2 03/17] PM: EM: Refactor em_pd_get_efficient_state() to be more flexible Date: Fri, 12 May 2023 10:57:29 +0100 Message-Id: <20230512095743.3393563-4-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230512095743.3393563-1-lukasz.luba@arm.com> References: <20230512095743.3393563-1-lukasz.luba@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765682565233815626?= X-GMAIL-MSGID: =?utf-8?q?1765682565233815626?= 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 Fri May 12 09:57:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 93077 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp4981312vqo; Fri, 12 May 2023 03:07:31 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4ipcjkutYA4QFh9cTlxaUDqvU3A53vsZa02TgnGPTHiAA2WxkKI+t3Gc9JmL6YeZlvSWqo X-Received: by 2002:a17:903:234c:b0:1a6:ff51:270 with SMTP id c12-20020a170903234c00b001a6ff510270mr28850426plh.29.1683886051079; Fri, 12 May 2023 03:07:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683886051; cv=none; d=google.com; s=arc-20160816; b=CbNg7VrzTr6EopuAx29PjbupvQv3k4XLxWYBLDhWALOCNFzj2TybjvJWJZzeyPo71A SoGuXVSDDvhY2t9Yd4cVQfK/Bk7Xlyv1+YcOcl9Mskg/B62pMR1Lduh9Fiizn9IqEgda 6d5jM3+0vhuoMBa51rU4JULvI+GxFxZGvEVTUKxEiu3YscIzes5icf1hD0ibo46+nvxB HTHGbSRx5CKmiPAzht3Q97Q54bVYWQNZu8PWJL+OfUlE6/SSWjUB2ePvwwhSVnhsETVC QEPeqkwsnbTydaDExju7OVxtimXjLg1z+htk1FV80bDIA6BjmezTYOLg3u00S7SaTyfy hq/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=f+KgCUtCwGg99e7rscpptLTMzgTXvcKjtBRBQjqBUKM=; b=RecwGtORcv8jv6ngYgyKfYX5HjBULeqkQxXb+u+d5p6024fWAtW8SsteIgVZNEqxJO 8i0pt8uXTR4pidAKnNVc//yXGMKXC0ljvh1cwJujQ1BHnS0UDKs7BzNF33wKoOCumJx+ XFrLIDDl54C1gVPSyQlPvih1ey/hYZmbO5Cp8lVAvo1rG/QXnCsHd6BkFVyUFHYYurnn VbN+PCxcY5J+u8hMJT8t8Ooa/1ie23C2TKFCUpwZBzo+or9dSF4f+mUnhWNCKzMOumvN DpU8QHeOO1ZEA2s1Fy/cTC0TbUx38zblefnweA+kPiHtzPpFbUkx8jfypJu1PJoMlC95 jHFw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b2-20020a170903228200b001a1bfe84f8dsi10553873plh.611.2023.05.12.03.07.16; Fri, 12 May 2023 03:07:31 -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 S240504AbjELJ6w (ORCPT + 99 others); Fri, 12 May 2023 05:58:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239935AbjELJ6Y (ORCPT ); Fri, 12 May 2023 05:58:24 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D3ED611DAE; Fri, 12 May 2023 02:58:09 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 2B9F61684; Fri, 12 May 2023 02:58:54 -0700 (PDT) Received: from e123648.arm.com (unknown [10.57.22.28]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id E04DF3F5A1; Fri, 12 May 2023 02:58:06 -0700 (PDT) From: Lukasz Luba To: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, rafael@kernel.org Cc: lukasz.luba@arm.com, dietmar.eggemann@arm.com, rui.zhang@intel.com, amit.kucheria@verdurent.com, amit.kachhap@gmail.com, daniel.lezcano@linaro.org, viresh.kumar@linaro.org, len.brown@intel.com, pavel@ucw.cz, Pierre.Gondois@arm.com, ionela.voinescu@arm.com, rostedt@goodmis.org, mhiramat@kernel.org Subject: [PATCH v2 04/17] PM: EM: Create a new function em_compute_costs() Date: Fri, 12 May 2023 10:57:30 +0100 Message-Id: <20230512095743.3393563-5-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230512095743.3393563-1-lukasz.luba@arm.com> References: <20230512095743.3393563-1-lukasz.luba@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765682499835181502?= X-GMAIL-MSGID: =?utf-8?q?1765682499835181502?= Create a dedicated function which will be easier to maintain and re-use in future. The upcoming changes for the modifiable EM perf_state table will use it. Signed-off-by: Lukasz Luba --- kernel/power/energy_model.c | 72 ++++++++++++++++++++++--------------- 1 file changed, 43 insertions(+), 29 deletions(-) diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c index 85a70b7da023..fd1066dcf38b 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -103,14 +103,52 @@ static void em_debug_create_pd(struct device *dev) {} static void em_debug_remove_pd(struct device *dev) {} #endif +static int em_compute_costs(struct device *dev, struct em_perf_state *table, + struct em_data_callback *cb, int nr_states, + unsigned long flags) +{ + unsigned long prev_cost = ULONG_MAX; + u64 fmax; + int i, ret; + + /* Compute the cost of each performance state. */ + fmax = (u64) table[nr_states - 1].frequency; + for (i = nr_states - 1; i >= 0; i--) { + unsigned long power_res, cost; + + if (flags & EM_PERF_DOMAIN_ARTIFICIAL) { + ret = cb->get_cost(dev, table[i].frequency, &cost); + if (ret || !cost || cost > EM_MAX_POWER) { + dev_err(dev, "EM: invalid cost %lu %d\n", + cost, ret); + return -EINVAL; + } + } else { + power_res = table[i].power; + cost = div64_u64(fmax * power_res, table[i].frequency); + } + + table[i].cost = cost; + + if (table[i].cost >= prev_cost) { + table[i].flags = EM_PERF_STATE_INEFFICIENT; + dev_dbg(dev, "EM: OPP:%lu is inefficient\n", + table[i].frequency); + } else { + prev_cost = table[i].cost; + } + } + + return 0; +} + static int em_create_perf_table(struct device *dev, struct em_perf_domain *pd, int nr_states, struct em_data_callback *cb, unsigned long flags) { - unsigned long power, freq, prev_freq = 0, prev_cost = ULONG_MAX; + unsigned long power, freq, prev_freq = 0; struct em_perf_state *table; int i, ret; - u64 fmax; table = kcalloc(nr_states, sizeof(*table), GFP_KERNEL); if (!table) @@ -154,33 +192,9 @@ static int em_create_perf_table(struct device *dev, struct em_perf_domain *pd, table[i].frequency = prev_freq = freq; } - /* Compute the cost of each performance state. */ - fmax = (u64) table[nr_states - 1].frequency; - for (i = nr_states - 1; i >= 0; i--) { - unsigned long power_res, cost; - - if (flags & EM_PERF_DOMAIN_ARTIFICIAL) { - ret = cb->get_cost(dev, table[i].frequency, &cost); - if (ret || !cost || cost > EM_MAX_POWER) { - dev_err(dev, "EM: invalid cost %lu %d\n", - cost, ret); - goto free_ps_table; - } - } else { - power_res = table[i].power; - cost = div64_u64(fmax * power_res, table[i].frequency); - } - - table[i].cost = cost; - - if (table[i].cost >= prev_cost) { - table[i].flags = EM_PERF_STATE_INEFFICIENT; - dev_dbg(dev, "EM: OPP:%lu is inefficient\n", - table[i].frequency); - } else { - prev_cost = table[i].cost; - } - } + ret = em_compute_costs(dev, table, cb, nr_states, flags); + if (ret) + goto free_ps_table; pd->table = table; pd->nr_perf_states = nr_states; From patchwork Fri May 12 09:57:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 93080 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp4981471vqo; Fri, 12 May 2023 03:07:45 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5h79kNBh3GB7iBf951Qo2RixotVwdfzgtvA/A5RjpaO+/+RMDH+Zn/Ic7bP6YaAteCvJMh X-Received: by 2002:a17:902:e545:b0:1ac:a661:a4c9 with SMTP id n5-20020a170902e54500b001aca661a4c9mr15223936plf.33.1683886065548; Fri, 12 May 2023 03:07:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683886065; cv=none; d=google.com; s=arc-20160816; b=qPuAgWGVS2fQjyi17Wpwsm6zZUBK54NrU64GXOZzMZgj/z9f1YWicXcLbkxzpq0d3T 3lArFkorT1vMUbRDbbKO8cGKDdcmYcNbX/8q4rkIIeYUTt4RsB3K8E8ihPqNufxeUv/i Rao10cehvXN89K1b5er04AdTTHNbn44JdtXHuM5/AxDSckCIJFmdTZrPEfZGMQ8at5m2 cb4EAtAWI8V5HBMYpy0u7wLLXfGoY4VZHN4h67T6yp97FkFLvFUKjLSsHpRbVo4kk8tL zPZ6ZpoZc9wKfjMzWDST0Q6au6uCQ1T2WwN7IWmrzIQIoZYyFaeqhAjCAlLvBuq6tHT/ Fz5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=EfOZSk7m7bdqoQ6Dm1HhvsSwYtv1LDKyrFKnVtbuJU8=; b=WZFXtztyMyHVEdpC4WGjjT3uMJZBQVXjPTQ2t7mOTYZO4s9hCzzIu2fsyBXl8JcXOu hPz+9zMSi0Y9okhTKjRjcUM0Ai4BA6ENSOCIUjFJppJ2xm9oX9e6lq7EhPtMJAPGODOV bFLWablVn2e5M9xcvGp0zRKFpUcYpKtc/6isCeGzwsOXv2ad8krVTVXcVCsf1kibpIov 02jCwU2Lu8uLK4eaF0zS6fouKoPOWfLYi9ltBpN2NWiW1AUI3tfL/oUWBInXmfBTlNk4 Zlz7CVPH2z3PcAaiiCmofwLVcXbGh8qYeAMcVl6OtNANmVe1UhcC834X6fte14uGlAhu hbug== 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 oo2-20020a17090b1c8200b0024b27e48a27si24713400pjb.74.2023.05.12.03.07.30; Fri, 12 May 2023 03:07:45 -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 S240431AbjELJ67 (ORCPT + 99 others); Fri, 12 May 2023 05:58:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240637AbjELJ6e (ORCPT ); Fri, 12 May 2023 05:58:34 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D23FB12081; Fri, 12 May 2023 02:58:12 -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 2C8291688; Fri, 12 May 2023 02:58:57 -0700 (PDT) Received: from e123648.arm.com (unknown [10.57.22.28]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id DFDC63F5A1; Fri, 12 May 2023 02:58:09 -0700 (PDT) From: Lukasz Luba To: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, rafael@kernel.org Cc: lukasz.luba@arm.com, dietmar.eggemann@arm.com, rui.zhang@intel.com, amit.kucheria@verdurent.com, amit.kachhap@gmail.com, daniel.lezcano@linaro.org, viresh.kumar@linaro.org, len.brown@intel.com, pavel@ucw.cz, Pierre.Gondois@arm.com, ionela.voinescu@arm.com, rostedt@goodmis.org, mhiramat@kernel.org Subject: [PATCH v2 05/17] trace: energy_model: Add trace event for EM runtime modifications Date: Fri, 12 May 2023 10:57:31 +0100 Message-Id: <20230512095743.3393563-6-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230512095743.3393563-1-lukasz.luba@arm.com> References: <20230512095743.3393563-1-lukasz.luba@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765682514860324644?= X-GMAIL-MSGID: =?utf-8?q?1765682514860324644?= 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 fd1066dcf38b..61d349fec545 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 Fri May 12 09:57:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 93069 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp4976414vqo; Fri, 12 May 2023 03:00:26 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4MOScNCdie6Qrmb0JPzz8lb0KUikwgq7LU8axEpLBeNTeAwgO8fchxbFaaHCJ/4SvqOF64 X-Received: by 2002:a17:902:c409:b0:1a9:778b:c1a8 with SMTP id k9-20020a170902c40900b001a9778bc1a8mr40535536plk.12.1683885625988; Fri, 12 May 2023 03:00:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683885625; cv=none; d=google.com; s=arc-20160816; b=WsQ2bitWKgJoqRqC2dryoeqL3HdyRCOndNV24vuXRgXzsumheU4+0dTcuRjo1zJPKH DHAtAn6dWUC4Yb9Xt7103MWmxq9g/oVyP0VMShHP9yKxm2UnTMG5vYLh4QXBSkrgtadi WtXznzCYUSwS+I9UdUXJTh3wb+EMzXer9W9nbovPkU/gNbIec6M7PeY1FzjmgdFbX3su EJ0TP7utjW40XkUAWIgQh2w7IpPBcZakk/J6fbXopECnlWseZ2C6rCNA4NCm1H3qylFO 36RFn3Jn/Nweu78bPphZqn0JgLuA9iwx2f0pBjLWJd8ojDEWhuEBJ68ldJshZSayk4/R yY5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=NTRuhr/lqT5WOL9niJWL5/o/B0yNXIb/4HueHfVYLro=; b=pdjjCy9HoOThXfJWzGF5/SzVTCTh+jVzH5zExDLL/aX/TsNSo8F7RGTqoZgoQFknYP LbH+eFhQW9kxocaTMLz0wh0YUZqe8ROK4wNB602/0xEwS0HVr7nmnW13R5JEUAkkCLYc sl1HYAX94lf0LiWP/QJJ2Ynk1O3vYhX2uCkIgPAopHfRDpcntzezhKGM18DZfW7yt+WG T1EJQwmpq9KPMJtGJBkcM0bXhMtl4y/+JxwyET4C3ZYG4HIQQZTOTN0pnokuFp/uQfJD fQ094O93aPBrC37hx27ATGv71zO6p+CuE0+SYMNYJHN2azAzV5GzvGlLeYUN51jMvK7v 0WpA== 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 l10-20020a17090270ca00b001a81e552dc7si8390839plt.637.2023.05.12.03.00.09; Fri, 12 May 2023 03:00:25 -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 S240686AbjELJ7F (ORCPT + 99 others); Fri, 12 May 2023 05:59:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240658AbjELJ6o (ORCPT ); Fri, 12 May 2023 05:58:44 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0A1411249D; Fri, 12 May 2023 02:58:16 -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 2C9D1168F; Fri, 12 May 2023 02:59:00 -0700 (PDT) Received: from e123648.arm.com (unknown [10.57.22.28]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id E05573F5A1; Fri, 12 May 2023 02:58:12 -0700 (PDT) From: Lukasz Luba To: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, rafael@kernel.org Cc: lukasz.luba@arm.com, dietmar.eggemann@arm.com, rui.zhang@intel.com, amit.kucheria@verdurent.com, amit.kachhap@gmail.com, daniel.lezcano@linaro.org, viresh.kumar@linaro.org, len.brown@intel.com, pavel@ucw.cz, Pierre.Gondois@arm.com, ionela.voinescu@arm.com, rostedt@goodmis.org, mhiramat@kernel.org Subject: [PATCH v2 06/17] PM: EM: Add update_power() callback for runtime modifications Date: Fri, 12 May 2023 10:57:32 +0100 Message-Id: <20230512095743.3393563-7-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230512095743.3393563-1-lukasz.luba@arm.com> References: <20230512095743.3393563-1-lukasz.luba@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765682054071561372?= X-GMAIL-MSGID: =?utf-8?q?1765682054071561372?= 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 Fri May 12 09:57:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 93083 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp4981648vqo; Fri, 12 May 2023 03:08:03 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7Dw0yTG5IuPEwaJAQBlOEluV2qxwNflRAULBCvFQLxnFki4ACpTtccmZLmkD0UciiGFvYW X-Received: by 2002:a05:6a00:2408:b0:643:aa2:4dd9 with SMTP id z8-20020a056a00240800b006430aa24dd9mr30308729pfh.7.1683886083654; Fri, 12 May 2023 03:08:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683886083; cv=none; d=google.com; s=arc-20160816; b=sECnHAUthDPGXyrq3iEfWTg0kjmNsBcD9KcR0Tj8K5X6cp8nssKOjBsdQ1DAeuGCbY apd1bHd6JNfiHVwpzAA26A3ZSXY+5Bv86yVmH/O1mT1FXrH2E9c0WHhsza+huqVLkcIi PrIn/sP9HIiJQWEKuE1LxE2gBNfpl1PON9iEACEsnl6bcT6n/U90HfKx5xmNOcw1Ofc/ BE9GrBuK3yk3Y9JvYgExycCG4ji6p1vCrr+XXEjMm3Wa2Srg8mZYPMEfqz7UyEty533Y 0fjpRIWhOm0ER++QOqj1LUCuBcE1J0DSo/w2jItxMkIcvmkg40SwKRnfEfJB/vjZ9dCi ZQEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=k3zcTIgtfrvX++AjltUauI/BY2ErmwoBhSBX/oeUcGU=; b=L6ssH0sgKtWVX8AdFQboP5tNK6yqG0hw7JlCYzkW5cKzLqvEZsJcxY+Q0VPauDP0iQ 7DrPisXgVIsBT+LfQF8qfFReSRMtzOzHfmm7twnu7E3j4SGT2IJGUYIYtitO+BNwuX6h RkZJTXywem1HH4oPiVHsSJW2vOB6MjDrmkuMdNj1vUUcvXklz/w5Q1gagBGAuKIQFolv 165CYHiQoQ+aMMX9YYkXmbejOXfwaV6cz2LKfYXp2XOsJAW7RvHcrWCHxgi8bZSGc9To MGWIGw9JdReld9dmXK3BemAyg2G2xMPBb8SFElYY27nGgkqqNata44HWD2gP4bqFT0e5 F1yQ== 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 c66-20020a621c45000000b006462446f478si9929081pfc.11.2023.05.12.03.07.45; Fri, 12 May 2023 03:08: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 S240599AbjELJ7N (ORCPT + 99 others); Fri, 12 May 2023 05:59:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240522AbjELJ6t (ORCPT ); Fri, 12 May 2023 05:58:49 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D06E1100D9; Fri, 12 May 2023 02:58: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 342C71691; Fri, 12 May 2023 02:59:03 -0700 (PDT) Received: from e123648.arm.com (unknown [10.57.22.28]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id DF6843F5A1; Fri, 12 May 2023 02:58:15 -0700 (PDT) From: Lukasz Luba To: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, rafael@kernel.org Cc: lukasz.luba@arm.com, dietmar.eggemann@arm.com, rui.zhang@intel.com, amit.kucheria@verdurent.com, amit.kachhap@gmail.com, daniel.lezcano@linaro.org, viresh.kumar@linaro.org, len.brown@intel.com, pavel@ucw.cz, Pierre.Gondois@arm.com, ionela.voinescu@arm.com, rostedt@goodmis.org, mhiramat@kernel.org Subject: [PATCH v2 07/17] PM: EM: Check if the get_cost() callback is present in em_compute_costs() Date: Fri, 12 May 2023 10:57:33 +0100 Message-Id: <20230512095743.3393563-8-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230512095743.3393563-1-lukasz.luba@arm.com> References: <20230512095743.3393563-1-lukasz.luba@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765682534515538707?= X-GMAIL-MSGID: =?utf-8?q?1765682534515538707?= 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 61d349fec545..8866d217714e 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -119,7 +119,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 Fri May 12 09:57:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 93070 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp4976493vqo; Fri, 12 May 2023 03:00:33 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5p8ypBTIlxgaauiS7RwywaC+SkNFmEhkxHFvAv27+17HBh2J11Pye0yyaRhakns6fj+JFD X-Received: by 2002:a17:90b:4d85:b0:247:529f:92d7 with SMTP id oj5-20020a17090b4d8500b00247529f92d7mr24649527pjb.8.1683885633238; Fri, 12 May 2023 03:00:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683885633; cv=none; d=google.com; s=arc-20160816; b=ZBglKXP9Bcji/aJO5vN/kbJCullB8g6C1c3o3WSzdVJkwprcuzkFyrk7GLvKnkpApj jwlVFSYY61f1sGtqvv/ppd+jfdP3w0+9tkfow6SEXvYn1B6vijz8csWf6f2sgsbY4Egk SaoKzKWn5NM32QgwvoegEf1MXQW4PgGrLA9bRVzW7iMuFQi8q4o9jSInbG9nCHeWxJ5z a/i5KT5Jd2MpY7KZiwExjBXvOibMz7udVAavbBu7MjMwDwfc3iRAIcOAlqbsTeJfo6v3 GtIQWuEuZEDwymrnFZjV9KVynA4HR7meq9QYKnZtyFwMFiAsVnkhKkzpg2zYJrHZnpUv xwbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=ANI0nTxZ6qBCHup6FVhx754TGTDlqMpyc5RMhAbWwkg=; b=0fQYq0g1Gi5GZVFbI64ATOJvJcgujaaGG0Eu09QnONCICte4neI+cm/WmKWEpP1EVD cbWJEqUpabqe/4xLKQ9MM8oEOeIO7SNKTC9Gk0Uh7ZRRsAEP3cV1oRttPzSIB+A+iN7P 8JJvncKyXgAWaf/l0PIi8hn5Rvv6daTNh7mHPSKIkUC2wqvzB1Hb3ySty0S70ZjNzY8c DYGs8sDEydWX6moUj7U+tkdYORIjdQPZr1+j0QEOxQCsDpIdpx/u6MynZkLviwVTnscL jNJED67/srr5OYTKggGdldZeKgnZuyd4JBnMQI/kk8ElqoIDUoW8WiJcJiwpnppVPh8o xTcw== 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-20020a639d08000000b00520dfb861fbsi9545640pgd.416.2023.05.12.03.00.14; Fri, 12 May 2023 03:00:33 -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 S240703AbjELJ7P (ORCPT + 99 others); Fri, 12 May 2023 05:59:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240467AbjELJ6v (ORCPT ); Fri, 12 May 2023 05:58:51 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 181E67693; Fri, 12 May 2023 02:58:22 -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 308531692; Fri, 12 May 2023 02:59:06 -0700 (PDT) Received: from e123648.arm.com (unknown [10.57.22.28]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id E4D4F3F5A1; Fri, 12 May 2023 02:58:18 -0700 (PDT) From: Lukasz Luba To: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, rafael@kernel.org Cc: lukasz.luba@arm.com, dietmar.eggemann@arm.com, rui.zhang@intel.com, amit.kucheria@verdurent.com, amit.kachhap@gmail.com, daniel.lezcano@linaro.org, viresh.kumar@linaro.org, len.brown@intel.com, pavel@ucw.cz, Pierre.Gondois@arm.com, ionela.voinescu@arm.com, rostedt@goodmis.org, mhiramat@kernel.org Subject: [PATCH v2 08/17] PM: EM: Introduce runtime modifiable table Date: Fri, 12 May 2023 10:57:34 +0100 Message-Id: <20230512095743.3393563-9-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230512095743.3393563-1-lukasz.luba@arm.com> References: <20230512095743.3393563-1-lukasz.luba@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765682062021845057?= X-GMAIL-MSGID: =?utf-8?q?1765682062021845057?= 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 8866d217714e..39d47028ef3d 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -213,6 +213,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; @@ -237,12 +238,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); @@ -438,20 +450,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 Fri May 12 09:57:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 93079 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp4981463vqo; Fri, 12 May 2023 03:07:44 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5bPYuirTLXqNgLdPjSBAcs+jMp/91jhQGptQ1Y4I685iw3k7W2CY9SVB6A8KplUAFzPbWt X-Received: by 2002:a17:903:185:b0:1a1:e237:5f0 with SMTP id z5-20020a170903018500b001a1e23705f0mr32181464plg.58.1683886064439; Fri, 12 May 2023 03:07:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683886064; cv=none; d=google.com; s=arc-20160816; b=VP2G7TzvcjeyXMYpjVIHb5xM5s77TOSDrFZhc8/yzlB9Jiha2pM24zSm5G5gGGTxDQ ZpdbVxmb98q1KcNt9RYRoqzAPh3jvOaG1q3UtZHQBSfIXG153mCAU8ritMpDTaCsxoxU uzkzavbGc+pbZpD4Ma6g8EtjI3VTHyxldaVH6oLcfTiUuFJViizAgfF5DH/eI8Jw4sK5 CxSzr0RyGUcGaDjLboXk2J7xhfzGlsPqbjwNezzqZTdrrNEV49i/g82kBDopDZUClKPb r+8SYKGurCbptTdpY1reSapoDtP/CF0D270L8JlIrFJ2cfFbtKu4batjMyCOMB47h92+ uKRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=iS5vZ5OToGuqCr2btwM5DCR2dKST/WKkHA7MV95MrHM=; b=M1kdpdDPgovNeACIo2lhiZrDSN8mJ/GgCRFeKuricJQ95MoTeXUgciHJFMZLwejVCC EuPriKEI7bEN9UDkUS1cvmmv9g1g/PWmmQROp3FnziT7CjNMSVD1EtXdDbBkkoy9ltz3 C49KcXkpT+LOudJQpVvh9srQDlKaIXsTB2wwj7b5snA9eA5eQFxZ6IYhBn1T78KIcxJ6 f7DkCOcqbtfuXDrs/oo0gkrsM6zKw85qQPa6uUSYQYrQkaZ+LNEYqMVODt2ctUXrYRji LHR+OTZjFBHlzpgMk06Hm467SC/7h9jPuv3GZ9CoRmD3ifbJ1GInHe/U2SfgDYyUB2Ra Xx8g== 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 b24-20020a170902d89800b001ac6c5900f7si8824074plz.191.2023.05.12.03.07.29; Fri, 12 May 2023 03:07:44 -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 S240606AbjELJ7Y (ORCPT + 99 others); Fri, 12 May 2023 05:59:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52756 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240592AbjELJ64 (ORCPT ); Fri, 12 May 2023 05:58:56 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B848C10A3B; Fri, 12 May 2023 02:58:24 -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 2B002169C; Fri, 12 May 2023 02:59:09 -0700 (PDT) Received: from e123648.arm.com (unknown [10.57.22.28]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id E0F013F5A1; Fri, 12 May 2023 02:58:21 -0700 (PDT) From: Lukasz Luba To: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, rafael@kernel.org Cc: lukasz.luba@arm.com, dietmar.eggemann@arm.com, rui.zhang@intel.com, amit.kucheria@verdurent.com, amit.kachhap@gmail.com, daniel.lezcano@linaro.org, viresh.kumar@linaro.org, len.brown@intel.com, pavel@ucw.cz, Pierre.Gondois@arm.com, ionela.voinescu@arm.com, rostedt@goodmis.org, mhiramat@kernel.org Subject: [PATCH v2 09/17] PM: EM: Add RCU mechanism which safely cleans the old data Date: Fri, 12 May 2023 10:57:35 +0100 Message-Id: <20230512095743.3393563-10-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230512095743.3393563-1-lukasz.luba@arm.com> References: <20230512095743.3393563-1-lukasz.luba@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765682513766069576?= X-GMAIL-MSGID: =?utf-8?q?1765682513766069576?= 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 39d47028ef3d..bc9b7dec0763 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); @@ -106,6 +109,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 Fri May 12 09:57:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 93081 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp4981572vqo; Fri, 12 May 2023 03:07:55 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5WdBXocJffEq5xDUYlUWkpMZZ+9U+9C5EbAxEkpyb22cIBr0qAeCraYOIzlL/EvQoYymHx X-Received: by 2002:a05:6a20:1611:b0:104:62a9:9006 with SMTP id l17-20020a056a20161100b0010462a99006mr2956037pzj.36.1683886074900; Fri, 12 May 2023 03:07:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683886074; cv=none; d=google.com; s=arc-20160816; b=lSvFpRD8Qohc8bCq33p7TsIA8+mSJhJw8S2Z7293PR1X6Wc61+MyjyyLuq3y2XVpAw BrAlcb92OuEkq8AcyJpVhR9s95jyksDLedC42MFQ5kLKtimgain7AevnH39wAyGfaRE3 FYExp5oW2mNL7CVuuQZF39qZTlW72mKKtcbdHEDGfo1mJ0SMfmGNeHGJJbrilzBq/+jq sHNDerdoMh+bURG5pg/H3MywbrvnJGRj2G4Pqgv7rcr+0NYLnBoYUOL7B3DcqIiZ6GvY 4UsOeP5mpAUQBCb+i2UEz06RJKnrHbXT0d4jpzIBPbetIGj9VU7lWQuRc56AeCvnaXF6 FpOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=0bAp2bP96TCtLp6s22oQfy+47WYWrQqPJhtkanh0fSQ=; b=LHCmkZV6mkmPHGxOdVSeSvED3V8vcLNDB0amdwhkJs3XzjJ6eE1BWR9TQ8iVV+Q/mM 9Ne/R1leZ92DMpG0rDF8K8MbiDdUNoYy5SlW3fMqTn1JFjYiQYJ4kAIL4n5X7JReBXu6 UGO6pZq1S+T5aFmPo1ui2w/oKjKwmY1txqS+I0Ixew9wNGPtnDIVZt0jA1/xsQIXAdvS Qq5LpqpYpiL8AJMjrydB+rvY3f7nIT4w0zCbDN/esjWbjLIuy6Mcb5Cf6f2kOXrAUVm4 UXVZVrSN+PHbM/PMowyp2EYcTuUqSlrKlMUOcVnhixFt5EOJZjVZQDcH8f18zN4n4BSC 3g+A== 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 n2-20020a637202000000b0050be719abc9si8276318pgc.167.2023.05.12.03.07.39; Fri, 12 May 2023 03:07:54 -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 S240633AbjELJ72 (ORCPT + 99 others); Fri, 12 May 2023 05:59:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240630AbjELJ67 (ORCPT ); Fri, 12 May 2023 05:58:59 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C227E1157E; Fri, 12 May 2023 02:58:27 -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 24F9C169E; Fri, 12 May 2023 02:59:12 -0700 (PDT) Received: from e123648.arm.com (unknown [10.57.22.28]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id DB8E33F5A1; Fri, 12 May 2023 02:58:24 -0700 (PDT) From: Lukasz Luba To: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, rafael@kernel.org Cc: lukasz.luba@arm.com, dietmar.eggemann@arm.com, rui.zhang@intel.com, amit.kucheria@verdurent.com, amit.kachhap@gmail.com, daniel.lezcano@linaro.org, viresh.kumar@linaro.org, len.brown@intel.com, pavel@ucw.cz, Pierre.Gondois@arm.com, ionela.voinescu@arm.com, rostedt@goodmis.org, mhiramat@kernel.org Subject: [PATCH v2 10/17] PM: EM: Add runtime update interface to modify EM power Date: Fri, 12 May 2023 10:57:36 +0100 Message-Id: <20230512095743.3393563-11-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230512095743.3393563-1-lukasz.luba@arm.com> References: <20230512095743.3393563-1-lukasz.luba@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765682525198961923?= X-GMAIL-MSGID: =?utf-8?q?1765682525198961923?= 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 bc9b7dec0763..b5675dda00e1 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -202,6 +202,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) @@ -521,6 +616,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); @@ -528,9 +625,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 Fri May 12 09:57:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 93071 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp4976967vqo; Fri, 12 May 2023 03:01:09 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5HiVm7TNqJ3+uCDjgC8ohzetRNVQ1mCsdwJ55KCtAIazq/z2OlV5aneEdmgEwaqObCZFMH X-Received: by 2002:a05:6a00:18a9:b0:643:59ed:5dc9 with SMTP id x41-20020a056a0018a900b0064359ed5dc9mr31652339pfh.12.1683885669290; Fri, 12 May 2023 03:01:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683885669; cv=none; d=google.com; s=arc-20160816; b=s+BfJsG85qdrMlSsfuGwX3qXBvKz7tL10I5Azu/sWdIUUm4KMwsQAX9/75yafkyjvy X3YGkWhjVjMc1TWgDt3DIDbpu7GH+e89OS9YqEts0jLVQwvcQ62WxRLoOoWvOOe0+1Ce WHzQOnxXmEZHbJaIdcWHggBJ015o7G/pE7GhBjxmgTW7zwuJ3LA1DwnQSFMok5GdtuVv +A4hhJ5IMsRZPAv5hWB9LsNyy15iH4b2+iSTquT3WdDhjQ+knpv2UmKpjEEnFR782Shi DSnHL4LiXoyiEn8gMNUtjxRrMzC4uO8PQnYZH4MmF+fpBBM0cs4Pqyq4CIhjiAa3EDpA AIiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=jZnIWVM+K7vQ+gDNduF3BctJbe8oLsdi69v52yiaI2s=; b=Sc1WLnrDlVG2lqvVV/HZaJ0AfeXSz+bDpkXcCTwVFDVagsCGi9NWXtscPj2rhUTuNR pjtr0ghRsO6CiMFuznlagka3/bWw7DbeDaOD1pemJsSC+4SidUmrLF/LoIDEjIDpPs8M pinO7GnEBQ6ETuaMdAzVESN3h3j6evoor3b27bo3VuWyPMwxND3Dibtvsgi+nq3fWwFI cUK3CpRtwI9XyEb4zlINow6z4fNSVJUNA2yALcOJPsXm2RPNHSfYsy3CR7R0rm5Hx2NE HiaWgcTUjP8j//iovl2q4Q71oiCDYbeY9qv1WbNlR5dylPuopnsdf+S+2Yo0Qdnz3mLa 1eUg== 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 a25-20020a637059000000b0052c89d50011si9350021pgn.676.2023.05.12.03.00.54; Fri, 12 May 2023 03:01:09 -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 S240669AbjELJ7d (ORCPT + 99 others); Fri, 12 May 2023 05:59:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240634AbjELJ7A (ORCPT ); Fri, 12 May 2023 05:59:00 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id BE36E11B4E; Fri, 12 May 2023 02:58:30 -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 1ECC2FEC; Fri, 12 May 2023 02:59:15 -0700 (PDT) Received: from e123648.arm.com (unknown [10.57.22.28]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id D5C9E3F5A1; Fri, 12 May 2023 02:58:27 -0700 (PDT) From: Lukasz Luba To: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, rafael@kernel.org Cc: lukasz.luba@arm.com, dietmar.eggemann@arm.com, rui.zhang@intel.com, amit.kucheria@verdurent.com, amit.kachhap@gmail.com, daniel.lezcano@linaro.org, viresh.kumar@linaro.org, len.brown@intel.com, pavel@ucw.cz, Pierre.Gondois@arm.com, ionela.voinescu@arm.com, rostedt@goodmis.org, mhiramat@kernel.org Subject: [PATCH v2 11/17] PM: EM: Use runtime modified EM for CPUs energy estimation in EAS Date: Fri, 12 May 2023 10:57:37 +0100 Message-Id: <20230512095743.3393563-12-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230512095743.3393563-1-lukasz.luba@arm.com> References: <20230512095743.3393563-1-lukasz.luba@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765682099584369315?= X-GMAIL-MSGID: =?utf-8?q?1765682099584369315?= 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 Fri May 12 09:57:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 93072 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp4977081vqo; Fri, 12 May 2023 03:01:17 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5686/o+DMNH2/1aVK4BLITJ/2v5QcSJuHcF/RBlC0dlzNS4p1cqrnnjJmeoZkkTwJVi5nr X-Received: by 2002:a17:903:124f:b0:1ac:451d:34a with SMTP id u15-20020a170903124f00b001ac451d034amr31343514plh.33.1683885677247; Fri, 12 May 2023 03:01:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683885677; cv=none; d=google.com; s=arc-20160816; b=UZNmnbayWF0++NAw0hPySjQO7tfWMy379uf4VfPjjuL4C3b+WU32bGtHqjV6eM8Whz ifSbLlpG6CDXCR+2LKe1K2JSWYFWb+IJug9Xp4fc4i24Szs/Jor+fKSk9+616erCLI08 BGXjRyAeJwwkQzDRm7SbOoqVt5cPvle8DOldOiMAw5XKJEx5UwE8/z+Se6OtrFfJaeyu KkhKkGD3aJWaPSDXzUdNZaVdZ+s8C+RBGd/eckrluXgAWKoxPmEHA1TgXToZyHpMZDx+ lsSjKpARvPHy6s8pWa2gO34YlddHawn574t9pTf4SxpF2MC9i7cZCxiW8V9EIBaw5/4C 8Q+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=2SFK6pyTWQW/iqBurzbGoGBE1AUdGVbwauLwyn/04j4=; b=cUWy9c+gwkE9BCkHy8ccM7i8VA0GjIR6g0NpLy8Lwg0s4iKbUZmKfo9cS/V2jkK4Mi Eb9izmbmS/fDllwUIoiFwyVV6rLboE5O5iob4EUcQ3PttvT5132uxygSplxHrerJgtFH JYornqAs0y3M3bCPhOr7fOFTIPaURIZgjqyyx2gSt8CWgYUkj5Cl2j3/b952U/pVl2sy m57COiR6pRr18jExGY7G8rKnWZASgw4K5ntzfWGf5X4ruyeqPZB0gX62z+bK7DkdLtzR geB20Ebzza70bZkOu0DmKTgZJlmBpR61cY54+OhCrkQDG/A6HtrK4NdOsgfTcTuMhwdj opdQ== 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 z5-20020a170902834500b0019e9c8e51f4si8289822pln.165.2023.05.12.03.01.02; Fri, 12 May 2023 03:01: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 S240729AbjELJ7g (ORCPT + 99 others); Fri, 12 May 2023 05:59:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240653AbjELJ7C (ORCPT ); Fri, 12 May 2023 05:59:02 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D00551208E; Fri, 12 May 2023 02:58:33 -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 182EC16A3; Fri, 12 May 2023 02:59:18 -0700 (PDT) Received: from e123648.arm.com (unknown [10.57.22.28]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id CF6D93F5A1; Fri, 12 May 2023 02:58:30 -0700 (PDT) From: Lukasz Luba To: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, rafael@kernel.org Cc: lukasz.luba@arm.com, dietmar.eggemann@arm.com, rui.zhang@intel.com, amit.kucheria@verdurent.com, amit.kachhap@gmail.com, daniel.lezcano@linaro.org, viresh.kumar@linaro.org, len.brown@intel.com, pavel@ucw.cz, Pierre.Gondois@arm.com, ionela.voinescu@arm.com, rostedt@goodmis.org, mhiramat@kernel.org Subject: [PATCH v2 12/17] PM: EM: Add argument to get_cost() for runtime modification Date: Fri, 12 May 2023 10:57:38 +0100 Message-Id: <20230512095743.3393563-13-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230512095743.3393563-1-lukasz.luba@arm.com> References: <20230512095743.3393563-1-lukasz.luba@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765682107920145445?= X-GMAIL-MSGID: =?utf-8?q?1765682107920145445?= 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 022e3555407c..f5353c10552b 100644 --- a/drivers/cpufreq/cppc_cpufreq.c +++ b/drivers/cpufreq/cppc_cpufreq.c @@ -574,7 +574,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 b5675dda00e1..456d9f2b4370 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -165,7 +165,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; @@ -177,7 +177,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); @@ -277,7 +278,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; @@ -347,7 +348,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 Fri May 12 09:57:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 93085 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp4981750vqo; Fri, 12 May 2023 03:08:16 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6nXpHIsmwV/uX/CAIcqYSkJCzlPt7L9lrvRF3M7R4kIsETFpKSQt5defA/G6UF4wVuHLzY X-Received: by 2002:a17:90b:b15:b0:246:bb61:4a56 with SMTP id bf21-20020a17090b0b1500b00246bb614a56mr23885787pjb.27.1683886096175; Fri, 12 May 2023 03:08:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683886096; cv=none; d=google.com; s=arc-20160816; b=ufu8o0SFtJ8s66+CDq7KclBKQUlKvzxrvpTnj9vvfGK70C29aw1MMUCFR6hR0o5ijj ZmnCxVpjMxaezsq9JdDiI2CizAC4fJXM0mUZDeS12P2XEAjf/oM9wgnFjas3q3auFoIC Y3vOTwMZx33kTC7OrSiUhcLEIRceUJjFMRSODt/5UvNpgP25s5MJU19fFGN/PUYhEyic PeuvK88aDlcYWZPZrl/GsRQw4PcwAcwKkPcOCTEfin26ym1vsV3+Brw4OVkr7yErzTp4 OTXDJxaK5A7QnUw5KaJptvZb+77ayiun1kNtSXKn0PBlJMpewPL3p6sK1xcjnxCpb934 NVJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=kw+Z/JUFljBE8v2FGcyn4WDpMAWBRrg088rUX6zumbg=; b=WPIK0biRHem3gDObXsyU+pPL3/EgdWD9+PCJ1GyktF0M+Bc+ZBsLbdkoiO2zGP8t6x 3eWwqSYUgjX4ypGwjvl8vGzUVHFA5MAfjHQxaB9lEWBMRCVx3Djqi2pWCYXOnS+7PFIy iuqpPCt9kNoHQZUUeTxm+6JagrO/JqiggQwWp9NwkHU4JE6OIkgYOlbMSdkQfbOfyq/n 6awjfUN5fNFneKGk72hnanFXM9UyuEgUr9Bkep0ABpMU7cMc9LIgmgDPoP/i6g2jFGQM yOCUmAUI9Vud2D44Hq9auXPW02cj/bJsJe62eIQV92e9TL7lp364cScbqcwCDTiUqPd6 KcSg== 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 s193-20020a6377ca000000b00530716f3674si4529684pgc.526.2023.05.12.03.07.59; Fri, 12 May 2023 03:08: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 S240734AbjELJ7s (ORCPT + 99 others); Fri, 12 May 2023 05:59:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53610 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240684AbjELJ7F (ORCPT ); Fri, 12 May 2023 05:59:05 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3A5AB11B76; Fri, 12 May 2023 02:58:36 -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 3AE9B1063; Fri, 12 May 2023 02:59:21 -0700 (PDT) Received: from e123648.arm.com (unknown [10.57.22.28]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id CA13D3F5A1; Fri, 12 May 2023 02:58:33 -0700 (PDT) From: Lukasz Luba To: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, rafael@kernel.org Cc: lukasz.luba@arm.com, dietmar.eggemann@arm.com, rui.zhang@intel.com, amit.kucheria@verdurent.com, amit.kachhap@gmail.com, daniel.lezcano@linaro.org, viresh.kumar@linaro.org, len.brown@intel.com, pavel@ucw.cz, Pierre.Gondois@arm.com, ionela.voinescu@arm.com, rostedt@goodmis.org, mhiramat@kernel.org Subject: [PATCH v2 13/17] PM: EM: Refactor struct em_perf_domain and add default_table Date: Fri, 12 May 2023 10:57:39 +0100 Message-Id: <20230512095743.3393563-14-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230512095743.3393563-1-lukasz.luba@arm.com> References: <20230512095743.3393563-1-lukasz.luba@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765682547083456548?= X-GMAIL-MSGID: =?utf-8?q?1765682547083456548?= 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 e2cc7bd30862..1d979c5e05ed 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; @@ -378,8 +383,10 @@ static unsigned int get_state_freq(struct cpufreq_cooling_device *cpufreq_cdev, #ifdef CONFIG_THERMAL_GOV_POWER_ALLOCATOR /* Use the Energy Model table if available */ if (cpufreq_cdev->em) { + struct em_perf_state *table; + 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 262e62ab6cf2..4207ef850582 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 456d9f2b4370..204fd415ebc9 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); } @@ -157,7 +158,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); @@ -261,7 +262,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; /* @@ -352,7 +353,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; @@ -366,7 +367,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; @@ -391,21 +392,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)) @@ -526,6 +537,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; @@ -584,7 +596,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"); @@ -638,12 +651,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 Fri May 12 09:57:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 93075 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp4980436vqo; Fri, 12 May 2023 03:06:13 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5atk3i4oMFtgQ5nSYZUcOqw20CVaUYvUOVrdH22eCaRgFJFcIfAR0oqocQLegXn++rypzQ X-Received: by 2002:a05:6a20:12c9:b0:100:b715:8ab2 with SMTP id v9-20020a056a2012c900b00100b7158ab2mr21585844pzg.46.1683885973095; Fri, 12 May 2023 03:06:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683885973; cv=none; d=google.com; s=arc-20160816; b=lZFdNBzM1wYtgxM2CgUgnz161gok14OC8vbGaOpwnkpGTSqJrN5HECpOfSEqosh+RW xtdCV2DSlqA9o9tkxy5zd8NjTdgc3vtlxDC86g2IggLmCA0FUDWMx+7F3aNFld/EEJ72 OJyDEFm8WC41+1le/A15canmDz4iFF6KdaBGl7EQaf+2GLZLUXzci4CZNfeGQidmVQ7E JaBJFzYkPVYUSXX5BAo0wO3H3QVT+XfdBjBxCSwlHkgp3Dnrq6Zarpia80iyGnz036lL 8gB+RFTDQ6gB0459a/hTXWRYh31AtZ+dcbZnggjMSagzRc8g8MYx9A5MY5CXHRx+0avq vJjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=uZ6LCuwJQnbsBRncQAVa3gPBxR624no8vJKTjuBlg+0=; b=YZCVg5a1Mi2vi14vhRKcPKbZOkxJd8qvSdPKO1ebHsOe+uXoYqMAnic2BVQQmoX42F Kai6T6qsNrbh8lY/xn6jpZPAE4M5SwB0/U+ItqDEf/nmzMFtKZWj0E5LPw62e9aWCF9U ZifNqo/TSxg8DAeInHrZrVNonpW9T8hX6xXHZ2p+yj/RvVy+HmkQVd4SVPaWu4U5/kjg 05w1+p8VkJ8eCnVwC4pV33QpzwuwIc0hNPuVsgEL0P11ElkoJkah59oS1WytYIaNQpU7 mauE1ZJDbKwV9lQHd98LAtpsoJuv2cHrFWRWJ1zXYerTp93miIbSn9y+vTtlglnVGdRi 5/IA== 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 f16-20020a63f110000000b0051ace49ded1si8765405pgi.886.2023.05.12.03.05.58; Fri, 12 May 2023 03:06: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 S239935AbjELJ7z (ORCPT + 99 others); Fri, 12 May 2023 05:59:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240692AbjELJ7H (ORCPT ); Fri, 12 May 2023 05:59:07 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 28A95124BE; Fri, 12 May 2023 02:58:40 -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 347E1139F; Fri, 12 May 2023 02:59:24 -0700 (PDT) Received: from e123648.arm.com (unknown [10.57.22.28]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id EB5643F5A1; Fri, 12 May 2023 02:58:36 -0700 (PDT) From: Lukasz Luba To: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, rafael@kernel.org Cc: lukasz.luba@arm.com, dietmar.eggemann@arm.com, rui.zhang@intel.com, amit.kucheria@verdurent.com, amit.kachhap@gmail.com, daniel.lezcano@linaro.org, viresh.kumar@linaro.org, len.brown@intel.com, pavel@ucw.cz, Pierre.Gondois@arm.com, ionela.voinescu@arm.com, rostedt@goodmis.org, mhiramat@kernel.org Subject: [PATCH v2 14/17] Documentation: EM: Add a new section about the design Date: Fri, 12 May 2023 10:57:40 +0100 Message-Id: <20230512095743.3393563-15-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230512095743.3393563-1-lukasz.luba@arm.com> References: <20230512095743.3393563-1-lukasz.luba@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765682418482578043?= X-GMAIL-MSGID: =?utf-8?q?1765682418482578043?= 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 Fri May 12 09:57: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: 93088 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp4982515vqo; Fri, 12 May 2023 03:09:45 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7FluY6YKkQKujm3yoo6fiB10WhT/H+LCvHzpjUEvIRGkncH2er7b75Fq3iigRiOnLwXf3D X-Received: by 2002:a05:6a00:1141:b0:646:5041:9729 with SMTP id b1-20020a056a00114100b0064650419729mr20158652pfm.0.1683886185216; Fri, 12 May 2023 03:09:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683886185; cv=none; d=google.com; s=arc-20160816; b=MzCYKUs5VveZdwC6F3ymS82gCxnInOAOxXcTUFsyHFpUnprLuDGfQaYe7+A1Q1mHMC RbsFu74NdzmMDfTeNrqnayuw+6kfrJCeLO02kB/fNxFvdYA1TrEBPhUmiKFp0yBr+S6R pPISdY2Y5U7Pny3sJhQ+ps83sR53pOLjfl++s87jtLnj7sUbWm49D7MVZqm4bA0XLxmH 6DN+UXwfUScCAcjj//qk2GD/GRpRzlWutSdtgrkZ55qjxWUfU+QTf25o7SgBdbn6hKdk TdlHwiUmZ+VuANpjZmraD/SCN6u2qKrBg1oTOnC+xqxZRAXmvo2y5B8tvGbqshREvBi6 C+bw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Y4XzLzFEBkmBIZ7liKgVa14SGG6rZUs6SI41g8yG728=; b=zCoIlbYxQf/vKmmct7l4edc2SkKopg1L8gPmoLM0M0OSLC/JaQSALn/exIst3l3yDF KK3GLteoRnbe1PRl7ozvEo1u8mwjaL4JT3gGebym0GlD5B63JJaVqFtxzg8E8a9cAF1T LTurcnQL+uC3q2+eD95dY5JPcCY/16h/2xAp+UZX9eZSDWQthU+fHGzGNCSYVLVUB7Ng XyWPE6zYoiDy/e7ZOUIJ3zQsFgtexJnHchwLNMVN0vIJT8FzhdK3cbi4d5IrnD9ofCKb FDIWLRsVvMviQoYF6YKVgbMmHVezQK8Wn32VlOgmZHQ6vYdcKvltzD4wd68AfkM+giB5 oW5g== 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 j13-20020a63cf0d000000b005139e5df68asi8803524pgg.433.2023.05.12.03.09.30; Fri, 12 May 2023 03:09:45 -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 S240587AbjELJ76 (ORCPT + 99 others); Fri, 12 May 2023 05:59:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239962AbjELJ7O (ORCPT ); Fri, 12 May 2023 05:59:14 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id BB49712E89; Fri, 12 May 2023 02:58:46 -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 2FA55165C; Fri, 12 May 2023 02:59:27 -0700 (PDT) Received: from e123648.arm.com (unknown [10.57.22.28]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id E4FBC3F5A1; Fri, 12 May 2023 02:58:39 -0700 (PDT) From: Lukasz Luba To: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, rafael@kernel.org Cc: lukasz.luba@arm.com, dietmar.eggemann@arm.com, rui.zhang@intel.com, amit.kucheria@verdurent.com, amit.kachhap@gmail.com, daniel.lezcano@linaro.org, viresh.kumar@linaro.org, len.brown@intel.com, pavel@ucw.cz, Pierre.Gondois@arm.com, ionela.voinescu@arm.com, rostedt@goodmis.org, mhiramat@kernel.org Subject: [PATCH v2 15/17] Documentation: EM: Add a runtime modifiable EM design description Date: Fri, 12 May 2023 10:57:41 +0100 Message-Id: <20230512095743.3393563-16-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230512095743.3393563-1-lukasz.luba@arm.com> References: <20230512095743.3393563-1-lukasz.luba@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765682640677232461?= X-GMAIL-MSGID: =?utf-8?q?1765682640677232461?= 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 Fri May 12 09:57: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: 93089 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp4982916vqo; Fri, 12 May 2023 03:10:33 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6CURDhAsi2E/x+EKrrHbdOKBSqFSoPeRFIbH08vNYX42wNTaQHvmOhZOJ2YbDXPYJAKe9Q X-Received: by 2002:a05:6a00:2451:b0:646:b944:4e1d with SMTP id d17-20020a056a00245100b00646b9444e1dmr17804423pfj.32.1683886233084; Fri, 12 May 2023 03:10:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683886233; cv=none; d=google.com; s=arc-20160816; b=Y+u4D0qQUYvXmB4xGCuhwGj0PKw0ToO8K8DSHb2AXFEgcLuVn+u+t7CMzLKxJWYUta GkRjre2Cd0Kmp/DBmQUp2ocC+GRPQMoo8DMSZD0ZhIpoSAp9OFxzAeqpQR0hMKu7YZxi G7XeSlcckilTSZ9VsG8yM7Ap0SeUL9sALyqz2ijyeh7ouYFjn0ZRy0i6xa6CY6RRw1rB 5ZLoSlBu8aKCRCaF8g7aDR41lDW0YQrLYDMDhbkNVYi2ah7SnkhV0H4oCW/pY9S0GyFS WGYy6ue4xKT83xID8wzok0qIQbBZv5nRJCVapM1shJrSVCHlE+oXHzL/3Eqg14zZ6j1+ 5ZCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=BxqLvb/kwD5VKm4qKkD+2mwkxSCLRnbCbPkfLUHNBz8=; b=nS7PFlAMiCBW81QuDnr7uPb42Ul2HfdrDT8GUf2pKq7yVuW+Q1IAFPfKRbE7FE46rh QgWB8xzcFQ4sol2PJzxY6stumrurBA8vOclSNHZTbYpVPduwg7Nq1EC+NLvstp2k/4iO 9zpPZ2JD4yeowZtVV4sBixLcBtVDPw1B/PAqe0rBguWf+Zm2W2DEwmh5pQ4OMAACqXN3 JYY80cGaRKxI41DdV9kZJZFP3u0Vp8BX8BnEI4n5yg6lcdcwdxUXkYTTrtty+mI838jI 1pFP4EsbMjDmThLBIo0a7Ueyxs/K4EkyB4yDqfjZAz0wHGv+ANWtaRJ5DRdqCZetowjL OjUQ== 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 b9-20020aa78ec9000000b00625c6092a12si9948998pfr.215.2023.05.12.03.10.18; Fri, 12 May 2023 03:10:33 -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 S240366AbjELKAM (ORCPT + 99 others); Fri, 12 May 2023 06:00:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53550 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240654AbjELJ7a (ORCPT ); Fri, 12 May 2023 05:59:30 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 47F5811DB4; Fri, 12 May 2023 02:59:03 -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 2E08D1684; Fri, 12 May 2023 02:59:30 -0700 (PDT) Received: from e123648.arm.com (unknown [10.57.22.28]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id E19C93F5A1; Fri, 12 May 2023 02:58: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 v2 16/17] Documentation: EM: Add example with driver modifying the EM Date: Fri, 12 May 2023 10:57:42 +0100 Message-Id: <20230512095743.3393563-17-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230512095743.3393563-1-lukasz.luba@arm.com> References: <20230512095743.3393563-1-lukasz.luba@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765682690716734475?= X-GMAIL-MSGID: =?utf-8?q?1765682690716734475?= 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 Fri May 12 09:57: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: 93078 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp4981387vqo; Fri, 12 May 2023 03:07:37 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7jvTfZA0kmXK+yvnkkO+r+ob2sYQ9SajwsIfYkZyT+AZEwH8Y+IfPartvR0eTPH/8v6JHS X-Received: by 2002:a17:90b:1d87:b0:24d:fb82:71ab with SMTP id pf7-20020a17090b1d8700b0024dfb8271abmr24783039pjb.26.1683886056803; Fri, 12 May 2023 03:07:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683886056; cv=none; d=google.com; s=arc-20160816; b=Nb2ExqNlrjNFrbkPAVSW7rBqs/PgsmhCvgX/sljZlm3dvbW4ZXQQzTKOSIAv2QNqTd h2nJhPzuy8MLQpl9otqDt40g9ZoL/AONA9eVQpcJKbkneacIq5Kh3I0OpLnPg8CUkc3E OZJBRNtnbHqs45WfWOyEMkf0mm0Z8C/45sJ0bxZAk7SByaTNS8QMLeqJ7fJz1ngQRX9Y Kbtsf+o+x1eOJ2hoT338f0fUSiHBMJErJ7HgvajA/hGTrHAeGQLyFtt+xzlIGZF3MQBZ T6AzPyTRjXqQwZxAitMlt/dmMKJR0jy3ZkUjEQjwybdhELSGDjzZ/2vP2Bwp4J1o6+6V g/WA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=xJvDFnbW8Z+tP3Sxw/naBBQGZ3enQ3TCHSsB0ixo5o0=; b=Xm6PU55kys0wwfIy1kxyVGYPADedJGpNKtHUf3GaDpHQHQWa/vgoGrO5flK7XaqYtc Pm8CIY86Hok1Ba5CMFV+ngNZHKFePadpCBsLJkzugV01JDzmw2OyHqR9ioF9P0Lw3Qo7 1zHkGFbeHCSAOxGPkIL0TkNNKHS79CMqWk+qvCt2bSSkZAOSVdp15+/oJRPIXwqyu/cu BIitWsrHWhSNnl0Jl/QSfQfNP/JimIZmwa/+rOBUKbqSgWwBwkCHQRg89yKKSbao0f1d PW59Y5b1kX1E+MzMk1KbrBWcMb9Ejq4GfQG9HIyig4CYwOa7HN2ApGtueSc8GcdKhByz QewA== 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 p8-20020a17090a930800b00247ad6e4188si21891014pjo.51.2023.05.12.03.07.21; Fri, 12 May 2023 03:07:36 -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 S240725AbjELKAU (ORCPT + 99 others); Fri, 12 May 2023 06:00:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240751AbjELJ7u (ORCPT ); Fri, 12 May 2023 05:59:50 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 09ABB12E90; Fri, 12 May 2023 02:59:10 -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 27D9B16F2; Fri, 12 May 2023 02:59:33 -0700 (PDT) Received: from e123648.arm.com (unknown [10.57.22.28]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id DEB273F5A1; Fri, 12 May 2023 02:58: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 v2 17/17] Documentation: EM: Describe the API of runtime modifications Date: Fri, 12 May 2023 10:57:43 +0100 Message-Id: <20230512095743.3393563-18-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230512095743.3393563-1-lukasz.luba@arm.com> References: <20230512095743.3393563-1-lukasz.luba@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765682505928059236?= X-GMAIL-MSGID: =?utf-8?q?1765682505928059236?= 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: