Skip to contentSkip to conversation

powercap: dtpm: Fix power limit distribution below the minimum power

PATCH New Mikhail Dmitrichenko 1 participant 1 message Dec 3

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 powercap: dtpm: Fix power limit distribution below the minimum power

DTPM represents the devices supporting the power limitation as a tree of nodes: the leaves are the devices themselves, like CPU performance domains or devfreq devices, and the intermediate nodes group their children.

When a power limit is set on an intermediate node, __set_power_limit_uw() distributes it among the children proportionally to their weights, which __dtpm_rebalance_weight() computes from the maximum power of the nodes only. So when the limit is close to the minimum power of the node, the share of a child having a high minimum power compared to its maximum power can be lower than its own minimum power.

For example, with a parent having two children, the first one with a power range of 80-1200 and the second one with a range of 400-3000, the parent's range is 480-4200. A limit of 500 gives a share of about 143 to the first child and 357 to the second one, below its minimum power of 400. As the second child can't go below its lowest performance state, the actual power of the children exceeds the parent's limit, while it could have been met by giving 400 to the second child and 100 to the first one.

Moreover, such a share is lower than the power of the lowest performance state of the child, so set_pd_power_limit() in the CPU and devfreq backends reads out of the bounds of the energy model table. This out-of-bounds access is addressed in the backends by [1], which is still needed, as the share can also be too low when the minimum power of a child is stale, e.g. right after a CPU of its performance domain is brought online.

The power limit of a node is never lower than the sum of the minimum power of its children, so a distribution where every child gets at least its minimum power always exists. When the share of a child is below its minimum power, give it its minimum power and take the difference from the siblings, proportionally to their headroom above their own minimum power. The distribution is unchanged when every share is at least the child's minimum power.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes a20d0ef97abf ("powercap/drivers/dtpm: Add API for dynamic thermal power management")

---

Changes in v2:
- Use mul_u64_u64_div_u64_roundup() when redistributing the deficit to avoid overflowing the intermediate product and the rounding addition, as pointed out by Sashiko.

Link to v1:
https://lore.kernel.org/all/[email protected]/

Sashiko review:
https://sashiko.dev/#/patchset/20261006151519.126065-1-mdmitrichenko%40astralinux.ru

 Documentation/power/powercap/dtpm.rst |  5 ++
 drivers/powercap/dtpm.c               | 68 +++++++++++++++++++++------
 2 files changed, 58 insertions(+), 15 deletions(-)
Documentation/power/powercap/dtpm.rst +5 -0
index a38dee3d815b9..997664da7ac75 100644
@@ -99,6 +99,11 @@ When a power limitation is applied to a node, then it is distributed along the c
    |
    `-- pd2 (w=486) --> power_limit = 1519mW
 
+As the weights are based on the maximum power only, the share of a node
+can be lower than its minimum power. In this case, the node gets its
+minimum power and the difference is taken from its siblings,
+proportionally to their headroom above their own minimum power.
+
 
 Flat description
 ----------------
drivers/powercap/dtpm.c +53 -15

85 lines not on this page · raw message

Signature · 1 line
2.43.0