Re: [PATCH] powernv: powercap: Add hard minimum powercap

From: Daniel Axtens
Date: Wed Feb 27 2019 - 23:45:06 EST


Shilpasri G Bhat <shilpa.bhat@xxxxxxxxxxxxxxxxxx> writes:

> In POWER9, OCC(On-Chip-Controller) provides for hard and soft system
> powercapping range. The hard powercap range is guaranteed while soft
> powercap may or may not be asserted due to various power-thermal
> reasons based on system configuration and workloads. This patch adds
> a sysfs file to export the hard minimum powercap limit to allow the
> user to set the appropriate powercap value that can be managed by the
> system.

Maybe it's common terminology and I'm just not aware of it, but what do
you mean by "asserted"? It doesn't appear elsewhere in the documentation
you're patching, and it's not a use of assert that I'm familiar with...

Regards,
Daniel

>
> Signed-off-by: Shilpasri G Bhat <shilpa.bhat@xxxxxxxxxxxxxxxxxx>
> ---
> .../ABI/testing/sysfs-firmware-opal-powercap | 10 ++++
> arch/powerpc/platforms/powernv/opal-powercap.c | 66 +++++++++-------------
> 2 files changed, 37 insertions(+), 39 deletions(-)
>
> diff --git a/Documentation/ABI/testing/sysfs-firmware-opal-powercap b/Documentation/ABI/testing/sysfs-firmware-opal-powercap
> index c9b66ec..65db4c1 100644
> --- a/Documentation/ABI/testing/sysfs-firmware-opal-powercap
> +++ b/Documentation/ABI/testing/sysfs-firmware-opal-powercap
> @@ -29,3 +29,13 @@ Description: System powercap directory and attributes applicable for
> creates a request for setting a new-powercap. The
> powercap requested must be between powercap-min
> and powercap-max.
> +
> +What: /sys/firmware/opal/powercap/system-powercap/powercap-hard-min
> +Date: Feb 2019
> +Contact: Linux for PowerPC mailing list <linuxppc-dev@xxxxxxxxxx>
> +Description: Hard minimum powercap
> +
> + This file provides the hard minimum powercap limit in
> + Watts. The powercap value above hard minimum is always
> + guaranteed to be asserted and the powercap value below
> + the hard minimum limit may or may not be guaranteed.
> diff --git a/arch/powerpc/platforms/powernv/opal-powercap.c b/arch/powerpc/platforms/powernv/opal-powercap.c
> index d90ee4f..38408e7 100644
> --- a/arch/powerpc/platforms/powernv/opal-powercap.c
> +++ b/arch/powerpc/platforms/powernv/opal-powercap.c
> @@ -139,10 +139,24 @@ static void powercap_add_attr(int handle, const char *name,
> attr->handle = handle;
> sysfs_attr_init(&attr->attr.attr);
> attr->attr.attr.name = name;
> - attr->attr.attr.mode = 0444;
> +
> + if (!strncmp(name, "powercap-current", strlen(name))) {
> + attr->attr.attr.mode = 0664;
> + attr->attr.store = powercap_store;
> + } else {
> + attr->attr.attr.mode = 0444;
> + }
> +
> attr->attr.show = powercap_show;
> }
>
> +static const char * const powercap_strs[] = {
> + "powercap-max",
> + "powercap-min",
> + "powercap-current",
> + "powercap-hard-min",
> +};
> +
> void __init opal_powercap_init(void)
> {
> struct device_node *powercap, *node;
> @@ -167,60 +181,34 @@ void __init opal_powercap_init(void)
>
> i = 0;
> for_each_child_of_node(powercap, node) {
> - u32 cur, min, max;
> - int j = 0;
> - bool has_cur = false, has_min = false, has_max = false;
> + u32 id;
> + int j, count = 0;
>
> - if (!of_property_read_u32(node, "powercap-min", &min)) {
> - j++;
> - has_min = true;
> - }
> -
> - if (!of_property_read_u32(node, "powercap-max", &max)) {
> - j++;
> - has_max = true;
> - }
> + for (j = 0; j < ARRAY_SIZE(powercap_strs); j++)
> + if (!of_property_read_u32(node, powercap_strs[j], &id))
> + count++;
>
> - if (!of_property_read_u32(node, "powercap-current", &cur)) {
> - j++;
> - has_cur = true;
> - }
> -
> - pcaps[i].pattrs = kcalloc(j, sizeof(struct powercap_attr),
> + pcaps[i].pattrs = kcalloc(count, sizeof(struct powercap_attr),
> GFP_KERNEL);
> if (!pcaps[i].pattrs)
> goto out_pcaps_pattrs;
>
> - pcaps[i].pg.attrs = kcalloc(j + 1, sizeof(struct attribute *),
> + pcaps[i].pg.attrs = kcalloc(count + 1,
> + sizeof(struct attribute *),
> GFP_KERNEL);
> if (!pcaps[i].pg.attrs) {
> kfree(pcaps[i].pattrs);
> goto out_pcaps_pattrs;
> }
>
> - j = 0;
> pcaps[i].pg.name = kasprintf(GFP_KERNEL, "%pOFn", node);
> - if (has_min) {
> - powercap_add_attr(min, "powercap-min",
> - &pcaps[i].pattrs[j]);
> - pcaps[i].pg.attrs[j] = &pcaps[i].pattrs[j].attr.attr;
> - j++;
> - }
> -
> - if (has_max) {
> - powercap_add_attr(max, "powercap-max",
> - &pcaps[i].pattrs[j]);
> - pcaps[i].pg.attrs[j] = &pcaps[i].pattrs[j].attr.attr;
> - j++;
> - }
> + for (j = 0; j < ARRAY_SIZE(powercap_strs); j++) {
> + if (of_property_read_u32(node, powercap_strs[j], &id))
> + continue;
>
> - if (has_cur) {
> - powercap_add_attr(cur, "powercap-current",
> + powercap_add_attr(id, powercap_strs[j],
> &pcaps[i].pattrs[j]);
> - pcaps[i].pattrs[j].attr.attr.mode |= 0220;
> - pcaps[i].pattrs[j].attr.store = powercap_store;
> pcaps[i].pg.attrs[j] = &pcaps[i].pattrs[j].attr.attr;
> - j++;
> }
>
> if (sysfs_create_group(powercap_kobj, &pcaps[i].pg)) {
> --
> 1.8.3.1