From patchwork Fri Mar 18 17:56:14 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jesse Barnes X-Patchwork-Id: 644611 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p2IIMCVp012120 for ; Fri, 18 Mar 2011 18:22:33 GMT Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E12E09F029 for ; Fri, 18 Mar 2011 10:57:02 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from cpoproxy2-pub.bluehost.com (cpoproxy2-pub.bluehost.com [67.222.39.38]) by gabe.freedesktop.org (Postfix) with SMTP id CF79E9EF5F for ; Fri, 18 Mar 2011 10:56:22 -0700 (PDT) Received: (qmail 27365 invoked by uid 0); 18 Mar 2011 17:56:22 -0000 Received: from unknown (HELO box514.bluehost.com) (74.220.219.114) by cpoproxy2.bluehost.com with SMTP; 18 Mar 2011 17:56:22 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=virtuousgeek.org; h=Received:From:To:Cc:Subject:Date:Message-Id:X-Mailer:X-Identified-User; b=pA4/mGzvCSs+UMTzBX75gfGTIYIjUvmvQLUPAJ8mP7B9fqcj+NIY4i+x3ykxY1PJ/LvLSrSTPE1JOA86wM0tSKqDx8MU/S+4of7pCfzuQk+l9hXuI9RazB+l3195zvnm; Received: from c-67-174-193-198.hsd1.ca.comcast.net ([67.174.193.198] helo=jbarnes-hp6360) by box514.bluehost.com with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.69) (envelope-from ) id 1Q0duP-0007y2-Ac; Fri, 18 Mar 2011 11:56:21 -0600 From: Jesse Barnes To: intel-gfx@lists.freedesktop.org Date: Fri, 18 Mar 2011 10:56:14 -0700 Message-Id: <1300470975-2521-1-git-send-email-jbarnes@virtuousgeek.org> X-Mailer: git-send-email 1.7.1 X-Identified-User: {10642:box514.bluehost.com:virtuous:virtuousgeek.org} {sentby:smtp auth 67.174.193.198 authed with jbarnes@virtuousgeek.org} Subject: [Intel-gfx] [PATCH 1/2] drm/i915: add SNB power monitoring 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: , MIME-Version: 1.0 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 (demeter1.kernel.org [140.211.167.41]); Fri, 18 Mar 2011 18:22:33 +0000 (UTC) diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c index d659f36..9094c71 100644 --- a/drivers/gpu/drm/i915/i915_debugfs.c +++ b/drivers/gpu/drm/i915/i915_debugfs.c @@ -1088,27 +1088,59 @@ static int i915_sr_status(struct seq_file *m, void *unused) return 0; } +/* Return current power draw in mW */ +static unsigned long i915_cur_power(struct drm_device *dev) +{ + drm_i915_private_t *dev_priv = dev->dev_private; + u32 pkg_power, units, tunit, eunit, punit; + unsigned long energy, time; + + units = I915_READ(GEN6_PKG_POWER_SKU_UNIT); + pkg_power = I915_READ(GEN6_PKG_ENERGY_STATUS); + + tunit = (units >> 16) & 0xf; /* 1s / 2^tunit */ + eunit = (units >> 8) & 0x1f; /* 1J / 2^enuit */ + punit = units & 0xf; /* 1W / 2^punit */ + + energy = pkg_power - dev_priv->last_pkg_power; + time = jiffies_to_msecs(jiffies) - dev_priv->last_pkg_power_time; + energy /= (1 << (eunit - 10)); + + dev_priv->last_pkg_power = pkg_power; + dev_priv->last_pkg_power_time = jiffies_to_msecs(jiffies); + + return (energy * 1000) / time; +} + static int i915_emon_status(struct seq_file *m, void *unused) { struct drm_info_node *node = (struct drm_info_node *) m->private; struct drm_device *dev = node->minor->dev; drm_i915_private_t *dev_priv = dev->dev_private; - unsigned long temp, chipset, gfx; int ret; ret = mutex_lock_interruptible(&dev->struct_mutex); if (ret) return ret; - temp = i915_mch_val(dev_priv); - chipset = i915_chipset_val(dev_priv); - gfx = i915_gfx_val(dev_priv); - mutex_unlock(&dev->struct_mutex); + if (IS_GEN5(dev)) { + unsigned long temp, chipset, gfx; + + temp = i915_mch_val(dev_priv); + chipset = i915_chipset_val(dev_priv); + gfx = i915_gfx_val(dev_priv); - seq_printf(m, "GMCH temp: %ld\n", temp); - seq_printf(m, "Chipset power: %ld\n", chipset); - seq_printf(m, "GFX power: %ld\n", gfx); - seq_printf(m, "Total power: %ld\n", chipset + gfx); + seq_printf(m, "GMCH temp: %ld\n", temp); + seq_printf(m, "Chipset power: %ld\n", chipset); + seq_printf(m, "GFX power: %ld\n", gfx); + seq_printf(m, "Total power: %ld\n", chipset + gfx); + } else if (IS_GEN6(dev)) { + unsigned long power = i915_cur_power(dev); + + trace_i915_pkg_power(power); + seq_printf(m, "Current power draw: %ldmW\n", power); + } + mutex_unlock(&dev->struct_mutex); return 0; } diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h index 3d4fd01..c8a21ce 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h @@ -697,6 +697,8 @@ typedef struct drm_i915_private { int r_t; u8 corr; spinlock_t *mchdev_lock; + u32 last_pkg_power; + unsigned long last_pkg_power_time; enum no_fbc_reason no_fbc_reason; diff --git a/drivers/gpu/drm/i915/i915_reg.h b/drivers/gpu/drm/i915/i915_reg.h index e1be98f..acf786c 100644 --- a/drivers/gpu/drm/i915/i915_reg.h +++ b/drivers/gpu/drm/i915/i915_reg.h @@ -1244,6 +1244,9 @@ #define GEN6_RP_STATE_LIMITS 0x145994 #define GEN6_RP_STATE_CAP 0x145998 +#define GEN6_PKG_POWER_SKU_UNIT 0x145938 +#define GEN6_PKG_ENERGY_STATUS 0x14593c + /* * Logical Context regs */ diff --git a/drivers/gpu/drm/i915/i915_trace.h b/drivers/gpu/drm/i915/i915_trace.h index d623fef..e102c76 100644 --- a/drivers/gpu/drm/i915/i915_trace.h +++ b/drivers/gpu/drm/i915/i915_trace.h @@ -410,6 +410,20 @@ TRACE_EVENT(i915_reg_rw, (u32)(__entry->val >> 32)) ); +TRACE_EVENT(i915_pkg_power, + TP_PROTO(unsigned long power), + TP_ARGS(power), + TP_STRUCT__entry( + __field(unsigned long, power) + ), + + TP_fast_assign( + __entry->power = power; + ), + + TP_printk("pkg power=%ld", __entry->power) +); + #endif /* _I915_TRACE_H_ */ /* This part must be outside protection */ diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c index f569841..6c7361e 100644 --- a/drivers/gpu/drm/i915/intel_display.c +++ b/drivers/gpu/drm/i915/intel_display.c @@ -6959,6 +6959,9 @@ void gen6_enable_rps(struct drm_i915_private *dev_priv) I915_WRITE(GEN6_PMINTRMSK, 0); __gen6_force_wake_put(dev_priv); + + dev_priv->last_pkg_power = I915_READ(GEN6_PKG_ENERGY_STATUS); + dev_priv->last_pkg_power_time = jiffies_to_msecs(jiffies); } void intel_enable_clock_gating(struct drm_device *dev)