[PATCH 1/3] powercap, intel_rapl, implement get_max_time_window
The MSR_PKG_POWER_INFO register (Intel ASDM, section 14.9.3 "Package RAPL Domain") provides a maximum time window which the system can support. This window is read-only and is currently not examined when setting the time windows for the package. This patch implements get_max_time_window_us() and checks the window when a user attempts to set power capping for the package. Before the patch it was possible to set the window to, for example, 1 micro seconds: [root@intel-chiefriver-03 rhel7]# echo 1 > /sys/devices/virtual/powercap/intel-rapl/intel-rapl\:0/constraint_0_time_window_us; egrep ^ /sys/devices/virtual/powercap/intel-rapl/intel-rapl\:0/constraint_0_time_window_us /sys/devices/virtual/powercap/intel-rapl/intel-rapl:0/constraint_0_time_window_us:1:9765 but from 'turbostat -d', the package is limited to 976us: cpu0: MSR_PKG_POWER_INFO: 0x01200168 (45 W TDP, RAPL 36 - 0 W, 0.000977 sec.) (Note, there appears to be a rounding issue in turbostat which needs to also be fixed. Looking at the values in the register it is clear the value is 1/1024 = 976us.) After the patch we are limited by the maximum time window: [root@intel-chiefriver-03 rhel7]# echo 1 > /sys/devices/virtual/powercap/intel-rapl/intel-rapl\:0/constraint_0_time_window_us; egrep ^ /sys/devices/virtual/powercap/intel-rapl/intel-rapl\:0/constraint_0_time_window_us -bash: echo: write error: Invalid argument /sys/devices/virtual/powercap/intel-rapl/intel-rapl:0/constraint_0_time_window_us:1:976 Cc: "Rafael J. Wysocki" Cc: Prarit Bhargava Cc: Radivoje Jovanovic Cc: Seiichi Ikarashi Cc: Mathias Krause Cc: Ajay Thomas Signed-off-by: Prarit Bhargava --- drivers/powercap/intel_rapl.c | 31 +++ drivers/powercap/powercap_sys.c |6 -- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/drivers/powercap/intel_rapl.c b/drivers/powercap/intel_rapl.c index cc97f08..f765b2c 100644 --- a/drivers/powercap/intel_rapl.c +++ b/drivers/powercap/intel_rapl.c @@ -493,13 +493,42 @@ static int get_current_power_limit(struct powercap_zone *power_zone, int id, return ret; } +static int get_max_time_window(struct powercap_zone *power_zone, int id, + u64 *data) +{ + struct rapl_domain *rd; + int ret = 0; + u64 val; + + get_online_cpus(); + rd = power_zone_to_rapl_domain(power_zone); + + if (rapl_read_data_raw(rd, MAX_TIME_WINDOW, true, )) + ret = -EIO; + else + *data = val; + + put_online_cpus(); + return ret; +} + static int set_time_window(struct powercap_zone *power_zone, int id, u64 window) { struct rapl_domain *rd; int ret = 0; + u64 max_window; get_online_cpus(); + ret = get_max_time_window(power_zone, id, _window); + if (ret < 0) + goto out; + + if (window > max_window) { + ret = -EINVAL; + goto out; + } + rd = power_zone_to_rapl_domain(power_zone); switch (rd->rpl[id].prim_id) { case PL1_ENABLE: @@ -511,6 +540,7 @@ static int set_time_window(struct powercap_zone *power_zone, int id, default: ret = -EINVAL; } +out: put_online_cpus(); return ret; } @@ -590,6 +620,7 @@ static struct powercap_zone_constraint_ops constraint_ops = { .set_time_window_us = set_time_window, .get_time_window_us = get_time_window, .get_max_power_uw = get_max_power, + .get_max_time_window_us = get_max_time_window, .get_name = get_constraint_name, }; diff --git a/drivers/powercap/powercap_sys.c b/drivers/powercap/powercap_sys.c index 84419af..7d77b83 100644 --- a/drivers/powercap/powercap_sys.c +++ b/drivers/powercap/powercap_sys.c @@ -101,7 +101,7 @@ static ssize_t store_constraint_##_attr(struct device *dev,\ int err; \ u64 value; \ struct powercap_zone *power_zone = to_powercap_zone(dev); \ - int id; \ + int id, ret; \ struct powercap_zone_constraint *pconst;\ \ if (!sscanf(dev_attr->attr.name, "constraint_%d_", )) \ @@ -113,8 +113,10 @@ static ssize_t store_constraint_##_attr(struct device *dev,\ if (err) \ return -EINVAL; \ if (pconst && pconst->ops && pconst->ops->set_##_attr) { \ - if (!pconst->ops->set_##_attr(power_zone, id, value)) \ + ret = pconst->ops->set_##_attr(power_zone, id, value); \ + if (!ret) \ return count; \ + return ret; \ } \ \ return -ENODATA; \ -- 1.7.9.3
[PATCH 1/3] powercap, intel_rapl, implement get_max_time_window
The MSR_PKG_POWER_INFO register (Intel ASDM, section 14.9.3 "Package RAPL Domain") provides a maximum time window which the system can support. This window is read-only and is currently not examined when setting the time windows for the package. This patch implements get_max_time_window_us() and checks the window when a user attempts to set power capping for the package. Before the patch it was possible to set the window to, for example, 1 micro seconds: [root@intel-chiefriver-03 rhel7]# echo 1 > /sys/devices/virtual/powercap/intel-rapl/intel-rapl\:0/constraint_0_time_window_us; egrep ^ /sys/devices/virtual/powercap/intel-rapl/intel-rapl\:0/constraint_0_time_window_us /sys/devices/virtual/powercap/intel-rapl/intel-rapl:0/constraint_0_time_window_us:1:9765 but from 'turbostat -d', the package is limited to 976us: cpu0: MSR_PKG_POWER_INFO: 0x01200168 (45 W TDP, RAPL 36 - 0 W, 0.000977 sec.) (Note, there appears to be a rounding issue in turbostat which needs to also be fixed. Looking at the values in the register it is clear the value is 1/1024 = 976us.) After the patch we are limited by the maximum time window: [root@intel-chiefriver-03 rhel7]# echo 1 > /sys/devices/virtual/powercap/intel-rapl/intel-rapl\:0/constraint_0_time_window_us; egrep ^ /sys/devices/virtual/powercap/intel-rapl/intel-rapl\:0/constraint_0_time_window_us -bash: echo: write error: Invalid argument /sys/devices/virtual/powercap/intel-rapl/intel-rapl:0/constraint_0_time_window_us:1:976 Cc: "Rafael J. Wysocki"Cc: Prarit Bhargava Cc: Radivoje Jovanovic Cc: Seiichi Ikarashi Cc: Mathias Krause Cc: Ajay Thomas Signed-off-by: Prarit Bhargava --- drivers/powercap/intel_rapl.c | 31 +++ drivers/powercap/powercap_sys.c |6 -- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/drivers/powercap/intel_rapl.c b/drivers/powercap/intel_rapl.c index cc97f08..f765b2c 100644 --- a/drivers/powercap/intel_rapl.c +++ b/drivers/powercap/intel_rapl.c @@ -493,13 +493,42 @@ static int get_current_power_limit(struct powercap_zone *power_zone, int id, return ret; } +static int get_max_time_window(struct powercap_zone *power_zone, int id, + u64 *data) +{ + struct rapl_domain *rd; + int ret = 0; + u64 val; + + get_online_cpus(); + rd = power_zone_to_rapl_domain(power_zone); + + if (rapl_read_data_raw(rd, MAX_TIME_WINDOW, true, )) + ret = -EIO; + else + *data = val; + + put_online_cpus(); + return ret; +} + static int set_time_window(struct powercap_zone *power_zone, int id, u64 window) { struct rapl_domain *rd; int ret = 0; + u64 max_window; get_online_cpus(); + ret = get_max_time_window(power_zone, id, _window); + if (ret < 0) + goto out; + + if (window > max_window) { + ret = -EINVAL; + goto out; + } + rd = power_zone_to_rapl_domain(power_zone); switch (rd->rpl[id].prim_id) { case PL1_ENABLE: @@ -511,6 +540,7 @@ static int set_time_window(struct powercap_zone *power_zone, int id, default: ret = -EINVAL; } +out: put_online_cpus(); return ret; } @@ -590,6 +620,7 @@ static struct powercap_zone_constraint_ops constraint_ops = { .set_time_window_us = set_time_window, .get_time_window_us = get_time_window, .get_max_power_uw = get_max_power, + .get_max_time_window_us = get_max_time_window, .get_name = get_constraint_name, }; diff --git a/drivers/powercap/powercap_sys.c b/drivers/powercap/powercap_sys.c index 84419af..7d77b83 100644 --- a/drivers/powercap/powercap_sys.c +++ b/drivers/powercap/powercap_sys.c @@ -101,7 +101,7 @@ static ssize_t store_constraint_##_attr(struct device *dev,\ int err; \ u64 value; \ struct powercap_zone *power_zone = to_powercap_zone(dev); \ - int id; \ + int id, ret; \ struct powercap_zone_constraint *pconst;\ \ if (!sscanf(dev_attr->attr.name, "constraint_%d_", )) \ @@ -113,8 +113,10 @@ static ssize_t store_constraint_##_attr(struct device *dev,\ if (err) \ return -EINVAL; \ if (pconst && pconst->ops && pconst->ops->set_##_attr) { \ - if (!pconst->ops->set_##_attr(power_zone, id, value)) \ + ret = pconst->ops->set_##_attr(power_zone, id, value); \ + if (!ret) \ return count; \ + return ret; \ } \ \ return -ENODATA; \ -- 1.7.9.3
Re: [PATCH 1/3] powercap, intel_rapl, implement get_max_time_window
On 01/21/2016 07:27 PM, Seiichi Ikarashi wrote: > On 2016-01-22 01:15, Prarit Bhargava wrote: >> The MSR_PKG_POWER_INFO register (Intel ASDM, section 14.9.3 >> "Package RAPL Domain") provides a maximum time window which the >> system can support. This window is read-only and is currently >> not examined when setting the time windows for the package. >> >> This patch implements get_max_time_window_us() and checks the window when >> a user attempts to set power capping for the package. >> >> Before the patch it was possible to set the window to, for example, 1 >> micro seconds: >> >> [root@intel-chiefriver-03 rhel7]# echo 1 > >> /sys/devices/virtual/powercap/intel-rapl/intel-rapl\:0/constraint_0_time_window_us; >> egrep ^ >> /sys/devices/virtual/powercap/intel-rapl/intel-rapl\:0/constraint_0_time_window_us >> >> /sys/devices/virtual/powercap/intel-rapl/intel-rapl:0/constraint_0_time_window_us:1:9765 >> >> but from 'turbostat -d', the package is limited to 976us: >> >> cpu0: MSR_PKG_POWER_INFO: 0x01200168 (45 W TDP, RAPL 36 - 0 W, 0.000977 sec.) >> >> (Note, there appears to be a rounding issue in turbostat which needs to >> also be fixed. Looking at the values in the register it is clear the >> value is 1/1024 = 976us.) >> >> After the patch we are limited by the maximum time window: >> >> [root@intel-chiefriver-03 rhel7]# echo 1 > >> /sys/devices/virtual/powercap/intel-rapl/intel-rapl\:0/constraint_0_time_window_us; >> egrep ^ >> /sys/devices/virtual/powercap/intel-rapl/intel-rapl\:0/constraint_0_time_window_us >> >> -bash: echo: write error: Invalid argument >> /sys/devices/virtual/powercap/intel-rapl/intel-rapl:0/constraint_0_time_window_us:1:976 >> >> Cc: "Rafael J. Wysocki" >> Cc: Prarit Bhargava >> Cc: Radivoje Jovanovic >> Cc: Seiichi Ikarashi >> Cc: Mathias Krause >> Cc: Ajay Thomas >> Signed-off-by: Prarit Bhargava >> --- >> drivers/powercap/intel_rapl.c | 31 +++ >> drivers/powercap/powercap_sys.c |6 -- >> 2 files changed, 35 insertions(+), 2 deletions(-) >> >> diff --git a/drivers/powercap/intel_rapl.c b/drivers/powercap/intel_rapl.c >> index cc97f08..f765b2c 100644 >> --- a/drivers/powercap/intel_rapl.c >> +++ b/drivers/powercap/intel_rapl.c >> @@ -493,13 +493,42 @@ static int get_current_power_limit(struct >> powercap_zone *power_zone, int id, >> return ret; >> } >> >> +static int get_max_time_window(struct powercap_zone *power_zone, int id, >> + u64 *data) > > The 2nd arg "id" is not necessary. It is required by the powercap_sys code. If I remove this then I have to create separate sysfs store and show files and I think it isn't worth it to do so. P. > > -- > Seiichi >
Re: [PATCH 1/3] powercap, intel_rapl, implement get_max_time_window
On 01/21/2016 07:27 PM, Seiichi Ikarashi wrote: > On 2016-01-22 01:15, Prarit Bhargava wrote: >> The MSR_PKG_POWER_INFO register (Intel ASDM, section 14.9.3 >> "Package RAPL Domain") provides a maximum time window which the >> system can support. This window is read-only and is currently >> not examined when setting the time windows for the package. >> >> This patch implements get_max_time_window_us() and checks the window when >> a user attempts to set power capping for the package. >> >> Before the patch it was possible to set the window to, for example, 1 >> micro seconds: >> >> [root@intel-chiefriver-03 rhel7]# echo 1 > >> /sys/devices/virtual/powercap/intel-rapl/intel-rapl\:0/constraint_0_time_window_us; >> egrep ^ >> /sys/devices/virtual/powercap/intel-rapl/intel-rapl\:0/constraint_0_time_window_us >> >> /sys/devices/virtual/powercap/intel-rapl/intel-rapl:0/constraint_0_time_window_us:1:9765 >> >> but from 'turbostat -d', the package is limited to 976us: >> >> cpu0: MSR_PKG_POWER_INFO: 0x01200168 (45 W TDP, RAPL 36 - 0 W, 0.000977 sec.) >> >> (Note, there appears to be a rounding issue in turbostat which needs to >> also be fixed. Looking at the values in the register it is clear the >> value is 1/1024 = 976us.) >> >> After the patch we are limited by the maximum time window: >> >> [root@intel-chiefriver-03 rhel7]# echo 1 > >> /sys/devices/virtual/powercap/intel-rapl/intel-rapl\:0/constraint_0_time_window_us; >> egrep ^ >> /sys/devices/virtual/powercap/intel-rapl/intel-rapl\:0/constraint_0_time_window_us >> >> -bash: echo: write error: Invalid argument >> /sys/devices/virtual/powercap/intel-rapl/intel-rapl:0/constraint_0_time_window_us:1:976 >> >> Cc: "Rafael J. Wysocki">> Cc: Prarit Bhargava >> Cc: Radivoje Jovanovic >> Cc: Seiichi Ikarashi >> Cc: Mathias Krause >> Cc: Ajay Thomas >> Signed-off-by: Prarit Bhargava >> --- >> drivers/powercap/intel_rapl.c | 31 +++ >> drivers/powercap/powercap_sys.c |6 -- >> 2 files changed, 35 insertions(+), 2 deletions(-) >> >> diff --git a/drivers/powercap/intel_rapl.c b/drivers/powercap/intel_rapl.c >> index cc97f08..f765b2c 100644 >> --- a/drivers/powercap/intel_rapl.c >> +++ b/drivers/powercap/intel_rapl.c >> @@ -493,13 +493,42 @@ static int get_current_power_limit(struct >> powercap_zone *power_zone, int id, >> return ret; >> } >> >> +static int get_max_time_window(struct powercap_zone *power_zone, int id, >> + u64 *data) > > The 2nd arg "id" is not necessary. It is required by the powercap_sys code. If I remove this then I have to create separate sysfs store and show files and I think it isn't worth it to do so. P. > > -- > Seiichi >
Re: [PATCH 1/3] powercap, intel_rapl, implement get_max_time_window
On 2016-01-22 01:15, Prarit Bhargava wrote: > The MSR_PKG_POWER_INFO register (Intel ASDM, section 14.9.3 > "Package RAPL Domain") provides a maximum time window which the > system can support. This window is read-only and is currently > not examined when setting the time windows for the package. > > This patch implements get_max_time_window_us() and checks the window when > a user attempts to set power capping for the package. > > Before the patch it was possible to set the window to, for example, 1 > micro seconds: > > [root@intel-chiefriver-03 rhel7]# echo 1 > > /sys/devices/virtual/powercap/intel-rapl/intel-rapl\:0/constraint_0_time_window_us; > egrep ^ > /sys/devices/virtual/powercap/intel-rapl/intel-rapl\:0/constraint_0_time_window_us > > /sys/devices/virtual/powercap/intel-rapl/intel-rapl:0/constraint_0_time_window_us:1:9765 > > but from 'turbostat -d', the package is limited to 976us: > > cpu0: MSR_PKG_POWER_INFO: 0x01200168 (45 W TDP, RAPL 36 - 0 W, 0.000977 sec.) > > (Note, there appears to be a rounding issue in turbostat which needs to > also be fixed. Looking at the values in the register it is clear the > value is 1/1024 = 976us.) > > After the patch we are limited by the maximum time window: > > [root@intel-chiefriver-03 rhel7]# echo 1 > > /sys/devices/virtual/powercap/intel-rapl/intel-rapl\:0/constraint_0_time_window_us; > egrep ^ > /sys/devices/virtual/powercap/intel-rapl/intel-rapl\:0/constraint_0_time_window_us > > -bash: echo: write error: Invalid argument > /sys/devices/virtual/powercap/intel-rapl/intel-rapl:0/constraint_0_time_window_us:1:976 > > Cc: "Rafael J. Wysocki" > Cc: Prarit Bhargava > Cc: Radivoje Jovanovic > Cc: Seiichi Ikarashi > Cc: Mathias Krause > Cc: Ajay Thomas > Signed-off-by: Prarit Bhargava > --- > drivers/powercap/intel_rapl.c | 31 +++ > drivers/powercap/powercap_sys.c |6 -- > 2 files changed, 35 insertions(+), 2 deletions(-) > > diff --git a/drivers/powercap/intel_rapl.c b/drivers/powercap/intel_rapl.c > index cc97f08..f765b2c 100644 > --- a/drivers/powercap/intel_rapl.c > +++ b/drivers/powercap/intel_rapl.c > @@ -493,13 +493,42 @@ static int get_current_power_limit(struct powercap_zone > *power_zone, int id, > return ret; > } > > +static int get_max_time_window(struct powercap_zone *power_zone, int id, > +u64 *data) The 2nd arg "id" is not necessary. -- Seiichi
[PATCH 1/3] powercap, intel_rapl, implement get_max_time_window
The MSR_PKG_POWER_INFO register (Intel ASDM, section 14.9.3 "Package RAPL Domain") provides a maximum time window which the system can support. This window is read-only and is currently not examined when setting the time windows for the package. This patch implements get_max_time_window_us() and checks the window when a user attempts to set power capping for the package. Before the patch it was possible to set the window to, for example, 1 micro seconds: [root@intel-chiefriver-03 rhel7]# echo 1 > /sys/devices/virtual/powercap/intel-rapl/intel-rapl\:0/constraint_0_time_window_us; egrep ^ /sys/devices/virtual/powercap/intel-rapl/intel-rapl\:0/constraint_0_time_window_us /sys/devices/virtual/powercap/intel-rapl/intel-rapl:0/constraint_0_time_window_us:1:9765 but from 'turbostat -d', the package is limited to 976us: cpu0: MSR_PKG_POWER_INFO: 0x01200168 (45 W TDP, RAPL 36 - 0 W, 0.000977 sec.) (Note, there appears to be a rounding issue in turbostat which needs to also be fixed. Looking at the values in the register it is clear the value is 1/1024 = 976us.) After the patch we are limited by the maximum time window: [root@intel-chiefriver-03 rhel7]# echo 1 > /sys/devices/virtual/powercap/intel-rapl/intel-rapl\:0/constraint_0_time_window_us; egrep ^ /sys/devices/virtual/powercap/intel-rapl/intel-rapl\:0/constraint_0_time_window_us -bash: echo: write error: Invalid argument /sys/devices/virtual/powercap/intel-rapl/intel-rapl:0/constraint_0_time_window_us:1:976 Cc: "Rafael J. Wysocki" Cc: Prarit Bhargava Cc: Radivoje Jovanovic Cc: Seiichi Ikarashi Cc: Mathias Krause Cc: Ajay Thomas Signed-off-by: Prarit Bhargava --- drivers/powercap/intel_rapl.c | 31 +++ drivers/powercap/powercap_sys.c |6 -- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/drivers/powercap/intel_rapl.c b/drivers/powercap/intel_rapl.c index cc97f08..f765b2c 100644 --- a/drivers/powercap/intel_rapl.c +++ b/drivers/powercap/intel_rapl.c @@ -493,13 +493,42 @@ static int get_current_power_limit(struct powercap_zone *power_zone, int id, return ret; } +static int get_max_time_window(struct powercap_zone *power_zone, int id, + u64 *data) +{ + struct rapl_domain *rd; + int ret = 0; + u64 val; + + get_online_cpus(); + rd = power_zone_to_rapl_domain(power_zone); + + if (rapl_read_data_raw(rd, MAX_TIME_WINDOW, true, )) + ret = -EIO; + else + *data = val; + + put_online_cpus(); + return ret; +} + static int set_time_window(struct powercap_zone *power_zone, int id, u64 window) { struct rapl_domain *rd; int ret = 0; + u64 max_window; get_online_cpus(); + ret = get_max_time_window(power_zone, id, _window); + if (ret < 0) + goto out; + + if (window > max_window) { + ret = -EINVAL; + goto out; + } + rd = power_zone_to_rapl_domain(power_zone); switch (rd->rpl[id].prim_id) { case PL1_ENABLE: @@ -511,6 +540,7 @@ static int set_time_window(struct powercap_zone *power_zone, int id, default: ret = -EINVAL; } +out: put_online_cpus(); return ret; } @@ -590,6 +620,7 @@ static struct powercap_zone_constraint_ops constraint_ops = { .set_time_window_us = set_time_window, .get_time_window_us = get_time_window, .get_max_power_uw = get_max_power, + .get_max_time_window_us = get_max_time_window, .get_name = get_constraint_name, }; diff --git a/drivers/powercap/powercap_sys.c b/drivers/powercap/powercap_sys.c index 84419af..7d77b83 100644 --- a/drivers/powercap/powercap_sys.c +++ b/drivers/powercap/powercap_sys.c @@ -101,7 +101,7 @@ static ssize_t store_constraint_##_attr(struct device *dev,\ int err; \ u64 value; \ struct powercap_zone *power_zone = to_powercap_zone(dev); \ - int id; \ + int id, ret; \ struct powercap_zone_constraint *pconst;\ \ if (!sscanf(dev_attr->attr.name, "constraint_%d_", )) \ @@ -113,8 +113,10 @@ static ssize_t store_constraint_##_attr(struct device *dev,\ if (err) \ return -EINVAL; \ if (pconst && pconst->ops && pconst->ops->set_##_attr) { \ - if (!pconst->ops->set_##_attr(power_zone, id, value)) \ + ret = pconst->ops->set_##_attr(power_zone, id, value); \ + if (!ret) \ return count; \ + return ret; \ } \ \ return -ENODATA; \ -- 1.7.9.3
[PATCH 1/3] powercap, intel_rapl, implement get_max_time_window
The MSR_PKG_POWER_INFO register (Intel ASDM, section 14.9.3 "Package RAPL Domain") provides a maximum time window which the system can support. This window is read-only and is currently not examined when setting the time windows for the package. This patch implements get_max_time_window_us() and checks the window when a user attempts to set power capping for the package. Before the patch it was possible to set the window to, for example, 1 micro seconds: [root@intel-chiefriver-03 rhel7]# echo 1 > /sys/devices/virtual/powercap/intel-rapl/intel-rapl\:0/constraint_0_time_window_us; egrep ^ /sys/devices/virtual/powercap/intel-rapl/intel-rapl\:0/constraint_0_time_window_us /sys/devices/virtual/powercap/intel-rapl/intel-rapl:0/constraint_0_time_window_us:1:9765 but from 'turbostat -d', the package is limited to 976us: cpu0: MSR_PKG_POWER_INFO: 0x01200168 (45 W TDP, RAPL 36 - 0 W, 0.000977 sec.) (Note, there appears to be a rounding issue in turbostat which needs to also be fixed. Looking at the values in the register it is clear the value is 1/1024 = 976us.) After the patch we are limited by the maximum time window: [root@intel-chiefriver-03 rhel7]# echo 1 > /sys/devices/virtual/powercap/intel-rapl/intel-rapl\:0/constraint_0_time_window_us; egrep ^ /sys/devices/virtual/powercap/intel-rapl/intel-rapl\:0/constraint_0_time_window_us -bash: echo: write error: Invalid argument /sys/devices/virtual/powercap/intel-rapl/intel-rapl:0/constraint_0_time_window_us:1:976 Cc: "Rafael J. Wysocki"Cc: Prarit Bhargava Cc: Radivoje Jovanovic Cc: Seiichi Ikarashi Cc: Mathias Krause Cc: Ajay Thomas Signed-off-by: Prarit Bhargava --- drivers/powercap/intel_rapl.c | 31 +++ drivers/powercap/powercap_sys.c |6 -- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/drivers/powercap/intel_rapl.c b/drivers/powercap/intel_rapl.c index cc97f08..f765b2c 100644 --- a/drivers/powercap/intel_rapl.c +++ b/drivers/powercap/intel_rapl.c @@ -493,13 +493,42 @@ static int get_current_power_limit(struct powercap_zone *power_zone, int id, return ret; } +static int get_max_time_window(struct powercap_zone *power_zone, int id, + u64 *data) +{ + struct rapl_domain *rd; + int ret = 0; + u64 val; + + get_online_cpus(); + rd = power_zone_to_rapl_domain(power_zone); + + if (rapl_read_data_raw(rd, MAX_TIME_WINDOW, true, )) + ret = -EIO; + else + *data = val; + + put_online_cpus(); + return ret; +} + static int set_time_window(struct powercap_zone *power_zone, int id, u64 window) { struct rapl_domain *rd; int ret = 0; + u64 max_window; get_online_cpus(); + ret = get_max_time_window(power_zone, id, _window); + if (ret < 0) + goto out; + + if (window > max_window) { + ret = -EINVAL; + goto out; + } + rd = power_zone_to_rapl_domain(power_zone); switch (rd->rpl[id].prim_id) { case PL1_ENABLE: @@ -511,6 +540,7 @@ static int set_time_window(struct powercap_zone *power_zone, int id, default: ret = -EINVAL; } +out: put_online_cpus(); return ret; } @@ -590,6 +620,7 @@ static struct powercap_zone_constraint_ops constraint_ops = { .set_time_window_us = set_time_window, .get_time_window_us = get_time_window, .get_max_power_uw = get_max_power, + .get_max_time_window_us = get_max_time_window, .get_name = get_constraint_name, }; diff --git a/drivers/powercap/powercap_sys.c b/drivers/powercap/powercap_sys.c index 84419af..7d77b83 100644 --- a/drivers/powercap/powercap_sys.c +++ b/drivers/powercap/powercap_sys.c @@ -101,7 +101,7 @@ static ssize_t store_constraint_##_attr(struct device *dev,\ int err; \ u64 value; \ struct powercap_zone *power_zone = to_powercap_zone(dev); \ - int id; \ + int id, ret; \ struct powercap_zone_constraint *pconst;\ \ if (!sscanf(dev_attr->attr.name, "constraint_%d_", )) \ @@ -113,8 +113,10 @@ static ssize_t store_constraint_##_attr(struct device *dev,\ if (err) \ return -EINVAL; \ if (pconst && pconst->ops && pconst->ops->set_##_attr) { \ - if (!pconst->ops->set_##_attr(power_zone, id, value)) \ + ret = pconst->ops->set_##_attr(power_zone, id, value); \ + if (!ret) \ return count; \ + return ret; \ } \ \ return -ENODATA; \ -- 1.7.9.3
Re: [PATCH 1/3] powercap, intel_rapl, implement get_max_time_window
On 2016-01-22 01:15, Prarit Bhargava wrote: > The MSR_PKG_POWER_INFO register (Intel ASDM, section 14.9.3 > "Package RAPL Domain") provides a maximum time window which the > system can support. This window is read-only and is currently > not examined when setting the time windows for the package. > > This patch implements get_max_time_window_us() and checks the window when > a user attempts to set power capping for the package. > > Before the patch it was possible to set the window to, for example, 1 > micro seconds: > > [root@intel-chiefriver-03 rhel7]# echo 1 > > /sys/devices/virtual/powercap/intel-rapl/intel-rapl\:0/constraint_0_time_window_us; > egrep ^ > /sys/devices/virtual/powercap/intel-rapl/intel-rapl\:0/constraint_0_time_window_us > > /sys/devices/virtual/powercap/intel-rapl/intel-rapl:0/constraint_0_time_window_us:1:9765 > > but from 'turbostat -d', the package is limited to 976us: > > cpu0: MSR_PKG_POWER_INFO: 0x01200168 (45 W TDP, RAPL 36 - 0 W, 0.000977 sec.) > > (Note, there appears to be a rounding issue in turbostat which needs to > also be fixed. Looking at the values in the register it is clear the > value is 1/1024 = 976us.) > > After the patch we are limited by the maximum time window: > > [root@intel-chiefriver-03 rhel7]# echo 1 > > /sys/devices/virtual/powercap/intel-rapl/intel-rapl\:0/constraint_0_time_window_us; > egrep ^ > /sys/devices/virtual/powercap/intel-rapl/intel-rapl\:0/constraint_0_time_window_us > > -bash: echo: write error: Invalid argument > /sys/devices/virtual/powercap/intel-rapl/intel-rapl:0/constraint_0_time_window_us:1:976 > > Cc: "Rafael J. Wysocki"> Cc: Prarit Bhargava > Cc: Radivoje Jovanovic > Cc: Seiichi Ikarashi > Cc: Mathias Krause > Cc: Ajay Thomas > Signed-off-by: Prarit Bhargava > --- > drivers/powercap/intel_rapl.c | 31 +++ > drivers/powercap/powercap_sys.c |6 -- > 2 files changed, 35 insertions(+), 2 deletions(-) > > diff --git a/drivers/powercap/intel_rapl.c b/drivers/powercap/intel_rapl.c > index cc97f08..f765b2c 100644 > --- a/drivers/powercap/intel_rapl.c > +++ b/drivers/powercap/intel_rapl.c > @@ -493,13 +493,42 @@ static int get_current_power_limit(struct powercap_zone > *power_zone, int id, > return ret; > } > > +static int get_max_time_window(struct powercap_zone *power_zone, int id, > +u64 *data) The 2nd arg "id" is not necessary. -- Seiichi
[PATCH 1/3] powercap, intel_rapl, implement get_max_time_window
The MSR_PKG_POWER_INFO register (Intel ASDM, section 14.9.3 "Package RAPL Domain") provides a maximum time window which the system can support. This window is read-only and is currently not examined when setting the time windows for the package. This patch implements get_max_time_window_us() and checks the window when a user attempts to set power capping for the package. Before the patch it was possible to set the window to, for example, 1 micro seconds: [root@intel-chiefriver-03 rhel7]# echo 1 > /sys/devices/virtual/powercap/intel-rapl/intel-rapl\:0/constraint_0_time_window_us; egrep ^ /sys/devices/virtual/powercap/intel-rapl/intel-rapl\:0/constraint_0_time_window_us /sys/devices/virtual/powercap/intel-rapl/intel-rapl:0/constraint_0_time_window_us:1:9765 but from 'turbostat -d', the package is limited to 976us: cpu0: MSR_PKG_POWER_INFO: 0x01200168 (45 W TDP, RAPL 36 - 0 W, 0.000977 sec.) (Note, there appears to be a rounding issue in turbostat which needs to also be fixed. Looking at the values in the register it is clear the value is 1/1024 = 976us.) After the patch we are limited by the maximum time window: [root@intel-chiefriver-03 rhel7]# echo 1 > /sys/devices/virtual/powercap/intel-rapl/intel-rapl\:0/constraint_0_time_window_us; egrep ^ /sys/devices/virtual/powercap/intel-rapl/intel-rapl\:0/constraint_0_time_window_us -bash: echo: write error: Invalid argument /sys/devices/virtual/powercap/intel-rapl/intel-rapl:0/constraint_0_time_window_us:1:976 Cc: "Rafael J. Wysocki" Cc: Prarit Bhargava Cc: Radivoje Jovanovic Cc: Seiichi Ikarashi Cc: Mathias Krause Cc: Ajay Thomas Signed-off-by: Prarit Bhargava --- drivers/powercap/intel_rapl.c | 31 +++ drivers/powercap/powercap_sys.c |6 -- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/drivers/powercap/intel_rapl.c b/drivers/powercap/intel_rapl.c index cc97f08..f765b2c 100644 --- a/drivers/powercap/intel_rapl.c +++ b/drivers/powercap/intel_rapl.c @@ -493,13 +493,42 @@ static int get_current_power_limit(struct powercap_zone *power_zone, int id, return ret; } +static int get_max_time_window(struct powercap_zone *power_zone, int id, + u64 *data) +{ + struct rapl_domain *rd; + int ret = 0; + u64 val; + + get_online_cpus(); + rd = power_zone_to_rapl_domain(power_zone); + + if (rapl_read_data_raw(rd, MAX_TIME_WINDOW, true, )) + ret = -EIO; + else + *data = val; + + put_online_cpus(); + return ret; +} + static int set_time_window(struct powercap_zone *power_zone, int id, u64 window) { struct rapl_domain *rd; int ret = 0; + u64 max_window; get_online_cpus(); + ret = get_max_time_window(power_zone, id, _window); + if (ret < 0) + goto out; + + if (window > max_window) { + ret = -EINVAL; + goto out; + } + rd = power_zone_to_rapl_domain(power_zone); switch (rd->rpl[id].prim_id) { case PL1_ENABLE: @@ -511,6 +540,7 @@ static int set_time_window(struct powercap_zone *power_zone, int id, default: ret = -EINVAL; } +out: put_online_cpus(); return ret; } @@ -590,6 +620,7 @@ static struct powercap_zone_constraint_ops constraint_ops = { .set_time_window_us = set_time_window, .get_time_window_us = get_time_window, .get_max_power_uw = get_max_power, + .get_max_time_window_us = get_max_time_window, .get_name = get_constraint_name, }; diff --git a/drivers/powercap/powercap_sys.c b/drivers/powercap/powercap_sys.c index 84419af..7d77b83 100644 --- a/drivers/powercap/powercap_sys.c +++ b/drivers/powercap/powercap_sys.c @@ -101,7 +101,7 @@ static ssize_t store_constraint_##_attr(struct device *dev,\ int err; \ u64 value; \ struct powercap_zone *power_zone = to_powercap_zone(dev); \ - int id; \ + int id, ret; \ struct powercap_zone_constraint *pconst;\ \ if (!sscanf(dev_attr->attr.name, "constraint_%d_", )) \ @@ -113,8 +113,10 @@ static ssize_t store_constraint_##_attr(struct device *dev,\ if (err) \ return -EINVAL; \ if (pconst && pconst->ops && pconst->ops->set_##_attr) { \ - if (!pconst->ops->set_##_attr(power_zone, id, value)) \ + ret = pconst->ops->set_##_attr(power_zone, id, value); \ + if (!ret) \ return count; \ + return ret; \ } \ \ return -ENODATA; \ -- 1.7.9.3 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at
[PATCH 1/3] powercap, intel_rapl, implement get_max_time_window
The MSR_PKG_POWER_INFO register (Intel ASDM, section 14.9.3 "Package RAPL Domain") provides a maximum time window which the system can support. This window is read-only and is currently not examined when setting the time windows for the package. This patch implements get_max_time_window_us() and checks the window when a user attempts to set power capping for the package. Before the patch it was possible to set the window to, for example, 1 micro seconds: [root@intel-chiefriver-03 rhel7]# echo 1 > /sys/devices/virtual/powercap/intel-rapl/intel-rapl\:0/constraint_0_time_window_us; egrep ^ /sys/devices/virtual/powercap/intel-rapl/intel-rapl\:0/constraint_0_time_window_us /sys/devices/virtual/powercap/intel-rapl/intel-rapl:0/constraint_0_time_window_us:1:9765 but from 'turbostat -d', the package is limited to 976us: cpu0: MSR_PKG_POWER_INFO: 0x01200168 (45 W TDP, RAPL 36 - 0 W, 0.000977 sec.) (Note, there appears to be a rounding issue in turbostat which needs to also be fixed. Looking at the values in the register it is clear the value is 1/1024 = 976us.) After the patch we are limited by the maximum time window: [root@intel-chiefriver-03 rhel7]# echo 1 > /sys/devices/virtual/powercap/intel-rapl/intel-rapl\:0/constraint_0_time_window_us; egrep ^ /sys/devices/virtual/powercap/intel-rapl/intel-rapl\:0/constraint_0_time_window_us -bash: echo: write error: Invalid argument /sys/devices/virtual/powercap/intel-rapl/intel-rapl:0/constraint_0_time_window_us:1:976 Cc: "Rafael J. Wysocki"Cc: Prarit Bhargava Cc: Radivoje Jovanovic Cc: Seiichi Ikarashi Cc: Mathias Krause Cc: Ajay Thomas Signed-off-by: Prarit Bhargava --- drivers/powercap/intel_rapl.c | 31 +++ drivers/powercap/powercap_sys.c |6 -- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/drivers/powercap/intel_rapl.c b/drivers/powercap/intel_rapl.c index cc97f08..f765b2c 100644 --- a/drivers/powercap/intel_rapl.c +++ b/drivers/powercap/intel_rapl.c @@ -493,13 +493,42 @@ static int get_current_power_limit(struct powercap_zone *power_zone, int id, return ret; } +static int get_max_time_window(struct powercap_zone *power_zone, int id, + u64 *data) +{ + struct rapl_domain *rd; + int ret = 0; + u64 val; + + get_online_cpus(); + rd = power_zone_to_rapl_domain(power_zone); + + if (rapl_read_data_raw(rd, MAX_TIME_WINDOW, true, )) + ret = -EIO; + else + *data = val; + + put_online_cpus(); + return ret; +} + static int set_time_window(struct powercap_zone *power_zone, int id, u64 window) { struct rapl_domain *rd; int ret = 0; + u64 max_window; get_online_cpus(); + ret = get_max_time_window(power_zone, id, _window); + if (ret < 0) + goto out; + + if (window > max_window) { + ret = -EINVAL; + goto out; + } + rd = power_zone_to_rapl_domain(power_zone); switch (rd->rpl[id].prim_id) { case PL1_ENABLE: @@ -511,6 +540,7 @@ static int set_time_window(struct powercap_zone *power_zone, int id, default: ret = -EINVAL; } +out: put_online_cpus(); return ret; } @@ -590,6 +620,7 @@ static struct powercap_zone_constraint_ops constraint_ops = { .set_time_window_us = set_time_window, .get_time_window_us = get_time_window, .get_max_power_uw = get_max_power, + .get_max_time_window_us = get_max_time_window, .get_name = get_constraint_name, }; diff --git a/drivers/powercap/powercap_sys.c b/drivers/powercap/powercap_sys.c index 84419af..7d77b83 100644 --- a/drivers/powercap/powercap_sys.c +++ b/drivers/powercap/powercap_sys.c @@ -101,7 +101,7 @@ static ssize_t store_constraint_##_attr(struct device *dev,\ int err; \ u64 value; \ struct powercap_zone *power_zone = to_powercap_zone(dev); \ - int id; \ + int id, ret; \ struct powercap_zone_constraint *pconst;\ \ if (!sscanf(dev_attr->attr.name, "constraint_%d_", )) \ @@ -113,8 +113,10 @@ static ssize_t store_constraint_##_attr(struct device *dev,\ if (err) \ return -EINVAL; \ if (pconst && pconst->ops && pconst->ops->set_##_attr) { \ - if (!pconst->ops->set_##_attr(power_zone, id, value)) \ + ret = pconst->ops->set_##_attr(power_zone, id, value); \ + if (!ret) \ return count; \ + return ret; \ } \ \ return -ENODATA; \ -- 1.7.9.3 -- To unsubscribe from this list: send the line
Re: [PATCH 1/3] powercap, intel_rapl, implement get_max_time_window
On 12/17/2015 12:45 AM, Seiichi Ikarashi wrote: > On 2015-12-15 22:02, Prarit Bhargava wrote: >> The MSR_PKG_POWER_INFO register (Intel ASDM, section 14.9.3 >> "Package RAPL Domain") provides a maximum time window which the >> system can support. This window is read-only and is currently >> not examined when setting the time windows for the package. > > I have been having a question here long time. > Maximum Time Window (bits 53:48) in MSR_PKG_POWER_INFO is only > 6-bit length even though Time Window for Power Limit #1 (bits 23:17) > and Time Window for Power Limit #2 (bits 55:49) in MSR_PKG_POWER_LIMIT > are both 7-bit length, not 6. While looking at the MSR settings I had exactly the same question! I too would like to know the answer. > > Do Intel guys have an answer for it? > > > The patch itself looks good to me. > Just minor comments below: > >> diff --git a/drivers/powercap/intel_rapl.c b/drivers/powercap/intel_rapl.c >> index cc97f08..f765b2c 100644 >> --- a/drivers/powercap/intel_rapl.c >> +++ b/drivers/powercap/intel_rapl.c >> @@ -493,13 +493,42 @@ static int get_current_power_limit(struct >> powercap_zone *power_zone, int id, >> return ret; >> } >> >> +static int get_max_time_window(struct powercap_zone *power_zone, int id, > > The 2nd arg "id" is not necessary. I'll drop this in v2. > >> + u64 *data) >> +{ >> +struct rapl_domain *rd; >> +int ret = 0; >> +u64 val; >> + >> +get_online_cpus(); >> +rd = power_zone_to_rapl_domain(power_zone); >> + >> +if (rapl_read_data_raw(rd, MAX_TIME_WINDOW, true, )) > > rapl_read_data_raw() can return -EINVAL and -ENODEV other than -EIO. > >> +ret = -EIO; > > Is it OK to limit ret to -EIO here? AFAICT it seems like it. The only error that can occur here (at least by the time this code is executed) is that there is a range error. -EIO seems appropriate. > >> +else >> +*data = val; >> + >> +put_online_cpus(); >> +return ret; >> +} >> + >> static int set_time_window(struct powercap_zone *power_zone, int id, >> u64 window) >> { >> struct rapl_domain *rd; >> int ret = 0; >> +u64 max_window; >> >> get_online_cpus(); >> +ret = get_max_time_window(power_zone, id, _window); >> +if (ret < 0) >> +goto out; >> + >> +if (window > max_window) { >> +ret = -EINVAL; >> +goto out; >> +} >> + >> rd = power_zone_to_rapl_domain(power_zone); >> switch (rd->rpl[id].prim_id) { >> case PL1_ENABLE: >> @@ -511,6 +540,7 @@ static int set_time_window(struct powercap_zone >> *power_zone, int id, >> default: >> ret = -EINVAL; >> } >> +out: >> put_online_cpus(); >> return ret; >> } >> @@ -590,6 +620,7 @@ static struct powercap_zone_constraint_ops >> constraint_ops = { >> .set_time_window_us = set_time_window, >> .get_time_window_us = get_time_window, >> .get_max_power_uw = get_max_power, >> +.get_max_time_window_us = get_max_time_window, >> .get_name = get_constraint_name, >> }; >> >> diff --git a/drivers/powercap/powercap_sys.c >> b/drivers/powercap/powercap_sys.c >> index 84419af..7d77b83 100644 >> --- a/drivers/powercap/powercap_sys.c >> +++ b/drivers/powercap/powercap_sys.c >> @@ -101,7 +101,7 @@ static ssize_t store_constraint_##_attr(struct device >> *dev,\ >> int err; \ >> u64 value; \ >> struct powercap_zone *power_zone = to_powercap_zone(dev); \ >> -int id; \ >> +int id, ret; \ >> struct powercap_zone_constraint *pconst;\ >> \ >> if (!sscanf(dev_attr->attr.name, "constraint_%d_", )) \ >> @@ -113,8 +113,10 @@ static ssize_t store_constraint_##_attr(struct device >> *dev,\ >> if (err) \ >> return -EINVAL; \ >> if (pconst && pconst->ops && pconst->ops->set_##_attr) { \ >> -if (!pconst->ops->set_##_attr(power_zone, id, value)) \ >> +ret = pconst->ops->set_##_attr(power_zone, id, value); \ >> +if (!ret) \ >> return count; \ >> +return ret; \ > > An opposite question to above. > Is it OK not to limit the return value to -EINVAL here? > Do you want this function to return -EIO or something? In this case, no, because the define is used by other values. I think that would limit all erros in the set_* functions to be -EIO. P. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH 1/3] powercap, intel_rapl, implement get_max_time_window
On 12/17/2015 12:45 AM, Seiichi Ikarashi wrote: > On 2015-12-15 22:02, Prarit Bhargava wrote: >> The MSR_PKG_POWER_INFO register (Intel ASDM, section 14.9.3 >> "Package RAPL Domain") provides a maximum time window which the >> system can support. This window is read-only and is currently >> not examined when setting the time windows for the package. > > I have been having a question here long time. > Maximum Time Window (bits 53:48) in MSR_PKG_POWER_INFO is only > 6-bit length even though Time Window for Power Limit #1 (bits 23:17) > and Time Window for Power Limit #2 (bits 55:49) in MSR_PKG_POWER_LIMIT > are both 7-bit length, not 6. While looking at the MSR settings I had exactly the same question! I too would like to know the answer. > > Do Intel guys have an answer for it? > > > The patch itself looks good to me. > Just minor comments below: > >> diff --git a/drivers/powercap/intel_rapl.c b/drivers/powercap/intel_rapl.c >> index cc97f08..f765b2c 100644 >> --- a/drivers/powercap/intel_rapl.c >> +++ b/drivers/powercap/intel_rapl.c >> @@ -493,13 +493,42 @@ static int get_current_power_limit(struct >> powercap_zone *power_zone, int id, >> return ret; >> } >> >> +static int get_max_time_window(struct powercap_zone *power_zone, int id, > > The 2nd arg "id" is not necessary. I'll drop this in v2. > >> + u64 *data) >> +{ >> +struct rapl_domain *rd; >> +int ret = 0; >> +u64 val; >> + >> +get_online_cpus(); >> +rd = power_zone_to_rapl_domain(power_zone); >> + >> +if (rapl_read_data_raw(rd, MAX_TIME_WINDOW, true, )) > > rapl_read_data_raw() can return -EINVAL and -ENODEV other than -EIO. > >> +ret = -EIO; > > Is it OK to limit ret to -EIO here? AFAICT it seems like it. The only error that can occur here (at least by the time this code is executed) is that there is a range error. -EIO seems appropriate. > >> +else >> +*data = val; >> + >> +put_online_cpus(); >> +return ret; >> +} >> + >> static int set_time_window(struct powercap_zone *power_zone, int id, >> u64 window) >> { >> struct rapl_domain *rd; >> int ret = 0; >> +u64 max_window; >> >> get_online_cpus(); >> +ret = get_max_time_window(power_zone, id, _window); >> +if (ret < 0) >> +goto out; >> + >> +if (window > max_window) { >> +ret = -EINVAL; >> +goto out; >> +} >> + >> rd = power_zone_to_rapl_domain(power_zone); >> switch (rd->rpl[id].prim_id) { >> case PL1_ENABLE: >> @@ -511,6 +540,7 @@ static int set_time_window(struct powercap_zone >> *power_zone, int id, >> default: >> ret = -EINVAL; >> } >> +out: >> put_online_cpus(); >> return ret; >> } >> @@ -590,6 +620,7 @@ static struct powercap_zone_constraint_ops >> constraint_ops = { >> .set_time_window_us = set_time_window, >> .get_time_window_us = get_time_window, >> .get_max_power_uw = get_max_power, >> +.get_max_time_window_us = get_max_time_window, >> .get_name = get_constraint_name, >> }; >> >> diff --git a/drivers/powercap/powercap_sys.c >> b/drivers/powercap/powercap_sys.c >> index 84419af..7d77b83 100644 >> --- a/drivers/powercap/powercap_sys.c >> +++ b/drivers/powercap/powercap_sys.c >> @@ -101,7 +101,7 @@ static ssize_t store_constraint_##_attr(struct device >> *dev,\ >> int err; \ >> u64 value; \ >> struct powercap_zone *power_zone = to_powercap_zone(dev); \ >> -int id; \ >> +int id, ret; \ >> struct powercap_zone_constraint *pconst;\ >> \ >> if (!sscanf(dev_attr->attr.name, "constraint_%d_", )) \ >> @@ -113,8 +113,10 @@ static ssize_t store_constraint_##_attr(struct device >> *dev,\ >> if (err) \ >> return -EINVAL; \ >> if (pconst && pconst->ops && pconst->ops->set_##_attr) { \ >> -if (!pconst->ops->set_##_attr(power_zone, id, value)) \ >> +ret = pconst->ops->set_##_attr(power_zone, id, value); \ >> +if (!ret) \ >> return count; \ >> +return ret; \ > > An opposite question to above. > Is it OK not to limit the return value to -EINVAL here? > Do you want this function to return -EIO or something? In this case, no, because the define is used by other values. I think that would limit all erros in the set_* functions to be -EIO. P. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH 1/3] powercap, intel_rapl, implement get_max_time_window
On 2015-12-15 22:02, Prarit Bhargava wrote: > The MSR_PKG_POWER_INFO register (Intel ASDM, section 14.9.3 > "Package RAPL Domain") provides a maximum time window which the > system can support. This window is read-only and is currently > not examined when setting the time windows for the package. I have been having a question here long time. Maximum Time Window (bits 53:48) in MSR_PKG_POWER_INFO is only 6-bit length even though Time Window for Power Limit #1 (bits 23:17) and Time Window for Power Limit #2 (bits 55:49) in MSR_PKG_POWER_LIMIT are both 7-bit length, not 6. Do Intel guys have an answer for it? The patch itself looks good to me. Just minor comments below: > diff --git a/drivers/powercap/intel_rapl.c b/drivers/powercap/intel_rapl.c > index cc97f08..f765b2c 100644 > --- a/drivers/powercap/intel_rapl.c > +++ b/drivers/powercap/intel_rapl.c > @@ -493,13 +493,42 @@ static int get_current_power_limit(struct powercap_zone > *power_zone, int id, > return ret; > } > > +static int get_max_time_window(struct powercap_zone *power_zone, int id, The 2nd arg "id" is not necessary. > +u64 *data) > +{ > + struct rapl_domain *rd; > + int ret = 0; > + u64 val; > + > + get_online_cpus(); > + rd = power_zone_to_rapl_domain(power_zone); > + > + if (rapl_read_data_raw(rd, MAX_TIME_WINDOW, true, )) rapl_read_data_raw() can return -EINVAL and -ENODEV other than -EIO. > + ret = -EIO; Is it OK to limit ret to -EIO here? > + else > + *data = val; > + > + put_online_cpus(); > + return ret; > +} > + > static int set_time_window(struct powercap_zone *power_zone, int id, > u64 window) > { > struct rapl_domain *rd; > int ret = 0; > + u64 max_window; > > get_online_cpus(); > + ret = get_max_time_window(power_zone, id, _window); > + if (ret < 0) > + goto out; > + > + if (window > max_window) { > + ret = -EINVAL; > + goto out; > + } > + > rd = power_zone_to_rapl_domain(power_zone); > switch (rd->rpl[id].prim_id) { > case PL1_ENABLE: > @@ -511,6 +540,7 @@ static int set_time_window(struct powercap_zone > *power_zone, int id, > default: > ret = -EINVAL; > } > +out: > put_online_cpus(); > return ret; > } > @@ -590,6 +620,7 @@ static struct powercap_zone_constraint_ops constraint_ops > = { > .set_time_window_us = set_time_window, > .get_time_window_us = get_time_window, > .get_max_power_uw = get_max_power, > + .get_max_time_window_us = get_max_time_window, > .get_name = get_constraint_name, > }; > > diff --git a/drivers/powercap/powercap_sys.c b/drivers/powercap/powercap_sys.c > index 84419af..7d77b83 100644 > --- a/drivers/powercap/powercap_sys.c > +++ b/drivers/powercap/powercap_sys.c > @@ -101,7 +101,7 @@ static ssize_t store_constraint_##_attr(struct device > *dev,\ > int err; \ > u64 value; \ > struct powercap_zone *power_zone = to_powercap_zone(dev); \ > - int id; \ > + int id, ret; \ > struct powercap_zone_constraint *pconst;\ > \ > if (!sscanf(dev_attr->attr.name, "constraint_%d_", )) \ > @@ -113,8 +113,10 @@ static ssize_t store_constraint_##_attr(struct device > *dev,\ > if (err) \ > return -EINVAL; \ > if (pconst && pconst->ops && pconst->ops->set_##_attr) { \ > - if (!pconst->ops->set_##_attr(power_zone, id, value)) \ > + ret = pconst->ops->set_##_attr(power_zone, id, value); \ > + if (!ret) \ > return count; \ > + return ret; \ An opposite question to above. Is it OK not to limit the return value to -EINVAL here? Do you want this function to return -EIO or something? > } \ > \ > return -ENODATA; \ > -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH 1/3] powercap, intel_rapl, implement get_max_time_window
On 2015-12-15 22:02, Prarit Bhargava wrote: > The MSR_PKG_POWER_INFO register (Intel ASDM, section 14.9.3 > "Package RAPL Domain") provides a maximum time window which the > system can support. This window is read-only and is currently > not examined when setting the time windows for the package. I have been having a question here long time. Maximum Time Window (bits 53:48) in MSR_PKG_POWER_INFO is only 6-bit length even though Time Window for Power Limit #1 (bits 23:17) and Time Window for Power Limit #2 (bits 55:49) in MSR_PKG_POWER_LIMIT are both 7-bit length, not 6. Do Intel guys have an answer for it? The patch itself looks good to me. Just minor comments below: > diff --git a/drivers/powercap/intel_rapl.c b/drivers/powercap/intel_rapl.c > index cc97f08..f765b2c 100644 > --- a/drivers/powercap/intel_rapl.c > +++ b/drivers/powercap/intel_rapl.c > @@ -493,13 +493,42 @@ static int get_current_power_limit(struct powercap_zone > *power_zone, int id, > return ret; > } > > +static int get_max_time_window(struct powercap_zone *power_zone, int id, The 2nd arg "id" is not necessary. > +u64 *data) > +{ > + struct rapl_domain *rd; > + int ret = 0; > + u64 val; > + > + get_online_cpus(); > + rd = power_zone_to_rapl_domain(power_zone); > + > + if (rapl_read_data_raw(rd, MAX_TIME_WINDOW, true, )) rapl_read_data_raw() can return -EINVAL and -ENODEV other than -EIO. > + ret = -EIO; Is it OK to limit ret to -EIO here? > + else > + *data = val; > + > + put_online_cpus(); > + return ret; > +} > + > static int set_time_window(struct powercap_zone *power_zone, int id, > u64 window) > { > struct rapl_domain *rd; > int ret = 0; > + u64 max_window; > > get_online_cpus(); > + ret = get_max_time_window(power_zone, id, _window); > + if (ret < 0) > + goto out; > + > + if (window > max_window) { > + ret = -EINVAL; > + goto out; > + } > + > rd = power_zone_to_rapl_domain(power_zone); > switch (rd->rpl[id].prim_id) { > case PL1_ENABLE: > @@ -511,6 +540,7 @@ static int set_time_window(struct powercap_zone > *power_zone, int id, > default: > ret = -EINVAL; > } > +out: > put_online_cpus(); > return ret; > } > @@ -590,6 +620,7 @@ static struct powercap_zone_constraint_ops constraint_ops > = { > .set_time_window_us = set_time_window, > .get_time_window_us = get_time_window, > .get_max_power_uw = get_max_power, > + .get_max_time_window_us = get_max_time_window, > .get_name = get_constraint_name, > }; > > diff --git a/drivers/powercap/powercap_sys.c b/drivers/powercap/powercap_sys.c > index 84419af..7d77b83 100644 > --- a/drivers/powercap/powercap_sys.c > +++ b/drivers/powercap/powercap_sys.c > @@ -101,7 +101,7 @@ static ssize_t store_constraint_##_attr(struct device > *dev,\ > int err; \ > u64 value; \ > struct powercap_zone *power_zone = to_powercap_zone(dev); \ > - int id; \ > + int id, ret; \ > struct powercap_zone_constraint *pconst;\ > \ > if (!sscanf(dev_attr->attr.name, "constraint_%d_", )) \ > @@ -113,8 +113,10 @@ static ssize_t store_constraint_##_attr(struct device > *dev,\ > if (err) \ > return -EINVAL; \ > if (pconst && pconst->ops && pconst->ops->set_##_attr) { \ > - if (!pconst->ops->set_##_attr(power_zone, id, value)) \ > + ret = pconst->ops->set_##_attr(power_zone, id, value); \ > + if (!ret) \ > return count; \ > + return ret; \ An opposite question to above. Is it OK not to limit the return value to -EINVAL here? Do you want this function to return -EIO or something? > } \ > \ > return -ENODATA; \ > -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[PATCH 1/3] powercap, intel_rapl, implement get_max_time_window
The MSR_PKG_POWER_INFO register (Intel ASDM, section 14.9.3 "Package RAPL Domain") provides a maximum time window which the system can support. This window is read-only and is currently not examined when setting the time windows for the package. This patch implements get_max_time_window_us() and checks the window when a user attempts to set power capping for the package. Before the patch it was possible to set the window to, for example, 1 micro seconds: [root@intel-chiefriver-03 rhel7]# echo 1 > /sys/devices/virtual/powercap/intel-rapl/intel-rapl\:0/constraint_0_time_window_us; egrep ^ /sys/devices/virtual/powercap/intel-rapl/intel-rapl\:0/constraint_0_time_window_us /sys/devices/virtual/powercap/intel-rapl/intel-rapl:0/constraint_0_time_window_us:1:9765 but from 'turbostat -d', the package is limited to 976us: cpu0: MSR_PKG_POWER_INFO: 0x01200168 (45 W TDP, RAPL 36 - 0 W, 0.000977 sec.) (Note, there appears to be a rounding issue in turbostat which needs to also be fixed. Looking at the values in the register it is clear the value is 1/1024 = 976us.) After the patch we are limited by the maximum time window: [root@intel-chiefriver-03 rhel7]# echo 1 > /sys/devices/virtual/powercap/intel-rapl/intel-rapl\:0/constraint_0_time_window_us; egrep ^ /sys/devices/virtual/powercap/intel-rapl/intel-rapl\:0/constraint_0_time_window_us -bash: echo: write error: Invalid argument /sys/devices/virtual/powercap/intel-rapl/intel-rapl:0/constraint_0_time_window_us:1:976 Cc: "Rafael J. Wysocki" Cc: Prarit Bhargava Cc: Radivoje Jovanovic Cc: Seiichi Ikarashi Cc: Mathias Krause Cc: Ajay Thomas Signed-off-by: Prarit Bhargava --- drivers/powercap/intel_rapl.c | 31 +++ drivers/powercap/powercap_sys.c |6 -- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/drivers/powercap/intel_rapl.c b/drivers/powercap/intel_rapl.c index cc97f08..f765b2c 100644 --- a/drivers/powercap/intel_rapl.c +++ b/drivers/powercap/intel_rapl.c @@ -493,13 +493,42 @@ static int get_current_power_limit(struct powercap_zone *power_zone, int id, return ret; } +static int get_max_time_window(struct powercap_zone *power_zone, int id, + u64 *data) +{ + struct rapl_domain *rd; + int ret = 0; + u64 val; + + get_online_cpus(); + rd = power_zone_to_rapl_domain(power_zone); + + if (rapl_read_data_raw(rd, MAX_TIME_WINDOW, true, )) + ret = -EIO; + else + *data = val; + + put_online_cpus(); + return ret; +} + static int set_time_window(struct powercap_zone *power_zone, int id, u64 window) { struct rapl_domain *rd; int ret = 0; + u64 max_window; get_online_cpus(); + ret = get_max_time_window(power_zone, id, _window); + if (ret < 0) + goto out; + + if (window > max_window) { + ret = -EINVAL; + goto out; + } + rd = power_zone_to_rapl_domain(power_zone); switch (rd->rpl[id].prim_id) { case PL1_ENABLE: @@ -511,6 +540,7 @@ static int set_time_window(struct powercap_zone *power_zone, int id, default: ret = -EINVAL; } +out: put_online_cpus(); return ret; } @@ -590,6 +620,7 @@ static struct powercap_zone_constraint_ops constraint_ops = { .set_time_window_us = set_time_window, .get_time_window_us = get_time_window, .get_max_power_uw = get_max_power, + .get_max_time_window_us = get_max_time_window, .get_name = get_constraint_name, }; diff --git a/drivers/powercap/powercap_sys.c b/drivers/powercap/powercap_sys.c index 84419af..7d77b83 100644 --- a/drivers/powercap/powercap_sys.c +++ b/drivers/powercap/powercap_sys.c @@ -101,7 +101,7 @@ static ssize_t store_constraint_##_attr(struct device *dev,\ int err; \ u64 value; \ struct powercap_zone *power_zone = to_powercap_zone(dev); \ - int id; \ + int id, ret; \ struct powercap_zone_constraint *pconst;\ \ if (!sscanf(dev_attr->attr.name, "constraint_%d_", )) \ @@ -113,8 +113,10 @@ static ssize_t store_constraint_##_attr(struct device *dev,\ if (err) \ return -EINVAL; \ if (pconst && pconst->ops && pconst->ops->set_##_attr) { \ - if (!pconst->ops->set_##_attr(power_zone, id, value)) \ + ret = pconst->ops->set_##_attr(power_zone, id, value); \ + if (!ret) \ return count; \ + return ret; \ } \ \ return -ENODATA; \ -- 1.7.9.3 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at
[PATCH 1/3] powercap, intel_rapl, implement get_max_time_window
The MSR_PKG_POWER_INFO register (Intel ASDM, section 14.9.3 "Package RAPL Domain") provides a maximum time window which the system can support. This window is read-only and is currently not examined when setting the time windows for the package. This patch implements get_max_time_window_us() and checks the window when a user attempts to set power capping for the package. Before the patch it was possible to set the window to, for example, 1 micro seconds: [root@intel-chiefriver-03 rhel7]# echo 1 > /sys/devices/virtual/powercap/intel-rapl/intel-rapl\:0/constraint_0_time_window_us; egrep ^ /sys/devices/virtual/powercap/intel-rapl/intel-rapl\:0/constraint_0_time_window_us /sys/devices/virtual/powercap/intel-rapl/intel-rapl:0/constraint_0_time_window_us:1:9765 but from 'turbostat -d', the package is limited to 976us: cpu0: MSR_PKG_POWER_INFO: 0x01200168 (45 W TDP, RAPL 36 - 0 W, 0.000977 sec.) (Note, there appears to be a rounding issue in turbostat which needs to also be fixed. Looking at the values in the register it is clear the value is 1/1024 = 976us.) After the patch we are limited by the maximum time window: [root@intel-chiefriver-03 rhel7]# echo 1 > /sys/devices/virtual/powercap/intel-rapl/intel-rapl\:0/constraint_0_time_window_us; egrep ^ /sys/devices/virtual/powercap/intel-rapl/intel-rapl\:0/constraint_0_time_window_us -bash: echo: write error: Invalid argument /sys/devices/virtual/powercap/intel-rapl/intel-rapl:0/constraint_0_time_window_us:1:976 Cc: "Rafael J. Wysocki"Cc: Prarit Bhargava Cc: Radivoje Jovanovic Cc: Seiichi Ikarashi Cc: Mathias Krause Cc: Ajay Thomas Signed-off-by: Prarit Bhargava --- drivers/powercap/intel_rapl.c | 31 +++ drivers/powercap/powercap_sys.c |6 -- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/drivers/powercap/intel_rapl.c b/drivers/powercap/intel_rapl.c index cc97f08..f765b2c 100644 --- a/drivers/powercap/intel_rapl.c +++ b/drivers/powercap/intel_rapl.c @@ -493,13 +493,42 @@ static int get_current_power_limit(struct powercap_zone *power_zone, int id, return ret; } +static int get_max_time_window(struct powercap_zone *power_zone, int id, + u64 *data) +{ + struct rapl_domain *rd; + int ret = 0; + u64 val; + + get_online_cpus(); + rd = power_zone_to_rapl_domain(power_zone); + + if (rapl_read_data_raw(rd, MAX_TIME_WINDOW, true, )) + ret = -EIO; + else + *data = val; + + put_online_cpus(); + return ret; +} + static int set_time_window(struct powercap_zone *power_zone, int id, u64 window) { struct rapl_domain *rd; int ret = 0; + u64 max_window; get_online_cpus(); + ret = get_max_time_window(power_zone, id, _window); + if (ret < 0) + goto out; + + if (window > max_window) { + ret = -EINVAL; + goto out; + } + rd = power_zone_to_rapl_domain(power_zone); switch (rd->rpl[id].prim_id) { case PL1_ENABLE: @@ -511,6 +540,7 @@ static int set_time_window(struct powercap_zone *power_zone, int id, default: ret = -EINVAL; } +out: put_online_cpus(); return ret; } @@ -590,6 +620,7 @@ static struct powercap_zone_constraint_ops constraint_ops = { .set_time_window_us = set_time_window, .get_time_window_us = get_time_window, .get_max_power_uw = get_max_power, + .get_max_time_window_us = get_max_time_window, .get_name = get_constraint_name, }; diff --git a/drivers/powercap/powercap_sys.c b/drivers/powercap/powercap_sys.c index 84419af..7d77b83 100644 --- a/drivers/powercap/powercap_sys.c +++ b/drivers/powercap/powercap_sys.c @@ -101,7 +101,7 @@ static ssize_t store_constraint_##_attr(struct device *dev,\ int err; \ u64 value; \ struct powercap_zone *power_zone = to_powercap_zone(dev); \ - int id; \ + int id, ret; \ struct powercap_zone_constraint *pconst;\ \ if (!sscanf(dev_attr->attr.name, "constraint_%d_", )) \ @@ -113,8 +113,10 @@ static ssize_t store_constraint_##_attr(struct device *dev,\ if (err) \ return -EINVAL; \ if (pconst && pconst->ops && pconst->ops->set_##_attr) { \ - if (!pconst->ops->set_##_attr(power_zone, id, value)) \ + ret = pconst->ops->set_##_attr(power_zone, id, value); \ + if (!ret) \ return count; \ + return ret; \ } \ \ return -ENODATA; \ -- 1.7.9.3 -- To unsubscribe from this list: send the line