Skip to content

Commit 3b4bd49

Browse files
committed
Pull Dynamic Thermal Power Management (DTPM) framework changes for v5.16 from Daniel Lezcano: - Simplify and make the code more self-encapsulate by dealing with the dtpm structure only (Daniel Lezcano) - Fix power intialization (Daniel Lezcano) - Add the CPU load consideration when estimating the instaneous power consumption (Daniel Lezcano) * tag 'dtpm-v5.16' of https://git.linaro.org/people/daniel.lezcano/linux: powercap/drivers/dtpm: Fix power limit initialization powercap/drivers/dtpm: Scale the power with the load powercap/drivers/dtpm: Use container_of instead of a private data field powercap/drivers/dtpm: Simplify the dtpm table powercap/drivers/dtpm: Encapsulate even more the code
2 parents 519d819 + 5d8cb8d commit 3b4bd49

File tree

4 files changed

+173
-161
lines changed

4 files changed

+173
-161
lines changed

drivers/powercap/dtpm.c

Lines changed: 37 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,6 @@ static void __dtpm_sub_power(struct dtpm *dtpm)
116116
parent->power_limit -= dtpm->power_limit;
117117
parent = parent->parent;
118118
}
119-
120-
__dtpm_rebalance_weight(root);
121119
}
122120

123121
static void __dtpm_add_power(struct dtpm *dtpm)
@@ -130,45 +128,45 @@ static void __dtpm_add_power(struct dtpm *dtpm)
130128
parent->power_limit += dtpm->power_limit;
131129
parent = parent->parent;
132130
}
131+
}
132+
133+
static int __dtpm_update_power(struct dtpm *dtpm)
134+
{
135+
int ret;
136+
137+
__dtpm_sub_power(dtpm);
138+
139+
ret = dtpm->ops->update_power_uw(dtpm);
140+
if (ret)
141+
pr_err("Failed to update power for '%s': %d\n",
142+
dtpm->zone.name, ret);
133143

134-
__dtpm_rebalance_weight(root);
144+
if (!test_bit(DTPM_POWER_LIMIT_FLAG, &dtpm->flags))
145+
dtpm->power_limit = dtpm->power_max;
146+
147+
__dtpm_add_power(dtpm);
148+
149+
if (root)
150+
__dtpm_rebalance_weight(root);
151+
152+
return ret;
135153
}
136154

137155
/**
138156
* dtpm_update_power - Update the power on the dtpm
139157
* @dtpm: a pointer to a dtpm structure to update
140-
* @power_min: a u64 representing the new power_min value
141-
* @power_max: a u64 representing the new power_max value
142158
*
143159
* Function to update the power values of the dtpm node specified in
144160
* parameter. These new values will be propagated to the tree.
145161
*
146162
* Return: zero on success, -EINVAL if the values are inconsistent
147163
*/
148-
int dtpm_update_power(struct dtpm *dtpm, u64 power_min, u64 power_max)
164+
int dtpm_update_power(struct dtpm *dtpm)
149165
{
150-
int ret = 0;
166+
int ret;
151167

152168
mutex_lock(&dtpm_lock);
153-
154-
if (power_min == dtpm->power_min && power_max == dtpm->power_max)
155-
goto unlock;
156-
157-
if (power_max < power_min) {
158-
ret = -EINVAL;
159-
goto unlock;
160-
}
161-
162-
__dtpm_sub_power(dtpm);
163-
164-
dtpm->power_min = power_min;
165-
dtpm->power_max = power_max;
166-
if (!test_bit(DTPM_POWER_LIMIT_FLAG, &dtpm->flags))
167-
dtpm->power_limit = power_max;
168-
169-
__dtpm_add_power(dtpm);
170-
171-
unlock:
169+
ret = __dtpm_update_power(dtpm);
172170
mutex_unlock(&dtpm_lock);
173171

174172
return ret;
@@ -359,24 +357,18 @@ static struct powercap_zone_ops zone_ops = {
359357
};
360358

361359
/**
362-
* dtpm_alloc - Allocate and initialize a dtpm struct
363-
* @name: a string specifying the name of the node
364-
*
365-
* Return: a struct dtpm pointer, NULL in case of error
360+
* dtpm_init - Allocate and initialize a dtpm struct
361+
* @dtpm: The dtpm struct pointer to be initialized
362+
* @ops: The dtpm device specific ops, NULL for a virtual node
366363
*/
367-
struct dtpm *dtpm_alloc(struct dtpm_ops *ops)
364+
void dtpm_init(struct dtpm *dtpm, struct dtpm_ops *ops)
368365
{
369-
struct dtpm *dtpm;
370-
371-
dtpm = kzalloc(sizeof(*dtpm), GFP_KERNEL);
372366
if (dtpm) {
373367
INIT_LIST_HEAD(&dtpm->children);
374368
INIT_LIST_HEAD(&dtpm->sibling);
375369
dtpm->weight = 1024;
376370
dtpm->ops = ops;
377371
}
378-
379-
return dtpm;
380372
}
381373

382374
/**
@@ -436,6 +428,7 @@ int dtpm_register(const char *name, struct dtpm *dtpm, struct dtpm *parent)
436428

437429
if (dtpm->ops && !(dtpm->ops->set_power_uw &&
438430
dtpm->ops->get_power_uw &&
431+
dtpm->ops->update_power_uw &&
439432
dtpm->ops->release))
440433
return -EINVAL;
441434

@@ -455,7 +448,10 @@ int dtpm_register(const char *name, struct dtpm *dtpm, struct dtpm *parent)
455448
root = dtpm;
456449
}
457450

458-
__dtpm_add_power(dtpm);
451+
if (dtpm->ops && !dtpm->ops->update_power_uw(dtpm)) {
452+
__dtpm_add_power(dtpm);
453+
dtpm->power_limit = dtpm->power_max;
454+
}
459455

460456
pr_info("Registered dtpm node '%s' / %llu-%llu uW, \n",
461457
dtpm->zone.name, dtpm->power_min, dtpm->power_max);
@@ -465,9 +461,9 @@ int dtpm_register(const char *name, struct dtpm *dtpm, struct dtpm *parent)
465461
return 0;
466462
}
467463

468-
static int __init dtpm_init(void)
464+
static int __init init_dtpm(void)
469465
{
470-
struct dtpm_descr **dtpm_descr;
466+
struct dtpm_descr *dtpm_descr;
471467

472468
pct = powercap_register_control_type(NULL, "dtpm", NULL);
473469
if (IS_ERR(pct)) {
@@ -476,8 +472,8 @@ static int __init dtpm_init(void)
476472
}
477473

478474
for_each_dtpm_table(dtpm_descr)
479-
(*dtpm_descr)->init(*dtpm_descr);
475+
dtpm_descr->init();
480476

481477
return 0;
482478
}
483-
late_initcall(dtpm_init);
479+
late_initcall(init_dtpm);

0 commit comments

Comments
 (0)