From patchwork Sat Dec 18 13:00:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 12686041 X-Patchwork-Delegate: daniel.lezcano@linaro.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 40340C4332F for ; Sat, 18 Dec 2021 13:00:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233204AbhLRNAe (ORCPT ); Sat, 18 Dec 2021 08:00:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233022AbhLRNAe (ORCPT ); Sat, 18 Dec 2021 08:00:34 -0500 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F67BC06173E for ; Sat, 18 Dec 2021 05:00:33 -0800 (PST) Received: by mail-wm1-x329.google.com with SMTP id y196so3423435wmc.3 for ; Sat, 18 Dec 2021 05:00:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JCbNL7RiUna5qq8DaSMW/coH4epXCMjSWD6ZnOXRFI0=; b=u4gwbRii2rQYALroefHK1y6OAg/PaB5d8cxYkVOxNfQfP/GSpkOTw4lM0b9sykdRGn I5+TfxMLFW4Yz9DjXmmwADnnilA4jAI3OuH+2kj279neBPdyczuIvIKan+BZxt1abCOC PYvHZoojRGkGcKQVmwOZVt1XScnzpH93n3cT0kdV+KDJ4QLvkVW8g+u48CO+9sCgVbi+ IM8GXnnDHqRZPDHHNChAWlGub8OWoFq1V1IwRCwrtEzywv2SqESfkq3jDHxS/vHMIzCq Y/6l37BlHAuffQ5iGLgabgk+gX6l3IXwpC+2N3WfHvO+x+p5njBf0nTvVHjxH/2oigQn 0Nrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JCbNL7RiUna5qq8DaSMW/coH4epXCMjSWD6ZnOXRFI0=; b=o5oj5Uup8ukoCpMsrnyxyHauBKDBSpFc3cRFgmzwNgqj1t57UF61Njs9pOTRM6LUcE dfToLfreYwiy/SFtpgknMnF/dRBN1P2yRpXSMrS0v8Zx4uAOMS1f5pw5zZwSJjyStunX wpp77ndJ7D5TcI+v+d/BdEJXZFzNG/pb6l0rhc2V7A/7gy2EzR9bblwgKKZX5qPE53Yd yrYFRAlOQAZZOPw2jgulz2itpPZbjT0iIUcF5b4SUwncXMYhIAltz7hKAyKB7ZX6tD8u LHTilBF7gc/E8dELyDokK9KJSY+pJ9NhGaZJCkzNUzberqL9FXo4l8XV9+3gQQws5fYM +6cA== X-Gm-Message-State: AOAM531rxMLFty8/wUe/FgPxD1JDj7O2xaDTnSN3n3iyD5N4BSGYkmPB JTBF8063Oag3XH4vmUcyUCrl5Q== X-Google-Smtp-Source: ABdhPJxXBs2crqxznWfWrplA3JeMlkC5cBhIFjXjof2wb1mGSFgRnncc6sy5NXR1PO3YD3c6rLebKQ== X-Received: by 2002:a05:600c:a4c:: with SMTP id c12mr6702096wmq.60.1639832431971; Sat, 18 Dec 2021 05:00:31 -0800 (PST) Received: from localhost.localdomain ([2a01:e34:ed2f:f020:1f0f:c9b8:ee5c:5c2f]) by smtp.gmail.com with ESMTPSA id j16sm1465785wms.12.2021.12.18.05.00.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Dec 2021 05:00:31 -0800 (PST) From: Daniel Lezcano To: daniel.lezcano@linaro.org, rjw@rjwysocki.net Cc: lukasz.luba@arm.com, robh@kernel.org, heiko@sntech.de, arnd@linaro.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, ulf.hansson@linaro.org, Arnd Bergmann , linux-arch@vger.kernel.org (open list:GENERIC INCLUDE/ASM HEADER FILES) Subject: [PATCH v5 1/6] powercap/drivers/dtpm: Move dtpm table from init to data section Date: Sat, 18 Dec 2021 14:00:09 +0100 Message-Id: <20211218130014.4037640-2-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211218130014.4037640-1-daniel.lezcano@linaro.org> References: <20211218130014.4037640-1-daniel.lezcano@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The dtpm table is used to let the different dtpm backends to register their setup callbacks in a single place and preventing to export multiple functions all around the kernel. That allows the dtpm code to be self-encapsulated. The dtpm hierarchy will be passed as a parameter by a platform specific code and that will lead to the creation of the different dtpm nodes. The function creating the hierarchy could be called from a module at init time or when it is loaded. However, at this moment the table is already freed as it belongs to the init section and the creation will lead to a invalid memory access. Fix this by moving the table to the data section. Signed-off-by: Daniel Lezcano --- include/asm-generic/vmlinux.lds.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h index 42f3866bca69..50d494d94d6c 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -362,7 +362,8 @@ BRANCH_PROFILE() \ TRACE_PRINTKS() \ BPF_RAW_TP() \ - TRACEPOINT_STR() + TRACEPOINT_STR() \ + DTPM_TABLE() /* * Data section helpers @@ -723,7 +724,6 @@ ACPI_PROBE_TABLE(irqchip) \ ACPI_PROBE_TABLE(timer) \ THERMAL_TABLE(governor) \ - DTPM_TABLE() \ EARLYCON_TABLE() \ LSM_TABLE() \ EARLY_LSM_TABLE() \ From patchwork Sat Dec 18 13:00:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 12686043 X-Patchwork-Delegate: daniel.lezcano@linaro.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BA459C433F5 for ; Sat, 18 Dec 2021 13:00:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233242AbhLRNAh (ORCPT ); Sat, 18 Dec 2021 08:00:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233230AbhLRNAf (ORCPT ); Sat, 18 Dec 2021 08:00:35 -0500 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36909C061574 for ; Sat, 18 Dec 2021 05:00:35 -0800 (PST) Received: by mail-wr1-x436.google.com with SMTP id s1so9409589wrg.1 for ; Sat, 18 Dec 2021 05:00:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Ex98898ORuSQfXO3nt1xbryRupEWOc+Ws7IWvi7Y958=; b=MSiX8872aULjxwwWkBGaY+6CBTB4Bk8og4GFTKrZcV/QR7h9Rib64/2uVR6t/iTRNM pWwECd2NZ7wsGlKxsobev/zTSah25gQzRty9YfL4JF2qZQE/yr/+2LyBKqswZLrz0x1V G3iM+/TXQR2kAdgQ9kjs0PeoHUJMrVTPEK1dtmTpT6CQ2ykfW04SYDVK2YcvQO/Ko9BL zbskONb+0IxVZKhEEuAsI1zBjWtLdQMf1iBfwPVV21B0l3DRSkp/p7s0cZ+sJCmf5/Zo N5ChbsSQrWozpzDLGQNEOClloAuIys7jA4GFvF2cWphyJqmsQxLJ0B2/RSvzsaQ7oLTR GTGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Ex98898ORuSQfXO3nt1xbryRupEWOc+Ws7IWvi7Y958=; b=DXHn1ImVuuuOv13ZtL6P1LhdchJn/qLjFLiV6JM0Nd27YI+BvXA3+To7Om2UrHvxHq c0rR+pO8V0CY1ZbcRxYm3JovoQWUaA/3zSuIsIZkB94T3FSSnlIgeFkNmxAtU+UbPN19 DO9yQ/pjXzV5EzQnzzINTrpdSHuJzwMfe8dZ7pJnAvU8c3UMGhkRPUvcr3mnyUUCQ8j1 fq4BUDZKAcC9eRYmi/6qkX0IQNAwyAS8G7CNAy4vl2lwpFs7qq7ZsYY5CII+WQ0M+0Ax VN+mkA5nDlshvEgGYSTg/+4zy/Mx/h3Wae6i/VO/7FzTOpw3bO/toZ6S8ViIz3EZgWtw xeuA== X-Gm-Message-State: AOAM532AjJrUDZYz9fljIUa1dG8RQJDm31WaSbqOE3sOONtXjCCPVZlX IQnZh/HHt9/afkKLL9RKMe9aSQ== X-Google-Smtp-Source: ABdhPJx1TFiCgA5HbwOo6OFSCSrP6j7DJZt+8Gf9pGtTd265i0qCfhzr2/PgJeD4Vo/417lUWht0IA== X-Received: by 2002:adf:cd8a:: with SMTP id q10mr6060897wrj.164.1639832433691; Sat, 18 Dec 2021 05:00:33 -0800 (PST) Received: from localhost.localdomain ([2a01:e34:ed2f:f020:1f0f:c9b8:ee5c:5c2f]) by smtp.gmail.com with ESMTPSA id j16sm1465785wms.12.2021.12.18.05.00.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Dec 2021 05:00:33 -0800 (PST) From: Daniel Lezcano To: daniel.lezcano@linaro.org, rjw@rjwysocki.net Cc: lukasz.luba@arm.com, robh@kernel.org, heiko@sntech.de, arnd@linaro.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, ulf.hansson@linaro.org, "Rafael J. Wysocki" , Daniel Lezcano Subject: [PATCH v5 2/6] powercap/drivers/dtpm: Add hierarchy creation Date: Sat, 18 Dec 2021 14:00:10 +0100 Message-Id: <20211218130014.4037640-3-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211218130014.4037640-1-daniel.lezcano@linaro.org> References: <20211218130014.4037640-1-daniel.lezcano@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The DTPM framework is available but without a way to configure it. This change provides a way to create a hierarchy of DTPM node where the power consumption reflects the sum of the children's power consumption. It is up to the platform to specify an array of dtpm nodes where each element has a pointer to its parent, except the top most one. The type of the node gives the indication of which initialization callback to call. At this time, we can create a virtual node, where its purpose is to be a parent in the hierarchy, and a DT node where the name describes its path. In order to ensure a nice self-encapsulation, the DTPM table descriptors contains a couple of initialization functions, one to setup the DTPM backend and one to initialize it up. With this approach, the DTPM framework has a very few material to export. Signed-off-by: Daniel Lezcano --- drivers/powercap/Kconfig | 1 + drivers/powercap/dtpm.c | 155 ++++++++++++++++++++++++++++++++++-- drivers/powercap/dtpm_cpu.c | 2 +- include/linux/dtpm.h | 21 ++++- 4 files changed, 171 insertions(+), 8 deletions(-) diff --git a/drivers/powercap/Kconfig b/drivers/powercap/Kconfig index 8242e8c5ed77..b1ca339957e3 100644 --- a/drivers/powercap/Kconfig +++ b/drivers/powercap/Kconfig @@ -46,6 +46,7 @@ config IDLE_INJECT config DTPM bool "Power capping for Dynamic Thermal Power Management (EXPERIMENTAL)" + depends on OF help This enables support for the power capping for the dynamic thermal power management userspace engine. diff --git a/drivers/powercap/dtpm.c b/drivers/powercap/dtpm.c index 0fe70687c198..1611c86de5f5 100644 --- a/drivers/powercap/dtpm.c +++ b/drivers/powercap/dtpm.c @@ -23,6 +23,7 @@ #include #include #include +#include #define DTPM_POWER_LIMIT_FLAG 0 @@ -461,19 +462,163 @@ int dtpm_register(const char *name, struct dtpm *dtpm, struct dtpm *parent) return 0; } -static int __init init_dtpm(void) +static struct dtpm *dtpm_setup_virtual(const struct dtpm_node *hierarchy, + struct dtpm *parent) +{ + struct dtpm *dtpm; + int ret; + + dtpm = kzalloc(sizeof(*dtpm), GFP_KERNEL); + if (!dtpm) + return ERR_PTR(-ENOMEM); + dtpm_init(dtpm, NULL); + + ret = dtpm_register(hierarchy->name, dtpm, parent); + if (ret) { + pr_err("Failed to register dtpm node '%s': %d\n", + hierarchy->name, ret); + kfree(dtpm); + return ERR_PTR(ret); + } + + return dtpm; +} + +static struct dtpm *dtpm_setup_dt(const struct dtpm_node *hierarchy, + struct dtpm *parent) +{ + struct dtpm_descr *dtpm_descr; + struct device_node *np; + int ret; + + np = of_find_node_by_path(hierarchy->name); + if (!np) { + pr_err("Failed to find '%s'\n", hierarchy->name); + return ERR_PTR(-ENXIO); + } + + for_each_dtpm_table(dtpm_descr) { + + ret = dtpm_descr->setup(parent, np); + if (ret) { + pr_err("Failed to setup '%s': %d\n", hierarchy->name, ret); + of_node_put(np); + return ERR_PTR(ret); + } + + of_node_put(np); + } + + /* + * By returning a NULL pointer, we let know the caller there + * is no child for us as we are a leaf of the tree + */ + return NULL; +} + +typedef struct dtpm * (*dtpm_node_callback_t)(const struct dtpm_node *, struct dtpm *); + +dtpm_node_callback_t dtpm_node_callback[] = { + [DTPM_NODE_VIRTUAL] = dtpm_setup_virtual, + [DTPM_NODE_DT] = dtpm_setup_dt, +}; + +static int dtpm_for_each_child(const struct dtpm_node *hierarchy, + const struct dtpm_node *it, struct dtpm *parent) +{ + struct dtpm *dtpm; + int i, ret; + + for (i = 0; hierarchy[i].name; i++) { + + if (hierarchy[i].parent != it) + continue; + + dtpm = dtpm_node_callback[hierarchy[i].type](&hierarchy[i], parent); + if (!dtpm || IS_ERR(dtpm)) + continue; + + ret = dtpm_for_each_child(hierarchy, &hierarchy[i], dtpm); + if (ret) + return ret; + } + + return 0; +} + +/** + * dtpm_create_hierarchy - Create the dtpm hierarchy + * @hierarchy: An array of struct dtpm_node describing the hierarchy + * + * The function is called by the platform specific code with the + * description of the different node in the hierarchy. It creates the + * tree in the sysfs filesystem under the powercap dtpm entry. + * + * The expected tree has the format: + * + * struct dtpm_node hierarchy[] = { + * [0] { .name = "topmost" }, + * [1] { .name = "package", .parent = &hierarchy[0] }, + * [2] { .name = "/cpus/cpu0", .type = DTPM_NODE_DT, .parent = &hierarchy[1] }, + * [3] { .name = "/cpus/cpu1", .type = DTPM_NODE_DT, .parent = &hierarchy[1] }, + * [4] { .name = "/cpus/cpu2", .type = DTPM_NODE_DT, .parent = &hierarchy[1] }, + * [5] { .name = "/cpus/cpu3", .type = DTPM_NODE_DT, .parent = &hierarchy[1] }, + * [6] { } + * }; + * + * The last element is always an empty one and marks the end of the + * array. + * + * Return: zero on success, a negative value in case of error. Errors + * are reported back from the underlying functions. + */ +int dtpm_create_hierarchy(struct of_device_id *dtpm_match_table) { + const struct of_device_id *match; + const struct dtpm_node *hierarchy; struct dtpm_descr *dtpm_descr; + struct device_node *np; + int ret; + + np = of_find_node_by_path("/"); + if (!np) + return -ENODEV; + + match = of_match_node(dtpm_match_table, np); + of_node_put(np); + + if (!match) + return -ENODEV; + + hierarchy = match->data; + if (!hierarchy) + return -EFAULT; + + ret = dtpm_for_each_child(hierarchy, NULL, NULL); + if (ret) + return ret; + + for_each_dtpm_table(dtpm_descr) { + + if (!dtpm_descr->init) + continue; + + dtpm_descr->init(); + } + + return 0; +} +EXPORT_SYMBOL_GPL(dtpm_create_hierarchy); + +static int __init init_dtpm(void) +{ pct = powercap_register_control_type(NULL, "dtpm", NULL); if (IS_ERR(pct)) { pr_err("Failed to register control type\n"); return PTR_ERR(pct); } - for_each_dtpm_table(dtpm_descr) - dtpm_descr->init(); - return 0; } -late_initcall(init_dtpm); +fs_initcall_sync(init_dtpm); diff --git a/drivers/powercap/dtpm_cpu.c b/drivers/powercap/dtpm_cpu.c index b740866b228d..6bffb44c75aa 100644 --- a/drivers/powercap/dtpm_cpu.c +++ b/drivers/powercap/dtpm_cpu.c @@ -269,4 +269,4 @@ static int __init dtpm_cpu_init(void) return 0; } -DTPM_DECLARE(dtpm_cpu, dtpm_cpu_init); +DTPM_DECLARE(dtpm_cpu, dtpm_cpu_init, NULL); diff --git a/include/linux/dtpm.h b/include/linux/dtpm.h index d37e5d06a357..5a6b31eaf7e4 100644 --- a/include/linux/dtpm.h +++ b/include/linux/dtpm.h @@ -32,23 +32,39 @@ struct dtpm_ops { void (*release)(struct dtpm *); }; +struct device_node; + typedef int (*dtpm_init_t)(void); +typedef int (*dtpm_setup_t)(struct dtpm *, struct device_node *); struct dtpm_descr { dtpm_init_t init; + dtpm_setup_t setup; +}; + +enum DTPM_NODE_TYPE { + DTPM_NODE_VIRTUAL = 0, + DTPM_NODE_DT, +}; + +struct dtpm_node { + enum DTPM_NODE_TYPE type; + const char *name; + struct dtpm_node *parent; }; /* Init section thermal table */ extern struct dtpm_descr __dtpm_table[]; extern struct dtpm_descr __dtpm_table_end[]; -#define DTPM_TABLE_ENTRY(name, __init) \ +#define DTPM_TABLE_ENTRY(name, __init, __setup) \ static struct dtpm_descr __dtpm_table_entry_##name \ __used __section("__dtpm_table") = { \ .init = __init, \ + .setup = __setup, \ } -#define DTPM_DECLARE(name, init) DTPM_TABLE_ENTRY(name, init) +#define DTPM_DECLARE(name, init, setup) DTPM_TABLE_ENTRY(name, init, setup) #define for_each_dtpm_table(__dtpm) \ for (__dtpm = __dtpm_table; \ @@ -70,4 +86,5 @@ void dtpm_unregister(struct dtpm *dtpm); int dtpm_register(const char *name, struct dtpm *dtpm, struct dtpm *parent); +int dtpm_create_hierarchy(struct of_device_id *dtpm_match_table); #endif From patchwork Sat Dec 18 13:00:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 12686045 X-Patchwork-Delegate: daniel.lezcano@linaro.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B70E2C4332F for ; Sat, 18 Dec 2021 13:00:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233251AbhLRNAh (ORCPT ); Sat, 18 Dec 2021 08:00:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233241AbhLRNAh (ORCPT ); Sat, 18 Dec 2021 08:00:37 -0500 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 790A3C061574 for ; Sat, 18 Dec 2021 05:00:36 -0800 (PST) Received: by mail-wm1-x334.google.com with SMTP id b186-20020a1c1bc3000000b00345734afe78so3286810wmb.0 for ; Sat, 18 Dec 2021 05:00:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hik1Ew47qtvoaoQPBwSqmP9iF+Hk1zIVyb0fsefpwXU=; b=GzFN4UefBx0laykv6Zwg7pEq1+EAUbsyKbx6AVLTNdAHslCUEN3tBeGnzJroWjsmhh qUhWsji2g2tm27/NZyIG51JJQCSBJ0CqCa2+JQdMd0uAy9Otvl9FhnMoZ7HkiJcG76f4 gu+C+z+i7GqiYsF6KLSuEYxAihpkIC5damwHnVjUHG4EmVj/IFXBSyA2SipJy6vy8lET 9MXfTrIni9eKR2PMHrNeDMNmHnei5TtzQhtKnfeWSUm+ibx80VYY/M6Ez5dgWCKPA/wB uuOV0HRD44DO/ctS2Mg1EiJ/l0koYw+STrXylmet58LA6sEtqUfFHRN6Q8W8tGdSwn16 uUuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hik1Ew47qtvoaoQPBwSqmP9iF+Hk1zIVyb0fsefpwXU=; b=rscC1vS7U3UGWqJl6epWekms/Lx10aYxzQKfilZVIJPCkbhfMsgv/aN+8Y464mapB3 k78i8JgUj2zvjoCh7yRIvH3pJdndClQCyWzfY29ptsD1GdKTawO6j91d8KFjxZTKMaFO E+nUpF02ducpnXZ1Rgmf1CQWV1rJC/0KI9lGe9xoddJVy268vIsa05uh7QO7CK/aGYri 1K100dxb2kjtU10vagYm3vBg3cZc+I6lpxiydGN/LZ5q0Zr4dETyQfErxk3z0Y845p1U SvkCC8QMmS90LglrRRLCqNE5cg3pB9JHxvR+gGZEHOhQBtssVIrH5FFPWarabVetEm0i YqHQ== X-Gm-Message-State: AOAM531uaWEsQfSrlzbv7V5yKRj2C/I+hND7tJtsIqhzmzGvNT9lqjQe XrW4dZQPFCFfE3ezwA7dyFcQFQ== X-Google-Smtp-Source: ABdhPJwByO/pO1dDzzwFGphL1YqsL1H2rh9fyawiwIX/hNuHVwXE2pcVQ3eqQc71yMLx0PPnvdfuOA== X-Received: by 2002:a05:600c:1f05:: with SMTP id bd5mr6638452wmb.171.1639832435001; Sat, 18 Dec 2021 05:00:35 -0800 (PST) Received: from localhost.localdomain ([2a01:e34:ed2f:f020:1f0f:c9b8:ee5c:5c2f]) by smtp.gmail.com with ESMTPSA id j16sm1465785wms.12.2021.12.18.05.00.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Dec 2021 05:00:34 -0800 (PST) From: Daniel Lezcano To: daniel.lezcano@linaro.org, rjw@rjwysocki.net Cc: lukasz.luba@arm.com, robh@kernel.org, heiko@sntech.de, arnd@linaro.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, ulf.hansson@linaro.org, Daniel Lezcano , "Rafael J. Wysocki" Subject: [PATCH v5 3/6] powercap/drivers/dtpm: Add CPU DT initialization support Date: Sat, 18 Dec 2021 14:00:11 +0100 Message-Id: <20211218130014.4037640-4-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211218130014.4037640-1-daniel.lezcano@linaro.org> References: <20211218130014.4037640-1-daniel.lezcano@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Based on the previous DT changes in the core code, use the 'setup' callback to initialize the CPU DTPM backend. Code is reorganized to stick to the DTPM table description. No functional changes. Signed-off-by: Daniel Lezcano Reviewed-by: Ulf Hansson --- drivers/powercap/dtpm_cpu.c | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/drivers/powercap/dtpm_cpu.c b/drivers/powercap/dtpm_cpu.c index 6bffb44c75aa..ca605911523b 100644 --- a/drivers/powercap/dtpm_cpu.c +++ b/drivers/powercap/dtpm_cpu.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -176,6 +177,17 @@ static int cpuhp_dtpm_cpu_offline(unsigned int cpu) } static int cpuhp_dtpm_cpu_online(unsigned int cpu) +{ + struct dtpm_cpu *dtpm_cpu; + + dtpm_cpu = per_cpu(dtpm_per_cpu, cpu); + if (dtpm_cpu) + return dtpm_update_power(&dtpm_cpu->dtpm); + + return 0; +} + +static int __dtpm_cpu_setup(int cpu, struct dtpm *parent) { struct dtpm_cpu *dtpm_cpu; struct cpufreq_policy *policy; @@ -183,6 +195,10 @@ static int cpuhp_dtpm_cpu_online(unsigned int cpu) char name[CPUFREQ_NAME_LEN]; int ret = -ENOMEM; + dtpm_cpu = per_cpu(dtpm_per_cpu, cpu); + if (dtpm_cpu) + return 0; + policy = cpufreq_cpu_get(cpu); if (!policy) return 0; @@ -191,10 +207,6 @@ static int cpuhp_dtpm_cpu_online(unsigned int cpu) if (!pd) return -EINVAL; - dtpm_cpu = per_cpu(dtpm_per_cpu, cpu); - if (dtpm_cpu) - return dtpm_update_power(&dtpm_cpu->dtpm); - dtpm_cpu = kzalloc(sizeof(*dtpm_cpu), GFP_KERNEL); if (!dtpm_cpu) return -ENOMEM; @@ -207,7 +219,7 @@ static int cpuhp_dtpm_cpu_online(unsigned int cpu) snprintf(name, sizeof(name), "cpu%d-cpufreq", dtpm_cpu->cpu); - ret = dtpm_register(name, &dtpm_cpu->dtpm, NULL); + ret = dtpm_register(name, &dtpm_cpu->dtpm, parent); if (ret) goto out_kfree_dtpm_cpu; @@ -231,7 +243,18 @@ static int cpuhp_dtpm_cpu_online(unsigned int cpu) return ret; } -static int __init dtpm_cpu_init(void) +static int dtpm_cpu_setup(struct dtpm *dtpm, struct device_node *np) +{ + int cpu; + + cpu = of_cpu_node_to_id(np); + if (cpu < 0) + return 0; + + return __dtpm_cpu_setup(cpu, dtpm); +} + +static int dtpm_cpu_init(void) { int ret; @@ -269,4 +292,4 @@ static int __init dtpm_cpu_init(void) return 0; } -DTPM_DECLARE(dtpm_cpu, dtpm_cpu_init, NULL); +DTPM_DECLARE(dtpm_cpu, dtpm_cpu_init, dtpm_cpu_setup); From patchwork Sat Dec 18 13:00:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 12686047 X-Patchwork-Delegate: daniel.lezcano@linaro.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 39F38C433F5 for ; Sat, 18 Dec 2021 13:00:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233264AbhLRNAk (ORCPT ); Sat, 18 Dec 2021 08:00:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233256AbhLRNAj (ORCPT ); Sat, 18 Dec 2021 08:00:39 -0500 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56690C061574 for ; Sat, 18 Dec 2021 05:00:38 -0800 (PST) Received: by mail-wm1-x32d.google.com with SMTP id 203so344927wmb.5 for ; Sat, 18 Dec 2021 05:00:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XRtSRhv3I6GjbIaBndvp8XiBC8v+f6H0Oym54m9OYJk=; b=Y2AOCv7Kfn4X9cGi87UWfX+lkA31SnWIHSQo7lkXKa/86ubsjsS80kg9ou94lsfeq6 Ed+4gRLsPEK42iatVPGqwkF4fpVahBaIGR2CQtkdtqKNkRjyrP5KP3uYoaNVOUWRexxE N7VqiOx+LIdoDB9UR/6DWGzwNEvDmdZq+lpoiaUAR57dnhll2jxpc2rYUgADUrl+JGh3 X6KmsR5MoRtWeNvN1qrZGqaZ4s7c8hTUL4nyA8PNEtaJnCoR8uBJTnv41oC8DADwvU+e 9o+YMgveHWaXhBVzwNYfzj2KKdV56g95TOG+VsOKF7mbvBimKjsNGEL2mKyCByqdeQPx wYyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XRtSRhv3I6GjbIaBndvp8XiBC8v+f6H0Oym54m9OYJk=; b=AL9ildbGqibP+Vg2pdNUoP++HEzNae76ZpuI4aYBjEQTSdEYYTYHhE+4wpD+4ML86l JqzwqW+kSJqm70MDyn6WoRmno1AL2l7VOGxZCaCps1v+pWwAeq2+O3qraxW3iVtjst9x HOUg4EK6eb9FqM9SJf7Sv7IasBQEaR2MqnSFZtw16gtMeZcK5hEpd+ce+NYhfI4QJcxN bnmxZCuf+nxolnQ8lyGEv1sgUsWbhQnGDgU3pE0y3ZMUqdmh8xgzf9GFZ8jH/0e0JZLP vsm65KNRYQHkvOw3CqhjMjBcfHVS9m4YUVc3FkmiFVufflN4r2YlIyF7kA2utcU4p2wY 1izA== X-Gm-Message-State: AOAM5315aDMQdR3n/FA4LjmnneAvbehhQHOhRnASZS+qEr/thdJb5+xS EsJi8kjIOB32SGbKKu+FZXXPxA== X-Google-Smtp-Source: ABdhPJz+P72nJND4uskpnWqEqh60n4W45WpWU5viO93fwHtP1aExU91V4shWycbTXMQIn+kVGd+Csw== X-Received: by 2002:a05:600c:a4a:: with SMTP id c10mr5596846wmq.145.1639832436842; Sat, 18 Dec 2021 05:00:36 -0800 (PST) Received: from localhost.localdomain ([2a01:e34:ed2f:f020:1f0f:c9b8:ee5c:5c2f]) by smtp.gmail.com with ESMTPSA id j16sm1465785wms.12.2021.12.18.05.00.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Dec 2021 05:00:36 -0800 (PST) From: Daniel Lezcano To: daniel.lezcano@linaro.org, rjw@rjwysocki.net Cc: lukasz.luba@arm.com, robh@kernel.org, heiko@sntech.de, arnd@linaro.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, ulf.hansson@linaro.org, Chanwoo Choi , Kyungmin Park , MyungJoo Ham , "Rafael J. Wysocki" , Daniel Lezcano Subject: [PATCH v5 4/6] powercap/drivers/dtpm: Add dtpm devfreq with energy model support Date: Sat, 18 Dec 2021 14:00:12 +0100 Message-Id: <20211218130014.4037640-5-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211218130014.4037640-1-daniel.lezcano@linaro.org> References: <20211218130014.4037640-1-daniel.lezcano@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Currently the dtpm supports the CPUs via cpufreq and the energy model. This change provides the same for the device which supports devfreq. Each device supporting devfreq and having an energy model can be added to the hierarchy. The concept is the same as the cpufreq DTPM support: the QoS is used to aggregate the requests and the energy model gives the value of the instantaneous power consumption ponderated by the load of the device. Cc: Chanwoo Choi Cc: Lukasz Luba Cc: Kyungmin Park Cc: MyungJoo Ham Signed-off-by: Daniel Lezcano --- drivers/powercap/Kconfig | 7 ++ drivers/powercap/Makefile | 1 + drivers/powercap/dtpm_devfreq.c | 201 ++++++++++++++++++++++++++++++++ 3 files changed, 209 insertions(+) create mode 100644 drivers/powercap/dtpm_devfreq.c diff --git a/drivers/powercap/Kconfig b/drivers/powercap/Kconfig index b1ca339957e3..515e3ceb3393 100644 --- a/drivers/powercap/Kconfig +++ b/drivers/powercap/Kconfig @@ -57,4 +57,11 @@ config DTPM_CPU help This enables support for CPU power limitation based on energy model. + +config DTPM_DEVFREQ + bool "Add device power capping based on the energy model" + depends on DTPM && ENERGY_MODEL + help + This enables support for device power limitation based on + energy model. endif diff --git a/drivers/powercap/Makefile b/drivers/powercap/Makefile index fabcf388a8d3..494617cdad88 100644 --- a/drivers/powercap/Makefile +++ b/drivers/powercap/Makefile @@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only obj-$(CONFIG_DTPM) += dtpm.o obj-$(CONFIG_DTPM_CPU) += dtpm_cpu.o +obj-$(CONFIG_DTPM_DEVFREQ) += dtpm_devfreq.o obj-$(CONFIG_POWERCAP) += powercap_sys.o obj-$(CONFIG_INTEL_RAPL_CORE) += intel_rapl_common.o obj-$(CONFIG_INTEL_RAPL) += intel_rapl_msr.o diff --git a/drivers/powercap/dtpm_devfreq.c b/drivers/powercap/dtpm_devfreq.c new file mode 100644 index 000000000000..fd3817f71f44 --- /dev/null +++ b/drivers/powercap/dtpm_devfreq.c @@ -0,0 +1,201 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright 2021 Linaro Limited + * + * Author: Daniel Lezcano + * + * The devfreq device combined with the energy model and the load can + * give an estimation of the power consumption as well as limiting the + * power. + * + */ +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +#include +#include +#include +#include +#include +#include +#include +#include + +struct dtpm_devfreq { + struct dtpm dtpm; + struct dev_pm_qos_request qos_req; + struct devfreq *devfreq; +}; + +static struct dtpm_devfreq *to_dtpm_devfreq(struct dtpm *dtpm) +{ + return container_of(dtpm, struct dtpm_devfreq, dtpm); +} + +static int update_pd_power_uw(struct dtpm *dtpm) +{ + struct dtpm_devfreq *dtpm_devfreq = to_dtpm_devfreq(dtpm); + struct devfreq *devfreq = dtpm_devfreq->devfreq; + struct device *dev = devfreq->dev.parent; + struct em_perf_domain *pd = em_pd_get(dev); + + dtpm->power_min = pd->table[0].power; + dtpm->power_min *= MICROWATT_PER_MILLIWATT; + + dtpm->power_max = pd->table[pd->nr_perf_states - 1].power; + dtpm->power_max *= MICROWATT_PER_MILLIWATT; + + return 0; +} + +static u64 set_pd_power_limit(struct dtpm *dtpm, u64 power_limit) +{ + struct dtpm_devfreq *dtpm_devfreq = to_dtpm_devfreq(dtpm); + struct devfreq *devfreq = dtpm_devfreq->devfreq; + struct device *dev = devfreq->dev.parent; + struct em_perf_domain *pd = em_pd_get(dev); + unsigned long freq; + u64 power; + int i; + + for (i = 0; i < pd->nr_perf_states; i++) { + + power = pd->table[i].power * MICROWATT_PER_MILLIWATT; + if (power > power_limit) + break; + } + + freq = pd->table[i - 1].frequency; + + dev_pm_qos_update_request(&dtpm_devfreq->qos_req, freq); + + power_limit = pd->table[i - 1].power * MICROWATT_PER_MILLIWATT; + + return power_limit; +} + +static void _normalize_load(struct devfreq_dev_status *status) +{ + if (status->total_time > 0xfffff) { + status->total_time >>= 10; + status->busy_time >>= 10; + } + + status->busy_time <<= 10; + status->busy_time /= status->total_time ? : 1; + + status->busy_time = status->busy_time ? : 1; + status->total_time = 1024; +} + +static u64 get_pd_power_uw(struct dtpm *dtpm) +{ + struct dtpm_devfreq *dtpm_devfreq = to_dtpm_devfreq(dtpm); + struct devfreq *devfreq = dtpm_devfreq->devfreq; + struct device *dev = devfreq->dev.parent; + struct em_perf_domain *pd = em_pd_get(dev); + struct devfreq_dev_status status; + unsigned long freq; + u64 power; + int i; + + mutex_lock(&devfreq->lock); + status = devfreq->last_status; + mutex_unlock(&devfreq->lock); + + freq = DIV_ROUND_UP(status.current_frequency, HZ_PER_KHZ); + _normalize_load(&status); + + for (i = 0; i < pd->nr_perf_states; i++) { + + if (pd->table[i].frequency < freq) + continue; + + power = pd->table[i].power * MICROWATT_PER_MILLIWATT; + power *= status.busy_time; + power >>= 10; + + return power; + } + + return 0; +} + +static void pd_release(struct dtpm *dtpm) +{ + struct dtpm_devfreq *dtpm_devfreq = to_dtpm_devfreq(dtpm); + + if (dev_pm_qos_request_active(&dtpm_devfreq->qos_req)) + dev_pm_qos_remove_request(&dtpm_devfreq->qos_req); + + kfree(dtpm_devfreq); +} + +static struct dtpm_ops dtpm_ops = { + .set_power_uw = set_pd_power_limit, + .get_power_uw = get_pd_power_uw, + .update_power_uw = update_pd_power_uw, + .release = pd_release, +}; + +static int __dtpm_devfreq_setup(struct devfreq *devfreq, struct dtpm *parent) +{ + struct device *dev = devfreq->dev.parent; + struct dtpm_devfreq *dtpm_devfreq; + struct em_perf_domain *pd; + int ret = -ENOMEM; + + pd = em_pd_get(dev); + if (!pd) { + ret = dev_pm_opp_of_register_em(dev, NULL); + if (ret) { + pr_err("No energy model available for '%s'\n", dev_name(dev)); + return -EINVAL; + } + } + + dtpm_devfreq = kzalloc(sizeof(*dtpm_devfreq), GFP_KERNEL); + if (!dtpm_devfreq) + return -ENOMEM; + + dtpm_init(&dtpm_devfreq->dtpm, &dtpm_ops); + + dtpm_devfreq->devfreq = devfreq; + + ret = dtpm_register(dev_name(dev), &dtpm_devfreq->dtpm, parent); + if (ret) { + pr_err("Failed to register '%s': %d\n", dev_name(dev), ret); + goto out_dtpm_devfreq; + } + + ret = dev_pm_qos_add_request(dev, &dtpm_devfreq->qos_req, + DEV_PM_QOS_MAX_FREQUENCY, + PM_QOS_MAX_FREQUENCY_DEFAULT_VALUE); + if (ret) { + pr_err("Failed to add QoS request: %d\n", ret); + goto out_dtpm_unregister; + } + + dtpm_update_power(&dtpm_devfreq->dtpm); + + return 0; + +out_dtpm_unregister: + dtpm_unregister(&dtpm_devfreq->dtpm); +out_dtpm_devfreq: + kfree(dtpm_devfreq); + + return ret; +} + +static int dtpm_devfreq_setup(struct dtpm *dtpm, struct device_node *np) +{ + struct devfreq *devfreq; + + devfreq = devfreq_get_devfreq_by_node(np); + if (IS_ERR(devfreq)) + return 0; + + return __dtpm_devfreq_setup(devfreq, dtpm); +} + +DTPM_DECLARE(dtpm_dev, NULL, dtpm_devfreq_setup); From patchwork Sat Dec 18 13:00:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 12686049 X-Patchwork-Delegate: daniel.lezcano@linaro.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 56AE3C433F5 for ; Sat, 18 Dec 2021 13:00:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233281AbhLRNAs (ORCPT ); Sat, 18 Dec 2021 08:00:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233254AbhLRNAm (ORCPT ); Sat, 18 Dec 2021 08:00:42 -0500 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F2E7C061746 for ; Sat, 18 Dec 2021 05:00:42 -0800 (PST) Received: by mail-wr1-x430.google.com with SMTP id j18so9416366wrd.2 for ; Sat, 18 Dec 2021 05:00:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bFrG3jh1s5lAFnowWpm51QcHRy95WOWLO0hOKfLwkAQ=; b=h4X0nR9C/gIczMARHZo3uC+j/8Z2sId88Si8wlDGqCUt4kajYq+3wPntNdZyiy0fIX 7S/+1HawPe87vjZtswRqbxXlQGZ6n9RT9cHanwSNaXlMvAq5G5qv7DZ+gFSeIV1ybF41 VO+B5kODFNDtJMvvOax7rQHaSZFN6lVhWrOCWLI2UziVBb58Y+2hHA0yGp0tnr7WzBWE fNZPzY/lErvwKC+k1qE+ofcX7MIgLo8PPG66kaNErZrfrFuaR2WeV4aOq1l5vAB5btb3 nTJgw2lAY55Jee6TEIeLOrWFc45Sd3yXJxxzf5cBYYOwWOFtbX+BT4IJ4nx7gRV+3DeZ rQ7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bFrG3jh1s5lAFnowWpm51QcHRy95WOWLO0hOKfLwkAQ=; b=eovW+0IPhhOKBDv6YQ9mQJfNRDdVYKMeY+mQdYoj7HuzskvLbR3hj0GxE8Z5jo83Z/ VEemSr1zVPAPA3c21mZuKEeUcUeaXyVA8SKFqcl9hegDzF7NgUZrwMUrNmC7hEhh1o5Z jtGLIXJL4VeOyra0v/nf8Uqj9HB+xCcCTazMf6BJqvpz8ibT0eAVZKcOGq05teZYnqX7 AZOmxtnD22tecbnALp8A0kzH+4lPFcYl6xiOlQQBJNYhzx2A6S4rDfaJWZx9aQBYyaI0 m9AWZQ3eHw54l7/2gzicWM7bi4FvxNvgMI+9SJtd+9ZK9t2GkkPJyTg84zUO+/qMsNWE 4wiA== X-Gm-Message-State: AOAM531s5qs7R+anB3eyvv5KcJ9NRnd61lfh0hjhdwvoFk4uOveyP0J9 e3I1VnC720Ul7oeMYLGhYQTj/Q== X-Google-Smtp-Source: ABdhPJwQJq2AfoqfQVqk3a7iBERI4zg3RIYnxZCE9RJKE8RaDu3lhZqX9mQXoSWx5OoqfDCBv9GgdQ== X-Received: by 2002:a05:6000:18ad:: with SMTP id b13mr6142117wri.195.1639832441000; Sat, 18 Dec 2021 05:00:41 -0800 (PST) Received: from localhost.localdomain ([2a01:e34:ed2f:f020:1f0f:c9b8:ee5c:5c2f]) by smtp.gmail.com with ESMTPSA id j16sm1465785wms.12.2021.12.18.05.00.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Dec 2021 05:00:40 -0800 (PST) From: Daniel Lezcano To: daniel.lezcano@linaro.org, rjw@rjwysocki.net Cc: lukasz.luba@arm.com, robh@kernel.org, heiko@sntech.de, arnd@linaro.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, ulf.hansson@linaro.org, Geert Uytterhoeven , linux-arm-kernel@lists.infradead.org (moderated list:ARM/Rockchip SoC support), linux-rockchip@lists.infradead.org (open list:ARM/Rockchip SoC support) Subject: [PATCH v5 5/6] rockchip/soc/drivers: Add DTPM description for rk3399 Date: Sat, 18 Dec 2021 14:00:13 +0100 Message-Id: <20211218130014.4037640-6-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211218130014.4037640-1-daniel.lezcano@linaro.org> References: <20211218130014.4037640-1-daniel.lezcano@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The DTPM framework does support now the hierarchy description. The platform specific code can call the hierarchy creation function with an array of struct dtpm_node pointing to their parent. This patch provides a description of the big and Little CPUs and the GPU and tie them together under a virtual package name. Only rk3399 is described now. The description could be extended in the future with the memory controller with devfreq if it has the energy information. The hierarchy uses the GPU devfreq with the panfrost driver, and this one could be loaded as a module. If the hierarchy is created before the panfrost driver is loaded, it will fail. For this reason the Kconfig option depends on the panfrost Kconfig's option. If this one is compiled as a module, automatically the dtpm hierarchy code will be a module also. Module loading ordering will fix this chicken-egg problem. Signed-off-by: Daniel Lezcano --- drivers/soc/rockchip/Kconfig | 8 +++++ drivers/soc/rockchip/Makefile | 1 + drivers/soc/rockchip/dtpm.c | 56 +++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 drivers/soc/rockchip/dtpm.c diff --git a/drivers/soc/rockchip/Kconfig b/drivers/soc/rockchip/Kconfig index 25eb2c1e31bb..a88fe6d3064a 100644 --- a/drivers/soc/rockchip/Kconfig +++ b/drivers/soc/rockchip/Kconfig @@ -34,4 +34,12 @@ config ROCKCHIP_PM_DOMAINS If unsure, say N. +config ROCKCHIP_DTPM + tristate "Rockchip DTPM hierarchy" + depends on DTPM && DRM_PANFROST + help + Describe the hierarchy for the Dynamic Thermal Power + Management tree on this platform. That will create all the + power capping capable devices. + endif diff --git a/drivers/soc/rockchip/Makefile b/drivers/soc/rockchip/Makefile index 875032f7344e..05f31a4e743c 100644 --- a/drivers/soc/rockchip/Makefile +++ b/drivers/soc/rockchip/Makefile @@ -5,3 +5,4 @@ obj-$(CONFIG_ROCKCHIP_GRF) += grf.o obj-$(CONFIG_ROCKCHIP_IODOMAIN) += io-domain.o obj-$(CONFIG_ROCKCHIP_PM_DOMAINS) += pm_domains.o +obj-$(CONFIG_ROCKCHIP_DTPM) += dtpm.o diff --git a/drivers/soc/rockchip/dtpm.c b/drivers/soc/rockchip/dtpm.c new file mode 100644 index 000000000000..77edc565c110 --- /dev/null +++ b/drivers/soc/rockchip/dtpm.c @@ -0,0 +1,56 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright 2021 Linaro Limited + * + * Author: Daniel Lezcano + * + * DTPM hierarchy description + */ +#include +#include +#include +#include + +static struct dtpm_node __initdata rk3399_hierarchy[] = { + [0]{ .name = "rk3399" }, + [1]{ .name = "package", + .parent = &rk3399_hierarchy[0] }, + [2]{ .name = "/cpus/cpu@0", + .type = DTPM_NODE_DT, + .parent = &rk3399_hierarchy[1] }, + [3]{ .name = "/cpus/cpu@1", + .type = DTPM_NODE_DT, + .parent = &rk3399_hierarchy[1] }, + [4]{ .name = "/cpus/cpu@2", + .type = DTPM_NODE_DT, + .parent = &rk3399_hierarchy[1] }, + [5]{ .name = "/cpus/cpu@3", + .type = DTPM_NODE_DT, + .parent = &rk3399_hierarchy[1] }, + [6]{ .name = "/cpus/cpu@100", + .type = DTPM_NODE_DT, + .parent = &rk3399_hierarchy[1] }, + [7]{ .name = "/cpus/cpu@101", + .type = DTPM_NODE_DT, + .parent = &rk3399_hierarchy[1] }, + [8]{ .name = "rockchip,rk3399-mali", + .type = DTPM_NODE_DT, + .parent = &rk3399_hierarchy[1] }, + [9]{ }, +}; + +static struct of_device_id __initdata rockchip_dtpm_match_table[] = { + { .compatible = "rockchip,rk3399", .data = rk3399_hierarchy }, + {}, +}; + +static int __init rockchip_dtpm_init(void) +{ + return dtpm_create_hierarchy(rockchip_dtpm_match_table); +} +late_initcall(rockchip_dtpm_init); + +MODULE_DESCRIPTION("Rockchip DTPM driver"); +MODULE_LICENSE("GPL"); +MODULE_ALIAS("platform:dtpm"); +MODULE_AUTHOR("Daniel Lezcano X-Patchwork-Id: 12686051 X-Patchwork-Delegate: daniel.lezcano@linaro.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 425A0C433FE for ; Sat, 18 Dec 2021 13:00:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233273AbhLRNAt (ORCPT ); Sat, 18 Dec 2021 08:00:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233268AbhLRNAr (ORCPT ); Sat, 18 Dec 2021 08:00:47 -0500 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 429ABC061751 for ; Sat, 18 Dec 2021 05:00:44 -0800 (PST) Received: by mail-wr1-x432.google.com with SMTP id r17so9028738wrc.3 for ; Sat, 18 Dec 2021 05:00:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=p5i8bAyKNCVvvWULTiQQCBvHxMUgvB2ssJ2ppV6n34w=; b=ydyFnsfD0j+C/gkrXEBeottbW99utAA/sHLtcRwhIV96kBnR+kfAxiD804powfEdk3 ESRlm07ZyRHgcy0GXsdDDVTyepYfgM4cCrHVqBhN18vLwSeyaZijRkkEOFLjsQQDDgDw O4315YNQUfUL6GBHqaQ15dOHXQfp11u/HitiBLwoBJJePbDScrP3vxTwX4NN4G/Y/2d2 q6tcBpa4zVIA7S8P1OBo6XEY6miO366xOg/sy15cmckMSzPPquYfS+dJL7srkMI/yfE5 0+KH7frWDAr1SY8W7TUeEIcewXYTz8ezpcU31B3rAA3LcMf3tIEevPZqrZv6nXNiEKFw f83w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=p5i8bAyKNCVvvWULTiQQCBvHxMUgvB2ssJ2ppV6n34w=; b=GYmasKEEs6SZrgXU80XdVgswYFnG7RXRW7I55lYxLzLNNIN7v6k3Pb0oCmGjRL9Mc9 e9D4zjx/Xv0x/lnLOJ1nc8vdeDmgDbmN5BTgw2WysWd7YJ5xbRC6JJoNgTCplvIimSaW +Wu6LRIrKSYUW9I8JItVbTf3C/LP9Stug5pxrOwiA5YSnIsHlmMNPFcW43qScrnMAaby ZVL5Bw6UvoPFokSW6poIUgC4+VLC3BO3O4CvcenTXS03bxftf5Ic0AWSa1Nt/DH2kMsc khu5ICrX5BFxM4ZnAdMm50WfhXTeg3USbLt6tZ3EKMedHjtE++3LYKKwQB96nitI278B QmgA== X-Gm-Message-State: AOAM533CvpjSKL3Wp+tQzLjm9lyRFNmF1EgFmtBP2HH3sZB7mruB95A/ aHSGUqgOAYc04msfIZQ750BZVg== X-Google-Smtp-Source: ABdhPJys+xI4SwBaTi9xDAxJhmT8aMjKzm6rvNQgmGmf6cpusjutiCLuPZdAGACX4Zk4RK0Me0NI6Q== X-Received: by 2002:a5d:42d2:: with SMTP id t18mr1281979wrr.271.1639832442739; Sat, 18 Dec 2021 05:00:42 -0800 (PST) Received: from localhost.localdomain ([2a01:e34:ed2f:f020:1f0f:c9b8:ee5c:5c2f]) by smtp.gmail.com with ESMTPSA id j16sm1465785wms.12.2021.12.18.05.00.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Dec 2021 05:00:42 -0800 (PST) From: Daniel Lezcano To: daniel.lezcano@linaro.org, rjw@rjwysocki.net Cc: lukasz.luba@arm.com, robh@kernel.org, heiko@sntech.de, arnd@linaro.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, ulf.hansson@linaro.org, Andy Gross , Bjorn Andersson , linux-arm-msm@vger.kernel.org (open list:ARM/QUALCOMM SUPPORT) Subject: [PATCH v5 6/6] qcom/soc/drivers: Add DTPM description for sdm845 Date: Sat, 18 Dec 2021 14:00:14 +0100 Message-Id: <20211218130014.4037640-7-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211218130014.4037640-1-daniel.lezcano@linaro.org> References: <20211218130014.4037640-1-daniel.lezcano@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The DTPM framework does support now the hierarchy description. The platform specific code can call the hierarchy creation function with an array of struct dtpm_node pointing to their parents. This patch provides a description of the big and Little CPUs and the GPU and tie them together under a virtual package name. Only sdm845 is described. The description could be extended in the future with the memory controller with devfreq if it has the energy information. Signed-off-by: Daniel Lezcano --- drivers/soc/qcom/Kconfig | 9 ++++++ drivers/soc/qcom/Makefile | 1 + drivers/soc/qcom/dtpm.c | 65 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 drivers/soc/qcom/dtpm.c diff --git a/drivers/soc/qcom/Kconfig b/drivers/soc/qcom/Kconfig index e718b8735444..f21c1df2f2f9 100644 --- a/drivers/soc/qcom/Kconfig +++ b/drivers/soc/qcom/Kconfig @@ -228,4 +228,13 @@ config QCOM_APR application processor and QDSP6. APR is used by audio driver to configure QDSP6 ASM, ADM and AFE modules. + +config QCOM_DTPM + tristate "Qualcomm DTPM hierarchy" + depends on DTPM + help + Describe the hierarchy for the Dynamic Thermal Power + Management tree on this platform. That will create all the + power capping capable devices. + endmenu diff --git a/drivers/soc/qcom/Makefile b/drivers/soc/qcom/Makefile index 70d5de69fd7b..cf38496c3f61 100644 --- a/drivers/soc/qcom/Makefile +++ b/drivers/soc/qcom/Makefile @@ -28,3 +28,4 @@ obj-$(CONFIG_QCOM_LLCC) += llcc-qcom.o obj-$(CONFIG_QCOM_RPMHPD) += rpmhpd.o obj-$(CONFIG_QCOM_RPMPD) += rpmpd.o obj-$(CONFIG_QCOM_KRYO_L2_ACCESSORS) += kryo-l2-accessors.o +obj-$(CONFIG_QCOM_DTPM) += dtpm.o diff --git a/drivers/soc/qcom/dtpm.c b/drivers/soc/qcom/dtpm.c new file mode 100644 index 000000000000..c15283f59494 --- /dev/null +++ b/drivers/soc/qcom/dtpm.c @@ -0,0 +1,65 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright 2021 Linaro Limited + * + * Author: Daniel Lezcano + * + * DTPM hierarchy description + */ +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +#include +#include +#include +#include + +static struct dtpm_node __initdata sdm845_hierarchy[] = { + [0]{ .name = "sdm845" }, + [1]{ .name = "package", + .parent = &sdm845_hierarchy[0] }, + [2]{ .name = "/cpus/cpu@0", + .type = DTPM_NODE_DT, + .parent = &sdm845_hierarchy[1] }, + [3]{ .name = "/cpus/cpu@100", + .type = DTPM_NODE_DT, + .parent = &sdm845_hierarchy[1] }, + [4]{ .name = "/cpus/cpu@200", + .type = DTPM_NODE_DT, + .parent = &sdm845_hierarchy[1] }, + [5]{ .name = "/cpus/cpu@300", + .type = DTPM_NODE_DT, + .parent = &sdm845_hierarchy[1] }, + [6]{ .name = "/cpus/cpu@400", + .type = DTPM_NODE_DT, + .parent = &sdm845_hierarchy[1] }, + [7]{ .name = "/cpus/cpu@500", + .type = DTPM_NODE_DT, + .parent = &sdm845_hierarchy[1] }, + [8]{ .name = "/cpus/cpu@600", + .type = DTPM_NODE_DT, + .parent = &sdm845_hierarchy[1] }, + [9]{ .name = "/cpus/cpu@700", + .type = DTPM_NODE_DT, + .parent = &sdm845_hierarchy[1] }, + [10]{ .name = "/soc@0/gpu@5000000", + .type = DTPM_NODE_DT, + .parent = &sdm845_hierarchy[1] }, + [11]{ }, +}; + +static struct of_device_id __initdata sdm845_dtpm_match_table[] = { + { .compatible = "qcom,sdm845", .data = sdm845_hierarchy }, + {}, +}; + +static int __init sdm845_dtpm_init(void) +{ + return dtpm_create_hierarchy(sdm845_dtpm_match_table); +} +late_initcall(sdm845_dtpm_init); + +MODULE_DESCRIPTION("Qualcomm DTPM driver"); +MODULE_LICENSE("GPL"); +MODULE_ALIAS("platform:dtpm"); +MODULE_AUTHOR("Daniel Lezcano