From patchwork Wed Nov 29 11:08: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: 171246 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a5a7:0:b0:403:3b70:6f57 with SMTP id d7csp260841vqn; Wed, 29 Nov 2023 03:08:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IHbgq36fJKjzRHVMORo32BpJjlNbHOqgT07TWgGAa5WDKyCG4CK7aEw11h0WRsTspnCH6fD X-Received: by 2002:a05:6a20:3944:b0:18b:3168:d1a1 with SMTP id r4-20020a056a20394400b0018b3168d1a1mr20846255pzg.46.1701256101381; Wed, 29 Nov 2023 03:08:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701256101; cv=none; d=google.com; s=arc-20160816; b=UFrwydh9j7QWzx4+OJJBJtxYg54Yb/m8OYovBCDr1EvK7Q36hfD8Ydd/4LaOfg+ymZ vGQe+vFpWDp9rghmgfmnHi+D4wYPMajILUkp7ID83qCozlWertaKITyKy4la2zrMsRaB EUw6Lh9ZmcpLDfn1+thfzb0U4ukTFLSxUvmgXkt9TcM0rkAi6KtsB5ZCgC+OkBiImMQJ hBKfMCEeXlzeuibiVKFWkTGJe9S2fkWTmip4a+ekrsC7iqXzAEEWtt58o9viKX0JndGS t2Kk+yXPEAmiasmC/klTH7ZI3PBJppKEZgl0Nalf2xmvDNMZ00HULwpK6SOU5uCYWOjR sHqQ== 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=CvRxWlezltaPSrKhr8+Jp+swHqiEdDNCUWXIzHw5lUgn6PT+HnWn47pdI+EPKRZN2x b634fhGEomqpeSkoYG7XeYzRtTIobCSG7mSTlSh5vaddBcklL8R2ozosmLoZS0xNDG9v 0yXfMGo67p3HD1GcS6wVTjwPRkBXFwmU1q3an6rnl1PyLwT91+8A3ixJoPFWtO51kbUm 5DVOcT8NFkTS8w9JPiO7Y72IZEuA2OR+H4itbfBWKzlxl7f9FSLv8s0WxmRWGfl9M1sa K0txnJKJR/DmVX6GN2IedgJkHCXiyQZukEZ4QFvd8+2INljmHMJkWmRU1V+zs54gz1fr nTWQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id z7-20020a631907000000b005b8f60baea9si13988328pgl.801.2023.11.29.03.08.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 03:08:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (Postfix) with ESMTP id 159AC80A9DDC; Wed, 29 Nov 2023 03:08:14 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231197AbjK2LH7 (ORCPT + 99 others); Wed, 29 Nov 2023 06:07:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231255AbjK2LH6 (ORCPT ); Wed, 29 Nov 2023 06:07:58 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B941510F0; Wed, 29 Nov 2023 03:08:04 -0800 (PST) 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 AF04BC15; Wed, 29 Nov 2023 03:08:51 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.4.241]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 149003F5A1; Wed, 29 Nov 2023 03:08:01 -0800 (PST) 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 v5 01/23] PM: EM: Add missing newline for the message log Date: Wed, 29 Nov 2023 11:08:31 +0000 Message-Id: <20231129110853.94344-2-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231129110853.94344-1-lukasz.luba@arm.com> References: <20231129110853.94344-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,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.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 (fry.vger.email [0.0.0.0]); Wed, 29 Nov 2023 03:08:14 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783896317523501490 X-GMAIL-MSGID: 1783896317523501490 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 Wed Nov 29 11:08: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: 171248 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a5a7:0:b0:403:3b70:6f57 with SMTP id d7csp261080vqn; Wed, 29 Nov 2023 03:08:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IFej65C/HOIDxeIsikSnfwcq79KN/iNs2i2E1KVlbkoTQ+t3aHYPa22W7lZYFYWeky2QXy/ X-Received: by 2002:a9d:5d0b:0:b0:6d3:282b:deee with SMTP id b11-20020a9d5d0b000000b006d3282bdeeemr19337937oti.12.1701256134441; Wed, 29 Nov 2023 03:08:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701256134; cv=none; d=google.com; s=arc-20160816; b=YJ09AkEe6AhRMJD0//e0bexSR/hzGDaS2O9ye/W4npXVIMFKzamxja0C8fbRbbCtR3 YEeUu4ppgoieGfAzCdmYHwtvvRX8/PR+H941ta1frcW/CIJEa2dAsxyz9VFyORbxitk2 9+6cFaGucyyIFj5547MZe0VnZ3x7q6uUclxQAC0vLMYZvL+l8latroyCJF74UlD8j+5V h/StfruTGmxJMHVUIYMcngIBHm13l8T/sWp97ZDUVDEjJLCqKVufbmGSl/skXaRJW7e2 dhV8DNGp8McpFq7ZzB7sWshYktQNki/pUarApL/ZZievllbyGMVxY7bnZigGAVtDAYTA kImg== 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=Dn3T/Q0d9aQheDGMy+OaTURuhfWKkx83TyCMS1BTVoQ=; fh=jF+j1UEDAwnYbShW3HmO1TshMsWh36Jt7pSLTP62NeE=; b=OJvvL70aE9ZuVyBXgZJ2DJc6o022A+3r+mWBGAXUXejdzaHZhQwjTUylEhnNegt+FZ zzMxgsFQK/Wz+Lfvxoraxqt26qFHABjr11Vlj3T6VajKBz5MNptmbwJYI5D+4p7oz2i5 TIzVJMY7c45iGmKiejB442qdS8T4jJW7flJaRGa17iXo8QcYUMT0g4QjurI7g6c4JI5y fXiKzHI3FzjVa9Y4AjvPoA51yKCZb5Flzq58lNOFNhx5rzOrysRCRV/Kjk/dorVRku0U 3AjHTrR7QWEwYmG5k07c7ZWk0jdruRAUGWzSV4A/rtLA6r9fW66UmhMZIzntYVAfYHEq kB9Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id o2-20020a634e42000000b005c1cc7273bbsi14208006pgl.746.2023.11.29.03.08.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 03:08:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (Postfix) with ESMTP id 6375280A9DE7; Wed, 29 Nov 2023 03:08:48 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231749AbjK2LIO (ORCPT + 99 others); Wed, 29 Nov 2023 06:08:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231470AbjK2LIE (ORCPT ); Wed, 29 Nov 2023 06:08:04 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 240BA1998; Wed, 29 Nov 2023 03:08:10 -0800 (PST) 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 1BADA1424; Wed, 29 Nov 2023 03:08:57 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.4.241]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 7EEDF3F5A1; Wed, 29 Nov 2023 03:08:07 -0800 (PST) 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 v5 03/23] PM: EM: Find first CPU active while updating OPP efficiency Date: Wed, 29 Nov 2023 11:08:33 +0000 Message-Id: <20231129110853.94344-4-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231129110853.94344-1-lukasz.luba@arm.com> References: <20231129110853.94344-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,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.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 (fry.vger.email [0.0.0.0]); Wed, 29 Nov 2023 03:08:48 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783896352297506111 X-GMAIL-MSGID: 1783896352297506111 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 active CPU from the Performance Domain. This is needed since the first CPU in the cpumask might be offline when we run this code path. 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..aa7c89f9e115 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 active 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 Wed Nov 29 11:08: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: 171247 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a5a7:0:b0:403:3b70:6f57 with SMTP id d7csp260966vqn; Wed, 29 Nov 2023 03:08:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IESd4fsY6i3hLI4zEGxBGDEQwigBh2BvopP6FyVg6eZndVD4fdMiY7ClJqCsv3tsEgSX9y0 X-Received: by 2002:a05:6808:23c9:b0:3b5:ae0d:b208 with SMTP id bq9-20020a05680823c900b003b5ae0db208mr26364144oib.6.1701256120256; Wed, 29 Nov 2023 03:08:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701256120; cv=none; d=google.com; s=arc-20160816; b=Y4pjw15pPkyJDVdOFodsL4PDjYaw23MGO7QeYWAaesN2+TkBisR+Wkn1huZJSU4cxX +P9fGuHimFpoiQWSa7f4Ay3bAJE/2iAQ/qI0PvLIz9Kp1v6tcvqcG5fWtVrvAk4ldUbk WXMTRAXpJMxYsxAK1kli/fbhxBajkFxTY40pVW/RnshQ03TcgnzyD1iunnwqQVXFcANy jUP/ON+is+303yZBZocXP7qjVkvem0GwcCkpUwxIKLdb0eTA3rMrsz+TcMRbdYUGJeve 3sBlmz2vyHhgzUQkSivP12GLkD+zWxnb/82HkFNHEidChTtbrLONVl1lV+dQ0KfhonAJ d2Yg== 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=Sawye+NUIXAgeLuzVkl846BKan+X4OMUU72I4xhbKYI=; fh=jF+j1UEDAwnYbShW3HmO1TshMsWh36Jt7pSLTP62NeE=; b=UfdEX12/C7f3lAqYCy6WgoTPfaqmTPnrElFwQnHYjF5BBJr6+PEppgb3ZJKDqC2IXL FiUE3ZrCqU4F7D/6kBl3aKHXJYwHHxGD89FOtINaAU4MDO+gmlw13aEaOAzkyAK69KIo 1pfLTIVr9s1RgGwKmUvL/JfYLmfyvcojdfPOR9a+eQ4OviXk7+M3gekWyNrEkXq1pJWc RQjGO5sQTJcggv1gKHPEHdHQnVP0+ZAUv9yje4uxrPyrnh7c/JaY5Qu0qy2rXwJPsmwm rV3OwQNQVG/b/dHZivpZSwDxTFgin64dyqfYSJh+gmyjxTTVnyrE3eTMkPwRl6hKJxH4 3UBg== 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 c32-20020a631c60000000b005c216b7d4easi11669420pgm.473.2023.11.29.03.08.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 03:08:40 -0800 (PST) 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 79C4D804A481; Wed, 29 Nov 2023 03:08:33 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231853AbjK2LIS (ORCPT + 99 others); Wed, 29 Nov 2023 06:08:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231645AbjK2LIM (ORCPT ); Wed, 29 Nov 2023 06:08:12 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D708310FC; Wed, 29 Nov 2023 03:08:12 -0800 (PST) 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 C3B712F4; Wed, 29 Nov 2023 03:08:59 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.4.241]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 343DB3F5A1; Wed, 29 Nov 2023 03:08:10 -0800 (PST) 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 v5 04/23] PM: EM: Refactor em_pd_get_efficient_state() to be more flexible Date: Wed, 29 Nov 2023 11:08:34 +0000 Message-Id: <20231129110853.94344-5-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231129110853.94344-1-lukasz.luba@arm.com> References: <20231129110853.94344-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,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.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 (howler.vger.email [0.0.0.0]); Wed, 29 Nov 2023 03:08:34 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783896337274399885 X-GMAIL-MSGID: 1783896337274399885 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 Wed Nov 29 11:08: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: 171252 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a5a7:0:b0:403:3b70:6f57 with SMTP id d7csp261279vqn; Wed, 29 Nov 2023 03:09:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IFGK6w9SN6LwRP5XqMH24wwZAgLbdXO1aJp7swWI2m7u4v/wr5+optHbh6yhyiLUEYsJGay X-Received: by 2002:a05:6a20:3c90:b0:180:e3f1:4f60 with SMTP id b16-20020a056a203c9000b00180e3f14f60mr20084051pzj.45.1701256158098; Wed, 29 Nov 2023 03:09:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701256158; cv=none; d=google.com; s=arc-20160816; b=F20h4uaUKdcepJuf8b91FFovWQFmJvzwC7IK6MgcVkAkl212J2RIQBwgk8bnVt0eFr NtccY5lgAuKr0/HWrOUz/Tq0PORDdClP6t+vkBIABeNjJkmm+Ab/f7kiIdKpXlbA4hUs ndF+si2Hf0PMsUP2+euP4i3S4ZUsmfStmOy0w3H0vc7oVAOewyqUJAF3p2L+FB1twcfW vmAg22Q3+AVHzOlFoMAa+osn99iGvA9nkE8Hn+Nku0Kk6eSs9CymRIm500Ye9K45auJ8 36PvpLE+lJV+Ga6CyBcykqMuLnq/MvqFqsEzr4mpeuo6FRxl4MSSh55NJZPNG6YXNJyu fyTw== 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=+vNdGSrJXMSHlpsEzY6qXG3SFCKPDLNddytqE2e+UDk=; fh=jF+j1UEDAwnYbShW3HmO1TshMsWh36Jt7pSLTP62NeE=; b=wdfpXLawGnHDC/iFxolY3FoQEa0gQGIYxVy584TZShyUFZuEs1YKAC3+o1UuX309hD d8rQbykFt4RQyOYiiSd06+sa6Qvwph471BJKf6YR1cO/NjUr1wdKbofpNiEgQb52GYiW 128z0ZOxyjojheV/VWAZ/6NaGXLJlimQ0lO7npItEIzY6aFY56LNt9T7hoUNuaIYSRNJ IgbyJtOvcbKPo0kLvsrd+/MfYdrkZiX5+oeCEtpRY6UFstRlo62CNTeWQiRYvDdWhWSE r65Bm9x2stFnGz5Quiy1WaQIBOs1k88fji677+aE6a/Wyd9Mzj0I/K7XBbl4JdFN1caV RByQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id i2-20020a635402000000b005b7160263f2si13678332pgb.154.2023.11.29.03.09.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 03:09:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (Postfix) with ESMTP id 5284580A9E1F; Wed, 29 Nov 2023 03:09:11 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231569AbjK2LIY (ORCPT + 99 others); Wed, 29 Nov 2023 06:08:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231754AbjK2LIO (ORCPT ); Wed, 29 Nov 2023 06:08:14 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B7D671BD3; Wed, 29 Nov 2023 03:08:15 -0800 (PST) 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 789412F4; Wed, 29 Nov 2023 03:09:02 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.4.241]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id DC6E53F5A1; Wed, 29 Nov 2023 03:08:12 -0800 (PST) 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 v5 05/23] PM: EM: Refactor a new function em_compute_costs() Date: Wed, 29 Nov 2023 11:08:35 +0000 Message-Id: <20231129110853.94344-6-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231129110853.94344-1-lukasz.luba@arm.com> References: <20231129110853.94344-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,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.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 (fry.vger.email [0.0.0.0]); Wed, 29 Nov 2023 03:09:11 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783896377228769206 X-GMAIL-MSGID: 1783896377228769206 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). This change is not expected to alter the general functionality. 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 aa7c89f9e115..3bea930410c6 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 Wed Nov 29 11:08: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: 171249 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a5a7:0:b0:403:3b70:6f57 with SMTP id d7csp261133vqn; Wed, 29 Nov 2023 03:09:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IEBgAxnRnfXr7g50Gk9X01sMMK6uYRwTRzEdEQfVHgnLzxoSxfOryWEhLkisGrB6Qn0ToiR X-Received: by 2002:a17:903:181:b0:1c6:21b4:30bb with SMTP id z1-20020a170903018100b001c621b430bbmr18916980plg.15.1701256139778; Wed, 29 Nov 2023 03:08:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701256139; cv=none; d=google.com; s=arc-20160816; b=V3z0dFqemBTWL7SNVXEak5YHMPDuxU0kIEs0D5a7Hpe6jB+T5HsPV4tdjrGO1Z/QCQ m33TQbKrPEpjvkYgzrBgI26qoOvkmzU7a2TwAaJjCxysVGxDq5f2uEW+7UMil//gwafh GjNRrsJI4heHMi1+4i/x9rLzkEUr4t3XIFfQ3mdJAMco2oiE3WatMZwF1TPNhp0lUgF3 ktk7Q2HCHEI6EkMyXzM59t2ULFkLcV8McgkT8TCtrwEXnuUnoQ4gZsQyaA/EjmiEYGH+ kcCVQz/Nq+v3PkzHgmUUUrJFFaCapjmWxjLLPSasa4YFFomd+cVwu63jg2Cg/2dpcJCI 1UsA== 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=wN28uzk/4zD0K3Rir9ePnJkCxMkfPw9SWPzBQwuGU1o=; fh=jF+j1UEDAwnYbShW3HmO1TshMsWh36Jt7pSLTP62NeE=; b=ew7MdB8D2L3kVetD1HNteJReJ8C3xPI4br8hQbu13p/NSH6i+S4ZEqWn+U4BpwW3a3 C+H56cJMMQflRxwdMcQuS8PQr8hiGoQ/88MsEbCEUqbGD2K0nMaNKjqu7HiAMAPHqAPO Ya7mi6yqVNuvabX/fSt5o0HbS3es1hxYaM+sidYjrX1R36G9uaqqvANyuOLc7bgRtM99 ED774UeDJEv/jrF886iro45NXJJ30cgNhVKw1Ira4RvHGuAFt0auUlJrFoqTGZiPdE2p /fyCeYC7cs5ulKPc9DoaVAoU1igFtkeUzZPJHWWHSpSbKNrNI3uteafb2AiuzOT8GLm7 UWyg== 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:3 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 lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id b18-20020a170902d51200b001c5fb45613dsi9890268plg.318.2023.11.29.03.08.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 03:08:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (Postfix) with ESMTP id F0105808E679; Wed, 29 Nov 2023 03:08:54 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231470AbjK2LIn (ORCPT + 99 others); Wed, 29 Nov 2023 06:08:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232300AbjK2LI0 (ORCPT ); Wed, 29 Nov 2023 06:08:26 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 093E61FC3; Wed, 29 Nov 2023 03:08:21 -0800 (PST) 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 DF2262F4; Wed, 29 Nov 2023 03:09:07 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.4.241]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 506623F5A1; Wed, 29 Nov 2023 03:08:18 -0800 (PST) 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 v5 07/23] PM: EM: Refactor how the EM table is allocated and populated Date: Wed, 29 Nov 2023 11:08:37 +0000 Message-Id: <20231129110853.94344-8-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231129110853.94344-1-lukasz.luba@arm.com> References: <20231129110853.94344-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,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.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 (lipwig.vger.email [0.0.0.0]); Wed, 29 Nov 2023 03:08:55 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783896357827171269 X-GMAIL-MSGID: 1783896357827171269 Split the process of allocation and data initialization for the EM table. The upcoming changes for modifiable EM will use it. This change is not expected to alter the general functionality. Signed-off-by: Lukasz Luba --- kernel/power/energy_model.c | 52 ++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c index 3c8542443dd4..99426b5eedb6 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -142,18 +142,25 @@ static int em_compute_costs(struct device *dev, struct em_perf_state *table, return 0; } +static int em_allocate_perf_table(struct em_perf_domain *pd, + int nr_states) +{ + pd->table = kcalloc(nr_states, sizeof(struct em_perf_state), + GFP_KERNEL); + if (!pd->table) + return -ENOMEM; + + return 0; +} + static int em_create_perf_table(struct device *dev, struct em_perf_domain *pd, + struct em_perf_state *table, int nr_states, struct em_data_callback *cb, unsigned long flags) { unsigned long power, freq, prev_freq = 0; - struct em_perf_state *table; int i, ret; - table = kcalloc(nr_states, sizeof(*table), GFP_KERNEL); - if (!table) - return -ENOMEM; - /* Build the list of performance states for this performance domain */ for (i = 0, freq = 0; i < nr_states; i++, freq++) { /* @@ -165,7 +172,7 @@ static int em_create_perf_table(struct device *dev, struct em_perf_domain *pd, if (ret) { dev_err(dev, "EM: invalid perf. state: %d\n", ret); - goto free_ps_table; + return -EINVAL; } /* @@ -175,7 +182,7 @@ static int em_create_perf_table(struct device *dev, struct em_perf_domain *pd, if (freq <= prev_freq) { dev_err(dev, "EM: non-increasing freq: %lu\n", freq); - goto free_ps_table; + return -EINVAL; } /* @@ -185,7 +192,7 @@ static int em_create_perf_table(struct device *dev, struct em_perf_domain *pd, if (!power || power > EM_MAX_POWER) { dev_err(dev, "EM: invalid power: %lu\n", power); - goto free_ps_table; + return -EINVAL; } table[i].power = power; @@ -194,16 +201,9 @@ static int em_create_perf_table(struct device *dev, struct em_perf_domain *pd, 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; + return -EINVAL; return 0; - -free_ps_table: - kfree(table); - return -EINVAL; } static int em_create_pd(struct device *dev, int nr_states, @@ -234,11 +234,15 @@ static int em_create_pd(struct device *dev, int nr_states, return -ENOMEM; } - ret = em_create_perf_table(dev, pd, nr_states, cb, flags); - if (ret) { - kfree(pd); - return ret; - } + pd->nr_perf_states = nr_states; + + ret = em_allocate_perf_table(pd, nr_states); + if (ret) + goto free_pd; + + ret = em_create_perf_table(dev, pd, pd->table, nr_states, cb, flags); + if (ret) + goto free_pd_table; if (_is_cpu_device(dev)) for_each_cpu(cpu, cpus) { @@ -249,6 +253,12 @@ static int em_create_pd(struct device *dev, int nr_states, dev->em_pd = pd; return 0; + +free_pd_table: + kfree(pd->table); +free_pd: + kfree(pd); + return -EINVAL; } static void From patchwork Wed Nov 29 11:08: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: 171250 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a5a7:0:b0:403:3b70:6f57 with SMTP id d7csp261224vqn; Wed, 29 Nov 2023 03:09:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IFV/86eZM/gntdoJq3/p7u6hdTKco1pqxvtAqEi025meKEePprzJtbJvBX0rFyPtCmdofZ5 X-Received: by 2002:a17:903:230c:b0:1cf:c6a3:1652 with SMTP id d12-20020a170903230c00b001cfc6a31652mr10374776plh.12.1701256151440; Wed, 29 Nov 2023 03:09:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701256151; cv=none; d=google.com; s=arc-20160816; b=s2k3PR/IE/C9VD5ZarSPCujg8kP5Xbceorj3fy0GhJuYu86K5XVWn5cIOD7nOz9CQp AswpBfvX9+jdRUGLVmJ8HACEXVEJK6TwhkiECz6EfS92GunenBC2Gsd9y9izJfWobUm6 AFhSzPicLK+f9S02iFE0PphT4oMusiwK1PBzouFcUDbH1Y+/jracxaXAVpQ0Z5Tcr1yN LrEi9YtHoTrd1nQb2l23OOi1hGM3lYSQop7n5PttVz9r5/6fj2tjtqnS0TGO+WVGvX/k IdzdZSb08L5p0T7aLREVIW4vb9x6RlLUIYJFKucWpDd8EiDQEu5EYqATteOSEWXuzZ7V xABA== 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=2nQs8BSW9u6eZoHqTyCL3e0E85lWc9oBkJPtRriIxBE=; fh=jF+j1UEDAwnYbShW3HmO1TshMsWh36Jt7pSLTP62NeE=; b=yrMWpb3Vk76krDNqVtSkb3X5QfFbBA3L5A6y7YeRP8XdE6qUjh9/SMxtihCfwvjtoJ o/pMjFrYcclU+c24OvI7qLeX4Fb8fx8ux+VLNyZM6jyTVbqnh1yWtgqdRh0RjHzrOyVi pidDrolShysR1vNRtdnFIXp+JEh+uFsvFj1o/OgZ8sZvd0nzUW3MgYSmNf6SB26//cwX WIydUqVswzA/nuPpmKg8n2fC82N7kaB9IyoYEd9czd55F/5zmBUHV4K/KhR1225xFVlh PfRUQFphjeRHbWVMghSVPY6OSCyoCwAinHKvIzft2No0FAiIVitMK5HOPqDGH8dBd3a9 733g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id l18-20020a170903245200b001d01341e775si1529779pls.592.2023.11.29.03.09.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 03:09:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (Postfix) with ESMTP id 84831803A50C; Wed, 29 Nov 2023 03:09:08 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232203AbjK2LIq (ORCPT + 99 others); Wed, 29 Nov 2023 06:08:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231430AbjK2LIa (ORCPT ); Wed, 29 Nov 2023 06:08:30 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 070641FCE; Wed, 29 Nov 2023 03:08:23 -0800 (PST) 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 91017C15; Wed, 29 Nov 2023 03:09:10 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.4.241]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 02EED3F5A1; Wed, 29 Nov 2023 03:08:20 -0800 (PST) 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 v5 08/23] PM: EM: Introduce runtime modifiable table Date: Wed, 29 Nov 2023 11:08:38 +0000 Message-Id: <20231129110853.94344-9-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231129110853.94344-1-lukasz.luba@arm.com> References: <20231129110853.94344-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,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.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 (lipwig.vger.email [0.0.0.0]); Wed, 29 Nov 2023 03:09:08 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783896369874835528 X-GMAIL-MSGID: 1783896369874835528 The new runtime table can be populated with a new power data to better reflect the actual efficiency of the device e.g. CPU. 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 EM data at runtime safely. Signed-off-by: Lukasz Luba --- include/linux/energy_model.h | 12 ++++++++ kernel/power/energy_model.c | 53 ++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/include/linux/energy_model.h b/include/linux/energy_model.h index 8069f526c9d8..1e618e431cac 100644 --- a/include/linux/energy_model.h +++ b/include/linux/energy_model.h @@ -36,9 +36,20 @@ struct em_perf_state { */ #define EM_PERF_STATE_INEFFICIENT BIT(0) +/** + * struct em_perf_table - Performance states table + * @rcu: RCU used for safe access and destruction + * @state: List of performance states, in ascending order + */ +struct em_perf_table { + struct rcu_head rcu; + struct em_perf_state state[]; +}; + /** * struct em_perf_domain - Performance domain * @table: List of performance states, in ascending order + * @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 @@ -54,6 +65,7 @@ struct em_perf_state { */ struct em_perf_domain { struct em_perf_state *table; + struct em_perf_table __rcu *runtime_table; int nr_perf_states; unsigned long flags; unsigned long cpus[]; diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c index 99426b5eedb6..489287666705 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); @@ -103,6 +106,31 @@ static void em_debug_create_pd(struct device *dev) {} static void em_debug_remove_pd(struct device *dev) {} #endif +static void em_destroy_table_rcu(struct rcu_head *rp) +{ + struct em_perf_table __rcu *runtime_table; + + runtime_table = container_of(rp, struct em_perf_table, rcu); + kfree(runtime_table); +} + +static void em_free_table(struct em_perf_table __rcu *table) +{ + call_rcu(&table->rcu, em_destroy_table_rcu); +} + +static struct em_perf_table __rcu * +em_allocate_table(struct em_perf_domain *pd) +{ + struct em_perf_table __rcu *table; + int table_size; + + table_size = sizeof(struct em_perf_state) * pd->nr_perf_states; + + table = kzalloc(sizeof(*table) + table_size, GFP_KERNEL); + return table; +} + static int em_compute_costs(struct device *dev, struct em_perf_state *table, struct em_data_callback *cb, int nr_states, unsigned long flags) @@ -153,6 +181,24 @@ static int em_allocate_perf_table(struct em_perf_domain *pd, return 0; } +static int em_create_runtime_table(struct em_perf_domain *pd) +{ + struct em_perf_table __rcu *runtime_table; + int table_size; + + runtime_table = em_allocate_table(pd); + if (!runtime_table) + return -ENOMEM; + + /* Initialize runtime table with existing data */ + table_size = sizeof(struct em_perf_state) * pd->nr_perf_states; + memcpy(runtime_table->state, pd->table, table_size); + + rcu_assign_pointer(pd->runtime_table, runtime_table); + + return 0; +} + static int em_create_perf_table(struct device *dev, struct em_perf_domain *pd, struct em_perf_state *table, int nr_states, struct em_data_callback *cb, @@ -244,6 +290,10 @@ static int em_create_pd(struct device *dev, int nr_states, if (ret) goto free_pd_table; + ret = em_create_runtime_table(pd); + if (ret) + goto free_pd_table; + if (_is_cpu_device(dev)) for_each_cpu(cpu, cpus) { cpu_dev = get_cpu_device(cpu); @@ -460,6 +510,9 @@ void em_dev_unregister_perf_domain(struct device *dev) em_debug_remove_pd(dev); kfree(dev->em_pd->table); + + em_free_table(dev->em_pd->runtime_table); + kfree(dev->em_pd); dev->em_pd = NULL; mutex_unlock(&em_pd_mutex); From patchwork Wed Nov 29 11:08: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: 171251 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a5a7:0:b0:403:3b70:6f57 with SMTP id d7csp261254vqn; Wed, 29 Nov 2023 03:09:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IF1+yEvFBDs6CtRd9jpBZ6dFlQkfgIhHFSYJkg5xlTxF0SfL7uGaWIVoYuAWNuwWuq8etWa X-Received: by 2002:a17:90b:1bc8:b0:285:ba29:4ba with SMTP id oa8-20020a17090b1bc800b00285ba2904bamr11018979pjb.7.1701256154935; Wed, 29 Nov 2023 03:09:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701256154; cv=none; d=google.com; s=arc-20160816; b=VvSnx8QYERLgyjz4lVwiX6RgvvUJQAqI8rBlKLPwYbZahkSeFj57mD+upCduWvamkN 1VsojVcqN+GBD8tmdE9v4RFm0uYMwsm3qPMxpEnRgVjxoKzLV1iYCiG0K3uybnrtTXjE 8jIdG/OgbY49wW3gSFfH3R1EdYzyXTFfj9raNTuyp1VTtc9ksNJRIPWi2ibJ/BOZ4l3k nEdpbSFtcNg2oGodjAkB8KQK68ymEn8dh6GSugQxZIHnHp/QSh5vv4cvN+fQ653xYw6B r8VnP+pCFuTZvlocZhaGLgSKo8EX7ZU9r8U/GxWjjjEXi8uHr3qdKGWGGPM+juECIapm mQIQ== 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=rU5YCboC/GcIpHk/fDUIpYrNvsd4my19E2aif2cffxc=; fh=jF+j1UEDAwnYbShW3HmO1TshMsWh36Jt7pSLTP62NeE=; b=jU7XAQ1C1gNbPZGdWQtXbEDsOSLleAnXWCI0iP8bc9hJSOPvLAC565MrPJskpvYvui ZuHHN4aiJWcwUhywSVkx2s+kRM05Ym37FHxHYyh8xZ2YN+zOUohJehVD0FeHcDBwGCJJ IAhn2+hG8Pj/Yz/+CzYfrjaEz9o1PJW7F4x/Abs6X06mrxhXoaEDPTXJ8nB7/Yp6Xp0f DTjPX/MEojB+N6G6x3bAetr39SxSiKTZWdZ9d6BQgNOTZJ1c9MMYb48pbC719Nwp/3/q hYUdBddJjipxvbWVKeEnc6zXUsnP63by/J1sZpAHzT6BV5b3e6rZgVxztWCqydBSJVX2 w3OQ== 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 w7-20020a17090abc0700b00280cd49099asi1046542pjr.46.2023.11.29.03.09.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 03:09:14 -0800 (PST) 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 C54E180423B4; Wed, 29 Nov 2023 03:09:10 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232454AbjK2LI7 (ORCPT + 99 others); Wed, 29 Nov 2023 06:08:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232450AbjK2LIe (ORCPT ); Wed, 29 Nov 2023 06:08:34 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6AAA61FEB; Wed, 29 Nov 2023 03:08:26 -0800 (PST) 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 422322F4; Wed, 29 Nov 2023 03:09:13 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.4.241]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id A925C3F5A1; Wed, 29 Nov 2023 03:08:23 -0800 (PST) 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 v5 09/23] PM: EM: Use runtime modified EM for CPUs energy estimation in EAS Date: Wed, 29 Nov 2023 11:08:39 +0000 Message-Id: <20231129110853.94344-10-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231129110853.94344-1-lukasz.luba@arm.com> References: <20231129110853.94344-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,T_SCC_BODY_TEXT_LINE 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]); Wed, 29 Nov 2023 03:09:11 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783896373639530377 X-GMAIL-MSGID: 1783896373639530377 The new Energy Model (EM) supports runtime modification of the performance state table to better model the power used by the SoC. Use this new feature to improve energy estimation and therefore task placement in Energy Aware Scheduler (EAS). Signed-off-by: Lukasz Luba --- include/linux/energy_model.h | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/include/linux/energy_model.h b/include/linux/energy_model.h index 1e618e431cac..94a77a813724 100644 --- a/include/linux/energy_model.h +++ b/include/linux/energy_model.h @@ -238,6 +238,7 @@ static inline unsigned long em_cpu_energy(struct em_perf_domain *pd, unsigned long max_util, unsigned long sum_util, unsigned long allowed_cpu_cap) { + struct em_perf_table *runtime_table; unsigned long freq, scale_cpu; struct em_perf_state *ps; int cpu, i; @@ -255,7 +256,14 @@ static inline unsigned long em_cpu_energy(struct em_perf_domain *pd, */ cpu = cpumask_first(to_cpumask(pd->cpus)); scale_cpu = arch_scale_cpu_capacity(cpu); - ps = &pd->table[pd->nr_perf_states - 1]; + + /* + * No rcu_read_lock() since it's already called by task scheduler. + * The runtime_table is always there for CPUs, so we don't check. + */ + runtime_table = rcu_dereference(pd->runtime_table); + + ps = &runtime_table->state[pd->nr_perf_states - 1]; max_util = map_util_perf(max_util); max_util = min(max_util, allowed_cpu_cap); @@ -265,9 +273,9 @@ static inline unsigned long em_cpu_energy(struct em_perf_domain *pd, * Find the lowest performance state of the Energy Model above the * requested frequency. */ - i = em_pd_get_efficient_state(pd->table, pd->nr_perf_states, freq, - pd->flags); - ps = &pd->table[i]; + i = em_pd_get_efficient_state(runtime_table->state, pd->nr_perf_states, + freq, pd->flags); + ps = &runtime_table->state[i]; /* * The capacity of a CPU in the domain at the performance state (ps) From patchwork Wed Nov 29 11:08:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 171253 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a5a7:0:b0:403:3b70:6f57 with SMTP id d7csp261396vqn; Wed, 29 Nov 2023 03:09:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IG2ftTwqAJwCYly3etUvGPleuUU7OyeC6MeWxYLP+xm9xuFaqxrV+GXQGg+9v9eTuKs7vqY X-Received: by 2002:a05:6a21:2711:b0:18b:1f3c:eeb9 with SMTP id rm17-20020a056a21271100b0018b1f3ceeb9mr16557698pzb.36.1701256172158; Wed, 29 Nov 2023 03:09:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701256171; cv=none; d=google.com; s=arc-20160816; b=yFFtqprhUPBHleC6DphnWKrGMG7OYySVwGcTK81fk05+GlqYfGvhYt+tim9Lau3GHG kw8m/k9gn0byK8KT8G+InjxlyoR14iezIn6eYwdcoq1BVykN4GwpECi6SZwm44GJhunm rKC4bJNCugjcZDCiKTD/X20bTRFT0TxfiSRhmWdty6UxnL6oTNNohayEzOBw+n5/3rzc ICJlnuP5FgEujA1gY0iklVGRQ1L1U2kYIwox3drC5KYFE25USxtDBUhDVdkVidC+1GXA ufI0wDoC7I3rDxRxaMiQQbZl22JktG5d3XJ9BVsFNxC/0LXV3vnGQG8AF/zpLhLezaBy Gxbg== 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=PoLfy7zu3UWgb2JA6nfONGW74VylY61vParIU9vFcwY=; fh=jF+j1UEDAwnYbShW3HmO1TshMsWh36Jt7pSLTP62NeE=; b=S1R6exFRaybzBzJgX9eFcU1rnAWRBZIAolkIoZdcorm4tFiWmev/vj1BGwj0I1UFxw Y4Dql/E0LQ0xt/vroK5TMQ2Nt5P7YmQe8ALASajWdE31OYvjDj/pOOILLSAS4mj1ARR9 SohgbFqyavUQrmtceCeG+MMZbYSu+Lb/t0WBX9baqZLgcs3BKFw8XchfK+wsX7Kx6RRT EkrCKts8STEZphDjGtSO6jq1n3xRXJgcBTy40ezmrqZ50uihz8h+QPW0E6ODKT/FZwQs eaCZKp1ZONBN8us3ZphLFfvQELxif0JNIvWimWeNKWh73m8UsForycVcrs1dg6E95LP6 IAag== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id h10-20020a170902f54a00b001cfe52e0208si5036782plf.538.2023.11.29.03.09.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 03:09:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (Postfix) with ESMTP id 80E7C80A9DDF; Wed, 29 Nov 2023 03:09:25 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231735AbjK2LJI (ORCPT + 99 others); Wed, 29 Nov 2023 06:09:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232596AbjK2LIh (ORCPT ); Wed, 29 Nov 2023 06:08:37 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0DAD01BC5; Wed, 29 Nov 2023 03:08:29 -0800 (PST) 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 E51B8C15; Wed, 29 Nov 2023 03:09:15 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.4.241]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 5A01B3F5A1; Wed, 29 Nov 2023 03:08:26 -0800 (PST) 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 v5 10/23] PM: EM: Add API for memory allocations for new tables Date: Wed, 29 Nov 2023 11:08:40 +0000 Message-Id: <20231129110853.94344-11-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231129110853.94344-1-lukasz.luba@arm.com> References: <20231129110853.94344-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,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.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 (fry.vger.email [0.0.0.0]); Wed, 29 Nov 2023 03:09:25 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783896391632250773 X-GMAIL-MSGID: 1783896391632250773 The runtime modified EM table can be provided from drivers. Create mechanism which allows safely allocate and free the table for device drivers. The same table can be used by the EAS in task scheduler code paths, so make sure the memory is not freed when the device driver module is unloaded. Signed-off-by: Lukasz Luba --- include/linux/energy_model.h | 11 +++++++++ kernel/power/energy_model.c | 44 ++++++++++++++++++++++++++++++++++-- 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/include/linux/energy_model.h b/include/linux/energy_model.h index 94a77a813724..e785211828fe 100644 --- a/include/linux/energy_model.h +++ b/include/linux/energy_model.h @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -39,10 +40,12 @@ struct em_perf_state { /** * struct em_perf_table - Performance states table * @rcu: RCU used for safe access and destruction + * @refcount: Reference count to track the owners * @state: List of performance states, in ascending order */ struct em_perf_table { struct rcu_head rcu; + struct kref refcount; struct em_perf_state state[]; }; @@ -184,6 +187,8 @@ int em_dev_register_perf_domain(struct device *dev, unsigned int nr_states, struct em_data_callback *cb, cpumask_t *span, bool microwatts); void em_dev_unregister_perf_domain(struct device *dev); +struct em_perf_table __rcu *em_allocate_table(struct em_perf_domain *pd); +void em_free_table(struct em_perf_table __rcu *table); /** * em_pd_get_efficient_state() - Get an efficient performance state from the EM @@ -368,6 +373,12 @@ static inline int em_pd_nr_perf_states(struct em_perf_domain *pd) { return 0; } +static inline +struct em_perf_table __rcu *em_allocate_table(struct em_perf_domain *pd) +{ + return NULL; +} +static inline void em_free_table(struct em_perf_table __rcu *table) {} #endif #endif diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c index 489287666705..489a358b9a00 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -114,12 +114,46 @@ static void em_destroy_table_rcu(struct rcu_head *rp) kfree(runtime_table); } -static void em_free_table(struct em_perf_table __rcu *table) +static void em_release_table_kref(struct kref *kref) { + struct em_perf_table __rcu *table; + + /* It was the last owner of this table so we can free */ + table = container_of(kref, struct em_perf_table, refcount); + call_rcu(&table->rcu, em_destroy_table_rcu); } -static struct em_perf_table __rcu * +static inline void em_inc_usage(struct em_perf_table __rcu *table) +{ + kref_get(&table->refcount); +} + +static void em_dec_usage(struct em_perf_table __rcu *table) +{ + kref_put(&table->refcount, em_release_table_kref); +} + +/** + * em_free_table() - Handles safe free of the EM table when needed + * @table : EM memory which is going to be freed + * + * No return values. + */ +void em_free_table(struct em_perf_table __rcu *table) +{ + em_dec_usage(table); +} + +/** + * em_allocate_table() - Handles safe allocation of the new EM table + * @table : EM memory which is going to be freed + * + * Increments the reference counter to mark that there is an owner of that + * EM table. That might be a device driver module or EAS. + * Returns allocated table or error. + */ +struct em_perf_table __rcu * em_allocate_table(struct em_perf_domain *pd) { struct em_perf_table __rcu *table; @@ -128,6 +162,12 @@ em_allocate_table(struct em_perf_domain *pd) table_size = sizeof(struct em_perf_state) * pd->nr_perf_states; table = kzalloc(sizeof(*table) + table_size, GFP_KERNEL); + if (!table) + return table; + + kref_init(&table->refcount); + em_inc_usage(table); + return table; } From patchwork Wed Nov 29 11:08:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 171254 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a5a7:0:b0:403:3b70:6f57 with SMTP id d7csp261603vqn; Wed, 29 Nov 2023 03:09:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IEOhULfI8axLnNvu+rvVplthYcO+ytSSwCFOQaaDNvfFY73Oo4olF6EdI9tQOB1hzCbf31H X-Received: by 2002:a17:902:d4c6:b0:1cf:cbea:69d7 with SMTP id o6-20020a170902d4c600b001cfcbea69d7mr12532115plg.54.1701256198221; Wed, 29 Nov 2023 03:09:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701256198; cv=none; d=google.com; s=arc-20160816; b=ZETlScK6iGOYds3ftu7m4jTeOGUWi9F5lkmzVDUHrjVQ4nt37fAJsz33KTxz8K+gwM /CD4ruLEyQWcqMERxT3dbH4Ilj627ZPIUi4Q3qKU9PDuw+LA0N63+NXcnnns4MBVrCLu X/sDuy/EozNXUjOFNLN2z0jG6opvNyYpHUHeRXnqMvGNLAj3amDE0MEytKpFBkPsYDL7 V6LMqWeBkX2G/4iqoAedW0N0CnRe522Nzdfibwmk9AbkG0jgSZuv4j27l21B19Ui6q/6 fGGBoQDDiJQ7sEATFAYDHLjlnvk+s45wV9d1QJXZ9II/aIbApbk0IK4B6EuDBd2xKAL+ j40A== 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=QwE0v4XQ4uCtto4wLo2xPdjsPNwymenAafjnZOkg4Co=; fh=jF+j1UEDAwnYbShW3HmO1TshMsWh36Jt7pSLTP62NeE=; b=ILivpuphV7Smz7ryj9nCmRDVbKJQMPkr2WTASRdtfj6QpeYISK6qepms+YrhRqNQFX DfIH/0v654z2BPKPQch+URwBhE7DJJ47XRjac/I+qXXBm6SzDNRb7ZeozWKOjz178iYz ++ixZb942kSwWuP6Ur6kGk7ABcbvu1fkLxjPqNT8E+dIdARlPaCRIMIXlkVGUazvezSW WW2R2Xq+gCEfTu7rWsMxAkjMJgHGCbjhihGxowOESBmJ6IJBl4wKldkyMLl2W/UWgepp tn/WJhHE+DxO6+S9m2gYJXEPWhEg27ZdlFW2wCkj3k7e3I5efxfg9qB7RDgUQ6e6ITai 5Xcg== 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 l6-20020a170903120600b001cfb1dae607si10612751plh.146.2023.11.29.03.09.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 03:09:58 -0800 (PST) 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 587DE8049D64; Wed, 29 Nov 2023 03:09:55 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232929AbjK2LJX (ORCPT + 99 others); Wed, 29 Nov 2023 06:09:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231793AbjK2LIu (ORCPT ); Wed, 29 Nov 2023 06:08:50 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 59BA02127; Wed, 29 Nov 2023 03:08:34 -0800 (PST) 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 45CA22F4; Wed, 29 Nov 2023 03:09:21 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.4.241]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id ADF103F5A1; Wed, 29 Nov 2023 03:08:31 -0800 (PST) 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 v5 12/23] PM: EM: Add helpers to read under RCU lock the EM table Date: Wed, 29 Nov 2023 11:08:42 +0000 Message-Id: <20231129110853.94344-13-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231129110853.94344-1-lukasz.luba@arm.com> References: <20231129110853.94344-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,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.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 (howler.vger.email [0.0.0.0]); Wed, 29 Nov 2023 03:09:55 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783896419439946332 X-GMAIL-MSGID: 1783896419439946332 To use the runtime modifiable EM table there is a need to use RCU read locking properly. Add helper functions for the device drivers and frameworks to make sure it's done properly. Signed-off-by: Lukasz Luba --- include/linux/energy_model.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/include/linux/energy_model.h b/include/linux/energy_model.h index 520a8c8ad849..ae3ccc8b9f44 100644 --- a/include/linux/energy_model.h +++ b/include/linux/energy_model.h @@ -341,6 +341,20 @@ static inline int em_pd_nr_perf_states(struct em_perf_domain *pd) return pd->nr_perf_states; } +static inline struct em_perf_state *em_get_table(struct em_perf_domain *pd) +{ + struct em_perf_table __rcu *runtime_table; + + rcu_read_lock(); + runtime_table = rcu_dereference(pd->runtime_table); + return runtime_table->state; +} + +static inline void em_put_table(void) +{ + rcu_read_unlock(); +} + #else struct em_data_callback {}; #define EM_ADV_DATA_CB(_active_power_cb, _cost_cb) { } @@ -387,6 +401,11 @@ int em_dev_update_perf_domain(struct device *dev, { return -EINVAL; } +static inline struct em_perf_state *em_get_table(struct em_perf_domain *pd) +{ + return NULL; +} +static inline void em_put_table(void) {} #endif #endif From patchwork Wed Nov 29 11:08:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 171255 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a5a7:0:b0:403:3b70:6f57 with SMTP id d7csp261692vqn; Wed, 29 Nov 2023 03:10:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IE5qFhzvCDfByTbA95DSm31NxzrZet51VEN9k5FdQhZmBNcKkXaMqktenp+7oR+RMELC0om X-Received: by 2002:a05:6808:1188:b0:3ae:5c89:dcc2 with SMTP id j8-20020a056808118800b003ae5c89dcc2mr24112317oil.34.1701256208146; Wed, 29 Nov 2023 03:10:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701256208; cv=none; d=google.com; s=arc-20160816; b=yHbO0SDj+FiOw53VuIkaxbHaz9qKp3EvkbMDoppH8q0/RnMm4o5c+jElR0RstOiPWh u2wJKAwF1WnVQug5rCV5qsCcA2sg66beb7GDwhHwh97YCxw6APAeLUmhuqr6TYq8jvBp W/h4NbBef99VU4gELfICaa8N7v14G3YTAPEtITNudM82RFUJ7NBWdOQfQzFOjtDO2ArG A/mpcz1TWGZ8ZJ7kB1J80c7dA5XTRPl2HnCF/O19Ne3YbGNJCmGIaTu4/9X6iLvSBwf9 KxSZ9f0QPAlSBn93DhBypkb9tBiVIBe+7o5clobqj4nV2c/6x+5TjU0TIOxxZwAteYC3 H7jQ== 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=oI/CJBbMKG25LhA6Tzvd2ktHQDORmMxqs3y+lDE0hco=; fh=jF+j1UEDAwnYbShW3HmO1TshMsWh36Jt7pSLTP62NeE=; b=VyC1QVfj7+IVBDSSR/+CUnmLjq2XHo9w1++dBssaA2PhoJ1FE+r59nRjCDTNF9dHSi /JQn8NnbHZ1xQDASYjVP2omgB+KsCfR208NZaisYDSOHgYFi0v6wDpayChWQYoHljSua oazyJZDwc6Gr+FPtKET6YxuptUbsL++W+eDpvlS/gkL6UgRDdU2+tTNqAwUQYRJvCTHN e9QTZ4k9TZOKPoPawBduUueyLe0aZrcj/mfutpPeAG8MuXsGcaMx9SGzwcMcLzy7Esov GyOERyXfpMWm/qaWZzVIb2WTLNL81LVSV68tbh4dO4bgxcrTMrVN0qh+s04FCa8dKkyI hlHA== 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 g14-20020a63200e000000b005b92d41764dsi14088450pgg.794.2023.11.29.03.10.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 03:10:08 -0800 (PST) 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 2C5A28042038; Wed, 29 Nov 2023 03:10:03 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232410AbjK2LJw (ORCPT + 99 others); Wed, 29 Nov 2023 06:09:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232584AbjK2LJG (ORCPT ); Wed, 29 Nov 2023 06:09:06 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B5EFC26A2; Wed, 29 Nov 2023 03:08:39 -0800 (PST) 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 9B56EC15; Wed, 29 Nov 2023 03:09:26 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.4.241]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 0DE443F5A1; Wed, 29 Nov 2023 03:08:36 -0800 (PST) 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 v5 14/23] PM: EM: Support late CPUs booting and capacity adjustment Date: Wed, 29 Nov 2023 11:08:44 +0000 Message-Id: <20231129110853.94344-15-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231129110853.94344-1-lukasz.luba@arm.com> References: <20231129110853.94344-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,T_SCC_BODY_TEXT_LINE 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]); Wed, 29 Nov 2023 03:10:03 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783896429837790393 X-GMAIL-MSGID: 1783896429837790393 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 and EM registrations. Signed-off-by: Lukasz Luba --- kernel/power/energy_model.c | 121 ++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c index b5016afe6a19..d3fa5a77de80 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) { @@ -596,6 +599,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); @@ -631,3 +638,117 @@ 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 void em_adjust_new_capacity(struct device *dev, + struct em_perf_domain *pd, + u64 max_cap) +{ + struct em_perf_table __rcu *runtime_table; + struct em_perf_state *table, *new_table; + int ret, table_size; + + runtime_table = em_allocate_table(pd); + if (!runtime_table) { + dev_warn(dev, "EM: allocation failed\n"); + return; + } + + new_table = runtime_table->state; + + table = em_get_table(pd); + /* Initialize data based on older runtime table */ + table_size = sizeof(struct em_perf_state) * pd->nr_perf_states; + memcpy(new_table, table, table_size); + + em_put_table(); + + em_init_performance(dev, pd, new_table, pd->nr_perf_states); + ret = em_compute_costs(dev, new_table, NULL, pd->nr_perf_states, + pd->flags); + if (ret) { + em_free_table(runtime_table); + return; + } + + ret = em_dev_update_perf_domain(dev, runtime_table); + if (ret) + dev_warn(dev, "EM: update failed %d\n", ret); + + /* + * This is one-time-update, so give up the ownership in this updater. + * The EM fwk will keep the reference and free the memory when needed. + */ + em_free_table(runtime_table); +} + +static void em_check_capacity_update(void) +{ + cpumask_var_t cpu_done_mask; + struct em_perf_state *table; + struct em_perf_domain *pd; + unsigned long cpu_capacity; + int cpu; + + if (!zalloc_cpumask_var(&cpu_done_mask, GFP_KERNEL)) { + pr_warn("no free memory\n"); + return; + } + + /* Check if CPUs capacity has changed than update EM */ + for_each_possible_cpu(cpu) { + struct cpufreq_policy *policy; + unsigned long em_max_perf; + struct device *dev; + int nr_states; + + if (cpumask_test_cpu(cpu, cpu_done_mask)) + continue; + + policy = cpufreq_cpu_get(cpu); + if (!policy) { + pr_debug("Accessing cpu%d policy failed\n", cpu); + schedule_delayed_work(&em_update_work, + msecs_to_jiffies(1000)); + break; + } + cpufreq_cpu_put(policy); + + pd = em_cpu_get(cpu); + if (!pd || em_is_artificial(pd)) + continue; + + cpumask_or(cpu_done_mask, cpu_done_mask, + em_span_cpus(pd)); + + nr_states = pd->nr_perf_states; + cpu_capacity = arch_scale_cpu_capacity(cpu); + + table = em_get_table(pd); + em_max_perf = table[pd->nr_perf_states - 1].performance; + em_put_table(); + + /* + * Check if the CPU capacity has been adjusted during boot + * and trigger the update for new performance values. + */ + if (em_max_perf == cpu_capacity) + continue; + + pr_debug("updating cpu%d cpu_cap=%lu old capacity=%lu\n", + cpu, cpu_capacity, em_max_perf); + + dev = get_cpu_device(cpu); + em_adjust_new_capacity(dev, pd, cpu_capacity); + } + + free_cpumask_var(cpu_done_mask); +} + +static void em_update_workfn(struct work_struct *work) +{ + em_check_capacity_update(); +} From patchwork Wed Nov 29 11:08:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 171256 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a5a7:0:b0:403:3b70:6f57 with SMTP id d7csp261764vqn; Wed, 29 Nov 2023 03:10:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IETJPOwLuRitRCOHXKssCufGQRZzagaD9CFT0EiT8EQK3uWhSnW9EZh1m+xBKmcJYTOIbee X-Received: by 2002:a05:6a20:d48e:b0:18a:db41:bd0a with SMTP id im14-20020a056a20d48e00b0018adb41bd0amr24129679pzb.39.1701256217750; Wed, 29 Nov 2023 03:10:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701256217; cv=none; d=google.com; s=arc-20160816; b=hT1avwEHseYXE8QLXwm2s7yRbnO/ihaBs63RLpj1a2hVqZR9H6wmSAWS8R0eqws/cV UMhNNM3IRq1VLs9ru7KY4c814D8MnYSXhdEcgIkEqr2RL/KusPZnuFoezste06cmJdsK ntejrsyk1z26TXAWmxRJ4BrJ8Bv9k1LTvpruvNq5Xe+YRCWckBFnJzF1Hc0zlbcDFB2W 1gv2lkPUR9yaxOikyCZmruPP0eMs9ZyaUxGMj1dX+epxodw4XEkbWHpFUzBztPjto6qi o19141DR0Y8f8hWKSXOtZG8MjkKPtyTzwmufsmAWl4Vy+7VccdpYLJ97pWJM6Bhm73k9 wsIw== 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=tU+tAWZeEwqVvqDn7Oi8np9FqFUn/tqC6KA6jfHXgbo=; fh=jF+j1UEDAwnYbShW3HmO1TshMsWh36Jt7pSLTP62NeE=; b=sLz5c4kt36H8bSWn7zsNzjRPhQVwvxMj3NonyAiMaRcKNuqSmhZ4+FblnaTQxOW5qN GuyEO5NkTWKXGNWzsO2QsFZe1nLaMGITJ7WIYhwfz53NzNEFGY6hNVtVpYFaHg2fLdmD hxVjPU2jv8OidVQTbMdn9lI4/EvJ4EvhymGiHy5+ZRuiXM2CGKFymBxtbKI7XJL0LMPi O+rzU40HSgTQALooAfJaGh9rOQjwSBfEwL2qztw2ErZofhdUBF/k62QVZZQFJbV6vuae gDLl4xOKz5CZj+83qApx8lgGcivVJDA05jmAlCA4ASXKyZWCXpMQEw7IxNLkl90VSLTX TqhQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id y17-20020a056a00191100b006cbd24bf0b7si3185426pfi.52.2023.11.29.03.10.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 03:10:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (Postfix) with ESMTP id D632A803A51E; Wed, 29 Nov 2023 03:10:13 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232584AbjK2LJy (ORCPT + 99 others); Wed, 29 Nov 2023 06:09:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232105AbjK2LJJ (ORCPT ); Wed, 29 Nov 2023 06:09:09 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 584061BEF; Wed, 29 Nov 2023 03:08:42 -0800 (PST) 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 4B5812F4; Wed, 29 Nov 2023 03:09:29 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.4.241]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id B2AEA3F5A1; Wed, 29 Nov 2023 03:08:39 -0800 (PST) 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 v5 15/23] PM: EM: Optimize em_cpu_energy() and remove division Date: Wed, 29 Nov 2023 11:08:45 +0000 Message-Id: <20231129110853.94344-16-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231129110853.94344-1-lukasz.luba@arm.com> References: <20231129110853.94344-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,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.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 (lipwig.vger.email [0.0.0.0]); Wed, 29 Nov 2023 03:10:14 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783896440012347107 X-GMAIL-MSGID: 1783896440012347107 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 e30750500b10..0f5621898a81 100644 --- a/include/linux/energy_model.h +++ b/include/linux/energy_model.h @@ -115,27 +115,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 @@ -249,29 +228,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); @@ -286,35 +252,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'. * @@ -323,11 +275,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 d3fa5a77de80..c6e5f35a5129 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -204,11 +204,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; @@ -220,8 +218,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 Wed Nov 29 11:08:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 171258 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a5a7:0:b0:403:3b70:6f57 with SMTP id d7csp262163vqn; Wed, 29 Nov 2023 03:11:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IHJfDXs+7Hb5DH2XCVvzeOuBULXehRYkn43arZxWCQ1znvyIjm+aJstP3qgP0g1ZRjo5tx8 X-Received: by 2002:a9d:6412:0:b0:6d7:fa94:b42e with SMTP id h18-20020a9d6412000000b006d7fa94b42emr20018850otl.22.1701256262968; Wed, 29 Nov 2023 03:11:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701256262; cv=none; d=google.com; s=arc-20160816; b=X8rKcxbgO8H8fBSzpnwFQNXyEsyOsuWkANaNs6wLB7VL4wM4D/BuG5a2mRYsPS0rG8 3xDHj9NJrx8W2j3JaKxoKbrXl2nI04PJhmxzYrk2RjyV8q550vg9O+O9TRfH53LqFWef mEbZZfS+t0VsSSALKPvCp48fy48vQYhraPgBX+nzsYMDXKVKrtWwZcrhIfUM0KBYHSVG CrJ//qFosYpQdwL81ujC+h7E42/2myHgpsl38OcJx4n+1WDxYo/qnlDQIEGpB/d7dhCU lpMisWu1Drf9CizwIsS3T8qTpKfvj7u9IVWi7SuOILIZ/rhwp0Lg8EcKyeAMF5xIF/vO 055A== 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=Hee0AAJLr+gya8++cWdj24mnZcQ/akFdRw6pgIZIUn4=; fh=jF+j1UEDAwnYbShW3HmO1TshMsWh36Jt7pSLTP62NeE=; b=m5Ej2VKhC+BOMrmGxLWQM/H1+wb0SUK9lmBFeaqI09g4fzx0NGCf3QDUZbCG6ml+Og IbVnXl8mFrpXkrdQUcHjfb/e963vNDi+NcgXMwPEVZ1U8HBtWoWseAW2H/K5dRYwnKZ9 sa17KvNfGJbLCnYlKmCQBHxy+EaNdu/g2y4TJjBdzaHMSsvML9qRw4lRG5w60PV2S5wp 6LQt5WrtOZ7K3ROV0lweVsx99TcZ6K0tEYR7W2Rm7eU5JYfDd0Xet7XksZmJYUQeMzxS auSrduItdTcMHUzL3OgwFMKnDrCNo2M82B97yUrznMtDPyrzjvM06VPY5U80ILj6PtGB PL1Q== 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 e25-20020a631e19000000b005c1eadbacb3si14090830pge.104.2023.11.29.03.11.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 03:11:02 -0800 (PST) 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 092F38049D5E; Wed, 29 Nov 2023 03:10:50 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231891AbjK2LKP (ORCPT + 99 others); Wed, 29 Nov 2023 06:10:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56046 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231875AbjK2LJf (ORCPT ); Wed, 29 Nov 2023 06:09:35 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C52AA1BF9; Wed, 29 Nov 2023 03:08:47 -0800 (PST) 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 A1B982F4; Wed, 29 Nov 2023 03:09:34 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.4.241]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 14FD73F5A1; Wed, 29 Nov 2023 03:08:44 -0800 (PST) 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 v5 17/23] powercap/dtpm_devfreq: Use new Energy Model interface to get table Date: Wed, 29 Nov 2023 11:08:47 +0000 Message-Id: <20231129110853.94344-18-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231129110853.94344-1-lukasz.luba@arm.com> References: <20231129110853.94344-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,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.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 (howler.vger.email [0.0.0.0]); Wed, 29 Nov 2023 03:10:50 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783896487250378467 X-GMAIL-MSGID: 1783896487250378467 Energy Model framework support modifications at runtime of the power values. Use the new EM table API which is protected with RCU. Align the code so that this RCU read section is short. This change is not expected to alter the general functionality. Signed-off-by: Lukasz Luba --- drivers/powercap/dtpm_devfreq.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/drivers/powercap/dtpm_devfreq.c b/drivers/powercap/dtpm_devfreq.c index 612c3b59dd5b..514aa0d9d9c2 100644 --- a/drivers/powercap/dtpm_devfreq.c +++ b/drivers/powercap/dtpm_devfreq.c @@ -37,11 +37,15 @@ 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 = em_get_table(pd); - dtpm->power_max = pd->table[pd->nr_perf_states - 1].power; + dtpm->power_min = table[0].power; + dtpm->power_max = table[pd->nr_perf_states - 1].power; + + em_put_table(); return 0; } @@ -51,20 +55,22 @@ 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; int i; + table = em_get_table(pd); for (i = 0; i < pd->nr_perf_states; i++) { - if (pd->table[i].power > power_limit) + if (table[i].power > power_limit) break; } - freq = pd->table[i - 1].frequency; + freq = table[i - 1].frequency; + power_limit = table[i - 1].power; + em_put_table(); dev_pm_qos_update_request(&dtpm_devfreq->qos_req, freq); - power_limit = pd->table[i - 1].power; - return power_limit; } @@ -89,8 +95,9 @@ 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; + u64 power = 0; int i; mutex_lock(&devfreq->lock); @@ -100,19 +107,21 @@ static u64 get_pd_power_uw(struct dtpm *dtpm) freq = DIV_ROUND_UP(status.current_frequency, HZ_PER_KHZ); _normalize_load(&status); + table = em_get_table(pd); 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; + power = table[i].power; power *= status.busy_time; power >>= 10; - return power; + break; } + em_put_table(); - return 0; + return power; } static void pd_release(struct dtpm *dtpm) From patchwork Wed Nov 29 11:08:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 171257 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a5a7:0:b0:403:3b70:6f57 with SMTP id d7csp262125vqn; Wed, 29 Nov 2023 03:10:59 -0800 (PST) X-Google-Smtp-Source: AGHT+IECIMNTZm2HP8dyEZBUX50+VbIfBjlo0EoroLISZ8iMW7JY9S6c8iI6MdF5Jl0U/Byb3hKa X-Received: by 2002:a05:6808:1707:b0:3b8:4406:73a with SMTP id bc7-20020a056808170700b003b84406073amr23144790oib.9.1701256259490; Wed, 29 Nov 2023 03:10:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701256259; cv=none; d=google.com; s=arc-20160816; b=S3rSxSJZcCK1ml3eXRGpVBVNDAiBldAkHAPYaaloxhX1yCfn/MmVMj1ew002m6R4jX Y2PeQafIZtbzcFBkjzEV5thJw3l+EqgOWQ8YCrt6t66q8VCQRdBBdtU8zq/woqGhtlO7 yGOS7XJUWcNKLqVXjXQklVerNB4fADOf3eJHAXVxcuMdSB/JTBIgkz59XjFEHdOzsBXF 4uo7flwW4e6X1x1qN4A12HgL5uJ11+M2eMIbIh6viQxRWco9FZxTzVqDaeQR3XElaZp1 kREt1ZD2kbZQlYEIfCZLgaKOh0RYHuecSD5r8QRT6C3ERAfsxAoNiAlkuodnI3Rss6v0 +ZUg== 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=i0ORcFjhY9ErutLfdoO+q/reWzicYmf5BjlsVGijKAs=; fh=jF+j1UEDAwnYbShW3HmO1TshMsWh36Jt7pSLTP62NeE=; b=CNT9qxQrVHqFsB66+DdWXKlswymmHlagGbQNUSrjvV4NtYEbXV+PPFFVjeNNYWTGmz neZTkZB2MizJSLosIDQacMgIS8eKS4Fo+BaO/AzXWRXE7F7IGazhkX5+GPvwM7HM53PS RSlLcErQMwuHpTEfHeDsn+1nNUbeU7FMwDa6ZYZo3WWI5yM5pf7n14up3kpQL1LrS1dl GC1r3MQafMr6uiwcwYwcqx3WTV+pmlq4tmJG1na4STr36gCMKWgOtrJN/iDCnBWUQwtm 4nJ/XwtXbq3q3pqXRYeW1cloRwJQ37owAOdkwEFIudsFU8Ml9eom9zRpqMHeFVxBZfvG zSbg== 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 f23-20020a63f117000000b0059cc8d682dfsi14564084pgi.814.2023.11.29.03.10.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 03:10:59 -0800 (PST) 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 1C3F2805B2D9; Wed, 29 Nov 2023 03:10:48 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232465AbjK2LKd (ORCPT + 99 others); Wed, 29 Nov 2023 06:10:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231483AbjK2LJp (ORCPT ); Wed, 29 Nov 2023 06:09:45 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4611B2712; Wed, 29 Nov 2023 03:08:53 -0800 (PST) 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 32BE62F4; Wed, 29 Nov 2023 03:09:40 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.4.241]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 976813F5A1; Wed, 29 Nov 2023 03:08:50 -0800 (PST) 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 v5 19/23] drivers/thermal/devfreq_cooling: Use new Energy Model interface Date: Wed, 29 Nov 2023 11:08:49 +0000 Message-Id: <20231129110853.94344-20-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231129110853.94344-1-lukasz.luba@arm.com> References: <20231129110853.94344-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,T_SCC_BODY_TEXT_LINE 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]); Wed, 29 Nov 2023 03:10:49 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783896483648641209 X-GMAIL-MSGID: 1783896483648641209 Energy Model framework support modifications at runtime of the power values. Use the new EM table API which is protected with RCU. Align the code so that this RCU read section is short. This change is not expected to alter the general functionality. Signed-off-by: Lukasz Luba --- drivers/thermal/devfreq_cooling.c | 43 ++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/drivers/thermal/devfreq_cooling.c b/drivers/thermal/devfreq_cooling.c index 262e62ab6cf2..b7aed5a3810e 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; @@ -100,7 +101,10 @@ static int devfreq_cooling_set_cur_state(struct thermal_cooling_device *cdev, if (dfc->em_pd) { perf_idx = dfc->max_state - state; - freq = dfc->em_pd->table[perf_idx].frequency * 1000; + + table = em_get_table(dfc->em_pd); + freq = table[perf_idx].frequency * 1000; + em_put_table(); } else { freq = dfc->freq_table[state]; } @@ -123,14 +127,20 @@ 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) { - int i; + struct em_perf_state *table; + int i, idx = -EINVAL; + table = em_get_table(em_pd); for (i = 0; i < em_pd->nr_perf_states; i++) { - if (em_pd->table[i].frequency == freq) - return i; + if (table[i].frequency != freq) + continue; + + idx = i; + break; } + em_put_table(); - return -EINVAL; + return idx; } static unsigned long get_voltage(struct devfreq *df, unsigned long freq) @@ -181,6 +191,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; @@ -204,7 +215,10 @@ 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; + table = em_get_table(dfc->em_pd); + dfc->res_util = table[state].power; + em_put_table(); + dfc->res_util /= MICROWATT_PER_MILLIWATT; dfc->res_util *= SCALE_ERROR_MITIGATION; @@ -225,7 +239,10 @@ 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; + table = em_get_table(dfc->em_pd); + *power = table[perf_idx].power; + em_put_table(); + *power /= MICROWATT_PER_MILLIWATT; /* Scale power for utilization */ *power *= status.busy_time; @@ -245,13 +262,18 @@ 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; perf_idx = dfc->max_state - state; - *power = dfc->em_pd->table[perf_idx].power; + + table = em_get_table(dfc->em_pd); + *power = table[perf_idx].power; + em_put_table(); + *power /= MICROWATT_PER_MILLIWATT; return 0; @@ -264,6 +286,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; @@ -288,13 +311,15 @@ static int devfreq_cooling_power2state(struct thermal_cooling_device *cdev, * Find the first cooling state that is within the power * budget. The EM power table is sorted ascending. */ + table = em_get_table(dfc->em_pd); 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; } + em_put_table(); *state = dfc->max_state - i; dfc->capped_state = *state; From patchwork Wed Nov 29 11:08:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 171263 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a5a7:0:b0:403:3b70:6f57 with SMTP id d7csp264999vqn; Wed, 29 Nov 2023 03:16:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IECAUKbtwSaF0hIFF6lHWYhEmt3MCT/S87lQRe4CmqaAYHI6MilhNuawPoqL6LTANxv9WA2 X-Received: by 2002:a17:902:d488:b0:1cf:f73c:a6e6 with SMTP id c8-20020a170902d48800b001cff73ca6e6mr4694583plg.7.1701256612974; Wed, 29 Nov 2023 03:16:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701256612; cv=none; d=google.com; s=arc-20160816; b=dsMUwWQo8mQ7mObs+CWTiga0YPZnKl8/Z3fC9RBaI4oAVNNkmzdcD9Iz67j0xbCwY/ XN1w+bjwkiLNfcgnTTycw9GMpz9/NdZ9A8XBA5b/XQADo1KSKU0YLrUcEDj+0LXW4qek YmD0SDyNv1CsewBagILke3di+Lbfma2A5pZ05nRl+qM9JJcvibft5GPk4auOTDZz3N1W p1hKHmvUMlpxZUN9txWpDYsuOLTjZcimJncjjgAppgUud4RqtVv2iETHu8rhDbdm6tuK BjUnDVqEE+I8wPn2IRGtDYyjemAMTUsaMaFAElv4hOVKA4Fvgn2nEVhD67wx2VgkRNWS nzog== 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=9BJt/X4yPQ/LP2HpG/9tF1QEMKPfMY80cNmXaG+R7CM=; fh=jF+j1UEDAwnYbShW3HmO1TshMsWh36Jt7pSLTP62NeE=; b=QKXUXhoC8RwM0pWtJr8G8RpPZ3WaxqXV+EPaPKCPMNKrXYalP2KKArK/DW8strcOvZ IsuiqfUMhYRWk2oLIC6OqolgSMlz9FU4Qt714ql1Ke4vo/WwtitslqrY4nEw7l8DDlzj v09wIzmJ/CXsCJNtarrs8OqXIaFpKWDYgChXO3Rk7xfllw4M21yofJsfZ4Rj/3jBIbTX MZv+yw1D/QXtv4ycAZPURvjvHpxark1aYbESJy/NRMdyn35EwLaApgcZq3RQal/3iBxe UjyN215OHLJUdG7k8T98+ATUfuM7zbCpwkRervAzJdyYNPdROqH2P9VgZzDTtZb8xabj 0HDA== 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 mb5-20020a170903098500b001c60f6cf46bsi351808plb.12.2023.11.29.03.16.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 03:16:52 -0800 (PST) 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 D80408050FAF; Wed, 29 Nov 2023 03:16:49 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232049AbjK2LQk (ORCPT + 99 others); Wed, 29 Nov 2023 06:16:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232847AbjK2LJx (ORCPT ); Wed, 29 Nov 2023 06:09:53 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id F272E272C; Wed, 29 Nov 2023 03:08:55 -0800 (PST) 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 D610E2F4; Wed, 29 Nov 2023 03:09:42 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.4.241]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 4A6CE3F5A1; Wed, 29 Nov 2023 03:08:53 -0800 (PST) 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 v5 20/23] PM: EM: Change debugfs configuration to use runtime EM table data Date: Wed, 29 Nov 2023 11:08:50 +0000 Message-Id: <20231129110853.94344-21-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231129110853.94344-1-lukasz.luba@arm.com> References: <20231129110853.94344-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,T_SCC_BODY_TEXT_LINE 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]); Wed, 29 Nov 2023 03:16:50 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783896854621914280 X-GMAIL-MSGID: 1783896854621914280 Dump the runtime EM table values which can be modified in time. In order to do that allocate chunk of debug memory which can be later freed automatically thanks to devm_kcalloc(). This design can handle the fact that the EM table memory can change after EM update, so debug code cannot use the pointer from initialization phase. Signed-off-by: Lukasz Luba --- kernel/power/energy_model.c | 65 ++++++++++++++++++++++++++++++++----- 1 file changed, 57 insertions(+), 8 deletions(-) diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c index c6e5f35a5129..cc47993b4d64 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -37,20 +37,63 @@ static bool _is_cpu_device(struct device *dev) #ifdef CONFIG_DEBUG_FS static struct dentry *rootdir; -static void em_debug_create_ps(struct em_perf_state *ps, struct dentry *pd) +struct em_dbg_info { + struct em_perf_domain *pd; + int ps_id; +}; + +#define DEFINE_EM_DBG_SHOW(name, fname) \ +static int em_debug_##fname##_show(struct seq_file *s, void *unused) \ +{ \ + struct em_dbg_info *em_dbg = s->private; \ + struct em_perf_state *table; \ + unsigned long val; \ + \ + table = em_get_table(em_dbg->pd); \ + val = table[em_dbg->ps_id].name; \ + em_put_table(); \ + \ + seq_printf(s, "%lu\n", val); \ + return 0; \ +} \ +DEFINE_SHOW_ATTRIBUTE(em_debug_##fname) + +DEFINE_EM_DBG_SHOW(frequency, frequency); +DEFINE_EM_DBG_SHOW(power, power); +DEFINE_EM_DBG_SHOW(cost, cost); +DEFINE_EM_DBG_SHOW(performance, performance); +DEFINE_EM_DBG_SHOW(flags, inefficiency); + +static void em_debug_create_ps(struct em_perf_domain *em_pd, + struct em_dbg_info *em_dbg, int i, + struct dentry *pd) { + struct em_perf_state *table; + unsigned long freq; struct dentry *d; char name[24]; - snprintf(name, sizeof(name), "ps:%lu", ps->frequency); + em_dbg[i].pd = em_pd; + em_dbg[i].ps_id = i; + + table = em_get_table(em_pd); + freq = table[i].frequency; + em_put_table(); + + snprintf(name, sizeof(name), "ps:%lu", freq); /* Create per-ps directory */ d = debugfs_create_dir(name, 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); + debugfs_create_file("frequency", 0444, d, &em_dbg[i], + &em_debug_frequency_fops); + debugfs_create_file("power", 0444, d, &em_dbg[i], + &em_debug_power_fops); + debugfs_create_file("cost", 0444, d, &em_dbg[i], + &em_debug_cost_fops); + debugfs_create_file("performance", 0444, d, &em_dbg[i], + &em_debug_performance_fops); + debugfs_create_file("inefficient", 0444, d, &em_dbg[i], + &em_debug_inefficiency_fops); } static int em_debug_cpus_show(struct seq_file *s, void *unused) @@ -73,6 +116,7 @@ DEFINE_SHOW_ATTRIBUTE(em_debug_flags); static void em_debug_create_pd(struct device *dev) { + struct em_dbg_info *em_dbg; struct dentry *d; int i; @@ -86,9 +130,14 @@ static void em_debug_create_pd(struct device *dev) debugfs_create_file("flags", 0444, d, dev->em_pd, &em_debug_flags_fops); + em_dbg = devm_kcalloc(dev, dev->em_pd->nr_perf_states, + sizeof(*em_dbg), GFP_KERNEL); + if (!em_dbg) + return; + /* 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(dev->em_pd, em_dbg, i, d); } From patchwork Wed Nov 29 11:08:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 171260 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a5a7:0:b0:403:3b70:6f57 with SMTP id d7csp262506vqn; Wed, 29 Nov 2023 03:11:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IENctbp9yr57hy7NmwMMIggJYr/yYJVnnzuyS0uyp9V/XDwSO99tnX8Z8YwtNes5G5PIcfZ X-Received: by 2002:a17:902:ea06:b0:1cf:f125:e065 with SMTP id s6-20020a170902ea0600b001cff125e065mr7130494plg.3.1701256311589; Wed, 29 Nov 2023 03:11:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701256311; cv=none; d=google.com; s=arc-20160816; b=k89b5ok4AVaucmEacEoc8mf1AQSjJMSs89kewBe9x61j4tv8T6pIvVFSciiRV34FhT gAGFYk6xkTj6xSOrYU1cvmQpK4GuFjVKGc0U0Ra9qrz6+rpi4c7nLa8KId03MHZ/mP+q Tf/mYz1hRUi4pq/86doVosPftffCm570RM+3ieBdOSovhmkxYEK9e3ngzuk7O4oDkrmj mt0xSMkjGcYhoNZALBIU+jYuxYRuZFpuMo9I89J26u21R4rD6kkN0kq7nVlJ/OYHrpAU iUPyVFvJrfxEDgFeseHhU60YEB9bxbXb9MSF8ZVIvdT8Q8Xq4TJ1qchxZWi+gdA9OOCz JAjA== 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=a8N2H8sZp51OSG1dnN2BOGTT4W5ePhs+P+IPm9RwFEg=; fh=jF+j1UEDAwnYbShW3HmO1TshMsWh36Jt7pSLTP62NeE=; b=OLSy8muqpVZJpY3lFpJqTpdzWQRLBUSxmyoKAKe3w618FJ6qcHuxeZXpf76bMWsm+V H4Wd2yyKZQ0+H2GYUhqw1OLrmzfPemGJ57Oxd42YyWCd5P6PAJFS9ulwCYZegJeDmmpo +0e/QvMn+ViMoeCIc7xa28F/lZprYN1b3pDyO8BvTGuYSy3tP1lNFUjL99fQmVGiGgsc uYbqbD6dgpICsLwtSFTBHRcRdSa7qHzCAcZxVF36vEVW1iisdJB42cog3yvOhTy/HYsy ZAypx0lhaSOB/A7Pn1IAgQAUiSTp4o69kwacO+ix7C24xU9hLY0SabHgeqW6DPhRxkrH cGhw== 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 jf3-20020a170903268300b001c4062a0e43si13421926plb.169.2023.11.29.03.11.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 03:11:51 -0800 (PST) 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 136DE8074795; Wed, 29 Nov 2023 03:11:12 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231626AbjK2LLB (ORCPT + 99 others); Wed, 29 Nov 2023 06:11:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232223AbjK2LKK (ORCPT ); Wed, 29 Nov 2023 06:10:10 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5031E1FE1; Wed, 29 Nov 2023 03:09:01 -0800 (PST) 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 35F6E2F4; Wed, 29 Nov 2023 03:09:48 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.4.241]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 9E0913F5A1; Wed, 29 Nov 2023 03:08:58 -0800 (PST) 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 v5 22/23] PM: EM: Add em_dev_compute_costs() as API for device drivers Date: Wed, 29 Nov 2023 11:08:52 +0000 Message-Id: <20231129110853.94344-23-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231129110853.94344-1-lukasz.luba@arm.com> References: <20231129110853.94344-1-lukasz.luba@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 29 Nov 2023 03:11:12 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783896538004251182 X-GMAIL-MSGID: 1783896538004251182 The device drivers can modify EM at runtime by providing a new EM table. The EM is used by the EAS and the em_perf_state::cost stores pre-calculated value to avoid overhead. This patch provides the API for device drivers to calculate the cost values properly (and not duplicate the same code). Signed-off-by: Lukasz Luba --- include/linux/energy_model.h | 8 ++++++++ kernel/power/energy_model.c | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/include/linux/energy_model.h b/include/linux/energy_model.h index 9c47388482a0..836622b1a0a1 100644 --- a/include/linux/energy_model.h +++ b/include/linux/energy_model.h @@ -170,6 +170,8 @@ int em_dev_register_perf_domain(struct device *dev, unsigned int nr_states, void em_dev_unregister_perf_domain(struct device *dev); struct em_perf_table __rcu *em_allocate_table(struct em_perf_domain *pd); void em_free_table(struct em_perf_table __rcu *table); +int em_dev_compute_costs(struct device *dev, struct em_perf_state *table, + int nr_states); /** * em_pd_get_efficient_state() - Get an efficient performance state from the EM @@ -355,6 +357,12 @@ static inline struct em_perf_state *em_get_table(struct em_perf_domain *pd) return NULL; } static inline void em_put_table(void) {} +static inline +int em_dev_compute_costs(struct device *dev, struct em_perf_state *table, + int nr_states) +{ + return -EINVAL; +} #endif #endif diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c index 234823c0e59d..fadfdefbe5f0 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -286,6 +286,24 @@ static int em_compute_costs(struct device *dev, struct em_perf_state *table, return 0; } +/** + * em_dev_compute_costs() - Calculate cost values for new runtime EM table + * @dev : Device for which the EM table is to be updated + * @table : The new EM table that is going to get the costs calculated + * + * Calculate the em_perf_state::cost values for new runtime EM table. The + * values are used for EAS during task placement. It also calculates and sets + * the efficiency flag for each performance state. When the function finish + * successfully the EM table is ready to be updated and used by EAS. + * + * Return 0 on success or a proper error in case of failure. + */ +int em_dev_compute_costs(struct device *dev, struct em_perf_state *table, + int nr_states) +{ + return em_compute_costs(dev, table, NULL, nr_states, 0); +} + /** * em_dev_update_perf_domain() - Update runtime EM table for a device * @dev : Device for which the EM is to be updated From patchwork Wed Nov 29 11:08:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 171259 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a5a7:0:b0:403:3b70:6f57 with SMTP id d7csp262367vqn; Wed, 29 Nov 2023 03:11:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IFNoGJKJ6LxpU9fmGi1FtvZexVvlBYcy188a7jD+uFBUL9SgPuWm4p7qqrWmuur5J6HRhYR X-Received: by 2002:a05:6a20:9384:b0:187:9521:92bc with SMTP id x4-20020a056a20938400b00187952192bcmr20169407pzh.58.1701256292325; Wed, 29 Nov 2023 03:11:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701256292; cv=none; d=google.com; s=arc-20160816; b=mxF78PAeLYGFje58cREpfk40N8FaVh4Id8WW1fk8wEEQWTyw03wN3q0cQAwx0w2TIo 1U1XFWHKK7UvglF89K6qhIT5tgLKaRmI4ZvlkewYdjeUXaypyZKJY02MTUC+KoOQVYbw ok9+XGqxQGzs4q2mblmZLqptZoGzUMdUQK+NKIoM+jg1RjYhDxm4X8zZaxNGnJJsXtp3 F/5DaqCVGRf0GtQ6xsy0d+e5hTaXY0bBOow9J0t18x2F7FdrpFEAq4z0CiusNPR3ERs9 EQmti5DQQ/N9MnnmQofiDUCAOVlAd4c2CvV8Jx+MbhLok96BGJYQjd0TeV2/kcy0u0V+ FPyg== 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=oDRLuLZqY7IgKk+vhJI0gZKgUtH2FhLAVRbidJsu8cU=; fh=jF+j1UEDAwnYbShW3HmO1TshMsWh36Jt7pSLTP62NeE=; b=b1x9ZdVT/e0T1Y1axIsWuT+wPpEog+Pz/K2WRhToUEH6H/czKlXRGAmENcHDH5O05h CcmqWqWCVqxBuYQx2bUeosvPLmF71++vbo2cgCG3nx4BrA6GiefzM15Dhk43VVyqdWSs d+2kd5uCaB3e2pX2641cqcG3SHzNMSS3svW3dm86VIknz0brv2qjycJQhYKi7eEdjIDG HODfinDQrh5psk0NspFo+kMtYnKFPFDP0XwUayi1gvZMzd76TtkWEX212Gtm+KpYJWm2 KCPvMhi9egG73HrQpd7tOpF02nXLXHFuyz1AP33IqL+y6bnw1cCG5ePcPVYfTWfHXALx 4+eg== 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 u5-20020a17090ae00500b00280386ec042si1079146pjy.149.2023.11.29.03.11.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 03:11:32 -0800 (PST) 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 84BFD80558AF; Wed, 29 Nov 2023 03:11:29 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232708AbjK2LLN (ORCPT + 99 others); Wed, 29 Nov 2023 06:11:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231880AbjK2LKP (ORCPT ); Wed, 29 Nov 2023 06:10:15 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id EDDDC1FD2; Wed, 29 Nov 2023 03:09:03 -0800 (PST) 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 D8F0FC15; Wed, 29 Nov 2023 03:09:50 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.4.241]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 4DDB73F5A1; Wed, 29 Nov 2023 03:09:01 -0800 (PST) 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 v5 23/23] Documentation: EM: Update with runtime modification design Date: Wed, 29 Nov 2023 11:08:53 +0000 Message-Id: <20231129110853.94344-24-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231129110853.94344-1-lukasz.luba@arm.com> References: <20231129110853.94344-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,T_SCC_BODY_TEXT_LINE 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]); Wed, 29 Nov 2023 03:11:29 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783896517752893258 X-GMAIL-MSGID: 1783896517752893258 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. Remove 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 | 206 +++++++++++++++++++++++++-- 1 file changed, 196 insertions(+), 10 deletions(-) diff --git a/Documentation/power/energy-model.rst b/Documentation/power/energy-model.rst index 13225965c9a4..1f8cf36914b1 100644 --- a/Documentation/power/energy-model.rst +++ b/Documentation/power/energy-model.rst @@ -72,16 +72,48 @@ required to have the same micro-architecture. CPUs in different performance domains can have different micro-architectures. -2. Core APIs +2. Design +----------------- + +2.1 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 provides +API for allocating/freeing the new memory for the modifiable EM table. +The old memory is freed automatically using RCU callback mechanism when there +are no owners anymore for the given EM runtime table instance. This is tracked +using kref mechanism. The device driver which provided the new EM at runtime, +should call EM API to free it safely when it's no longer needed. The EM +framework will handle the clean-up when it's possible. + +The kernel code which want to modify the EM values is protected from concurrent +access using a mutex. Therefore, the device driver code must run in sleeping +context when it tries 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. + +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 ------------ -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 +142,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 +188,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 +207,83 @@ 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 update the EM at runtime should use the following dedicated +function to allocate a new instance of the modified EM. The API is listed +below:: + + struct em_perf_table __rcu *em_allocate_table(struct em_perf_domain *pd); + +This allows to allocate a structure which contains the new EM table with +also RCU and kref needed by the EM framework. The 'struct em_perf_table' +contains array 'struct em_perf_state state[]' which is a list of performance +states in ascending order. That list must be populated by the device driver +which wants to update the EM. The list of frequencies can be taken from +existing EM (created during boot). The content in the 'struct em_perf_state' +must be populated by the driver as well. + +This is the API which does the EM update, using RCU pointers swap:: + + int em_dev_update_perf_domain(struct device *dev, + struct em_perf_table __rcu *new_table); + +Drivers must provide a pointer to the allocated and initialized new EM +'struct em_perf_table'. That new EM will be safely used inside the EM framework +and will be visible to other sub-systems in the kernel (thermal, powercap). +The main design goal for this API is to be fast and avoid extra calculations +or memory allocations at runtime. When pre-computed EMs are available in the +device driver, than it should be possible to simply re-use them with low +performance overhead. + +In order to free the EM, provided earlier by the driver (e.g. when the module +is unloaded), there is a need to call the API:: + + void em_free_table(struct em_perf_table __rcu *table); + +It will allow the EM framework to safely remove the memory, when there is +no other sub-system using it, e.g. EAS. + +To use the power values in other sub-systems (like thermal, powercap) there is +a need to call API which protects the reader and provide consistency of the EM +table data:: + struct em_perf_state *em_get_table(struct em_perf_domain *pd); -2.4 Description details of this API +It returns the 'struct em_perf_state' pointer which is an array of performance +states in ascending order. + +When the EM table is not needed anymore there is a need to call dedicated API:: + + void em_put_table(void); + +In this way the EM safely uses the RCU read section and protects the users. +It also allows the EM framework to manage the memory and free it. + +There is dedicated API for device drivers to calculate em_perf_state::cost +values:: + + int em_dev_compute_costs(struct device *dev, struct em_perf_state *table, + int nr_states); + +These 'cost' values from EM are used in EAS. The new EM table should be passed +together with the number of entries and device pointer. When the computation +of the cost values is done properly the return value from the function is 0. +The function takes care for right setting of inefficiency for each performance +state as well. It updates em_perf_state::flags accordingly. +Then such prepared new EM can be passed to the em_dev_update_perf_domain() +function, which will allow to use it. + +More details about the above APIs can be found in ```` +or in Section 4.2 with an example code showing simple implementation of the +updating mechanism in a device driver. + + +3.5 Description details of this API ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. kernel-doc:: include/linux/energy_model.h :internal: @@ -187,8 +292,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 +350,81 @@ 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_thermal_em_update() function. The driver is woken +up periodically to check the temperature and modify the EM data:: + + -> drivers/soc/example/example_em_mod.c + + 01 static void foo_get_new_em(struct device *dev) + 02 { + 03 struct em_perf_table __rcu *runtime_table; + 04 struct em_perf_state *table, *new_table; + 05 struct em_perf_domain *pd; + 06 unsigned long freq; + 07 int i, ret; + 08 + 09 pd = em_pd_get(dev); + 10 if (!pd) + 11 return; + 12 + 13 runtime_table = em_allocate_table(pd); + 14 if (!runtime_table) + 15 return; + 16 + 17 new_table = runtime_table->state; + 18 + 19 table = em_get_table(pd); + 20 for (i = 0; i < pd->nr_perf_states; i++) { + 21 freq = table[i].frequency; + 22 foo_get_power_perf_values(dev, freq, &new_table[i]); + 23 } + 24 em_put_table(); + 25 + 26 /* Calculate 'cost' values for EAS */ + 27 ret = em_dev_compute_costs(dev, table, pd->nr_perf_states); + 28 if (ret) { + 29 dev_warn(dev, "EM: compute costs failed %d\n", ret); + 30 em_free_table(runtime_table); + 31 return; + 32 } + 33 + 34 ret = em_dev_update_perf_domain(dev, runtime_table); + 35 if (ret) { + 36 dev_warn(dev, "EM: update failed %d\n", ret); + 37 em_free_table(runtime_table); + 38 return; + 39 } + 40 + 41 ctx->runtime_table = runtime_table; + 42 } + 43 + 44 /* + 45 * Function called periodically to check the temperature and + 46 * update the EM if needed + 47 */ + 48 static void foo_thermal_em_update(struct foo_context *ctx) + 49 { + 50 struct device *dev = ctx->dev; + 51 int cpu; + 52 + 53 ctx->temperature = foo_get_temp(dev, ctx); + 54 if (ctx->temperature < FOO_EM_UPDATE_TEMP_THRESHOLD) + 55 return; + 56 + 57 foo_get_new_em(dev); + 58 } + 59 + 60 static void foo_exit(void) + 61 { + 62 struct foo_context *ctx = glob_ctx; + 63 + 64 em_free_table(ctx->runtime_table); + 65 } + 66 + 67 module_exit(foo_exit);