@@ -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: March 2019
+Contact: Linux for PowerPC mailing list <linuxppc-dev@ozlabs.org>
+Description: Hard minimum powercap
+
+ This file provides the hard minimum powercap limit in Watts.
+ The powercap value above hard minimum limit is guaranteed to be
+ enforced by OCC and the powercap value below this limit may or
+ may not be guaranteed.
@@ -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)) {
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 enforced by OCC 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. Signed-off-by: Shilpasri G Bhat <shilpa.bhat@linux.vnet.ibm.com> --- Changes from V1: - s/asserted/enforced by OCC .../ABI/testing/sysfs-firmware-opal-powercap | 10 ++++ arch/powerpc/platforms/powernv/opal-powercap.c | 66 +++++++++------------- 2 files changed, 37 insertions(+), 39 deletions(-)