From patchwork Fri Jul 8 12:24:34 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konstantin Belousov X-Patchwork-Id: 956512 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p68CPTq1021977 for ; Fri, 8 Jul 2011 12:25:50 GMT Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id EA5CA9EF6D for ; Fri, 8 Jul 2011 05:25:28 -0700 (PDT) X-Original-To: Intel-gfx@lists.freedesktop.org Delivered-To: Intel-gfx@lists.freedesktop.org Received: from mail.zoral.com.ua (mx0.zoral.com.ua [91.193.166.200]) by gabe.freedesktop.org (Postfix) with ESMTP id 20E109E926 for ; Fri, 8 Jul 2011 05:24:43 -0700 (PDT) Received: from deviant.kiev.zoral.com.ua (root@deviant.kiev.zoral.com.ua [10.1.1.148]) by mail.zoral.com.ua (8.14.2/8.14.2) with ESMTP id p68COYPW078681 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 8 Jul 2011 15:24:34 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: from deviant.kiev.zoral.com.ua (kostik@localhost [127.0.0.1]) by deviant.kiev.zoral.com.ua (8.14.4/8.14.4) with ESMTP id p68COYZX049477; Fri, 8 Jul 2011 15:24:34 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: (from kostik@localhost) by deviant.kiev.zoral.com.ua (8.14.4/8.14.4/Submit) id p68COYfI049476; Fri, 8 Jul 2011 15:24:34 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: deviant.kiev.zoral.com.ua: kostik set sender to kostikbel@gmail.com using -f Date: Fri, 8 Jul 2011 15:24:34 +0300 From: Konstantin Belousov To: Chris Wilson Message-ID: <20110708122434.GW48734@deviant.kiev.zoral.com.ua> References: <20110708092651.GN48734@deviant.kiev.zoral.com.ua> Mime-Version: 1.0 In-Reply-To: User-Agent: Mutt/1.4.2.3i X-Virus-Scanned: clamav-milter 0.95.2 at skuns.kiev.zoral.com.ua X-Virus-Status: Clean X-Spam-Status: No, score=-3.3 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00, DNS_FROM_OPENWHOIS autolearn=no version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on skuns.kiev.zoral.com.ua Cc: Intel-gfx Subject: Re: [Intel-gfx] i915_chipset_val() X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: intel-gfx-bounces+patchwork-intel-gfx=patchwork.kernel.org@lists.freedesktop.org Errors-To: intel-gfx-bounces+patchwork-intel-gfx=patchwork.kernel.org@lists.freedesktop.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Fri, 08 Jul 2011 12:25:50 +0000 (UTC) On Fri, Jul 08, 2011 at 10:42:02AM +0100, Chris Wilson wrote: > On Fri, 8 Jul 2011 12:26:51 +0300, Konstantin Belousov wrote: > > i915_chipset_val saves the jiffies count of the invocation in last_time1. > > Then, on the next call, the diff between current jiffies value and > > last_time1 is used as divisor. > > > > I have a suspicious that two rapid calls to i915_chipset_val() may result > > in division by zero. This looks as user-controllable action, since > > debugfs, if configured, would export i915_chipset_val() as emon status. > > > > I did not tested the Linux, but in the (ported) code I am able to get > > into the described situation. As a workaround, I cached the previous > > return value from i915_chipset_val() and return it instead of doing > > the calculation if consequtive calls are close enough. > > > > What do you think ? (patch is not directly applicable to Linux). > > You're right. But I would go even further and say that if the difference > is less than say 10ms then we have not accumulated enough samples for the > calculation to be stable. > > > unsigned long i915_mch_val(struct drm_i915_private *dev_priv) > > diff --git a/sys/dev/drm/i915_drv.h b/sys/dev/drm/i915_drv.h > > index 5e6340b..36d066a 100644 > > --- a/sys/dev/drm/i915_drv.h > > +++ b/sys/dev/drm/i915_drv.h > > @@ -579,6 +579,7 @@ typedef struct drm_i915_private { > > > > u64 last_count1; > > unsigned long last_time1; > > + unsigned long last_chipset_val; > > u64 last_count2; > > struct timespec last_time2; > > unsigned long gfx_power; > > We need to thank Jesse for such informative variable names. Not even a > comment to mention that they are part of IPS. I agree, I did the following, relative to the previous patch diff --git a/sys/dev/drm/i915_dma.c b/sys/dev/drm/i915_dma.c index 773a171..07100f4 100644 --- a/sys/dev/drm/i915_dma.c +++ b/sys/dev/drm/i915_dma.c @@ -1592,9 +1592,9 @@ unsigned long i915_chipset_val(struct drm_i915_private *dev_priv) * sysctl(8) reads the value of sysctl twice in rapid * succession. There is high chance that it happens in the * same timer tick. Use the cached value to not divide by - * zero. + * zero and give the hw a chance to gather more samples. */ - if (diff1 == 0) + if (diff1 <= 10) return (dev_priv->last_chipset_val); count1 = I915_READ(DMIEC);