Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…o/linux

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
  • Loading branch information
rafaeljw committed Oct 21, 2021
2 parents 519d819 + 5d8cb8d commit 3b4bd49
Show file tree
Hide file tree
Showing 4 changed files with 173 additions and 161 deletions.
78 changes: 37 additions & 41 deletions drivers/powercap/dtpm.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,6 @@ static void __dtpm_sub_power(struct dtpm *dtpm)
parent->power_limit -= dtpm->power_limit;
parent = parent->parent;
}

__dtpm_rebalance_weight(root);
}

static void __dtpm_add_power(struct dtpm *dtpm)
Expand All @@ -130,45 +128,45 @@ static void __dtpm_add_power(struct dtpm *dtpm)
parent->power_limit += dtpm->power_limit;
parent = parent->parent;
}
}

static int __dtpm_update_power(struct dtpm *dtpm)
{
int ret;

__dtpm_sub_power(dtpm);

ret = dtpm->ops->update_power_uw(dtpm);
if (ret)
pr_err("Failed to update power for '%s': %d\n",
dtpm->zone.name, ret);

__dtpm_rebalance_weight(root);
if (!test_bit(DTPM_POWER_LIMIT_FLAG, &dtpm->flags))
dtpm->power_limit = dtpm->power_max;

__dtpm_add_power(dtpm);

if (root)
__dtpm_rebalance_weight(root);

return ret;
}

/**
* dtpm_update_power - Update the power on the dtpm
* @dtpm: a pointer to a dtpm structure to update
* @power_min: a u64 representing the new power_min value
* @power_max: a u64 representing the new power_max value
*
* Function to update the power values of the dtpm node specified in
* parameter. These new values will be propagated to the tree.
*
* Return: zero on success, -EINVAL if the values are inconsistent
*/
int dtpm_update_power(struct dtpm *dtpm, u64 power_min, u64 power_max)
int dtpm_update_power(struct dtpm *dtpm)
{
int ret = 0;
int ret;

mutex_lock(&dtpm_lock);

if (power_min == dtpm->power_min && power_max == dtpm->power_max)
goto unlock;

if (power_max < power_min) {
ret = -EINVAL;
goto unlock;
}

__dtpm_sub_power(dtpm);

dtpm->power_min = power_min;
dtpm->power_max = power_max;
if (!test_bit(DTPM_POWER_LIMIT_FLAG, &dtpm->flags))
dtpm->power_limit = power_max;

__dtpm_add_power(dtpm);

unlock:
ret = __dtpm_update_power(dtpm);
mutex_unlock(&dtpm_lock);

return ret;
Expand Down Expand Up @@ -359,24 +357,18 @@ static struct powercap_zone_ops zone_ops = {
};

/**
* dtpm_alloc - Allocate and initialize a dtpm struct
* @name: a string specifying the name of the node
*
* Return: a struct dtpm pointer, NULL in case of error
* dtpm_init - Allocate and initialize a dtpm struct
* @dtpm: The dtpm struct pointer to be initialized
* @ops: The dtpm device specific ops, NULL for a virtual node
*/
struct dtpm *dtpm_alloc(struct dtpm_ops *ops)
void dtpm_init(struct dtpm *dtpm, struct dtpm_ops *ops)
{
struct dtpm *dtpm;

dtpm = kzalloc(sizeof(*dtpm), GFP_KERNEL);
if (dtpm) {
INIT_LIST_HEAD(&dtpm->children);
INIT_LIST_HEAD(&dtpm->sibling);
dtpm->weight = 1024;
dtpm->ops = ops;
}

return dtpm;
}

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

if (dtpm->ops && !(dtpm->ops->set_power_uw &&
dtpm->ops->get_power_uw &&
dtpm->ops->update_power_uw &&
dtpm->ops->release))
return -EINVAL;

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

__dtpm_add_power(dtpm);
if (dtpm->ops && !dtpm->ops->update_power_uw(dtpm)) {
__dtpm_add_power(dtpm);
dtpm->power_limit = dtpm->power_max;
}

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

static int __init dtpm_init(void)
static int __init init_dtpm(void)
{
struct dtpm_descr **dtpm_descr;
struct dtpm_descr *dtpm_descr;

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

for_each_dtpm_table(dtpm_descr)
(*dtpm_descr)->init(*dtpm_descr);
dtpm_descr->init();

return 0;
}
late_initcall(dtpm_init);
late_initcall(init_dtpm);
Loading

0 comments on commit 3b4bd49

Please sign in to comment.