From patchwork Mon Mar 21 12:27:15 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prarit Bhargava X-Patchwork-Id: 8632311 Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id A46459F294 for ; Mon, 21 Mar 2016 12:28:24 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B75A2202D1 for ; Mon, 21 Mar 2016 12:28:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BFAF02017E for ; Mon, 21 Mar 2016 12:28:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755609AbcCUM1n (ORCPT ); Mon, 21 Mar 2016 08:27:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58734 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755585AbcCUM1X (ORCPT ); Mon, 21 Mar 2016 08:27:23 -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 EFE5AC049E1B; 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 u2LCRJlb023265; Mon, 21 Mar 2016 08:27:22 -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 2/3 v4] powercap, intel_rapl, implement check for minimum time window Date: Mon, 21 Mar 2016 08:27:15 -0400 Message-Id: <1458563236-19269-3-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 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 Using an small value for the time window results in a bogus value for the time window. For example, [root@intel-chiefriver-03 linux]# echo 950 > /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:4501502475370496 The Intel ASDM doesn't explicitly define a minimum time window. The MSR_RAPL_POWER_UNIT register, read during initialization, does specify a minimum time window unit so that can be used as a lower bound for error checking. After this change the minimum time window is properly clamped: [root@intel-chiefriver-03 linux]# echo 950 > /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 | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/powercap/intel_rapl.c b/drivers/powercap/intel_rapl.c index feb063d..cf89b3d 100644 --- a/drivers/powercap/intel_rapl.c +++ b/drivers/powercap/intel_rapl.c @@ -516,6 +516,7 @@ static int set_time_window(struct powercap_zone *power_zone, int id, u64 window) { struct rapl_domain *rd; + struct rapl_package *rp; int ret = 0; u64 max_window; @@ -524,12 +525,18 @@ static int set_time_window(struct powercap_zone *power_zone, int id, if (ret < 0) goto out; - if (window > max_window) { + rd = power_zone_to_rapl_domain(power_zone); + rp = find_package_by_id(rd->package_id); + /* + * The Intel ASDM doesn't explicitly define a minimum time window. + * The MSR_RAPL_POWER_UNIT register, read during initialization, + * does contain the smallest unit of time that can be measured. + */ + if ((window > max_window) || (window < rp->time_unit)) { ret = -EINVAL; goto out; } - rd = power_zone_to_rapl_domain(power_zone); switch (rd->rpl[id].prim_id) { case PL1_ENABLE: rapl_write_data_raw(rd, TIME_WINDOW1, window);