powercap/drivers/dtpm: Create the dtpm hierarchy
Subsystems (4)
v7 cover powercap/drivers/dtpm: Create the dtpm hierarchy
The DTPM hierarchy is the base to build on top of it a power budget allocator. It reflects the power consumption of the group of devices and allows to cap their power.
The core code is there but there is no way to describe the desired hierarchy yet.
A first proposal introduced the description through configfs [1] but was rejected [2].
A second proposal based on the device tree with a binding similar to the power domains [3] was proposed but finally rejected [4].
This version delegates the hierarchy creation to the SoC with a specific and self-encapsulated code using an array to describe the tree. The SoC DTPM driver defines an array of nodes pointing to their parents. The hierarchy description can integrate a DT node and in the future a SCMI node, that means the description can mix different type of nodes.
As the DTPM tree depends on different devices which could be modules, the SoC specific description must always be compiled as a module and describe the module softdeps in order to let the userspace to handle proper loading ordering.
In addition to the hierarchy creation, the devfreq dtpm support is also integrated into this series.
This series was tested on a rock960 (revision B - rk3399 based) and a db845c (Qualcomm sdm845 based).
[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/YGYg6ZeZ1181%[email protected]/
[3] https://lore.kernel.org/all/[email protected]/
[4] https://lore.kernel.org/all/[email protected]/
Changelog:
V7:
- Added a couple of comments if a node in the hierarchy fails to create
- Fixed a double free in dtpm_devfreq in the error path
V6:
- Switched the init table to a subsystem arrays
- Checked 'setup' function is set before calling it
- Moved out of the loop the 'of_node_put'
- Explicitely add DTPM_NODE_VIRTUAL in documentation
- Moved powercap_register_control_type() into the hierarchy creation function
- Removed the sdm845 description
- Made rk3399 always as a module and added module softdeps
V5:
- Remove DT bindings
- Added description with an array
- Added simple description for rk3399 and sdm845
- Moved dtpm table to the data section
V4:
- Added missing powerzone-cells
- Changed powerzone name to comply with the pattern property
V3:
- Remove GPU section as no power is available (yet)
- Remove '#powerzone-cells' conforming to the bindings change
- Removed required property 'compatible'
- Removed powerzone-cells from the topmost node
- Removed powerzone-cells from cpus 'consumers' in example
- Set additionnal property to false
V2:
- Added pattern properties and stick to powerzone-*
- Added required property compatible and powerzone-cells
- Added additionnal property
- Added compatible
- Renamed to 'powerzones'
- Added missing powerzone-cells to the topmost node
- Fixed errors reported by 'make DT_CHECKER_FLAGS=-m dt_binding_check'
- Move description in the SoC dtsi specific file
- Fixed missing prototype warning reported by lkp@
V1: Initial post
Daniel Lezcano (5):
powercap/drivers/dtpm: Convert the init table section to a simple
array
powercap/drivers/dtpm: Add hierarchy creation powercap/drivers/dtpm: Add CPU DT initialization support powercap/drivers/dtpm: Add dtpm devfreq with energy model support rockchip/soc/drivers: Add DTPM description for rk3399
drivers/powercap/Kconfig | 8 ++ drivers/powercap/Makefile | 1 + drivers/powercap/dtpm.c | 192 +++++++++++++++++++++++++++- drivers/powercap/dtpm_cpu.c | 41 ++++-- drivers/powercap/dtpm_devfreq.c | 203 ++++++++++++++++++++++++++++++ drivers/powercap/dtpm_subsys.h | 22 ++++ drivers/soc/rockchip/Kconfig | 8 ++ drivers/soc/rockchip/Makefile | 1 + drivers/soc/rockchip/dtpm.c | 59 +++++++++ include/asm-generic/vmlinux.lds.h | 11 -- include/linux/dtpm.h | 33 +++-- 11 files changed, 540 insertions(+), 39 deletions(-) create mode 100644 drivers/powercap/dtpm_devfreq.c create mode 100644 drivers/powercap/dtpm_subsys.h create mode 100644 drivers/soc/rockchip/dtpm.c
Signature · 1 line
2.25.1
PATCH v7 1/5 powercap/drivers/dtpm: Convert the init table section to a simple array
The init table section is freed after the system booted. However the next changes will make per module the DTPM description, so the table won't be accessible when the module is loaded.
In order to fix that, we should move the table to the data section where there are very few entries and that makes strange to add it there.
The main goal of the table was to keep self-encapsulated code and we can keep it almost as it by using an array instead.
--- drivers/powercap/dtpm.c | 2 ++ drivers/powercap/dtpm_cpu.c | 5 ++++- drivers/powercap/dtpm_subsys.h | 18 ++++++++++++++++++ include/asm-generic/vmlinux.lds.h | 11 ----------- include/linux/dtpm.h | 24 +++--------------------- 5 files changed, 27 insertions(+), 33 deletions(-) create mode 100644 drivers/powercap/dtpm_subsys.h
drivers/powercap/dtpm.c +2 -0
@@ -24,6 +24,8 @@#include <linux/slab.h> #include <linux/mutex.h> +#include "dtpm_subsys.h" +#define DTPM_POWER_LIMIT_FLAG 0static const char *constraint_name[] = {
drivers/powercap/dtpm_cpu.c +4 -1
@@ -269,4 +269,7 @@ static int __init dtpm_cpu_init(void)return 0 ; } -DTPM_DECLARE (dtpm_cpu, dtpm_cpu_init); +struct dtpm_subsys_ops dtpm_cpu_ops = { + .name =KBUILD_MODNAME , + .init = dtpm_cpu_init, +};
drivers/powercap/dtpm_subsys.h new file +18 -0
@@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Copyright (C) 2022 Linaro Ltd +* +* Author: Daniel Lezcano <[email protected]> +*/ +#ifndef ___DTPM_SUBSYS_H__ +#define ___DTPM_SUBSYS_H__ + +extern struct dtpm_subsys_ops dtpm_cpu_ops; + +struct dtpm_subsys_ops *dtpm_subsys[] = { +#ifdef CONFIG_DTPM_CPU + &dtpm_cpu_ops, +#endif +}; + +#endif
include/asm-generic/vmlinux.lds.h +0 -11
@@ -321,16 +321,6 @@#define THERMAL_TABLE (name)#endif -#ifdef CONFIG_DTPM -#define DTPM_TABLE () \ - . = ALIGN(8); \ - __dtpm_table = .; \ - KEEP(*(__dtpm_table)) \ - __dtpm_table_end = .; -#else -#define DTPM_TABLE () -#endif -#define KERNEL_DTB () \ STRUCT_ALIGN(); \ __dtb_start = .; \
@@ -723,7 +713,6 @@ ACPI_PROBE_TABLE(irqchip) \ ACPI_PROBE_TABLE(timer) \ THERMAL_TABLE(governor) \ - DTPM_TABLE() \ EARLYCON_TABLE() \ LSM_TABLE() \ EARLY_LSM_TABLE() \
include/linux/dtpm.h +3 -21
@@ -32,29 +32,11 @@ struct dtpm_ops {void (*release)(struct dtpm *); }; -typedef int (*dtpm_init_t )(void ); - -struct dtpm_descr { -dtpm_init_t init; +struct dtpm_subsys_ops { +const char *name; +int (*init)(void ); }; -/* Init section thermal table */ -extern struct dtpm_descr __dtpm_table[]; -extern struct dtpm_descr __dtpm_table_end[]; - -#define DTPM_TABLE_ENTRY (name, __init) \ - static struct dtpm_descr __dtpm_table_entry_##name \ - __used __section("__dtpm_table") = { \ - .init = __init, \ - } - -#define DTPM_DECLARE (name, init) DTPM_TABLE_ENTRY(name, init) - -#define for_each_dtpm_table (__dtpm) \ - for (__dtpm = __dtpm_table; \ - __dtpm < __dtpm_table_end; \ - __dtpm++) -static inline struct dtpm *to_dtpm (struct powercap_zone *zone) { return container_of(zone, struct dtpm, zone);
Signature · 1 line
2.25.1
PATCH v7 2/5 powercap/drivers/dtpm: Add hierarchy creation
In reply to Daniel LezcanoThe 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 subsys array 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.
--- drivers/powercap/Kconfig | 1 + drivers/powercap/dtpm.c | 190 ++++++++++++++++++++++++++++++++++++++- include/linux/dtpm.h | 15 ++++ 3 files changed, 203 insertions(+), 3 deletions(-)
drivers/powercap/Kconfig +1 -0
@@ -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.
drivers/powercap/dtpm.c +187 -3
207 lines not on this page · raw message
include/linux/dtpm.h +15 -0
@@ -32,9 +32,23 @@ struct dtpm_ops {void (*release)(struct dtpm *); }; +struct device_node ; +struct dtpm_subsys_ops {const char *name;int (*init)(void ); +int (*setup)(struct dtpm *,struct device_node *); +}; + +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; };static inline struct dtpm *to_dtpm (struct powercap_zone *zone)
@@ -52,4 +66,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
Signature · 1 line
2.25.1
Re: [PATCH v7 2/5] powercap/drivers/dtpm: Add hierarchy creation
Quoted 14 lines · Daniel Lezcano
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.
Quoted 7 lines
In order to ensure a nice self-encapsulation, the DTPM subsys array 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 <[email protected]>Reviewed-by Ulf Hansson <[email protected]>
Yes, this looks good to me now. Thanks for adopting my suggestions.
Kind regards
Uffe
Quoted 268 lines
--- drivers/powercap/Kconfig | 1 + drivers/powercap/dtpm.c | 190 ++++++++++++++++++++++++++++++++++++++- include/linux/dtpm.h | 15 ++++ 3 files changed, 203 insertions(+), 3 deletions(-)drivers/powercap/Kconfig +1
-0@@ -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.drivers/powercap/dtpm.c +187
-3@@ -23,6 +23,7 @@#include <linux/powercap.h> #include <linux/slab.h> #include <linux/mutex.h> +#include <linux/of.h> #include "dtpm_subsys.h" @@ -463,14 +464,197 @@ 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 device_node *np; +int i, 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 (i =0 ; i <ARRAY_SIZE (dtpm_subsys); i++) { + +if (!dtpm_subsys[i]->setup) +continue ; + + ret = dtpm_subsys[i]->setup (parent, np); +if (ret) { +pr_err ("Failed to setup '%s': %d\n" , dtpm_subsys[i]->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); + +/* +* A NULL pointer means there is no children, hence we +* continue without going deeper in the recursivity. +*/ +if (!dtpm) +continue ; + +/* +* There are multiple reasons why the callback could +* fail. The generic glue is abstracting the backend +* and therefore it is not possible to report back or +* take a decision based on the error. In any case, +* if this call fails, it is not critical in the +* hierarchy creation, we can assume the underlying +* service is not found, so we continue without this +* branch in the tree but with a warning to log the +* information the node was not created. +*/ +if (IS_ERR (dtpm)) { +pr_warn ("Failed to create '%s' in the hierarchy\n" , + hierarchy[i].name); +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", type = DTPM_NODE_VIRTUAL }, +* [1] { .name = "package", .type = DTPM_NODE_VIRTUAL, .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 device_node *np; +int i, ret; + +if (pct) +return -EBUSY ; + pct =powercap_register_control_type (NULL ,"dtpm" ,NULL );if (IS_ERR (pct)) {pr_err ("Failed to register control type\n" ); -return PTR_ERR (pct); + ret =PTR_ERR (pct); + goto out_pct; + } + + ret = -ENODEV ; + np =of_find_node_by_path ("/" ); +if (!np) + goto out_err; + + match =of_match_node (dtpm_match_table, np); + +of_node_put (np); + +if (!match) + goto out_err; + + hierarchy = match->data; +if (!hierarchy) { + ret = -EFAULT ; + goto out_err; + } + + ret =dtpm_for_each_child (hierarchy,NULL ,NULL ); +if (ret) + goto out_err; + +for (i =0 ; i <ARRAY_SIZE (dtpm_subsys); i++) { + +if (!dtpm_subsys[i]->init) +continue ; + + ret = dtpm_subsys[i]->init (); +if (ret) +pr_info ("Failed to initialze '%s': %d" , + dtpm_subsys[i]->name, ret); }return 0 ; + +out_err: +powercap_unregister_control_type (pct); +out_pct: + pct =NULL ; + +return ret; } -late_initcall (init_dtpm); +EXPORT_SYMBOL_GPL (dtpm_create_hierarchy);include/linux/dtpm.h +15
-1@@ -32,9 +32,23 @@ struct dtpm_ops {void (*release)(struct dtpm *); }; +struct device_node ; +struct dtpm_subsys_ops {const char *name;int (*init)(void ); +int (*setup)(struct dtpm *,struct device_node *); +}; + +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; };static inline struct dtpm *to_dtpm (struct powercap_zone *zone)@@ -52,4 +66,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 --2.25.1
Re: [PATCH v7 2/5] powercap/drivers/dtpm: Add hierarchy creation
Quoted 20 lines · Ulf Hansson
Quoted 19 lines · Daniel Lezcano
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 subsys array 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.
Quoted 4 lines
Quoted 2 lines
Signed-off-by Daniel Lezcano <[email protected]>Reviewed-by Ulf Hansson <[email protected]>Yes, this looks good to me now. Thanks for adopting my suggestions.
Thanks for your time to review the code
Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook | <http://twitter.com/#!/linaroorg> Twitter | <http://www.linaro.org/linaro-blog/> Blog
PATCH v7 3/5 powercap/drivers/dtpm: Add CPU DT initialization support
In reply to Daniel LezcanoBased 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.
--- drivers/powercap/dtpm_cpu.c | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-)
drivers/powercap/dtpm_cpu.c +30 -6
@@ -21,6 +21,7 @@#include <linux/cpuhotplug.h> #include <linux/dtpm.h> #include <linux/energy_model.h> +#include <linux/of.h> #include <linux/pm_qos.h> #include <linux/slab.h> #include <linux/units.h>
@@ -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;
@@ -272,4 +295,5 @@ static int __init dtpm_cpu_init(void)struct dtpm_subsys_ops dtpm_cpu_ops = { .name =KBUILD_MODNAME , .init = dtpm_cpu_init, + .setup = dtpm_cpu_setup, };
Signature · 1 line
2.25.1
PATCH v7 4/5 powercap/drivers/dtpm: Add dtpm devfreq with energy model support
In reply to Daniel LezcanoCurrently 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.
--- drivers/powercap/Kconfig | 7 ++ drivers/powercap/Makefile | 1 + drivers/powercap/dtpm_devfreq.c | 203 ++++++++++++++++++++++++++++++++ drivers/powercap/dtpm_subsys.h | 4 + 4 files changed, 215 insertions(+) create mode 100644 drivers/powercap/dtpm_devfreq.c
drivers/powercap/Kconfig +7 -0
@@ -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
drivers/powercap/Makefile +1 -0
@@ -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
drivers/powercap/dtpm_devfreq.c new file +203 -0
203 lines not on this page · raw message
drivers/powercap/dtpm_subsys.h +4 -0
@@ -8,11 +8,15 @@#define ___DTPM_SUBSYS_H__extern struct dtpm_subsys_ops dtpm_cpu_ops; +extern struct dtpm_subsys_ops dtpm_devfreq_ops;struct dtpm_subsys_ops *dtpm_subsys[] = { #ifdef CONFIG_DTPM_CPU &dtpm_cpu_ops, #endif +#ifdef CONFIG_DTPM_DEVFREQ + &dtpm_devfreq_ops, +#endif };#endif
Signature · 1 line
2.25.1
PATCH v7 5/5 rockchip/soc/drivers: Add DTPM description for rk3399
In reply to Daniel LezcanoThe 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 / 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.
The description is always a module and it describes the soft dependencies. The userspace has to load the softdeps module in the right order.
--- drivers/soc/rockchip/Kconfig | 8 +++++ drivers/soc/rockchip/Makefile | 1 + drivers/soc/rockchip/dtpm.c | 59 +++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 drivers/soc/rockchip/dtpm.c
drivers/soc/rockchip/Kconfig +8 -0
@@ -34,4 +34,12 @@ config ROCKCHIP_PM_DOMAINS If unsure, say N. +config ROCKCHIP_DTPM + tristate "Rockchip DTPM hierarchy" + depends on DTPM && DRM_PANFROST && m + help + Describe the hierarchy for the Dynamic Thermal Power + Management tree on this platform. That will create all the + power capping capable devices. + endif
drivers/soc/rockchip/Makefile +1 -0
@@ -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
drivers/soc/rockchip/dtpm.c new file +59 -0
59 lines not on this page · raw message
Signature · 1 line
2.25.1
Re: [PATCH v7 5/5] rockchip/soc/drivers: Add DTPM description for rk3399
Hi Heiko,
do you have comments on this patch?
Quoted 116 lines · Daniel Lezcano
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_nodepointing to their parent.This patch provides a description of the big / 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.
The description is always a module and it describes the soft dependencies. The userspace has to load the softdeps module in the right order.
Signed-off-by Daniel Lezcano <[email protected]>--- drivers/soc/rockchip/Kconfig | 8 +++++ drivers/soc/rockchip/Makefile | 1 + drivers/soc/rockchip/dtpm.c | 59 +++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 drivers/soc/rockchip/dtpm.cdrivers/soc/rockchip/Kconfig +8
-0@@ -34,4 +34,12 @@ config ROCKCHIP_PM_DOMAINS If unsure, say N. +config ROCKCHIP_DTPM + tristate "Rockchip DTPM hierarchy" + depends on DTPM && DRM_PANFROST && m + help + Describe the hierarchy for the Dynamic Thermal Power + Management tree on this platform. That will create all the + power capping capable devices. + endifdrivers/soc/rockchip/Makefile +1
-0@@ -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.odrivers/soc/rockchip/dtpm.c new file +59
-0@@ -0,0 +1,59 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright 2021 Linaro Limited +* +* Author: Daniel Lezcano <[email protected]> +* +* DTPM hierarchy description +*/ +#include <linux/dtpm.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/platform_device.h> + +static struct dtpm_node __initdata rk3399_hierarchy[] = { + [0]{ .name = "rk3399", + .type =DTPM_NODE_VIRTUAL }, + [1]{ .name = "package", + .type =DTPM_NODE_VIRTUAL , + .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 = "/gpu@ff9a0000", + .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); +} +module_init (rockchip_dtpm_init); + +MODULE_SOFTDEP ("pre: panfrost cpufreq-dt" ); +MODULE_DESCRIPTION ("Rockchip DTPM driver" ); +MODULE_LICENSE ("GPL" ); +MODULE_ALIAS ("platform:dtpm" ); +MODULE_AUTHOR ("Daniel Lezcano <[email protected]" );
Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook | <http://twitter.com/#!/linaroorg> Twitter | <http://www.linaro.org/linaro-blog/> Blog
Re: [PATCH v7 5/5] rockchip/soc/drivers: Add DTPM description for rk3399
In reply to Daniel LezcanoHi Daniel,
Quoted 9 lines · Daniel Lezcano
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_nodepointing to their parent.This patch provides a description of the big / Little CPUs and the GPU and tie them together under a virtual 'package' name. Only rk3399 is described now.
Quoted 8 lines
The description could be extended in the future with the memory controller with devfreq.
The description is always a module and it describes the soft dependencies. The userspace has to load the softdeps module in the right order.
Signed-off-by Daniel Lezcano <[email protected]>
Thanks for your patch!
Quoted 1 line
---
Can you please insert a changelog here, especially if you don't CC all parties on the cover letter?
Yes, I can get it from lore, but it's easier for the audience if it's included here.
Thanks!
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip
Re: [PATCH v7 5/5] rockchip/soc/drivers: Add DTPM description for rk3399
Quoted 20 lines · Geert Uytterhoeven
Hi Daniel,
Quoted 16 lines · Daniel Lezcano
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_nodepointing to their parent.This patch provides a description of the big / 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.
The description is always a module and it describes the soft dependencies. The userspace has to load the softdeps module in the right order.
Quoted 8 lines
Quoted 1 line
Signed-off-by Daniel Lezcano <[email protected]>Thanks for your patch!
Quoted 1 line
---
Can you please insert a changelog here, especially if you don't CC all parties on the cover letter?
Ah yes, will do in the future
Quoted 2 lines
Yes, I can get it from lore, but it's easier for the audience if it's included here.
Changelog:
V7:
- No changes
V6:
- Made rk3399 always as a module and added module softdeps
V5:
- Module creation
Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook | <http://twitter.com/#!/linaroorg> Twitter | <http://www.linaro.org/linaro-blog/> Blog
Heiko Stübner
maintainerRe: [PATCH v7 5/5] rockchip/soc/drivers: Add DTPM description for rk3399
In reply to Daniel LezcanoAm Dienstag, 25. Januar 2022, 18:18:09 CET schrieb Daniel Lezcano:
Quoted 60 lines
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_nodepointing to their parent.This patch provides a description of the big / 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.
The description is always a module and it describes the soft dependencies. The userspace has to load the softdeps module in the right order.
Signed-off-by Daniel Lezcano <[email protected]>--- drivers/soc/rockchip/Kconfig | 8 +++++ drivers/soc/rockchip/Makefile | 1 + drivers/soc/rockchip/dtpm.c | 59 +++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 drivers/soc/rockchip/dtpm.cdrivers/soc/rockchip/Kconfig +8
-0@@ -34,4 +34,12 @@ config ROCKCHIP_PM_DOMAINS If unsure, say N. +config ROCKCHIP_DTPM + tristate "Rockchip DTPM hierarchy" + depends on DTPM && DRM_PANFROST && m + help + Describe the hierarchy for the Dynamic Thermal Power + Management tree on this platform. That will create all the + power capping capable devices. + endifdrivers/soc/rockchip/Makefile +1
-0@@ -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.odrivers/soc/rockchip/dtpm.c new file +4
-0@@ -0,0 +1,59 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright 2021 Linaro Limited +*
drivers/soc/rockchip/dtpm.c line 14
Quoted 10 lines
drivers/soc/rockchip/dtpm.c new file +10
-0+* Author: Daniel Lezcano <[email protected]> +* +* DTPM hierarchy description +*/ +#include <linux/dtpm.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/platform_device.h> + +static struct dtpm_node __initdata rk3399_hierarchy[] = {
The driver is tristate so buildable as module but uses __initdata. As it depends on panfrost (which also can be a module) you probably want a "__initdata_or_module" here .
Quoted 17 lines
drivers/soc/rockchip/dtpm.c new file +17
-0+ [0]{ .name = "rk3399", + .type = DTPM_NODE_VIRTUAL }, + [1]{ .name = "package", + .type = DTPM_NODE_VIRTUAL, + .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] },
drivers/soc/rockchip/dtpm.c line 41
Quoted 10 lines
drivers/soc/rockchip/dtpm.c new file +10
-0+ [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 = "/gpu@ff9a0000", + .type = DTPM_NODE_DT, + .parent = &rk3399_hierarchy[1] }, + [9]{ },
hmm, do we want a "/* sentinel */" inside the empty last entry? I think that is pretty common to denote the "this one is the last entry" of a dynamic list ;-)
drivers/soc/rockchip/dtpm.c line 53
Quoted 12 lines
drivers/soc/rockchip/dtpm.c new file +12
-0+}; + +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); +} +module_init (rockchip_dtpm_init);
Just for my understanding what happens on driver unload?
Thanks
Heiko
Quoted 7 lines
drivers/soc/rockchip/dtpm.c new file +6
-0+ +MODULE_SOFTDEP ("pre: panfrost cpufreq-dt" ); +MODULE_DESCRIPTION ("Rockchip DTPM driver" ); +MODULE_LICENSE ("GPL" ); +MODULE_ALIAS ("platform:dtpm" ); +MODULE_AUTHOR ("Daniel Lezcano <[email protected]" );
Re: [PATCH v7 5/5] rockchip/soc/drivers: Add DTPM description for rk3399
Hi Heiko,
thanks for your comments
Quoted 18 lines · Heiko Stübner
Am Dienstag, 25. Januar 2022, 18:18:09 CET schrieb Daniel Lezcano:
Quoted 17 lines
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_nodepointing to their parent.This patch provides a description of the big / 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.
The description is always a module and it describes the soft dependencies. The userspace has to load the softdeps module in the right order.
Signed-off-by Daniel Lezcano <[email protected]>
[ ... ]
Quoted 5 lines
Quoted 1 line
+static struct
dtpm_node__initdatark3399_hierarchy[] = {The driver is tristate so buildable as module but uses
__initdata. As it depends on panfrost (which also can be a module) you probably want a "__initdata_or_module" here .
Well, actually the dependency is wrong.
It should be:
depends on DTPM && m
It will be compiled always as a module.
Referring to the Documentation/kernel-hacking/hacking.rst
"After boot, the kernel frees up a special section; functions marked with ``__init`` and data structures marked with ``__initdata`` are dropped after boot is complete: similarly modules discard this memory after initialization."
So after the module is loaded and the hierarchy is created, nothing will stay in memory (except the future module exit function)
Quoted 23 lines
Quoted 23 lines
drivers/soc/rockchip/dtpm.c new file +23
-0+ [0]{ .name = "rk3399", + .type = DTPM_NODE_VIRTUAL }, + [1]{ .name = "package", + .type = DTPM_NODE_VIRTUAL, + .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] },
Quoted 8 lines
drivers/soc/rockchip/dtpm.c line 41
Quoted 4 lines
drivers/soc/rockchip/dtpm.c new file +4
-0+ [8]{ .name = "/gpu@ff9a0000", + .type = DTPM_NODE_DT, + .parent = &rk3399_hierarchy[1] }, + [9]{ },hmm, do we want a "/* sentinel */" inside the empty last entry? I think that is pretty common to denote the "this one is the last entry" of a dynamic list ;-)
Sure
Quoted 6 lines
Quoted 6 lines
drivers/soc/rockchip/dtpm.c new file +6
-0+}; + +static struct of_device_id __initdata rockchip_dtpm_match_table[] = { + { .compatible ="rockchip,rk3399" , .data = rk3399_hierarchy }, + {}, +};
Quoted 8 lines
drivers/soc/rockchip/dtpm.c line 53
Quoted 6 lines
drivers/soc/rockchip/dtpm.c new file +6
-0+ +static int __init rockchip_dtpm_init (void ) +{ +return dtpm_create_hierarchy (rockchip_dtpm_match_table); +} +module_init (rockchip_dtpm_init);Just for my understanding what happens on driver unload?
ATM it is not possible to unload it.
A second series with the hierarchy destruction will follow once this series is merged. The module unloading will be added here.
Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook | <http://twitter.com/#!/linaroorg> Twitter | <http://www.linaro.org/linaro-blog/> Blog
Heiko Stübner
maintainerRe: [PATCH v7 5/5] rockchip/soc/drivers: Add DTPM description for rk3399
In reply to Daniel LezcanoAm Dienstag, 25. Januar 2022, 18:18:09 CET schrieb Daniel Lezcano:
Quoted 9 lines
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_nodepointing to their parent.This patch provides a description of the big / Little CPUs and the GPU and tie them together under a virtual 'package' name. Only rk3399 is described now.
Quoted 8 lines
The description could be extended in the future with the memory controller with devfreq.
The description is always a module and it describes the soft dependencies. The userspace has to load the softdeps module in the right order.
Signed-off-by Daniel Lezcano <[email protected]>
Reviewed-by; Heiko Stuebner <[email protected]>