powercap/dtpm: Add the DTPM framework
Subsystems (5)
v4 cover powercap/dtpm: Add the DTPM framework
The density of components greatly increased the last decade bringing a numerous number of heating sources which are monitored by more than 20 sensors on recent SoC. The skin temperature, which is the case temperature of the device, must stay below approximately 45°C in order to comply with the legal requirements.
The skin temperature is managed as a whole by an user space daemon, which is catching the current application profile, to allocate a power budget to the different components where the resulting heating effect will comply with the skin temperature constraint.
This technique is called the Dynamic Thermal Power Management.
The Linux kernel does not provide any unified interface to act on the power of the different devices. Currently, the thermal framework is changed to export artificially the performance states of different devices via the cooling device software component with opaque values. This change is done regardless of the in-kernel logic to mitigate the temperature. The user space daemon uses all the available knobs to act on the power limit and those differ from one platform to another.
This series provides a Dynamic Thermal Power Management framework to provide an unified way to act on the power of the devices.
Changelog:
V4:
- Changed fine grain spinlocks by global tree mutex lock
- Dropped tested by tag from Lukasz
- Fixed rollback routine in dtpm_cpu
- Checked freq_qos_request_active() when releasing the dtpm_cpu node
V3:
- Fixed power-limit computation in addition with the hotplugging
- Improved the encapsulation
- Added specific ops for the leaves of the tree
- Simplified API and self-encapsulation
- Fixed documentation and generated it to check the content
V2:
- Fixed indentation
- Fixed typos in comments
- Fixed missing kfree for dtpm_cpu
- Capitalize letters in the Kconfig description
- Reduced name description
- Stringified section name
- Added more debug traces in the code
- Removed duplicate initialization in the dtpm cpu
Daniel Lezcano (4):
units: Add Watt units
Documentation/powercap/dtpm: Add documentation for dtpm powercap/drivers/dtpm: Add API for dynamic thermal power management powercap/drivers/dtpm: Add CPU energy model based support
Documentation/power/index.rst | 1 + Documentation/power/powercap/dtpm.rst | 210 ++++++++++++ drivers/powercap/Kconfig | 13 + drivers/powercap/Makefile | 2 + drivers/powercap/dtpm.c | 470 ++++++++++++++++++++++++++ drivers/powercap/dtpm_cpu.c | 257 ++++++++++++++ include/asm-generic/vmlinux.lds.h | 11 + include/linux/cpuhotplug.h | 1 + include/linux/dtpm.h | 77 +++++ include/linux/units.h | 4 + 10 files changed, 1046 insertions(+) create mode 100644 Documentation/power/powercap/dtpm.rst create mode 100644 drivers/powercap/dtpm.c create mode 100644 drivers/powercap/dtpm_cpu.c create mode 100644 include/linux/dtpm.h
--
2.17.1
PATCH v4 1/4 units: Add Watt units
As there are the temperature units, let's add the Watt macros definition.
--- include/linux/units.h | 4 ++++ 1 file changed, 4 insertions(+)
include/linux/units.h +4 -0
@@ -4,6 +4,10 @@#include <linux/kernel.h> +#define MILLIWATT_PER_WATT 1000L +#define MICROWATT_PER_MILLIWATT 1000L +#define MICROWATT_PER_WATT 1000000L +#define ABSOLUTE_ZERO_MILLICELSIUS -273150static inline long milli_kelvin_to_millicelsius (long t)
--
2.17.1
PATCH v4 2/4 Documentation/powercap/dtpm: Add documentation for dtpm
In reply to Daniel LezcanoThe dynamic thermal and power management is a technique to dynamically adjust the power consumption of different devices in order to ensure a global thermal constraint.
An userspace daemon is usually monitoring the temperature and the power to take immediate action on the device.
The DTPM framework provides an unified API to userspace to act on the power.
Document this framework.
--- Documentation/power/index.rst | 1 + Documentation/power/powercap/dtpm.rst | 210 ++++++++++++++++++++++++++ 2 files changed, 211 insertions(+) create mode 100644 Documentation/power/powercap/dtpm.rst
Documentation/power/index.rst +1 -0
@@ -30,6 +30,7 @@ Power Management userland-swsusp powercap/powercap + powercap/dtpm regulator/consumer regulator/design
Documentation/power/powercap/dtpm.rst new file +210 -0
210 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [PATCH v4 2/4] Documentation/powercap/dtpm: Add documentation for dtpm
Hi Daniel,
Only small issues found. The output build looks OK. The content LGTM.
Documentation/power/powercap/dtpm.rst
Quoted 42 lines · Daniel Lezcano
The dynamic thermal and power management is a technique to dynamically adjust the power consumption of different devices in order to ensure a global thermal constraint.
An userspace daemon is usually monitoring the temperature and the power to take immediate action on the device.
The DTPM framework provides an unified API to userspace to act on the power.
Document this framework.
Cc Thara Gopinath <[email protected]>Cc Lina Iyer <[email protected]>Cc Ram Chandrasekar <[email protected]>Cc Zhang Rui <[email protected]>Cc Jonathan Corbet <[email protected]>Signed-off-by Daniel Lezcano <[email protected]>--- Documentation/power/index.rst | 1 + Documentation/power/powercap/dtpm.rst | 210 ++++++++++++++++++++++++++ 2 files changed, 211 insertions(+)create mode 100644
Documentation/power/powercap/dtpm.rstDocumentation/power/index.rst +1
-0@@ -30,6 +30,7 @@ Power Management userland-swsusp powercap/powercap + powercap/dtpm regulator/consumer regulator/designDocumentation/power/powercap/dtpm.rst new file +0
-0@@ -0,0 +1,210 @@
Probably missing SPDX?
.. SPDX-License-Identifier: GPL-2.0-only
Quoted 6 lines
Documentation/power/powercap/dtpm.rst new file +6
-0+========================================== +Dynamic Thermal Power Management framework +========================================== + +On the embedded world, the complexity of the SoC leads to an +increasing number of hotspots which need to be monitored and mitigated
Documentation/power/powercap/dtpm.rst line 16
Quoted 10 lines
Documentation/power/powercap/dtpm.rst new file +10
-0+as a whole in order to prevent the temperature to go above the +normative and legally stated 'skin temperature'. + +Another aspect is to sustain the performance for a given power budget, +for example virtual reality where the user can feel dizziness if the +performance is capped while a big CPU is processing something else. Or +reduce the battery charging because the dissipated power is too high +compared with the power consumed by other devices. + +The userspace is the most adequate place to dynamically act on the
I have compared with PowerCap description and they use 'user space'. I am not an expert in grammar, but maybe DTPM should also use it.
Quoted 60 lines
Documentation/power/powercap/dtpm.rst new file +60
-0+different devices by limiting their power given an application +profile: it has the knowledge of the platform. + +The Dynamic Thermal Power Management (DTPM) is a technique acting on +the device power by limiting and/or balancing a power budget among +different devices. + +The DTPM framework provides an unified interface to act on the +device power. + +Overview +======== + +The DTPM framework relies on the powercap framework to create the +powercap entries in the sysfs directory and implement the backend +driver to do the connection with the power manageable device. + +The DTPM is a tree representation describing the power constraints +shared between devices, not their physical positions. + +The nodes of the tree are a virtual description aggregating the power +characteristics of the children nodes and their power limitations. + +The leaves of the tree are the real power manageable devices. + +For instance:: + + SoC + | + `-- pkg + | + |-- pd0 (cpu0-3) + | + `-- pd1 (cpu4-5) + +The pkg power will be the sum of pd0 and pd1 power numbers:: + + SoC (400mW - 3100mW) + | + `-- pkg (400mW - 3100mW) + | + |-- pd0 (100mW - 700mW) + | + `-- pd1 (300mW - 2400mW) + +When the nodes are inserted in the tree, their power characteristics are propagated to the parents:: + + SoC (600mW - 5900mW) + | + |-- pkg (400mW - 3100mW) + | | + | |-- pd0 (100mW - 700mW) + | | + | `-- pd1 (300mW - 2400mW) + | + `-- pd2 (200mW - 2800mW) + +Each node have a weight on a 2^10 basis reflecting the percentage of power consumption along the siblings:: + + SoC (w=1024)
Documentation/power/powercap/dtpm.rst line 86
Quoted 10 lines
Documentation/power/powercap/dtpm.rst new file +10
-0+ | + |-- pkg (w=538) + | | + | |-- pd0 (w=231) + | | + | `-- pd1 (w=794) + | + `-- pd2 (w=486) + + Note the sum of weights at the same level are equal to 1024.
This sentence landed inside the rectangle with the tree above. Just pointing out, because I don't know if it was by design or not.
Quoted 38 lines
Documentation/power/powercap/dtpm.rst new file +38
-0+ +When a power limitation is applied to a node, then it is distributed along the children given their weights. For example, if we set a power limitation of 3200mW at the 'SoC' root node, the resulting tree will be:: + + SoC (w=1024) <--- power_limit = 3200mW + | + |-- pkg (w=538) --> power_limit = 1681mW + | | + | |-- pd0 (w=231) --> power_limit = 378mW + | | + | `-- pd1 (w=794) --> power_limit = 1303mW + | + `-- pd2 (w=486) --> power_limit = 1519mW + + +Flat description +---------------- + +A root node is created and it is the parent of all the nodes. This +description is the simplest one and it is supposed to give to +userspace a flat representation of all the devices supporting the +power limitation without any power limitation distribution. + +Hierarchical description +------------------------ + +The different devices supporting the power limitation are represented +hierarchically. There is one root node, all intermediate nodes are +grouping the child nodes which can be intermediate nodes also or real +devices. + +The intermediate nodes aggregate the power information and allows to +set the power limit given the weight of the nodes. + +Userspace API +============= + +As stated in the overview, the DTPM framework is built on top of the +powercap framework. Thus the sysfs interface is the same, please refer
Documentation/power/powercap/dtpm.rst line 134
Quoted 10 lines
Documentation/power/powercap/dtpm.rst new file +10
-0+to the powercap documentation for further details. + + * power_uw: Instantaneous power consumption. If the node is an + intermediate node, then the power consumption will be the sum of all + children power consumption. + + * max_power_range_uw: The power range resulting of the maximum power + minus the minimum power. + + * name: The name of the node. This is implementation dependant. Even
s/dependant/dependent/
Quoted 20 lines
Documentation/power/powercap/dtpm.rst new file +20
-0+ if it is not recommended for the userspace, several nodes can have + the same name. + + * constraint_X_name: The name of the constraint. + + * constraint_X_max_power_uw: The maximum power limit to be applicable + to the node. + + * constraint_X_power_limit_uw: The power limit to be applied to the + node. If the value contained in constraint_X_max_power_uw is set, + the constraint will be removed. + + * constraint_X_time_window_us: The meaning of this file will depend + on the constraint number. + +Constraints +----------- + + * Constraint 0: The power limitation is immediately applied, without + limitation in time.
Documentation/power/powercap/dtpm.rst line 164
Quoted 10 lines
Documentation/power/powercap/dtpm.rst new file +10
-0+ +Kernel API +========== + +Overview +-------- + +The DTPM framework has no power limiting backend support. It is +generic and provides a set of API to let the different drivers to +implement the backend part for the power limitation and create a the
s/a the/the/
Quoted 37 lines
Documentation/power/powercap/dtpm.rst new file +36
-0+power constraints tree. + +It is up to the platform to provide the initialization function to +allocate and link the different nodes of the tree. + +A special macro has the role of declaring a node and the corresponding +initialization function via a description structure. This one contains +an optional parent field allowing to hook different devices to an +already existing tree at boot time. + +For instance:: + + struct dtpm_descr my_descr = { + .name = "my_name", + .init = my_init_func, + }; + + DTPM_DECLARE(my_descr); + +The nodes of the DTPM tree are described with dtpm structure. The +steps to add a new power limitable device is done in three steps: + + * Allocate the dtpm node + * Set the power number of the dtpm node + * Register the dtpm node + +The registration of the dtpm node is done with the powercap +ops. Basically, it must implements the callbacks to get and set the +power and the limit. + +Alternatively, if the node to be inserted is an intermediate one, then +a simple function to insert it as a future parent is available. + +If a device has its power characteristics changing, then the tree must +be updated with the new power numbers and weights. +
Documentation/power/powercap/dtpm.rst line 210
Quoted 10 lines
Documentation/power/powercap/dtpm.rst new file +10
-0+Nomenclature +------------ + + * dtpm_alloc() : Allocate and initialize a dtpm structure + + * dtpm_register() : Add the dtpm node to the tree + + * dtpm_unregister() : Remove the dtpm node from the tree + + * dtpm_update_power() : Update the power characteristics of the dtpm node
When you fix these small issues, feel free to add:
Regards,
Lukasz
PATCH v4 3/4 powercap/drivers/dtpm: Add API for dynamic thermal power management
In reply to Daniel LezcanoOn the embedded world, the complexity of the SoC leads to an increasing number of hotspots which need to be monitored and mitigated as a whole in order to prevent the temperature to go above the normative and legally stated 'skin temperature'.
Another aspect is to sustain the performance for a given power budget, for example virtual reality where the user can feel dizziness if the GPU performance is capped while a big CPU is processing something else. Or reduce the battery charging because the dissipated power is too high compared with the power consumed by other devices.
The userspace is the most adequate place to dynamically act on the different devices by limiting their power given an application
profile: it has the knowledge of the platform.
These userspace daemons are in charge of the Dynamic Thermal Power Management (DTPM).
Nowadays, the dtpm daemons are abusing the thermal framework as they act on the cooling device state to force a specific and arbitrary state without taking care of the governor decisions. Given the closed loop of some governors that can confuse the logic or directly enter in a decision conflict.
As the number of cooling device support is limited today to the CPU and the GPU, the dtpm daemons have little control on the power dissipation of the system. The out of tree solutions are hacking around here and there in the drivers, in the frameworks to have control on the devices. The common solution is to declare them as cooling devices.
There is no unification of the power limitation unit, opaque states are used.
This patch provides a way to create a hierarchy of constraints using the powercap framework. The devices which are registered as power limit-able devices are represented in this hierarchy as a tree. They are linked together with intermediate nodes which are just there to propagate the constraint to the children.
The leaves of the tree are the real devices, the intermediate nodes are virtual, aggregating the children constraints and power characteristics.
Each node have a weight on a 2^10 basis, in order to reflect the percentage of power distribution of the children's node. This percentage is used to dispatch the power limit to the children.
The weight is computed against the max power of the siblings.
This simple approach allows to do a fair distribution of the power limit.
--- drivers/powercap/Kconfig | 6 + drivers/powercap/Makefile | 1 + drivers/powercap/dtpm.c | 470 ++++++++++++++++++++++++++++++ include/asm-generic/vmlinux.lds.h | 11 + include/linux/dtpm.h | 75 +++++ 5 files changed, 563 insertions(+) create mode 100644 drivers/powercap/dtpm.c create mode 100644 include/linux/dtpm.h
drivers/powercap/Kconfig +6 -0
@@ -43,4 +43,10 @@ config IDLE_INJECT CPUs for power capping. Idle period can be injected synchronously on a set of specified CPUs or alternatively on a per CPU basis. + +config DTPM + bool "Power capping for Dynamic Thermal Power Management" + help + This enables support for the power capping for the dynamic + thermal power management userspace engine. endif
drivers/powercap/Makefile +1 -0
@@ -1,4 +1,5 @@ # SPDX-License-Identifier: GPL-2.0-only +obj-$(CONFIG_DTPM) += dtpm.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.c new file +470 -0
470 lines not on this page · raw message
include/asm-generic/vmlinux.lds.h +11 -0
@@ -316,6 +316,16 @@#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 = .; \
@@ -733,6 +743,7 @@ ACPI_PROBE_TABLE(irqchip) \ ACPI_PROBE_TABLE(timer) \ THERMAL_TABLE(governor) \ + DTPM_TABLE() \ EARLYCON_TABLE() \ LSM_TABLE() \ EARLY_LSM_TABLE() \
include/linux/dtpm.h new file +75 -0
75 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [PATCH v4 3/4] powercap/drivers/dtpm: Add API for dynamic thermal power management
Hi Daniel,
I realized small issue when I went through this new mutex code (which is safer IMHO).
On 12/1/20 7:28 PM, Daniel Lezcano wrote:
[snip]
Quoted 6 lines
drivers/powercap/dtpm.c new file +6
-0+int dtpm_register (const char *name,struct dtpm *dtpm,struct dtpm *parent) +{ +struct powercap_zone *pcz; + +if (!pct) +return -EAGAIN ;
drivers/powercap/dtpm.c line 423
Quoted 10 lines
drivers/powercap/dtpm.c new file +10
-0+ +if (root && !parent) +return -EBUSY ; + +if (!root && parent) +return -EINVAL ; + +if (parent && parent->ops) +return -EINVAL ; +
Maybe it worth to add a check of dtpm pointer here, just to play safe?
if (!dtpm) return -EINVAL;
The dtpm->ops might explode when we don't capture this miss-usage during reviews of future drivers/shim layers. What do you think?
drivers/powercap/dtpm.c line 428
Quoted 5 lines
drivers/powercap/dtpm.c new file +5
-0+if (dtpm->ops && !(dtpm->ops->set_power_uw && + dtpm->ops->get_power_uw && + dtpm->ops->release)) +return -EINVAL ; +
I am going to stress test the whole series with hotplug today and add review for patch 4/4.
Regards,
Lukasz
Lukasz Luba
Tested-byRe: [PATCH v4 3/4] powercap/drivers/dtpm: Add API for dynamic thermal power management
Quoted 36 lines · Lukasz Luba
Hi Daniel,
I realized small issue when I went through this new mutex code (which is safer IMHO).
On 12/1/20 7:28 PM, Daniel Lezcano wrote:
[snip]
Quoted 7 lines
+int
dtpm_register(const char *name, struct dtpm *dtpm, struct dtpm *parent)drivers/powercap/dtpm.c new file +5
-0+{ + struct powercap_zone *pcz; + + if (!pct) + return -EAGAIN;drivers/powercap/dtpm.c line 423
Quoted 10 lines
drivers/powercap/dtpm.c new file +10
-0+ + if (root && !parent) + return -EBUSY; + + if (!root && parent) + return -EINVAL; + + if (parent && parent->ops) + return -EINVAL; +Maybe it worth to add a check of dtpm pointer here, just to play safe?
if (!dtpm)
return-EINVAL;The
dtpm->opsmight explode when we don't capture this miss-usage during reviews of futuredrivers/shimlayers. What do you think?
Quoted 9 lines
Quoted 5 lines
+ if (
dtpm->ops&& !(dtpm->ops->set_power_uw && +dtpm->ops->get_power_uw&& +dtpm->ops->release))
+ return-EINVAL;
+I am going to stress test the whole series with hotplug today and add review for patch 4/4.
I have tested with a hotplug stress and looks OK with the mutex. You can add again the tag:
Regards,
Lukasz
PATCH v4 4/4 powercap/drivers/dtpm: Add CPU energy model based support
In reply to Daniel LezcanoWith the powercap dtpm controller, we are able to plug devices with power limitation features in the tree.
The following patch introduces the CPU power limitation based on the energy model and the performance states.
The power limitation is done at the performance domain level. If some CPUs are unplugged, the corresponding power will be subtracted from the performance domain total power.
It is up to the platform to initialize the dtpm tree and add the CPU.
Here is an example to create a simple tree with one root node called "pkg" and the CPU's performance domains.
static int dtpm_register_pkg(struct dtpm_descr *descr)
{
struct dtpm *pkg;
int ret;
pkg = dtpm_alloc(NULL);
if (!pkg)
return -ENOMEM;
ret = dtpm_register(descr->name, pkg, descr->parent);
if (ret)
return ret;
return dtpm_register_cpu(pkg);
}static struct dtpm_descr descr = {
.name = "pkg",
.init = dtpm_register_pkg,
};DTPM_DECLARE(descr);
--- drivers/powercap/Kconfig | 7 + drivers/powercap/Makefile | 1 + drivers/powercap/dtpm_cpu.c | 257 ++++++++++++++++++++++++++++++++++++ include/linux/cpuhotplug.h | 1 + include/linux/dtpm.h | 2 + 5 files changed, 268 insertions(+) create mode 100644 drivers/powercap/dtpm_cpu.c
drivers/powercap/Kconfig +7 -0
@@ -49,4 +49,11 @@ config DTPM help This enables support for the power capping for the dynamic thermal power management userspace engine. + +config DTPM_CPU + bool "Add CPU power capping based on the energy model" + depends on DTPM && ENERGY_MODEL + help + This enables support for CPU power limitation based on + energy model. endif
drivers/powercap/Makefile +1 -0
@@ -1,5 +1,6 @@ # SPDX-License-Identifier: GPL-2.0-only obj-$(CONFIG_DTPM) += dtpm.o +obj-$(CONFIG_DTPM_CPU) += dtpm_cpu.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_cpu.c new file +257 -0
257 lines not on this page · raw message
include/linux/cpuhotplug.h +1 -0
@@ -192,6 +192,7 @@ enum cpuhp_state {CPUHP_AP_ONLINE_DYN_END =CPUHP_AP_ONLINE_DYN +30 ,CPUHP_AP_X86_HPET_ONLINE ,CPUHP_AP_X86_KVM_CLK_ONLINE , +CPUHP_AP_DTPM_CPU_ONLINE ,CPUHP_AP_ACTIVE , CPUHP_ONLINE, };
include/linux/dtpm.h +2 -0
@@ -72,4 +72,6 @@ void dtpm_unregister(struct dtpm *dtpm);int dtpm_register (const char *name,struct dtpm *dtpm,struct dtpm *parent); +int dtpm_register_cpu (struct dtpm *parent); +#endif
Signature · 1 line
2.17.1
Re: [PATCH v4 4/4] powercap/drivers/dtpm: Add CPU energy model based support
Quoted 35 lines · Daniel Lezcano
With the powercap dtpm controller, we are able to plug devices with power limitation features in the tree.
The following patch introduces the CPU power limitation based on the energy model and the performance states.
The power limitation is done at the performance domain level. If some CPUs are unplugged, the corresponding power will be subtracted from the performance domain total power.
It is up to the platform to initialize the dtpm tree and add the CPU.
Here is an example to create a simple tree with one root node called "pkg" and the CPU's performance domains.
static int
dtpm_register_pkg(struct dtpm_descr *descr){ struct dtpm *pkg; int ret; pkg = dtpm_alloc(NULL); if (!pkg) return -ENOMEM; ret = dtpm_register(descr->name, pkg, descr->parent); if (ret) return ret; return dtpm_register_cpu(pkg); }static struct dtpm_descr descr = { .name = "pkg", .init = dtpm_register_pkg, };
Quoted 7 lines
DTPM_DECLARE(descr);Cc Thara Gopinath <[email protected]>Cc Lina Iyer <[email protected]>Cc Ram Chandrasekar <[email protected]>Cc Zhang Rui <[email protected]>Signed-off-by Daniel Lezcano <[email protected]>
LGTM
Regards,
Lukasz