From patchwork Mon Sep 25 08:11:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 144266 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp1053093vqu; Mon, 25 Sep 2023 01:17:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEh4SBKg1CQqJGon56snCBC5qUXeVDLGPUfBhhAH99QELalEq8gEqMA4nilyBZtPREqDBWK X-Received: by 2002:a17:902:8f94:b0:1c3:dad8:bb99 with SMTP id z20-20020a1709028f9400b001c3dad8bb99mr3347786plo.64.1695629854163; Mon, 25 Sep 2023 01:17:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695629854; cv=none; d=google.com; s=arc-20160816; b=TvGlVv98cyApaxBiTj6PyXhpo9gt0kVFLbYM7SIBncNwdFFB264j+MfIl2rOhE/sPW ufOTh77vi5TSqEdmnT2NCb2JUnPOVSKnyQeOe6/TM2za/C4UwhHs5FpFPs5G6JyyogZk /NTl/nAgvxSyetXCmTgB8EZs9GrrkENuW5hOT/MYk2peKdxKGy2Ut6ey+6alZbsAg2Lr xs3KnOkGs7dVn+rXFEhsT2sz5M/jYJKjJZpVUaBZlFA2W668KUyBLcq84TEhv6iYzaH7 oORSCEiFx6i90/wErdPiSPkgCtI+u4lG7h9egx1HkW1MtkfmU8JOmrOAf5BJkkJFdWea SDeA== 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=pofv311uiKaOWaJciLO0SASpSsyIrb2O7wIOuN/HC54=; fh=jF+j1UEDAwnYbShW3HmO1TshMsWh36Jt7pSLTP62NeE=; b=MBwAzLgGfOpSD9qtXzjYadENwmdwuaRT6O235MB1esyCwBDS+TV4OycX6Z4M1yHLSX 2NMY14tFGn0zJpZs3siXOQx4uGJJ6E7EoSR1J+5AbBDHCVvMPAmRCXKtspdtz+WlcjTn xATw9H+8uDz9g1KqDhmycS0PHOh/cYI17CxmwYsiAxGXA7NkH+jvhS4T8mK2VCGoj24G xDDoBRS81F8LCHVgzUC9KT5cqyiMDUeob54CRadPeCXihMlRxvfm32LJa8Fy4tLdA1aX c+mJcvtzeZwDrj0aYh9WGCnR95H5mRvOVr+Qzh03ptqeG4CAuixPTI/oJl7vm9mYe/Qf +Kjw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id u15-20020a170902e5cf00b001bf0916b665si9813977plf.393.2023.09.25.01.17.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 01:17:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id B7F0D809249B; Mon, 25 Sep 2023 01:11:49 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232697AbjIYILc (ORCPT + 30 others); Mon, 25 Sep 2023 04:11:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232643AbjIYILV (ORCPT ); Mon, 25 Sep 2023 04:11:21 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E3C02FB; Mon, 25 Sep 2023 01:11:14 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D67081424; Mon, 25 Sep 2023 01:11:52 -0700 (PDT) Received: from e129166.arm.com (unknown [10.57.93.139]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 2F96B3F5A1; Mon, 25 Sep 2023 01:11: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, mhiramat@kernel.org, qyousef@layalina.io, wvw@google.com Subject: [PATCH v4 01/18] PM: EM: Add missing newline for the message log Date: Mon, 25 Sep 2023 09:11:22 +0100 Message-Id: <20230925081139.1305766-2-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230925081139.1305766-1-lukasz.luba@arm.com> References: <20230925081139.1305766-1-lukasz.luba@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Mon, 25 Sep 2023 01:11:49 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777996769573790946 X-GMAIL-MSGID: 1777996769573790946 Fix missing newline for the string long in the error code path. 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 7b44f5b89fa1..8b9dd4a39f63 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -250,7 +250,7 @@ static void em_cpufreq_update_efficiencies(struct device *dev) policy = cpufreq_cpu_get(cpumask_first(em_span_cpus(pd))); if (!policy) { - dev_warn(dev, "EM: Access to CPUFreq policy failed"); + dev_warn(dev, "EM: Access to CPUFreq policy failed\n"); return; } From patchwork Mon Sep 25 08:11:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 144261 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp1052455vqu; Mon, 25 Sep 2023 01:15:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGAlUTxqyzSAOFcDQsID7JVN+A93L9edQpDMdjDERwO+aCKk0P5zuJnHVi9HZl06XduTRs3 X-Received: by 2002:a17:902:aa41:b0:1c5:f110:efa0 with SMTP id c1-20020a170902aa4100b001c5f110efa0mr3364541plr.30.1695629750244; Mon, 25 Sep 2023 01:15:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695629750; cv=none; d=google.com; s=arc-20160816; b=l9ogFnDiw7Qn9uvm9b/RjdaTC8UeTfR2+juu+g/XR+FooulITnzIvETEv182XWT2JP gZ7Is4Thb4yX4Bhy1j3P6YRWHas/vBQj/mQXH3C0jK2i7iTjOYahePc52YMTGgweM2gW pMhGOXwfrMJK3KN5o4kTz6WBbSie1SmP274lsBozCdlIWK+P9HfsH8BK5Em+KiXZsOSR BeQGyHGD/OK/ttkA0IlwgJvD+yD+CLkH02B7lmdRPphf2KLqD1YvIT2MMtYAe9HKv731 +U1ESU68+7x0b6XoNRKrCeRrFAxfUiQFnlzkT7SCEjojRFpMAff9kEt6m0iPt+z3TK32 ZstA== 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=e9cA+0DkJFR+tPXa3CKCd2sCKzNan0sHKPOnU9erHAE=; fh=jF+j1UEDAwnYbShW3HmO1TshMsWh36Jt7pSLTP62NeE=; b=CGkyH7J81/WtXZOblJUIRWvJY8ztvBt8G7HtdW2GwbtQ5pn6e26FYANgbiudmAcXsA mt45jDDWMLiCa8k4HaXTVM/hALZWn7klmwL8ZXZAgHIq+jAUN6DbM8cNAFEZJoMoaliV NPf4x3fP0Oyyt1Qzc1v8WDWCDVRl8pEdNctjyFPetDO5ORQDWqPCUlJkm15nB/1WNi/t i8JUSC+40gziBPZXTWwPALCLwOsnCYfjLjL63ESKrzHMKZK/TR5k/rs6ny/kkjrBbT64 YSfrZYQNkHUgvaoCIVX8XPm69cuNOH2dCHl6SP90ZZESYnaj17AMSQMn+CLltkGlz4V2 A+Ew== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id s11-20020a170903200b00b001b886a0c366si8522729pla.122.2023.09.25.01.15.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 01:15:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 393BA81A0C0E; Mon, 25 Sep 2023 01:11:53 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232673AbjIYILf (ORCPT + 30 others); Mon, 25 Sep 2023 04:11:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232693AbjIYIL0 (ORCPT ); Mon, 25 Sep 2023 04:11:26 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 00E5CFC; Mon, 25 Sep 2023 01:11:17 -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 9C4551474; Mon, 25 Sep 2023 01:11:55 -0700 (PDT) Received: from e129166.arm.com (unknown [10.57.93.139]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id F2E633F5A1; Mon, 25 Sep 2023 01:11:14 -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, mhiramat@kernel.org, qyousef@layalina.io, wvw@google.com Subject: [PATCH v4 02/18] PM: EM: Refactor em_cpufreq_update_efficiencies() arguments Date: Mon, 25 Sep 2023 09:11:23 +0100 Message-Id: <20230925081139.1305766-3-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230925081139.1305766-1-lukasz.luba@arm.com> References: <20230925081139.1305766-1-lukasz.luba@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Mon, 25 Sep 2023 01:11:53 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777996660836311192 X-GMAIL-MSGID: 1777996660836311192 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 8b9dd4a39f63..42486674b834 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 Mon Sep 25 08:11:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 144278 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp1055921vqu; Mon, 25 Sep 2023 01:25:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHv87KC3+FHq35lvWFpByEPKGWv7z+p3zbd7lFIPDZmXZnssHeZSLAH+uh8KS952hmtFXkY X-Received: by 2002:a05:6a20:430a:b0:133:1d62:dcbd with SMTP id h10-20020a056a20430a00b001331d62dcbdmr13500453pzk.28.1695630301702; Mon, 25 Sep 2023 01:25:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695630301; cv=none; d=google.com; s=arc-20160816; b=eweFERZyE+fS8ZUqImxGi1hykRHyRhYaW4Q8eFFywKdRX2uu9MrAQgduGHHcxqGozr 7Oyximo1WoegFXg5KGzUr8HeLv+ukDxl2KXH2ALgdwkJ9d9SYMvE9EvJudrpxjknxBhp xnFjfKJDMJ6Mh3DH/4VM+1lRiiiOm+o34d+7nYpNmaCWeOYyUiytNN8npEirpcvu5FPk lTHS5eOFEykM85Zw3TTlSG4OWVJ0Sr+jENOPzDSUop/SRxc4FXXUlKogpWsWGnNWmfh1 E1/pD47KKT9MYAsvsRirxtcCtATlaJGSeE1GXWVXelU6k8jhg3BWp8srS8ntggedkUwk UIEQ== 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=s2hKt+ICDgnm8fA7TQUJDDmWfVUUTFmc+SHXUzozYx4=; fh=jF+j1UEDAwnYbShW3HmO1TshMsWh36Jt7pSLTP62NeE=; b=FrEN4FAH57N1L7HRFiXPluWQE4Exv+097haVbBc3OFkJvw+cxv/BVC0USWS1fv1Ou6 H0upXBOhyjnm8E7Jad9crnwNqOYbdqHQshMK6LS/0+BmmVN6y50TOvJ3q76kGYavnNZY 0PoNxkVls8JOoD/VnC06P0ZCGBN6mrDBt7MEWEFxgoJnKPhORD1F7XS8Red8ZMtTL8WT q7UMA9LG5qislRgBXXiezudqnR80X8hJQjLEbl8bgYbaOqqfPEQceCdheQuy5m+bJw4y L+cVsXSOMzHZc4zzeHmOwcScWyqfk4SqIm6qdJ77hXReTB8Y0cue+JoQG8EzVsXYHVUI RiBg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id bv64-20020a632e43000000b0057745d87b50si9289160pgb.139.2023.09.25.01.25.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 01:25:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 2239280D6AFD; Mon, 25 Sep 2023 01:12:15 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232734AbjIYILm (ORCPT + 30 others); Mon, 25 Sep 2023 04:11:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232712AbjIYIL1 (ORCPT ); Mon, 25 Sep 2023 04:11:27 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A0EA6D3; Mon, 25 Sep 2023 01:11:20 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 706D21476; Mon, 25 Sep 2023 01:11:58 -0700 (PDT) Received: from e129166.arm.com (unknown [10.57.93.139]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id B8D2F3F5A1; Mon, 25 Sep 2023 01:11:17 -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, mhiramat@kernel.org, qyousef@layalina.io, wvw@google.com Subject: [PATCH v4 03/18] PM: EM: Find first CPU online while updating OPP efficiency Date: Mon, 25 Sep 2023 09:11:24 +0100 Message-Id: <20230925081139.1305766-4-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230925081139.1305766-1-lukasz.luba@arm.com> References: <20230925081139.1305766-1-lukasz.luba@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Mon, 25 Sep 2023 01:12:15 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777997238851893923 X-GMAIL-MSGID: 1777997238851893923 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 42486674b834..3dafdd7731c4 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\n"); return; From patchwork Mon Sep 25 08:11:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 144305 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp1064903vqu; Mon, 25 Sep 2023 01:48:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IETV40q+uNS1w5j0G3Fvvw46nP1KGNynGKgfGRBBG0a3KmoV1Y+a7F12pjx3nkHkQWpWDL6 X-Received: by 2002:a05:6a21:7897:b0:12e:73bb:cbb6 with SMTP id bf23-20020a056a21789700b0012e73bbcbb6mr7332819pzc.14.1695631718217; Mon, 25 Sep 2023 01:48:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695631718; cv=none; d=google.com; s=arc-20160816; b=FCnu+ukZOzVGmtTehr8FhvQ5YvQScfnE8Myt0O/t301mVFbwcnMx8dzRvW0eZc3eWS isaMPRoc0Zv+Z4a3KP4jXrRGutm4m8zLjocgZLW2b/lA9qejgQkyUib8592wpQXDZusO sq1YWZ3hNi7utvM3MY89/S4DsN1/RNjEbKduvn9P3N8o5tT8s1I7I9LWJgDEwSQoDqE5 K0Dlmw4KLZap1BCBGDtBxo6NlhytsfUUiPA2ddr5O3HFC6904wnqLs63Un0IZmyuge+u iPEbGx1Hk/XUIWOssyo3CAjZGDALzgakZhBcg1KRn10HqJWGQRDfLind2MHzlytPU7d3 JcdQ== 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=HfkuYA/xL5oppUy+KAWLxXiDZxtbOLAxnDNn6vWCmiY=; fh=jF+j1UEDAwnYbShW3HmO1TshMsWh36Jt7pSLTP62NeE=; b=XhXbGDA/7ByRZwOBgy4X1Pw+Gbn2vq6EibKb031oBXW27Uih6jop8TPcbo5K3eWLfX TvvquNTuVM3R5KxnqSDvlpfPieHPICwMp0C17kiFBaaGQ1kS4N71JgKIB3G6yKZS4anh jh2Rw8gjrUo2J5qe67dqWPKhybec6gd4Upv+NMdyauVjonGeivNaABvd/btZUuZ+htCj VXTxBEvzuYQS27ZhvrgP0gXPN2ifgO3Z3nEDB4vZW2UT8f2xZD7HkhPiciymciGid8Ft bgoG+tRvg5FEdWP7iEc14VhoKTUfJmWEspA0bNRtQ0cPwm3R+1UgqXs8pteh4LXI4WRZ Sh2Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id a6-20020a17090a740600b00274afd5346esi9506381pjg.151.2023.09.25.01.48.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 01:48:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id B80B38022A90; Mon, 25 Sep 2023 01:11:45 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232753AbjIYILi (ORCPT + 30 others); Mon, 25 Sep 2023 04:11:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232720AbjIYILc (ORCPT ); Mon, 25 Sep 2023 04:11:32 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 46EEB19A; Mon, 25 Sep 2023 01:11:23 -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 2E8CEDA7; Mon, 25 Sep 2023 01:12:01 -0700 (PDT) Received: from e129166.arm.com (unknown [10.57.93.139]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 861193F5A1; Mon, 25 Sep 2023 01:11:20 -0700 (PDT) From: Lukasz Luba To: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, rafael@kernel.org Cc: lukasz.luba@arm.com, dietmar.eggemann@arm.com, rui.zhang@intel.com, amit.kucheria@verdurent.com, amit.kachhap@gmail.com, daniel.lezcano@linaro.org, viresh.kumar@linaro.org, len.brown@intel.com, pavel@ucw.cz, mhiramat@kernel.org, qyousef@layalina.io, wvw@google.com Subject: [PATCH v4 04/18] PM: EM: Refactor em_pd_get_efficient_state() to be more flexible Date: Mon, 25 Sep 2023 09:11:25 +0100 Message-Id: <20230925081139.1305766-5-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230925081139.1305766-1-lukasz.luba@arm.com> References: <20230925081139.1305766-1-lukasz.luba@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Mon, 25 Sep 2023 01:11:45 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777998724570255772 X-GMAIL-MSGID: 1777998724570255772 The Energy Model (EM) is going to support runtime modification. There are going to be 2 EM tables which store information. This patch aims to prepare the code to be generic and use one of the tables. The function will no longer get a pointer to 'struct em_perf_domain' (the EM) but instead a pointer to 'struct em_perf_state' (which is one of the EM's tables). 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 for a given EM table. 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 Reviewed-by: Daniel Lezcano --- 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 Mon Sep 25 08:11:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 144282 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp1056423vqu; Mon, 25 Sep 2023 01:26:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF2BkdAxOE7QfRJ1ZTCatiLQcsBj9DA96rGbKkq4sytA0h3FLo7y8lfbh2UslvNjjLlrbGF X-Received: by 2002:a05:6a20:6a03:b0:15d:8eea:27a3 with SMTP id p3-20020a056a206a0300b0015d8eea27a3mr9867021pzk.3.1695630382546; Mon, 25 Sep 2023 01:26:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695630382; cv=none; d=google.com; s=arc-20160816; b=mMQ/k6xLIQB98yUC2X7F8eSL107txN0FfCuVr6Ir8MZJPIZTWTdoddWOEsbN7hxegg pOY9G0qTDaaWqx/gsiXUUVYtqBSgW6mCR0+0m3niSRPXTRB0ICfYIay4MNeBS47EkIiv vLNK2wqbr2aa2s8TXcLFF7XdyqqdTJDy2R6kmfMqBk+fjYJZGBiJtgNucfduLmAhpbgJ gnBI9jLeeGQAACAcZeE/wr8IP89Hd2n2+DNY0G/LKOiL6MXmtnoj+Ad9swiazc8CLqJQ HOJrNLfGTXh+G32cbDfmjAxk85Qg8fgBaXkNKHUQIyZ3l2WL+URX145T+3OOgu50E0f/ 0RGA== 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=vjyNlG9l6sJQEo4UObiKqmins20Z8kvgYFjwJ3ONRMs=; fh=jF+j1UEDAwnYbShW3HmO1TshMsWh36Jt7pSLTP62NeE=; b=e0DCxclfCqhr2BUREobZ4shrCvwNjw/ZzkuEw1zNZNBuBM3HmkE3EJkVggQKFqWNTG l06+EsD8hccZjzv+LA/eqyQPKbv30PiMtYwgYn4F/EJjISQDBjb+5ZpH2mrvi1uRH8Ek egQ4KWPXv+KmrUJmtrWu29fJ2n7zXWC9PSFUOVH4fGhZyDxkpDru6zOah+IKay3PIV3q slN19tPEK3029tpj793KL0MkCZH3l+ZQD61hBzKZDlPAEfQUTeJ3cUyoHky+SBbxkCYr tfu+U3nzrdGYWGnOvjP5U1ksIAf7E0vaRJPX/BaBsYGkvU5n/iaaeXz7pcyG1/SamNpg J2/g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id o73-20020a62cd4c000000b0069026fd5a31si8891604pfg.272.2023.09.25.01.26.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 01:26:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 2027F8095DD1; Mon, 25 Sep 2023 01:11:58 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232679AbjIYILp (ORCPT + 30 others); Mon, 25 Sep 2023 04:11:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42442 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232742AbjIYILe (ORCPT ); Mon, 25 Sep 2023 04:11:34 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 54E591BC; Mon, 25 Sep 2023 01:11:26 -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 182291424; Mon, 25 Sep 2023 01:12:04 -0700 (PDT) Received: from e129166.arm.com (unknown [10.57.93.139]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 4B7C93F5A1; Mon, 25 Sep 2023 01:11:23 -0700 (PDT) From: Lukasz Luba To: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, rafael@kernel.org Cc: lukasz.luba@arm.com, dietmar.eggemann@arm.com, rui.zhang@intel.com, amit.kucheria@verdurent.com, amit.kachhap@gmail.com, daniel.lezcano@linaro.org, viresh.kumar@linaro.org, len.brown@intel.com, pavel@ucw.cz, mhiramat@kernel.org, qyousef@layalina.io, wvw@google.com Subject: [PATCH v4 05/18] PM: EM: Refactor a new function em_compute_costs() Date: Mon, 25 Sep 2023 09:11:26 +0100 Message-Id: <20230925081139.1305766-6-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230925081139.1305766-1-lukasz.luba@arm.com> References: <20230925081139.1305766-1-lukasz.luba@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Mon, 25 Sep 2023 01:11:58 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777997323698540917 X-GMAIL-MSGID: 1777997323698540917 Refactor a dedicated function which will be easier to maintain and re-use in future. The upcoming changes for the modifiable EM perf_state table will use it (instead of duplicating the code). Signed-off-by: Lukasz Luba --- kernel/power/energy_model.c | 72 ++++++++++++++++++++++--------------- 1 file changed, 43 insertions(+), 29 deletions(-) diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c index 3dafdd7731c4..7ea882401833 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -103,14 +103,52 @@ static void em_debug_create_pd(struct device *dev) {} static void em_debug_remove_pd(struct device *dev) {} #endif +static int em_compute_costs(struct device *dev, struct em_perf_state *table, + struct em_data_callback *cb, int nr_states, + unsigned long flags) +{ + unsigned long prev_cost = ULONG_MAX; + u64 fmax; + int i, ret; + + /* Compute the cost of each performance state. */ + fmax = (u64) table[nr_states - 1].frequency; + for (i = nr_states - 1; i >= 0; i--) { + unsigned long power_res, cost; + + if (flags & EM_PERF_DOMAIN_ARTIFICIAL) { + ret = cb->get_cost(dev, table[i].frequency, &cost); + if (ret || !cost || cost > EM_MAX_POWER) { + dev_err(dev, "EM: invalid cost %lu %d\n", + cost, ret); + return -EINVAL; + } + } else { + power_res = table[i].power; + cost = div64_u64(fmax * power_res, table[i].frequency); + } + + table[i].cost = cost; + + if (table[i].cost >= prev_cost) { + table[i].flags = EM_PERF_STATE_INEFFICIENT; + dev_dbg(dev, "EM: OPP:%lu is inefficient\n", + table[i].frequency); + } else { + prev_cost = table[i].cost; + } + } + + return 0; +} + static int em_create_perf_table(struct device *dev, struct em_perf_domain *pd, int nr_states, struct em_data_callback *cb, unsigned long flags) { - unsigned long power, freq, prev_freq = 0, prev_cost = ULONG_MAX; + unsigned long power, freq, prev_freq = 0; struct em_perf_state *table; int i, ret; - u64 fmax; table = kcalloc(nr_states, sizeof(*table), GFP_KERNEL); if (!table) @@ -154,33 +192,9 @@ static int em_create_perf_table(struct device *dev, struct em_perf_domain *pd, table[i].frequency = prev_freq = freq; } - /* Compute the cost of each performance state. */ - fmax = (u64) table[nr_states - 1].frequency; - for (i = nr_states - 1; i >= 0; i--) { - unsigned long power_res, cost; - - if (flags & EM_PERF_DOMAIN_ARTIFICIAL) { - ret = cb->get_cost(dev, table[i].frequency, &cost); - if (ret || !cost || cost > EM_MAX_POWER) { - dev_err(dev, "EM: invalid cost %lu %d\n", - cost, ret); - goto free_ps_table; - } - } else { - power_res = table[i].power; - cost = div64_u64(fmax * power_res, table[i].frequency); - } - - table[i].cost = cost; - - if (table[i].cost >= prev_cost) { - table[i].flags = EM_PERF_STATE_INEFFICIENT; - dev_dbg(dev, "EM: OPP:%lu is inefficient\n", - table[i].frequency); - } else { - prev_cost = table[i].cost; - } - } + ret = em_compute_costs(dev, table, cb, nr_states, flags); + if (ret) + goto free_ps_table; pd->table = table; pd->nr_perf_states = nr_states; From patchwork Mon Sep 25 08:11: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: 144262 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp1052485vqu; Mon, 25 Sep 2023 01:15:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFjrH/MxwsSl9fXr8283467YGaQz2hoxtRAw2WSShbgxBqSIAJK7+l5HCT5LCNQ85h1j3ss X-Received: by 2002:a17:90a:df98:b0:277:3afc:f27 with SMTP id p24-20020a17090adf9800b002773afc0f27mr6303145pjv.1.1695629755659; Mon, 25 Sep 2023 01:15:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695629755; cv=none; d=google.com; s=arc-20160816; b=auiselqKHingazrs9l4zXurPFu+3dx9eZm9+NhyLhx8Uxj6nxeUl1ZLjgy8LWEcSMF NoDm4HrC8SOQc5l38HzwLqNIl7DJiQ6JVvcC7lcXiJ7ssXMM3R9NhVGd0RUlVSJY3Sfn jjcgFN3Z9rMP03cEmE2OW8nO8vxxU/E7QYJ7BT1JHFWohRDA70RVn0WrMzP/G0Thn/HG 6wMJ918GgFXjOuWbSqCubWwyHskEf0klqq3wFDyq6ByTKmZz7KuBZHb9ab1QzGKChcSc wgLTZX91TCV/DW03nF4TrCB6z7hyT/muhnVVeb8HR7adENWXg07rocr5OC5N6JFl80PT pjfg== 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=wQ0gPwSOogTwDaTP/PQzByHSEzyoInUXuUiU4l+qyK8=; fh=jF+j1UEDAwnYbShW3HmO1TshMsWh36Jt7pSLTP62NeE=; b=gk6QHcPNfFB0UWSaRt99k4XsTdpgwocf+JTxX/pONsbWOhK6lorAVG2g7bycHUX/QJ NgH3vhHcQdP0kOrG/L57Zf7YFsbDEE9aDFS3AWP34cpp4q4KTxyfPJIZ3/4HxauPWmCn /kYoWfMftXDJCpAYEdnaVeX5gs3gcguQP95loZVKIsbGYk5+5vv9g2b44hMUludAysZL MdYVsDcDHq52JUhZfYXL+57ZWPmz30MyM15tggaLcVuESTKVvJ+/rdfhxQ82b8lPqgd2 ULqz0gbBrOQevog/R3MAD4wY7YNKEOhb/QwkobSNygD1KLLH6RkDrdK88KrmIdjlIHXR tWeg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id p1-20020a17090a74c100b00274e16f797csi9368810pjl.20.2023.09.25.01.15.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 01:15:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 50F7B81A0C08; Mon, 25 Sep 2023 01:12:05 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232816AbjIYIL5 (ORCPT + 30 others); Mon, 25 Sep 2023 04:11:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42366 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232721AbjIYILg (ORCPT ); Mon, 25 Sep 2023 04:11:36 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 24452111; Mon, 25 Sep 2023 01:11:28 -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 B613FDA7; Mon, 25 Sep 2023 01:12:06 -0700 (PDT) Received: from e129166.arm.com (unknown [10.57.93.139]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 11E683F7BD; Mon, 25 Sep 2023 01:11:25 -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, mhiramat@kernel.org, qyousef@layalina.io, wvw@google.com Subject: [PATCH v4 06/18] PM: EM: Check if the get_cost() callback is present in em_compute_costs() Date: Mon, 25 Sep 2023 09:11:27 +0100 Message-Id: <20230925081139.1305766-7-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230925081139.1305766-1-lukasz.luba@arm.com> References: <20230925081139.1305766-1-lukasz.luba@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Mon, 25 Sep 2023 01:12:05 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777996666433692276 X-GMAIL-MSGID: 1777996666433692276 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 7ea882401833..35e07933b34a 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -116,7 +116,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 Mon Sep 25 08:11: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: 144270 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp1054275vqu; Mon, 25 Sep 2023 01:20:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEJ/V0pOnTMZFiWyI0LJbOWuTQ30hnxKNiHbmgUxmBK39DgSQnkAGuvR/iQsV7RKhPaiqf0 X-Received: by 2002:a05:6a20:8e10:b0:14c:5dc3:f1c9 with SMTP id y16-20020a056a208e1000b0014c5dc3f1c9mr5322277pzj.49.1695630046113; Mon, 25 Sep 2023 01:20:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695630046; cv=none; d=google.com; s=arc-20160816; b=i5EMzlh4kQ6GC/b566ZBa7zz9nQG/n5R+zLMK6aPBhe6A41hUolFnBqL/y284/VOJE fvVlwaanz+5ihc1PStlnomBm1kWA8czyu0hMfhnWj3a6mUg2mI7/eqE2tp8v+0QbhWrF 4A/Grin0GHX2TuJtpPMd61bs4fOusRCuujA3FmBDB3wTWE+WYtT5HZCdpgWI4S4MbqTC EquqhQbVP++1g1VXtMxkX8wnz4EbjIkpctRq5jLkIus7RyEImtKgkzsPP8J3QubMvzHG W+NQYOFs18vNN8cxYhRM1Npt4HLXMOVkCcNidQK0k5+ldbH1XF8xpAfIZcvqKyfONhs5 Zpbw== 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=IGOXDVxuvKvB9PThvJSo+khz6hk+CewYiKgr1qcCFAQ=; fh=jF+j1UEDAwnYbShW3HmO1TshMsWh36Jt7pSLTP62NeE=; b=SNISm1dK6OAES0Et2Y4ExcOgh1MSN0BrjGc7SSb41PtI7XqBMXu+QwY3L+3MbbJkbT r4jY9sBRxs6gbG+JW7neQ8lf8I8q8ZGXc/fEbU4XzzukdY2gm/QNXeuQxg/y0fQmbBYu czhvYTGjMbv6xvYiSgjxZFpBdv6CcH2HX3Xe4RzpF2tVMMpz1YcHJFkBrx85PbBRR0Kd jI6sp8l0h/w9bRZRLJ7aU69nc+0f/JVm7MjlT1MydXfzozcjAi1JhxNL8zu/7s+5QBTX qpPGhUzpqakYPgV5kDfxtPPAmZL2eYhHZrOtxp3e7Vc264It4VLLXOsUPgGrqB1OjtQ0 BAgw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id pj4-20020a17090b4f4400b00274681ee3adsi4381123pjb.8.2023.09.25.01.20.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 01:20:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 22483801C02D; Mon, 25 Sep 2023 01:12:05 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232839AbjIYIMA (ORCPT + 30 others); Mon, 25 Sep 2023 04:12:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232766AbjIYILl (ORCPT ); Mon, 25 Sep 2023 04:11:41 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D1814180; Mon, 25 Sep 2023 01:11:31 -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 9BCBA1424; Mon, 25 Sep 2023 01:12:09 -0700 (PDT) Received: from e129166.arm.com (unknown [10.57.93.139]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id D15053F5A1; Mon, 25 Sep 2023 01:11:28 -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, mhiramat@kernel.org, qyousef@layalina.io, wvw@google.com Subject: [PATCH v4 07/18] PM: EM: Refactor struct em_perf_domain and add default_table Date: Mon, 25 Sep 2023 09:11:28 +0100 Message-Id: <20230925081139.1305766-8-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230925081139.1305766-1-lukasz.luba@arm.com> References: <20230925081139.1305766-1-lukasz.luba@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Mon, 25 Sep 2023 01:12:06 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777996971030271052 X-GMAIL-MSGID: 1777996971030271052 The Energy Model is going to 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 will help to better distinguish 2 performance state tables. 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 | 24 ++++++++++++++++-------- drivers/thermal/devfreq_cooling.c | 23 +++++++++++++++++------ include/linux/energy_model.h | 24 ++++++++++++++++++------ kernel/power/energy_model.c | 26 ++++++++++++++++++++++---- 6 files changed, 108 insertions(+), 39 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..d468aca241e2 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,11 @@ 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 8069f526c9d8..d236e08e80dc 100644 --- a/include/linux/energy_model.h +++ b/include/linux/energy_model.h @@ -36,9 +36,19 @@ struct em_perf_state { */ #define EM_PERF_STATE_INEFFICIENT BIT(0) +/** + * struct em_perf_table - Performance states table + * @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 + * @default_table: Pointer to the default 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 @@ -53,7 +63,7 @@ struct em_perf_state { * field is unused. */ struct em_perf_domain { - struct em_perf_state *table; + struct em_perf_table *default_table; int nr_perf_states; unsigned long flags; unsigned long cpus[]; @@ -227,12 +237,14 @@ static inline unsigned long em_cpu_energy(struct em_perf_domain *pd, unsigned long allowed_cpu_cap) { unsigned long freq, scale_cpu; - struct em_perf_state *ps; + struct em_perf_state *table, *ps; int cpu, i; if (!sum_util) return 0; + table = pd->default_table->state; + /* * In order to predict the performance state, map the utilization of * the most utilized CPU of the performance domain to a requested @@ -243,7 +255,7 @@ 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]; + ps = &table[pd->nr_perf_states - 1]; max_util = map_util_perf(max_util); max_util = min(max_util, allowed_cpu_cap); @@ -253,9 +265,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, + i = em_pd_get_efficient_state(table, pd->nr_perf_states, freq, pd->flags); - ps = &pd->table[i]; + ps = &table[i]; /* * The capacity of a CPU in the domain at the performance state (ps) diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c index 35e07933b34a..797141638b29 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -66,6 +66,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; @@ -81,7 +82,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); } @@ -196,7 +197,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; @@ -210,6 +211,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 *default_table; struct em_perf_domain *pd; struct device *cpu_dev; int cpu, ret, num_cpus; @@ -234,8 +236,17 @@ 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; + } + + pd->default_table = default_table; + ret = em_create_perf_table(dev, pd, nr_states, cb, flags); if (ret) { + kfree(default_table); kfree(pd); return ret; } @@ -358,6 +369,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; @@ -416,7 +428,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"); @@ -435,12 +448,16 @@ EXPORT_SYMBOL_GPL(em_dev_register_perf_domain); */ void em_dev_unregister_perf_domain(struct device *dev) { + struct em_perf_domain *pd; + 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. @@ -449,7 +466,8 @@ void em_dev_unregister_perf_domain(struct device *dev) mutex_lock(&em_pd_mutex); em_debug_remove_pd(dev); - 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 Mon Sep 25 08:11: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: 144271 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp1054282vqu; Mon, 25 Sep 2023 01:20:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFCpPYh1Lc+lVEMiqzhWPiQdcXwUVGPpGGwODlCLTzOpxSLEtJJ+OEv3pSvyDfpNb5UWYqe X-Received: by 2002:a9d:63d0:0:b0:6c4:897a:31d0 with SMTP id e16-20020a9d63d0000000b006c4897a31d0mr7239796otl.24.1695630047313; Mon, 25 Sep 2023 01:20:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695630047; cv=none; d=google.com; s=arc-20160816; b=wGhwAX+ML4WdvkGrUNxv+ldBqlZMbeL0Wck8Daa2CDuwGi8nQKMGbkmV8BgyBwoiAj 90YMPsnkrQgiAawZi0cI4kN4LOSyx81fLvsCpFPfy+d35ZjB77mFYjg728yBoAoXNFFy 9GjdCxU8faTup4QDvF5L5lehSKShahkwrbfqmfIpgJJ86eFfdoe6pyJqQnXYobHm6rR5 lgceYFPXmGiFgG1pz3F20HJxiuwyAjq8LGhY832mOlNzwWNX+Uu8IqtN+JsfVv+3euwn gKNd3+LWMlF2G0jgdLpEAKo6HfRvqIj496ouqsXxwPcPaGbDjAWw1XE0Z8hceJxgpDMV 8lgg== 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=zWVE9oZix7BsBjximY0f8NX0YqxMrKBiowdm1HBWcJQ=; fh=jF+j1UEDAwnYbShW3HmO1TshMsWh36Jt7pSLTP62NeE=; b=t8yUov2t9UotHz+bmpNGi/Ig2qm4oAzuT/u4JNhdV7HKtD+Qpe7uct2s3aqdEd2Y+U +Z2nwJ3lQn5aKn0D8+5N/AjnCMUaYJxjev4KnASbB0zyCKkiEK4o9STaupVq5Y5zWvFJ woDiYXqxOMZ4WE1Ta/fHSRIaEI6+cvKilnCJveFfRfKbOVAF1oZIsZg96Pby8krCPB5j EPv+e9rvZ0YQ5fOfOmWqahJMME7NUgSi6WcfyltiUEtTdFBwic6sv0ecvQqUR6mnHreO zWgLD/wwTZ/tM0iXnagZd0bj2BKfDUnkVFt8oU7jRNXWH0xN9gwosg3/b8iMngIUy3Sg jE3w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id d19-20020a637353000000b0055b43079640si9710207pgn.707.2023.09.25.01.20.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 01:20:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id D304280E224D; Mon, 25 Sep 2023 01:12:12 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232693AbjIYIME (ORCPT + 30 others); Mon, 25 Sep 2023 04:12:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232768AbjIYILl (ORCPT ); Mon, 25 Sep 2023 04:11:41 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 672141AC; Mon, 25 Sep 2023 01:11:34 -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 5E703DA7; Mon, 25 Sep 2023 01:12:12 -0700 (PDT) Received: from e129166.arm.com (unknown [10.57.93.139]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id B604D3F5A1; Mon, 25 Sep 2023 01:11:31 -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, mhiramat@kernel.org, qyousef@layalina.io, wvw@google.com Subject: [PATCH v4 08/18] PM: EM: Add update_power() callback for runtime modifications Date: Mon, 25 Sep 2023 09:11:29 +0100 Message-Id: <20230925081139.1305766-9-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230925081139.1305766-1-lukasz.luba@arm.com> References: <20230925081139.1305766-1-lukasz.luba@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Mon, 25 Sep 2023 01:12:13 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777996972814941705 X-GMAIL-MSGID: 1777996972814941705 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. Signed-off-by: Lukasz Luba --- include/linux/energy_model.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/include/linux/energy_model.h b/include/linux/energy_model.h index d236e08e80dc..546dee90f716 100644 --- a/include/linux/energy_model.h +++ b/include/linux/energy_model.h @@ -168,6 +168,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 runtime modifications of EM. + * + * The update_power() is used by runtime 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) \ @@ -175,6 +195,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); @@ -331,6 +352,7 @@ struct em_data_callback {}; #define EM_ADV_DATA_CB(_active_power_cb, _cost_cb) { } #define EM_DATA_CB(_active_power_cb) { } #define EM_SET_ACTIVE_POWER_CB(em_cb, cb) do { } while (0) +#define EM_UPDATE_CB(_update_cb) { } static inline int em_dev_register_perf_domain(struct device *dev, unsigned int nr_states, From patchwork Mon Sep 25 08:11: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: 144264 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp1052582vqu; Mon, 25 Sep 2023 01:16:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHEe4VPijHSL443yiw8Fy6GQaqlA+oYDZD6RdamMo0Fbo6XVlqroGFxJRydmY0EGASafbqk X-Received: by 2002:a25:8181:0:b0:d7a:edf3:f0a9 with SMTP id p1-20020a258181000000b00d7aedf3f0a9mr4973020ybk.50.1695629770600; Mon, 25 Sep 2023 01:16:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695629770; cv=none; d=google.com; s=arc-20160816; b=jP/qC11UYUSKo2pUn1oXl2EueFRbzK6zkeemMZjcKmI1gQN+nIJ3DMr+tNwuMtZo37 IEQi8wu3znWnpFW3bYmV53YcYPZLsIckvjYfs7FWjzn/SfhJceiHx1W53vRqiQzKJv1p t30AWOYKB45K9xFplhzLndlrdJyXlqdad+/7W3koG7qf9cPIFj6a1MA/VV88+s6PMBhd P3+kI5hpGaH4mvemrqSxDWn9/xv12T/nqTEXrSvFeDK4pN3PUM9ZIG+jq+M7xg2uCV2z 5TYDM1zy9+T5VScoLhJfzKF6rJnlraHMxFKuAtydUbaUZNwR28+Kzy9IcgvCGiCQ/Y8C yxKg== 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=TxVNtN04ukMLXjud5BNXfBzCKEHUtvvz+tWDPCAgbm4=; fh=jF+j1UEDAwnYbShW3HmO1TshMsWh36Jt7pSLTP62NeE=; b=O00VIfbDdJYzU/shxVcsuolvWdNlsScFg5iN+NYbgh+5hdq9OXAi813SbWJLpkBVgo hVceovqAY3Xpiu0Ah7PgG/8UxqJvwHtq+VaWnyYbbeN/R+/tMogIyc/BZfktZ/+ClXHM GkQkQ3hgV7i47W90jQEwGnGLvY+38IGi7p13SEDAKX+T+Z5CraCSIzORnVOPjBFo49VY Kq/IjYoBb8C5ZxTMEm/amG3u7v5TIF1zaVBp6zmRGoAoPvLSeMupCoOtSj/q6xGV9rOU vuV7d7xufeJ9iD7ayVaoTXU2Emc4KGsFaJcFhDs7f77+6fDyOoDmGYI/wcQcOu2/kNRq y+fg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id q30-20020a63751e000000b00563fe2c1163si9318590pgc.168.2023.09.25.01.16.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 01:16:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 8520E80D7552; Mon, 25 Sep 2023 01:13:08 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232871AbjIYIMH (ORCPT + 30 others); Mon, 25 Sep 2023 04:12:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232712AbjIYILo (ORCPT ); Mon, 25 Sep 2023 04:11:44 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8E17611F; Mon, 25 Sep 2023 01:11:37 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 206901424; Mon, 25 Sep 2023 01:12:15 -0700 (PDT) Received: from e129166.arm.com (unknown [10.57.93.139]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 798103F5A1; Mon, 25 Sep 2023 01:11:34 -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, mhiramat@kernel.org, qyousef@layalina.io, wvw@google.com Subject: [PATCH v4 09/18] PM: EM: Introduce runtime modifiable table Date: Mon, 25 Sep 2023 09:11:30 +0100 Message-Id: <20230925081139.1305766-10-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230925081139.1305766-1-lukasz.luba@arm.com> References: <20230925081139.1305766-1-lukasz.luba@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Mon, 25 Sep 2023 01:13:08 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777996682286842056 X-GMAIL-MSGID: 1777996682286842056 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. All the other users (thermal, etc.) are still using the default (basic) EM. This fact drove the design of this feature. Signed-off-by: Lukasz Luba --- include/linux/energy_model.h | 4 +++- kernel/power/energy_model.c | 12 +++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/include/linux/energy_model.h b/include/linux/energy_model.h index 546dee90f716..740e7c25cfff 100644 --- a/include/linux/energy_model.h +++ b/include/linux/energy_model.h @@ -39,7 +39,7 @@ struct em_perf_state { /** * struct em_perf_table - Performance states table * @state: List of performance states, in ascending order - * @rcu: RCU used for safe access and destruction + * @rcu: RCU used only for runtime modifiable table */ struct em_perf_table { struct em_perf_state *state; @@ -49,6 +49,7 @@ struct em_perf_table { /** * struct em_perf_domain - Performance domain * @default_table: Pointer to the default em_perf_table + * @runtime_table: Pointer to the runtime modifiable 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 @@ -64,6 +65,7 @@ struct em_perf_table { */ struct em_perf_domain { struct em_perf_table *default_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 797141638b29..5b40db38b745 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -251,6 +251,9 @@ static int em_create_pd(struct device *dev, int nr_states, return ret; } + /* Initialize runtime table as default table. */ + rcu_assign_pointer(pd->runtime_table, default_table); + if (_is_cpu_device(dev)) for_each_cpu(cpu, cpus) { cpu_dev = get_cpu_device(cpu); @@ -448,6 +451,7 @@ EXPORT_SYMBOL_GPL(em_dev_register_perf_domain); */ void em_dev_unregister_perf_domain(struct device *dev) { + struct em_perf_table __rcu *runtime_table; struct em_perf_domain *pd; if (IS_ERR_OR_NULL(dev) || !dev->em_pd) @@ -457,18 +461,24 @@ void em_dev_unregister_perf_domain(struct 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); + runtime_table = pd->runtime_table; + + rcu_assign_pointer(pd->runtime_table, NULL); + synchronize_rcu(); + kfree(pd->default_table->state); kfree(pd->default_table); kfree(dev->em_pd); + dev->em_pd = NULL; mutex_unlock(&em_pd_mutex); } From patchwork Mon Sep 25 08:11: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: 144265 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp1052585vqu; Mon, 25 Sep 2023 01:16:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEkAXa8s4kqZHlEiK8fZng3L7MsnUI78ICUNWNVuV1fzZO9dYQlypMZzEyizS617iZ0KYeU X-Received: by 2002:a17:902:dacc:b0:1c6:2161:b171 with SMTP id q12-20020a170902dacc00b001c62161b171mr851571plx.4.1695629771046; Mon, 25 Sep 2023 01:16:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695629771; cv=none; d=google.com; s=arc-20160816; b=HaAGhCa/hRnhGXNAJAYhDazoXN6kUWltwWVfyIjiRK27XYhYxZu2x2Wbt6IefJUTaG 9CajlG7i4AP1kYGzp7R3DVyICSN583TwD8AEW+xEEm20RW1Fzbvf/oSX6+nEYM05o1/D cQFiXf8PCruliO+k3y/nK7EzRnF0OR966vvU5Q5cuSfaFj0dryH3xFtwUbnl0D8WuWqx amdSZwhykzedZ/JtulseyT7O1gE8tzaYblX7E53e0Rv8KP/s9xWGA7feDKRQzWJqI0L4 NWOqavsIZxEozL66Oo7naUIldorge8YTxXRTw3qaR7pdIPi7C/1PaCDlSMjTbq8ChL9z 1OYg== 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=OZGtcAO9gvKSB9TxBvOvG4wAGc013+YmWQ7pN5QSgPI=; fh=jF+j1UEDAwnYbShW3HmO1TshMsWh36Jt7pSLTP62NeE=; b=Ofk3bT4E8xmB/pEbyHt4AouGqVKIZAG5ni7R7awjcwBa/IK958Dws1huzrtVvtgpjN jPY351JZSy8tue+POXX8D4Q959bnwU2/CtEMNMc9eQvbomGCkGhHLFCCnOe0TVmk4sp9 Nc71Ht8ZGiJ5SUi/Ou5zGrfxA+lbSc92T1f3lRIDWhmw+xjL8IQZqgPiVm/Hi+FKsecN GFkroiVdzTTow7M3njmvl80yEoMcivUu7QwodQpSbfg9oggNAOOTS3LS2wQa9NjI77KD 849ZqTwEaRp7XFcaX3+6tCtLqxZCEidpj7rVtsWmdwmEzLbVS1cvXbzQ1ZWMQw7DzWRc Yspg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id y15-20020a17090264cf00b001c5f8995611si4978227pli.483.2023.09.25.01.16.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 01:16:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 55D0381A4A33; Mon, 25 Sep 2023 01:13:11 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232777AbjIYIML (ORCPT + 30 others); Mon, 25 Sep 2023 04:12:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55324 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232742AbjIYILq (ORCPT ); Mon, 25 Sep 2023 04:11:46 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E30441A7; Mon, 25 Sep 2023 01:11:39 -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 D7D0DDA7; Mon, 25 Sep 2023 01:12:17 -0700 (PDT) Received: from e129166.arm.com (unknown [10.57.93.139]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 3B8E93F5A1; Mon, 25 Sep 2023 01:11:37 -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, mhiramat@kernel.org, qyousef@layalina.io, wvw@google.com Subject: [PATCH v4 10/18] PM: EM: Add RCU mechanism which safely cleans the old data Date: Mon, 25 Sep 2023 09:11:31 +0100 Message-Id: <20230925081139.1305766-11-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230925081139.1305766-1-lukasz.luba@arm.com> References: <20230925081139.1305766-1-lukasz.luba@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Mon, 25 Sep 2023 01:13:11 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777996682523134679 X-GMAIL-MSGID: 1777996682523134679 The EM is going to support runtime modifications of the power data. Introduce 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 | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c index 5b40db38b745..2345837bfd2c 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -23,6 +23,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); @@ -104,6 +107,32 @@ 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_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); + + /* Don't free default table since it's used by other frameworks. */ + if (tmp != pd->default_table) + 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 Mon Sep 25 08:11: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: 144272 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp1054298vqu; Mon, 25 Sep 2023 01:20:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFtTCkQ/GGIUSI8k26/LRl/2xkQbn7BVv6VTQRBPNxAUqdYYLLMqimQUxve9bILb0ePH1Q2 X-Received: by 2002:a05:6830:4509:b0:6c4:f095:7b76 with SMTP id i9-20020a056830450900b006c4f0957b76mr563867otv.31.1695630049451; Mon, 25 Sep 2023 01:20:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695630049; cv=none; d=google.com; s=arc-20160816; b=xU8vv0EWWtbowbO1m2IuePqa18+yMQ7zpMsYRdgiDqg1FnEO7WYWMGVCe6cPmoHgBj KQAaC6RAUU9hGRJT6m9DKtVGQBIkZiysKJC2NXNevM989sQbWvjb/5nCBPsLtBpNaUjj qh7G8XUZ/MOLMsw7y0JCTko4+dD78Rl8V90JHt6bdzFDXyvQQsSush38GpGdIc+7wWy3 UmqfiYU2o09BQAlPoKMizzmmbawoD6Kai/lsaHIca4H/j5Bhm8hG/Ki1yXiC9hRIOUf7 u1b7A3W0WehAFFTx0W9d8x7qwcK1tUKF2TWnabXDh69TJgd787ZC9C4R8K5NDKBc9No+ mEhg== 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=SpQ4SpQ/nsSRUNHX9Fsso7TM1arsUyqdBOO/SxPH5j8=; fh=jF+j1UEDAwnYbShW3HmO1TshMsWh36Jt7pSLTP62NeE=; b=bFfN8nETFZeK1voWhUyAG2XfVCSLYA1SaZqG2Vbg7LU//HPw0w+rtmLwKZ+ZDHXiZd MHjI3pAB4ouq80iXPPifXi7guoYh4Gc0vJDWDbJRmaU9ZQCAF3qgZGe6gTDlGKhL4QNU Zu0LKah5CaG/NxLPorhYX+XdhzO1JInGwpq17WHX1NO/slNQOSKs4ekZdBIzXh2ogzov Q4c6zQ7Fdd+vPomPFvMOpUQG2WjQKbPOw0RA3hQzpZgNIwxJ1ateHTQgOpNpuavRhuV7 ABGf/hGFJPXM07gyvUczOgWio1N3o7jRnzMXqjPuYPvjj1pQBdG4mXrpBMllUtPRCPlx 9maw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id j9-20020a056a00234900b00690fe3ec830si10173119pfj.55.2023.09.25.01.20.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 01:20:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 2C30280E2254; Mon, 25 Sep 2023 01:12:20 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232796AbjIYIMQ (ORCPT + 30 others); Mon, 25 Sep 2023 04:12:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232792AbjIYIL4 (ORCPT ); Mon, 25 Sep 2023 04:11:56 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A55DBCC2; Mon, 25 Sep 2023 01:11:42 -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 9BA73DA7; Mon, 25 Sep 2023 01:12:20 -0700 (PDT) Received: from e129166.arm.com (unknown [10.57.93.139]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id F3A433F5A1; Mon, 25 Sep 2023 01:11: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, mhiramat@kernel.org, qyousef@layalina.io, wvw@google.com Subject: [PATCH v4 11/18] PM: EM: Add runtime update interface to modify EM power Date: Mon, 25 Sep 2023 09:11:32 +0100 Message-Id: <20230925081139.1305766-12-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230925081139.1305766-1-lukasz.luba@arm.com> References: <20230925081139.1305766-1-lukasz.luba@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Mon, 25 Sep 2023 01:12:20 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777996974855064897 X-GMAIL-MSGID: 1777996974855064897 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 | 111 +++++++++++++++++++++++++++++++++++ 2 files changed, 119 insertions(+) diff --git a/include/linux/energy_model.h b/include/linux/energy_model.h index 740e7c25cfff..8f055ab356ed 100644 --- a/include/linux/energy_model.h +++ b/include/linux/energy_model.h @@ -201,6 +201,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); @@ -384,6 +386,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 2345837bfd2c..78e1495dc87e 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -172,6 +172,101 @@ static int em_compute_costs(struct device *dev, struct em_perf_state *table, return 0; } +/** + * em_dev_update_perf_domain() - Update runtime 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 runtime 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->default_table->state[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: runtime 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) @@ -494,6 +589,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); @@ -501,9 +598,23 @@ void em_dev_unregister_perf_domain(struct device *dev) runtime_table = 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 + * memory allocated for runtime table (if there was such). + */ + if (runtime_table != pd->default_table) { + kfree(runtime_table->state); + kfree(runtime_table); + } + kfree(pd->default_table->state); kfree(pd->default_table); kfree(dev->em_pd); From patchwork Mon Sep 25 08:11: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: 144267 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp1053958vqu; Mon, 25 Sep 2023 01:19:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGtqR1QT3OZkKECAHUTSL+wknl+DQ2gS+1PZ39W8BQ9qw3sUb2kQT+R3DhzdlKNgFcbUBzv X-Received: by 2002:a05:6a00:1596:b0:691:27b:15b4 with SMTP id u22-20020a056a00159600b00691027b15b4mr17443192pfk.5.1695629990058; Mon, 25 Sep 2023 01:19:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695629990; cv=none; d=google.com; s=arc-20160816; b=yXo9JFd5Uu6HF0s8BYZfT9kNg0XkoP5zN+yXR7bH5Gm4eI1cL1dLdTKrsjgxbaK3oq TKuNau1hngILf83Nuc9U/OE+2nx03dL1u6Vq9hPQE5rxk2C8nMAGK5wq5NnSdya6VJpv dVvyvLxsXEQHMti8XF7el4BmZfKl9IbxayWmjAia/iTBVVqy6Sh2pURjxaSMQPc5XBfU oiUeE3kadF6knJk7xd5OVIapvAz0NX4Gw5hNca3EGP0QMdAcOtUKhkgX3Bgl2kI0U4FZ Furb/0su3cpWxsYG2uTNmIq0Wpqz5PkKoT8qim2hSuK6f4BJx5rsB2gVwk4PbxV0YYz/ B6wQ== 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=RNT2PYm7kSj3h3KVn/jbYVLHFNXeVPDEOdTiaHUlobA=; fh=jF+j1UEDAwnYbShW3HmO1TshMsWh36Jt7pSLTP62NeE=; b=iwvq1AvkVnG4Vc5wymljt/Pcfn94xJ5u95koiB+Zq1ISq2jIsBYgdlVTqy3BYo2+Dc fGq3vGZQ7tZd6s+6t48Nn7aG0D1wIKt4bIKf+bObuIY4DXngVo88s7yoiGrcZ+2peKF7 quHlVr34z0BspFg8MbGC/epaVqn1Olk8xvL6haps7NJTXQaJIhIvC3hdhTNYuBzUuZKD OZt5TGSC4375V0nzLCnVPJlSyW7JzdE3Qk5GijDEl1fchFfPMgM1zlOgINHlueOwFy/u N7FTacifZE0H0GZqP8DIheiATtMmnmlMrlMKZlnTjPLAHnBKKOuBFwhfiB3fEy9nNXmI a3kQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id p20-20020a056a000a1400b006902507d409si10244364pfh.174.2023.09.25.01.19.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 01:19:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 1AA1C80473EC; Mon, 25 Sep 2023 01:13:12 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232770AbjIYIMT (ORCPT + 30 others); Mon, 25 Sep 2023 04:12:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42564 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232810AbjIYIL5 (ORCPT ); Mon, 25 Sep 2023 04:11:57 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 761D7CCF; Mon, 25 Sep 2023 01:11:45 -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 5F6251424; Mon, 25 Sep 2023 01:12:23 -0700 (PDT) Received: from e129166.arm.com (unknown [10.57.93.139]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id B74273F5A1; Mon, 25 Sep 2023 01:11: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, mhiramat@kernel.org, qyousef@layalina.io, wvw@google.com Subject: [PATCH v4 12/18] PM: EM: Use runtime modified EM for CPUs energy estimation in EAS Date: Mon, 25 Sep 2023 09:11:33 +0100 Message-Id: <20230925081139.1305766-13-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230925081139.1305766-1-lukasz.luba@arm.com> References: <20230925081139.1305766-1-lukasz.luba@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Mon, 25 Sep 2023 01:13:12 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777996912677364641 X-GMAIL-MSGID: 1777996912677364641 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 | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/include/linux/energy_model.h b/include/linux/energy_model.h index 8f055ab356ed..41290ee2cdd0 100644 --- a/include/linux/energy_model.h +++ b/include/linux/energy_model.h @@ -261,15 +261,14 @@ 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 *table, *ps; + struct em_perf_state *ps; int cpu, i; if (!sum_util) return 0; - table = pd->default_table->state; - /* * In order to predict the performance state, map the utilization of * the most utilized CPU of the performance domain to a requested @@ -280,7 +279,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 = &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); @@ -290,9 +296,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(table, pd->nr_perf_states, freq, - pd->flags); - ps = &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 Mon Sep 25 08:11: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: 144276 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp1055232vqu; Mon, 25 Sep 2023 01:23:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHUAiYbuXoX1uNup3qf44Sd0/zrywIVl2yt8smPFk7cz1OTvsWMuedakr/HETNTvFP7GBAr X-Received: by 2002:a05:6871:7a5:b0:1d6:55a4:d97 with SMTP id o37-20020a05687107a500b001d655a40d97mr8362992oap.32.1695630193958; Mon, 25 Sep 2023 01:23:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695630193; cv=none; d=google.com; s=arc-20160816; b=lutp2ne4S6X30YXgh/WihokIrbGXin1w+/D8eCbPRK+swCrKMDeAPA2M7HH/BGJfm1 0ZVjuoGKTQa54Zpdvddq2AmytcxOiVJc0zSdIURvzAqkOpf0Idse6U7PnLADHom7kqDg gt/Z47//VDHpSR26dEHVyAztMAn/MqY71xO9l2oysrrcnp+TaYfONCWewjSE1Zhtk6+w vaKF0yp4xnRmx5uIkkXk6rmqn6RVlGYlxzdYvAmYmzvNO+twxrScx+3zFnMH1yL68cSG jqmahkzMoxOr+J/kl/muKIgT5h7FxUQA2BqeEth9GGoDeEiDIMRKScVDrXpdoBdcpW8w FTtQ== 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=2ByRDmIoN17/1nHY/JuUFxzL+VreR1Cv56cp6E6QxVk=; fh=jF+j1UEDAwnYbShW3HmO1TshMsWh36Jt7pSLTP62NeE=; b=V9gqnpoCy1iUDO1tI3ccpOrsWziRAuQKbi+dVeImfzxDjzwLbbjE7GsEBn4TldBTdW ei8/d9pGknrrX65VSwHaxUXQjxTV9x4GpcijpQJsUudmmfwfKIcZwoZ/neZ5tmTwWfMz LRuXdxVYIPNMAEfKZVTUHmeMTbyRx+vi7/s9f3voUUt8teuxvRdd1ZPT0f10RwABIWtr rJBeaI/p949zNWa98NW0H2LyRbrN4NyZN7ow2tNzRKLwLH7Mb74dOykVBYuKZsbnNsJF T6Xk12cd55UFN5LyepzH1hCmJJvokd6yLsxv1dMwubpa5bo30pOAfb5mfeX+xwl9w4rT yzow== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id n13-20020a65488d000000b0055e607f1e99si9282185pgs.882.2023.09.25.01.23.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 01:23:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 203B080E06A8; Mon, 25 Sep 2023 01:12:47 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232911AbjIYIM2 (ORCPT + 30 others); Mon, 25 Sep 2023 04:12:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232748AbjIYIL5 (ORCPT ); Mon, 25 Sep 2023 04:11:57 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2BE20CD9; Mon, 25 Sep 2023 01:11:48 -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 20F22DA7; Mon, 25 Sep 2023 01:12:26 -0700 (PDT) Received: from e129166.arm.com (unknown [10.57.93.139]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 799613F5A1; Mon, 25 Sep 2023 01:11: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, mhiramat@kernel.org, qyousef@layalina.io, wvw@google.com Subject: [PATCH v4 13/18] Documentation: EM: Update with runtime modification design Date: Mon, 25 Sep 2023 09:11:34 +0100 Message-Id: <20230925081139.1305766-14-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230925081139.1305766-1-lukasz.luba@arm.com> References: <20230925081139.1305766-1-lukasz.luba@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 25 Sep 2023 01:12:47 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777997126103845858 X-GMAIL-MSGID: 1777997126103845858 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 default EM. Change the other section IDs. Add documentation bit for the new feature which allows to modify the EM in runtime. Signed-off-by: Lukasz Luba --- Documentation/power/energy-model.rst | 144 +++++++++++++++++++++++++-- 1 file changed, 134 insertions(+), 10 deletions(-) diff --git a/Documentation/power/energy-model.rst b/Documentation/power/energy-model.rst index ef341be2882b..3115411f9839 100644 --- a/Documentation/power/energy-model.rst +++ b/Documentation/power/energy-model.rst @@ -72,16 +72,70 @@ 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 constant power information for each performance +state, which is accessible in: 'dev->em_pd->default_table->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 cover 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. The static power, which can +change during runtime due to variation of SOC temperature, is not modeled +either. + +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. + +There are two structures with the performance state tables in the EM: +a) dev->em_pd->default_table +b) dev->em_pd->runtime_table +They both point to the same memory location via: +'em_perf_table::state' pointer, until the first modification of the values +This should save memory on platforms which would never modify the EM. When +the first modification is made the 'default_table' (a) contains the old +EM which was created during the setup. The modified EM is available in the +'runtime_table' (b). + +Only EAS uses the 'runtime_table' and benefits from the updates to the +EM values. Other sub-systems (thermal, powercap) use the 'default_table' (a). + +The kernel code which want to modify the EM values is protected from concurrent +access using a mutex. Therefore, the code must use sleeping context when +they want to modify the EM. + +With the runtime modifiable EM we switch from a 'single and during the entire +runtime static EM' (system property) design to a 'single EM which can be +changed during runtime according e.g. to the workload' (system and workload +property) design. + + +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 +164,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 +210,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 +229,31 @@ 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.5 + + +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); -2.4 Description details of this API +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. + + +3.5 Description details of this API ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. kernel-doc:: include/linux/energy_model.h :internal: @@ -187,8 +262,11 @@ or in Section 2.4 :export: -3. 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(). @@ -242,3 +320,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 Mon Sep 25 08:11: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: 144263 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp1052573vqu; Mon, 25 Sep 2023 01:16:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFiPSYOAJ3Q3MVTm7ztVpxp3wHsC6Olx6dErKjWCVKDbs24yKLhmyQX+QMXPAi1VabOPHuY X-Received: by 2002:a05:6a00:b56:b0:690:3b59:cc7a with SMTP id p22-20020a056a000b5600b006903b59cc7amr9087758pfo.23.1695629767643; Mon, 25 Sep 2023 01:16:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695629767; cv=none; d=google.com; s=arc-20160816; b=BhUSWgQGqLb0IGTDydpwrWPKMkpDxSAeAOEUuLG34v26A3mxKfLGixpG39ZaGpLBWW G211aaTYXtgb4Vhr7nD/SuxXCQq5bmtC1+TxUa5UoZJpAged8utIrf9kVsJysKOVLaWM J+BJ3lwGVqQe4RBxL1OxVjduOlIm4XxWdBGwNh4ah0Bqdsyn/+uONrsw72lE8jAipXGh KPsfaKzyX5LR99JWzrMYcEV6M/vEdQNH1eNIo4Mezd9VTLjvLd7kXcANUJjnSIVxQggc aUb5/rOp4lBbnTwLWS0DJ9V6ZjIl89BF1BVeY3/SiGmK1/AN3uASip4xkwW8g1orcbCu CNrQ== 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=2uqPowGVKomAt5nYdsYuAdcoTjYvhkYvfxU72f+2Kqk=; fh=jF+j1UEDAwnYbShW3HmO1TshMsWh36Jt7pSLTP62NeE=; b=IA2UZKRWYuuudGjd2BzBYIElXW8HLhjOoQOiEv9tGq4Banp6icm/gxxXps6i3r571Z emiSc9HsHppALOgBLzAW37uUSA9B8C28tzciNTJUdCJ6likyhlbso5QHD9JEhkikfz1p BIUJAw4QpjKdZH3yYC1E7XW414ipIWCC6l47/pPNLxChRYCWxyS9Ku7NF7YVcn8sbfuN oc5OIg15tvzfdPAk9CcFV/M1//Tll2TD4lTHpex8dFYBCbg7RsLbfdPhkGM1bhPeG/vI YNrv0IUd55QKKisVRp6e68jAavpNZtF5tsyggDBhlskYYEmPNNl4oCpf/y5CpLqILa26 /4aA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id k2-20020aa788c2000000b0068e4a646d2csi10208370pff.252.2023.09.25.01.16.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 01:16:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 62D3581A1B86; Mon, 25 Sep 2023 01:12:46 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232850AbjIYIMb (ORCPT + 30 others); Mon, 25 Sep 2023 04:12:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232721AbjIYIL6 (ORCPT ); Mon, 25 Sep 2023 04:11:58 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E0DD4112; Mon, 25 Sep 2023 01:11:50 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D917BDA7; Mon, 25 Sep 2023 01:12:28 -0700 (PDT) Received: from e129166.arm.com (unknown [10.57.93.139]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 3BAB73F5A1; Mon, 25 Sep 2023 01:11:48 -0700 (PDT) From: Lukasz Luba To: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, rafael@kernel.org Cc: lukasz.luba@arm.com, dietmar.eggemann@arm.com, rui.zhang@intel.com, amit.kucheria@verdurent.com, amit.kachhap@gmail.com, daniel.lezcano@linaro.org, viresh.kumar@linaro.org, len.brown@intel.com, pavel@ucw.cz, mhiramat@kernel.org, qyousef@layalina.io, wvw@google.com Subject: [PATCH v4 14/18] PM: EM: Add performance field to struct em_perf_state Date: Mon, 25 Sep 2023 09:11:35 +0100 Message-Id: <20230925081139.1305766-15-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230925081139.1305766-1-lukasz.luba@arm.com> References: <20230925081139.1305766-1-lukasz.luba@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Mon, 25 Sep 2023 01:12:46 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777996679082024658 X-GMAIL-MSGID: 1777996679082024658 The performance doesn't scale linearly with the frequency. Also, it may be different in different workloads. Some CPUs are designed to be particularly good at some applications e.g. images or video processing and other CPUs in different. When those different types of CPUs are combined in one SoC they should be properly modeled to get max of the HW in Energy Aware Scheduler (EAS). The Energy Model (EM) provides the power vs. performance curves to the EAS, but assumes the CPUs capacity is fixed and scales linearly with the frequency. This patch allows to adjust the curve on the 'performance' axis as well. Signed-off-by: Lukasz Luba --- include/linux/energy_model.h | 11 ++++++----- kernel/power/energy_model.c | 27 +++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/include/linux/energy_model.h b/include/linux/energy_model.h index 41290ee2cdd0..37fc8490709d 100644 --- a/include/linux/energy_model.h +++ b/include/linux/energy_model.h @@ -12,6 +12,7 @@ /** * struct em_perf_state - Performance state of a performance domain + * @performance: Non-linear CPU performance at a given frequency * @frequency: The frequency in KHz, for consistency with CPUFreq * @power: The power consumed at this level (by 1 CPU or by a registered * device). It can be a total power: static and dynamic. @@ -20,6 +21,7 @@ * @flags: see "em_perf_state flags" description below. */ struct em_perf_state { + unsigned long performance; unsigned long frequency; unsigned long power; unsigned long cost; @@ -223,14 +225,14 @@ void em_dev_unregister_perf_domain(struct device *dev); */ static inline int em_pd_get_efficient_state(struct em_perf_state *table, int nr_perf_states, - unsigned long freq, unsigned long pd_flags) + unsigned long max_util, unsigned long pd_flags) { struct em_perf_state *ps; int i; for (i = 0; i < nr_perf_states; i++) { ps = &table[i]; - if (ps->frequency >= freq) { + if (ps->performance >= max_util) { if (pd_flags & EM_PERF_DOMAIN_SKIP_INEFFICIENCIES && ps->flags & EM_PERF_STATE_INEFFICIENT) continue; @@ -262,8 +264,8 @@ static inline unsigned long em_cpu_energy(struct em_perf_domain *pd, unsigned long allowed_cpu_cap) { struct em_perf_table *runtime_table; - unsigned long freq, scale_cpu; struct em_perf_state *ps; + unsigned long scale_cpu; int cpu, i; if (!sum_util) @@ -290,14 +292,13 @@ static inline unsigned long em_cpu_energy(struct em_perf_domain *pd, max_util = map_util_perf(max_util); max_util = min(max_util, allowed_cpu_cap); - freq = map_util_freq(max_util, ps->frequency, scale_cpu); /* * Find the lowest performance state of the Energy Model above the * requested frequency. */ i = em_pd_get_efficient_state(runtime_table->state, pd->nr_perf_states, - freq, pd->flags); + max_util, pd->flags); ps = &runtime_table->state[i]; /* diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c index 78e1495dc87e..c7ad42b42c46 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -46,6 +46,7 @@ static void em_debug_create_ps(struct em_perf_state *ps, struct dentry *pd) debugfs_create_ulong("frequency", 0444, d, &ps->frequency); debugfs_create_ulong("power", 0444, d, &ps->power); debugfs_create_ulong("cost", 0444, d, &ps->cost); + debugfs_create_ulong("performance", 0444, d, &ps->performance); debugfs_create_ulong("inefficient", 0444, d, &ps->flags); } @@ -133,6 +134,30 @@ static void em_perf_runtime_table_set(struct device *dev, call_rcu(&tmp->rcu, em_destroy_rt_table_rcu); } +static void em_init_performance(struct device *dev, struct em_perf_domain *pd, + struct em_perf_state *table, int nr_states) +{ + u64 fmax, max_cap; + int i, cpu; + + /* This is needed only for CPUs and EAS skip other devices */ + if (!_is_cpu_device(dev)) + return; + + cpu = cpumask_first(em_span_cpus(pd)); + + /* + * Calculate the performance value for each frequency with + * linear relationship. The final CPU capacity might not be ready at + * boot time, but the EM will be updated a bit later with correct one. + */ + fmax = (u64) table[nr_states - 1].frequency; + max_cap = (u64) arch_scale_cpu_capacity(cpu); + for (i = 0; i < nr_states; i++) + table[i].performance = div64_u64(max_cap * table[i].frequency, + fmax); +} + static int em_compute_costs(struct device *dev, struct em_perf_state *table, struct em_data_callback *cb, int nr_states, unsigned long flags) @@ -317,6 +342,8 @@ static int em_create_perf_table(struct device *dev, struct em_perf_domain *pd, table[i].frequency = prev_freq = freq; } + em_init_performance(dev, pd, table, nr_states); + ret = em_compute_costs(dev, table, cb, nr_states, flags); if (ret) goto free_ps_table; From patchwork Mon Sep 25 08:11: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: 144283 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp1056448vqu; Mon, 25 Sep 2023 01:26:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEL/1XeeRJJo3e2Enipz2dsXxru3zTvbEccGS7gyoFh3A7n57EH26nVmewdZgontvWNFlFd X-Received: by 2002:a17:902:d34c:b0:1b2:676d:1143 with SMTP id l12-20020a170902d34c00b001b2676d1143mr8572024plk.15.1695630386299; Mon, 25 Sep 2023 01:26:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695630386; cv=none; d=google.com; s=arc-20160816; b=PjwGplbS/z+E3Qey9bKnZf6BoEpJo/rYiWERC/7c4Si3ik8Me8Wvf1T7VvrKyYO8QH VTuVnBIVKSyCFYJiKTgCEnguOU2wH0+9adjG00RkuyN0pZVWyYdlRLlKmjJJXwC1zVWr 1HlyluGaa+bTFkL0srFD67gVELHmHc4iSrEVHQVAGN+YyIqYrMNPC2rbZHUtfgNAquJJ 8rxyy3/DjM3pan3OoPVU5GMqW07o/i9h71MtKei8jiNGj0MhkAf/9SQbv1fb7BSjgX8O rNfaRawu6KnLB33FqvFT3SCTlQ27HSvSm/PapPBfEoG+Om7Ct6+OT18yA36UMZhIEBVj cEGQ== 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=pOiAKtlY6omPX+ftujsJ2gEQaTN+9Ew2IF6RUKUXG64=; fh=jF+j1UEDAwnYbShW3HmO1TshMsWh36Jt7pSLTP62NeE=; b=VLdRqSdP4f54S5pL6UdqR5k5dOltY50RmYYWaSU0fjmdb+USOMvtay3u/ZZ/Hh7XuX nyOkJuMtTNI8yOWQSdLmY4zJ0IcZ/RsKoXLYE3EaiaaVTXWr6xiuEAfm1NPMe9/NIjrt 4HpEzSz3F8LzlYr7Eze/5AAMayCib2DEaehgEc/yciQHtPnC/dV9n7yaPocQ5r0llFso ufln/udSLh/b/ExMq9v7XdlfZqQtObjhCELyvbjhV/dvet8g8Q0lS/Y4NbFbexCWcwcX V7ygQnywZwr6RfnGR1fG7NqVRwf5TgJMzS9yhWu8h3K+6zLsblzFy/6b+N/QLZV+bB7R Gv7Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id q18-20020a17090311d200b001b89551a392si9949329plh.113.2023.09.25.01.26.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 01:26:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 66BC080BB804; Mon, 25 Sep 2023 01:12:55 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232721AbjIYIMe (ORCPT + 30 others); Mon, 25 Sep 2023 04:12:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56550 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232836AbjIYIMA (ORCPT ); Mon, 25 Sep 2023 04:12:00 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id CA983121; Mon, 25 Sep 2023 01:11:53 -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 9A5C2DA7; Mon, 25 Sep 2023 01:12:31 -0700 (PDT) Received: from e129166.arm.com (unknown [10.57.93.139]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id F3B753F5A1; Mon, 25 Sep 2023 01:11:50 -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, mhiramat@kernel.org, qyousef@layalina.io, wvw@google.com Subject: [PATCH v4 15/18] PM: EM: Adjust performance with runtime modification callback Date: Mon, 25 Sep 2023 09:11:36 +0100 Message-Id: <20230925081139.1305766-16-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230925081139.1305766-1-lukasz.luba@arm.com> References: <20230925081139.1305766-1-lukasz.luba@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Mon, 25 Sep 2023 01:12:55 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777997327995132662 X-GMAIL-MSGID: 1777997327995132662 The performance value may be modified at runtime together with the power value for each OPP. They both would form a different power and performance profile in the EM. Modify the callback interface to make this possible. Signed-off-by: Lukasz Luba --- include/linux/energy_model.h | 24 +++++++++++++++--------- kernel/power/energy_model.c | 7 ++++--- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/include/linux/energy_model.h b/include/linux/energy_model.h index 37fc8490709d..65a8794d1565 100644 --- a/include/linux/energy_model.h +++ b/include/linux/energy_model.h @@ -174,24 +174,29 @@ struct em_data_callback { unsigned long *cost); /** - * update_power() - Provide new power at the given performance state of - * a device + * update_power_perf() - Provide new power and performance 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) + * @perf : New performance value at the performance state + * (modified) * @priv : Pointer to private data useful for tracking context * during runtime modifications of EM. * - * The update_power() is used by runtime 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. + * The update_power_perf() is used by runtime modifiable EM. It aims to + * provide updated power and performance 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. The + * performance value should be lower or equal to the CPU max capacity + * (1024). * * 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); + int (*update_power_perf)(struct device *dev, unsigned long freq, + unsigned long *power, unsigned long *perf, + 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) \ @@ -199,7 +204,8 @@ 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 } +#define EM_UPDATE_CB(_update_pwr_perf_cb) \ + { .update_power_perf = &_update_pwr_perf_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 c7ad42b42c46..17a59a7717f7 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -217,11 +217,11 @@ 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; + unsigned long power, freq, perf; struct em_perf_domain *pd; int ret, i; - if (!cb || !cb->update_power) + if (!cb || !cb->update_power_perf) return -EINVAL; /* @@ -262,13 +262,14 @@ int em_dev_update_perf_domain(struct device *dev, struct em_data_callback *cb, * Call driver callback to get a new power value for * a given frequency. */ - ret = cb->update_power(dev, freq, &power, priv); + ret = cb->update_power_perf(dev, freq, &power, &perf, priv); if (ret) { dev_dbg(dev, "EM: runtime update error: %d\n", ret); goto free_runtime_state_table; } runtime_table->state[i].power = power; + runtime_table->state[i].performance = perf; } ret = em_compute_costs(dev, runtime_table->state, cb, From patchwork Mon Sep 25 08:11: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: 144280 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp1055987vqu; Mon, 25 Sep 2023 01:25:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG4jWutOytIDH4L2JV//TWScvCoiQ9/UPXkDCdxAh2YUQJS902IPLgKc2MF/sJ+Bs1exHT1 X-Received: by 2002:a81:4507:0:b0:59f:b0d1:9a60 with SMTP id s7-20020a814507000000b0059fb0d19a60mr792806ywa.1.1695630311772; Mon, 25 Sep 2023 01:25:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695630311; cv=none; d=google.com; s=arc-20160816; b=hDi3Ueh3hINGrzUX1l4NPNqV9FZ4N5siCAv485hTneLJDkGjRedO7/hFc6/+eYyyhV r5l20m1g1AT/zrHePagO5hQ/9pXKji8xX4B3YbvuGxnpLJQ+14vCtOq3mbebY148BPVe uoC0GuQ6FuVc3q1cd5kcz753AcKZI3fWq0mc9DC0kzDgEwHz6+xXyh2fOp0EnCxtjpDZ 5ZyJx+FWlomRcski8UQNOPHSEb4fms/Ij7w/n7JfOeYa4HmJiHQjgRKweDS9mj01HLrG SUiJvCnJJnQqXr99c10IZ4DE+JP5ReaD56U9d71pyKxDEwR2SDW9mXc9R7CGPWK222c+ bj2Q== 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=dFbsFov7oSEayfsH8V5+FAyzWnvYOXUodoc8Ak1aWD4=; fh=jF+j1UEDAwnYbShW3HmO1TshMsWh36Jt7pSLTP62NeE=; b=qtviMstRJGhnGxpY0gBck/N0aawIcj+gVmV+hdZmY9+UJfmW7W0p6qmcR6KwduIiML rqYtdioMhkVXJ1MzPI1600nV5mnLn6fQAQX0IHLkA2F5dT5FyOmYovV93Y1/rxfMdMWe /+l/xdVfeUnYRAWRT8p0zKhjzFkP0HNV8zt0hMulgbCPh+2z8VIbzStLEvOhlvOe/jSB R3nhO8G52dAtSijAex3LVvCI1fxVA/PGoQKmJL58mcIiYwEvr9B7IEFYizCVBuA+tT3x cxZ+H35F24efSYfPgKHFHMw9qRsaJPk23hqstI63fYZzs0xbuFe4uGo7R6sk3f+wK5WZ Fo+g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id w71-20020a63824a000000b0057806be7290si9420418pgd.451.2023.09.25.01.25.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 01:25:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 8CAC280236CB; Mon, 25 Sep 2023 01:13:13 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232859AbjIYIMl (ORCPT + 30 others); Mon, 25 Sep 2023 04:12:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42472 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232665AbjIYIMD (ORCPT ); Mon, 25 Sep 2023 04:12:03 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 74AF419C; Mon, 25 Sep 2023 01:11:56 -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 5B4B4DA7; Mon, 25 Sep 2023 01:12:34 -0700 (PDT) Received: from e129166.arm.com (unknown [10.57.93.139]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id B44523F5A1; Mon, 25 Sep 2023 01:11:53 -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, mhiramat@kernel.org, qyousef@layalina.io, wvw@google.com Subject: [PATCH v4 16/18] PM: EM: Support late CPUs booting and capacity adjustment Date: Mon, 25 Sep 2023 09:11:37 +0100 Message-Id: <20230925081139.1305766-17-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230925081139.1305766-1-lukasz.luba@arm.com> References: <20230925081139.1305766-1-lukasz.luba@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Mon, 25 Sep 2023 01:13:13 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777997249812384017 X-GMAIL-MSGID: 1777997249812384017 The patch adds needed infrastructure to handle the late CPUs boot, which might change the previous CPUs capacity values. With this changes the new CPUs which try to register EM will trigger the needed re-calculations for other CPUs EMs. Thanks to that the em_per_state::performance values will be aligned with the CPU capacity information after all CPUs finish the boot. Signed-off-by: Lukasz Luba --- kernel/power/energy_model.c | 108 ++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c index 17a59a7717f7..6bfd33c2e48c 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -25,6 +25,9 @@ static DEFINE_MUTEX(em_pd_mutex); static void em_cpufreq_update_efficiencies(struct device *dev, struct em_perf_state *table); +static void em_check_capacity_update(void); +static void em_update_workfn(struct work_struct *work); +static DECLARE_DELAYED_WORK(em_update_work, em_update_workfn); static bool _is_cpu_device(struct device *dev) { @@ -591,6 +594,10 @@ int em_dev_register_perf_domain(struct device *dev, unsigned int nr_states, unlock: mutex_unlock(&em_pd_mutex); + + if (_is_cpu_device(dev)) + em_check_capacity_update(); + return ret; } EXPORT_SYMBOL_GPL(em_dev_register_perf_domain); @@ -651,3 +658,104 @@ void em_dev_unregister_perf_domain(struct device *dev) mutex_unlock(&em_pd_mutex); } EXPORT_SYMBOL_GPL(em_dev_unregister_perf_domain); + +/* + * Adjustment of CPU performance values after boot, when all CPUs capacites + * are correctly calculated. + */ +static int get_updated_perf(struct device *dev, unsigned long freq, + unsigned long *power, unsigned long *perf, + void *priv) +{ + struct em_perf_state *table = priv; + int i, cpu, nr_states; + u64 fmax, max_cap; + + nr_states = dev->em_pd->nr_perf_states; + + cpu = cpumask_first(em_span_cpus(dev->em_pd)); + + fmax = (u64) table[nr_states - 1].frequency; + max_cap = (u64) arch_scale_cpu_capacity(cpu); + + for (i = 0; i < nr_states; i++) { + if (freq != table[i].frequency) + continue; + + *power = table[i].power; + *perf = div64_u64(max_cap * freq, fmax); + break; + } + + return 0; +} + +static void em_check_capacity_update(void) +{ + struct em_data_callback em_cb = EM_UPDATE_CB(get_updated_perf); + struct em_perf_table *runtime_table; + struct em_perf_domain *em_pd; + cpumask_var_t cpu_done_mask; + unsigned long cpu_capacity; + struct em_perf_state *ps; + struct device *dev; + int cpu, ret; + + if (!zalloc_cpumask_var(&cpu_done_mask, GFP_KERNEL)) { + pr_warn("EM: no free memory\n"); + return; + } + + /* Loop over all EMs and check if the CPU capacity has changed. */ + for_each_possible_cpu(cpu) { + unsigned long em_max_performance; + struct cpufreq_policy *policy; + + if (cpumask_test_cpu(cpu, cpu_done_mask)) + continue; + + policy = cpufreq_cpu_get(cpu); + if (!policy) { + pr_debug("EM: Accessing cpu%d policy failed\n", cpu); + schedule_delayed_work(&em_update_work, + msecs_to_jiffies(1000)); + break; + } + + em_pd = em_cpu_get(cpu); + if (!em_pd || em_is_artificial(em_pd)) + continue; + + cpu_capacity = arch_scale_cpu_capacity(cpu); + + rcu_read_lock(); + runtime_table = rcu_dereference(em_pd->runtime_table); + ps = &runtime_table->state[em_pd->nr_perf_states - 1]; + em_max_performance = ps->performance; + rcu_read_unlock(); + + /* + * Check if the CPU capacity has been adjusted during boot + * and trigger the update for new performance values. + */ + if (em_max_performance != cpu_capacity) { + dev = get_cpu_device(cpu); + ret = em_dev_update_perf_domain(dev, &em_cb, + em_pd->default_table->state); + if (ret) + dev_warn(dev, "EM: update failed %d\n", ret); + else + dev_info(dev, "EM: updated\n"); + } + + cpumask_or(cpu_done_mask, cpu_done_mask, + em_span_cpus(em_pd)); + } + + free_cpumask_var(cpu_done_mask); +} + +static void em_update_workfn(struct work_struct *work) +{ + em_check_capacity_update(); +} From patchwork Mon Sep 25 08:11: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: 144269 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp1054251vqu; Mon, 25 Sep 2023 01:20:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFOT6p29i3UoPIIYfMOGpWKRQD6ZUBNLQ0eMTFB/eCC3m8Ue5x+fQMeipm2jgOPQysyAcUA X-Received: by 2002:a17:903:2788:b0:1c0:d17a:bfef with SMTP id jw8-20020a170903278800b001c0d17abfefmr4057412plb.30.1695630041018; Mon, 25 Sep 2023 01:20:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695630041; cv=none; d=google.com; s=arc-20160816; b=NZaCZ5B4BVUi1zSI5LZ4qBLGlp8fEFy/GFXRFhgCVpMqw7sjBnQuUWRfAQri4RSoI5 UYuD0W1+UTGLN+1o3CrZ5TRnN4ZPMRd8qrWROPdg1DH9u30X1kXoKCgC9dJ4KRzahhJZ KXPLaP37+iU9o1E2qtoTQF62ALX6ZLu/KwHPgQxH4F+p0GYzyeXG0G74X6P7vse+Pbr1 +TbIA4HP5xeFJEKLTdYxekbmTGRdt4iRV6tKkjdE+ZN8TPSmAAJ+TXRow37mmqKA5HMc QoZSBvV/0BC6ahUOa1PsU1WLbLT8dhPQJJofXibdBw2xGCAaux1uzjB8nJZWQeNs2iQe 1xrA== 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=QparQ0KXqZxqgd48tgFxKSbKugmu0otexW/TJ46zkLg=; fh=jF+j1UEDAwnYbShW3HmO1TshMsWh36Jt7pSLTP62NeE=; b=OB0aCWc/20O3Pip34+0oo3tTi5DeQBOyjY6tOJnublL8oUlSOsSIEx0FgjOYbBkJne /wksNgX/ZboFtRQUP6k9GoLqEmWCTC0afuLyYyf67W2dx6mdKQefuSSY8S5X8cU/2nKO g7K3dVqZIvPKe/+WCF0wxW5YAjBuSFkuyruBWnUxIin8hY73vk+8QYm1U+cxpPaoV1Df RXZulusUx/WI7H273uHPD/959/FqlivllMle2f/2y9bRq0dwAo9cmL4JrD2jSeWB7sqI g3bs0TgEAI1lPJSIB0vfDW9jMrbaAZ1Ec+moiE+FBWLiJUmC0y4FZH5fUAiSShcnMWEz b4mw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id j10-20020a170902da8a00b001c563263222si10147806plx.376.2023.09.25.01.20.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 01:20:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 0F57580ECF91; Mon, 25 Sep 2023 01:12:49 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232887AbjIYIMu (ORCPT + 30 others); Mon, 25 Sep 2023 04:12:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232741AbjIYIMI (ORCPT ); Mon, 25 Sep 2023 04:12:08 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2BA2ECF3; Mon, 25 Sep 2023 01:11:59 -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 200B0DA7; Mon, 25 Sep 2023 01:12:37 -0700 (PDT) Received: from e129166.arm.com (unknown [10.57.93.139]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 7846F3F5A1; Mon, 25 Sep 2023 01:11:56 -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, mhiramat@kernel.org, qyousef@layalina.io, wvw@google.com Subject: [PATCH v4 17/18] PM: EM: Optimize em_cpu_energy() and remove division Date: Mon, 25 Sep 2023 09:11:38 +0100 Message-Id: <20230925081139.1305766-18-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230925081139.1305766-1-lukasz.luba@arm.com> References: <20230925081139.1305766-1-lukasz.luba@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Mon, 25 Sep 2023 01:12:49 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777996965782582138 X-GMAIL-MSGID: 1777996965782582138 The Energy Model (EM) can be modified at runtime which brings new possibilities. The em_cpu_energy() is called by the Energy Aware Scheduler (EAS) in it's hot path. The energy calculation uses power value for a given performance state (ps) and the CPU busy time as percentage for that given frequency, which effectively is: pd_nrg = ps->power * busy_time_pct (1) cpu_util busy_time_pct = ----------------- (2) ps->performance The 'ps->performance' is the CPU capacity (performance) at that given ps. Thus, in a situation when the OS is not overloaded and we have EAS working, the busy time is lower than 'ps->performance' that the CPU is running at. Therefore, in longer scheduling period we can treat the power value calculated above as the energy. We can optimize the last arithmetic operation in em_cpu_energy() and remove the division. This can be done because em_perf_state::cost, which is a special coefficient, can now hold the pre-calculated value including the 'ps->performance' information for a performance state (ps): ps->power ps->cost = --------------- (3) ps->performance In the past the 'ps->performance' had to be calculated at runtime every time the em_cpu_energy() was called. Thus there was this formula involved: ps->freq ps->performance = ------------- * scale_cpu (4) cpu_max_freq When we inject (4) into (2) than we can have this equation: cpu_util * cpu_max_freq busy_time_pct = ------------------------ (5) ps->freq * scale_cpu Because the right 'scale_cpu' value wasn't ready during the boot time and EM initialization, we had to perform the division by 'scale_cpu' at runtime. There was not safe mechanism to update EM at runtime. It has changed thanks to EM runtime modification feature. It is possible to avoid the division by 'scale_cpu' at runtime, because EM is updated whenever new max capacity CPU is set in the system or after the boot has finished and proper CPU capacity is ready. Use that feature and do the needed division during the calculation of the coefficient 'ps->cost'. That enhanced 'ps->cost' value can be then just multiplied simply by utilization: pd_nrg = ps->cost * \Sum cpu_util (6) to get the needed energy for whole Performance Domain (PD). With this optimization, the em_cpu_energy() should run faster on the Big CPU by 1.43x and on the Little CPU by 1.69x. Signed-off-by: Lukasz Luba --- include/linux/energy_model.h | 68 +++++------------------------------- kernel/power/energy_model.c | 7 ++-- 2 files changed, 12 insertions(+), 63 deletions(-) diff --git a/include/linux/energy_model.h b/include/linux/energy_model.h index 65a8794d1565..31c4e3b8f7c3 100644 --- a/include/linux/energy_model.h +++ b/include/linux/energy_model.h @@ -112,27 +112,6 @@ struct em_perf_domain { #define EM_MAX_NUM_CPUS 16 #endif -/* - * To avoid an overflow on 32bit machines while calculating the energy - * use a different order in the operation. First divide by the 'cpu_scale' - * which would reduce big value stored in the 'cost' field, then multiply by - * the 'sum_util'. This would allow to handle existing platforms, which have - * e.g. power ~1.3 Watt at max freq, so the 'cost' value > 1mln micro-Watts. - * In such scenario, where there are 4 CPUs in the Perf. Domain the 'sum_util' - * could be 4096, then multiplication: 'cost' * 'sum_util' would overflow. - * This reordering of operations has some limitations, we lose small - * precision in the estimation (comparing to 64bit platform w/o reordering). - * - * We are safe on 64bit machine. - */ -#ifdef CONFIG_64BIT -#define em_estimate_energy(cost, sum_util, scale_cpu) \ - (((cost) * (sum_util)) / (scale_cpu)) -#else -#define em_estimate_energy(cost, sum_util, scale_cpu) \ - (((cost) / (scale_cpu)) * (sum_util)) -#endif - struct em_data_callback { /** * active_power() - Provide power at the next performance state of @@ -271,29 +250,16 @@ static inline unsigned long em_cpu_energy(struct em_perf_domain *pd, { struct em_perf_table *runtime_table; struct em_perf_state *ps; - unsigned long scale_cpu; - int cpu, i; + int i; if (!sum_util) return 0; - /* - * In order to predict the performance state, map the utilization of - * the most utilized CPU of the performance domain to a requested - * frequency, like schedutil. Take also into account that the real - * frequency might be set lower (due to thermal capping). Thus, clamp - * max utilization to the allowed CPU capacity before calculating - * effective frequency. - */ - cpu = cpumask_first(to_cpumask(pd->cpus)); - scale_cpu = arch_scale_cpu_capacity(cpu); - /* * 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); @@ -308,35 +274,21 @@ static inline unsigned long em_cpu_energy(struct em_perf_domain *pd, ps = &runtime_table->state[i]; /* - * The capacity of a CPU in the domain at the performance state (ps) - * can be computed as: - * - * ps->freq * scale_cpu - * ps->cap = -------------------- (1) - * cpu_max_freq - * - * So, ignoring the costs of idle states (which are not available in - * the EM), the energy consumed by this CPU at that performance state + * The energy consumed by the CPU at the given performance state (ps) * is estimated as: * - * ps->power * cpu_util - * cpu_nrg = -------------------- (2) - * ps->cap + * ps->power + * cpu_nrg = --------------- * cpu_util (1) + * ps->performance * - * since 'cpu_util / ps->cap' represents its percentage of busy time. + * The 'cpu_util / ps->performance' represents its percentage of + * busy time. The idle cost is ignored (it's not available in the EM). * * NOTE: Although the result of this computation actually is in * units of power, it can be manipulated as an energy value * over a scheduling period, since it is assumed to be * constant during that interval. * - * By injecting (1) in (2), 'cpu_nrg' can be re-expressed as a product - * of two terms: - * - * ps->power * cpu_max_freq cpu_util - * cpu_nrg = ------------------------ * --------- (3) - * ps->freq scale_cpu - * * The first term is static, and is stored in the em_perf_state struct * as 'ps->cost'. * @@ -345,11 +297,9 @@ static inline unsigned long em_cpu_energy(struct em_perf_domain *pd, * total energy of the domain (which is the simple sum of the energy of * all of its CPUs) can be factorized as: * - * ps->cost * \Sum cpu_util - * pd_nrg = ------------------------ (4) - * scale_cpu + * pd_nrg = ps->cost * \Sum cpu_util (2) */ - return em_estimate_energy(ps->cost, sum_util, scale_cpu); + return ps->cost * sum_util; } /** diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c index 6bfd33c2e48c..cf9da7259f5e 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -166,11 +166,9 @@ static int em_compute_costs(struct device *dev, struct em_perf_state *table, 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; @@ -182,8 +180,9 @@ static int em_compute_costs(struct device *dev, struct em_perf_state *table, return -EINVAL; } } else { - power_res = table[i].power; - cost = div64_u64(fmax * power_res, table[i].frequency); + /* increase resolution of 'cost' precision */ + power_res = table[i].power * 10; + cost = power_res / table[i].performance; } table[i].cost = cost; From patchwork Mon Sep 25 08:11: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: 144275 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp1054437vqu; Mon, 25 Sep 2023 01:21:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IErli9PY8Sn/9PcsCDG4q70jY0chXen9KBQgOsaOUg+qqQAgLFci1WBmc205u47oLVOH7tN X-Received: by 2002:a81:4941:0:b0:586:cf7:2207 with SMTP id w62-20020a814941000000b005860cf72207mr5747867ywa.14.1695630070056; Mon, 25 Sep 2023 01:21:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695630070; cv=none; d=google.com; s=arc-20160816; b=g8JUjJtoVSPnjmbpIDpxBPwivd9jWlGWgjUAXe9nH1OdhJCa2QI7bKXc+Fg/bYRmHT hR3zHlKoEGZDoLM+hqG1Bn3oQGD8ABXZPD+RGoLxlfAHoKtae7sJFFlBIElGTJLOwiPe IT+NYCKZdY+eIkDUpIpLIaLmjGkBdv5vqqPz/Y32XjNYp1IO21w6FMaSxnvtbZs04mC7 yiBm/zs4Gn8kbiYmBt4DqCFMqR3hjs+xmokeNE1vKWPvsnQfXl1KOhJ+T02MYQa60Bko /kgjva0hKBHDBB6ob/MkXf1Xwjqj1oC1z98pAuSsjnhJKFDt7lbjbiWRQKA9bd2/beIv PxIA== 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=cowxUWPXQjH9rXomCyhqKk3MOFI575t/EUiMH5jv90Y=; fh=jF+j1UEDAwnYbShW3HmO1TshMsWh36Jt7pSLTP62NeE=; b=tzphzxOgJAeZDJe013uUKAWV6ogOdppKsruoXg1twUtPlTuXYtazXS0GGFrJQ3D7xy Ed7ktlFG30bQi84acSi0MjnTLlODWyBA8q2cQa2XZLrT1EkotjGRqNBIcmVD5yayaA1F jgfn5q3tuxDPPnPpuG+S98Lr1nfUE0frtFRuxxeBFFuFdzXs3FY+Qifs/erRATNZykCg FGQmLWv/VG94KM8D7Sy/VbcoSs0xS9PpBvcokmg5rNmVjNrPaOKu5vKO8der7+aGPSJe +eIuVtBnImP6eb3BLvvu8n5d9x0+uYB1pnBES5x2GfoI87skO0NngRB4+nUu7rEdZ08z BChg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id u191-20020a6385c8000000b00573f9dbef8asi9792408pgd.266.2023.09.25.01.21.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 01:21:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 8701C80190BC; Mon, 25 Sep 2023 01:13:01 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232752AbjIYINB (ORCPT + 30 others); Mon, 25 Sep 2023 04:13:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56426 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232808AbjIYIMS (ORCPT ); Mon, 25 Sep 2023 04:12:18 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0D483115; Mon, 25 Sep 2023 01:12:02 -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 D510CDA7; Mon, 25 Sep 2023 01:12:39 -0700 (PDT) Received: from e129166.arm.com (unknown [10.57.93.139]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 39C503F5A1; Mon, 25 Sep 2023 01:11:59 -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, mhiramat@kernel.org, qyousef@layalina.io, wvw@google.com Subject: [PATCH v4 18/18] Documentation: EM: Update information about performance field Date: Mon, 25 Sep 2023 09:11:39 +0100 Message-Id: <20230925081139.1305766-19-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230925081139.1305766-1-lukasz.luba@arm.com> References: <20230925081139.1305766-1-lukasz.luba@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE,TVD_PH_SUBJ_META1 autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 25 Sep 2023 01:13:01 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777996996474921606 X-GMAIL-MSGID: 1777996996474921606 The Energy Model supports the new information: performance for each performance state. Update the needed documentation part accordingly. Signed-off-by: Lukasz Luba --- Documentation/power/energy-model.rst | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Documentation/power/energy-model.rst b/Documentation/power/energy-model.rst index 3115411f9839..da3619c0b98a 100644 --- a/Documentation/power/energy-model.rst +++ b/Documentation/power/energy-model.rst @@ -125,6 +125,11 @@ runtime static EM' (system property) design to a 'single EM which can be changed during runtime according e.g. to the workload' (system and workload property) design. +It is possible also to modify the CPU performance values for each EM's +performance state. Thus, the full power and performance profile (which +is an exponential curve) can be changed according e.g. to the workload +or system property. + 3. Core APIs ------------ @@ -326,18 +331,18 @@ EM framework:: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 +The driver implements a mod_power_perf() 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) + 01 static int mod_power_perf(struct device *dev, unsigned long freq, + 02 unsigned long *power, unsigned long *perf, void *priv) 03 { 04 struct foo_context *ctx = priv; 05 - 06 /* Estimate power for the given frequency and temperature */ + 06 *perf = foo_estimate_performance(dev, freq); 07 *power = foo_estimate_power(dev, freq, ctx->temperature); 08 if (*power >= EM_MAX_POWER); 09 return -EINVAL;