From patchwork Mon Mar 21 12:27:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prarit Bhargava X-Patchwork-Id: 8632301 Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id BA3FAC0553 for ; Mon, 21 Mar 2016 12:28:19 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B268D2017E for ; Mon, 21 Mar 2016 12:28:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B2AB520212 for ; Mon, 21 Mar 2016 12:28:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755811AbcCUM1o (ORCPT ); Mon, 21 Mar 2016 08:27:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:15456 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755572AbcCUM1W (ORCPT ); Mon, 21 Mar 2016 08:27:22 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 01BBA144185; Mon, 21 Mar 2016 12:27:22 +0000 (UTC) Received: from prarit.bos.redhat.com (prarit-guest.khw.lab.eng.bos.redhat.com [10.16.186.145]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u2LCRJla023265; Mon, 21 Mar 2016 08:27:21 -0400 From: Prarit Bhargava To: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Prarit Bhargava , "Rafael J. Wysocki" , Radivoje Jovanovic , Seiichi Ikarashi , Mathias Krause , Ajay Thomas Subject: [PATCH 1/3 v4] powercap, intel_rapl, implement get_max_time_window Date: Mon, 21 Mar 2016 08:27:14 -0400 Message-Id: <1458563236-19269-2-git-send-email-prarit@redhat.com> In-Reply-To: <1458563236-19269-1-git-send-email-prarit@redhat.com> References: <1458563236-19269-1-git-send-email-prarit@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 21 Mar 2016 12:27:22 +0000 (UTC) Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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, 10000 micro seconds: [root@intel-chiefriver-03 rhel7]# echo 10000 > /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 10000 > /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 6c592dc..feb063d 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, &val)) + 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, &max_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 const 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 14bde0d..53fad0f 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_", &id)) \ @@ -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; \