Skip to contentSkip to conversation

drm/i915: add rc6 residency times to debugfs

PATCH Superseded Ben Widawsky 2 participants 12 messages Mar 25, 2012 – Mar 29, 2012

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 drm/i915: add rc6 residency times to debugfs

RC6 residency should be in intervals of 1.28us, and the counter wraps. Here is an example using awk to get the various RC6 and RC6+ residency times in seconds, since boot.

cat /sys/kernel/debug/dri/0/i915_drpc_info | grep residency | awk -F':' -F' ' '{print $5 * 1.28 / 1000000}'

This is primarily for QA, but has other applications as well. An upcoming patch to add interfaces should be more interesting to application developers.

---
 drivers/gpu/drm/i915/i915_debugfs.c |   11 +++++++++++
 drivers/gpu/drm/i915/i915_reg.h     |    5 +++++
 2 files changed, 16 insertions(+)
drivers/gpu/drm/i915/i915_debugfs.c +11 -0
index 66c90d4..72457ff 100644
@@ -1133,6 +1133,17 @@ static int gen6_drpc_info(struct seq_file *m)
 
 	seq_printf(m, "Core Power Down: %s\n",
 		   yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
+
+	seq_printf(m, "RC6 \"Locked to RPn\" residency since boot: %d\n",
+		   I915_READ(GEN6_GT_GFX_RC6_LOCKED));
+	/* Not exactly sure what this is */
+	seq_printf(m, "RC6 residency since boot: %d\n",
+		   I915_READ(GEN6_GT_GFX_RC6));
+	seq_printf(m, "RC6+ residency since boot: %d\n",
+		   I915_READ(GEN6_GT_GFX_RC6p));
+	seq_printf(m, "RC6++ residency since boot: %d\n",
+		   I915_READ(GEN6_GT_GFX_RC6pp));
+
 	return 0;
 }
 
drivers/gpu/drm/i915/i915_reg.h +5 -0
index f3609f2..b1c3d35 100644
@@ -3799,6 +3799,11 @@
 						 GEN6_PM_RP_DOWN_THRESHOLD | \
 						 GEN6_PM_RP_DOWN_TIMEOUT)
 
+#define GEN6_GT_GFX_RC6_LOCKED			0x138104
+#define GEN6_GT_GFX_RC6				0x138108
+#define GEN6_GT_GFX_RC6p			0x13810C
+#define GEN6_GT_GFX_RC6pp			0x138110
+
 #define GEN6_PCODE_MAILBOX			0x138124
 #define   GEN6_PCODE_READY			(1<<31)
 #define   GEN6_READ_OC_PARAMS			0xc
Signature · 1 line
1.7.9.4
#1 lore raw

PATCH 2/3 drm/i915: extract intel_enable_rc6()

nice to have elsewhere

CC Eugeni Dodonov <[email protected]>
---
 drivers/gpu/drm/i915/i915_drv.h      |    1 +
 drivers/gpu/drm/i915/intel_display.c |    2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_drv.h +1 -0
index bbbc1a4..22ab4db 100644
@@ -1414,6 +1414,7 @@ extern void ironlake_enable_rc6(struct drm_device *dev);
 extern void gen6_set_rps(struct drm_device *dev, u8 val);
 extern void intel_detect_pch(struct drm_device *dev);
 extern int intel_trans_dp_port_sel(struct drm_crtc *crtc);
+extern int intel_enable_rc6(const struct drm_device *dev);
 
 extern void __gen6_gt_force_wake_get(struct drm_i915_private *dev_priv);
 extern void __gen6_gt_force_wake_mt_get(struct drm_i915_private *dev_priv);
drivers/gpu/drm/i915/intel_display.c +1 -1
index ab62c96..efbf709 100644
@@ -8235,7 +8235,7 @@ void intel_init_emon(struct drm_device *dev)
 	dev_priv->corr = (lcfuse & LCFUSE_HIV_MASK);
 }
 
-static int intel_enable_rc6(struct drm_device *dev)
+int intel_enable_rc6(const struct drm_device *dev)
 {
 	/*
 	 * Respect the kernel parameter if it is set
Signature · 1 line
1.7.9.4
#2 lore raw

Re: [PATCH 2/3] drm/i915: extract intel_enable_rc6()

Quoted 4 lines · Ben Widawsky

nice to have elsewhere

CC Eugeni Dodonov <[email protected]>

I was momentarily confused with this commit message, until I've noticed that you need this in the next patch (I've assumed Eugeni needs to for something). So please slightly elaborate on the reasons for this.

Also I've wondered whether we shouldn't filter the individual rc6 levels? Or are all counters sane once you enable at least one of the rc6 levels? -Daniel

Quoted 37 lines
---
 drivers/gpu/drm/i915/i915_drv.h      |    1 +
 drivers/gpu/drm/i915/intel_display.c |    2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_drv.h +1 -0
index bbbc1a4..22ab4db 100644
@@ -1414,6 +1414,7 @@ extern void ironlake_enable_rc6(struct drm_device *dev);
 extern void gen6_set_rps(struct drm_device *dev, u8 val);
 extern void intel_detect_pch(struct drm_device *dev);
 extern int intel_trans_dp_port_sel(struct drm_crtc *crtc);
+extern int intel_enable_rc6(const struct drm_device *dev);
 
 extern void __gen6_gt_force_wake_get(struct drm_i915_private *dev_priv);
 extern void __gen6_gt_force_wake_mt_get(struct drm_i915_private *dev_priv);
drivers/gpu/drm/i915/intel_display.c +1 -1
index ab62c96..efbf709 100644
@@ -8235,7 +8235,7 @@ void intel_init_emon(struct drm_device *dev)
 	dev_priv->corr = (lcfuse & LCFUSE_HIV_MASK);
 }
 
-static int intel_enable_rc6(struct drm_device *dev)
+int intel_enable_rc6(const struct drm_device *dev)
 {
 	/*
 	 * Respect the kernel parameter if it is set
Signature · 6 lines
1.7.9.4

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 3 lines
Daniel Vetter
Mail: [email protected]
Mobile: +41 (0)79 365 57 48
#3 lore raw

Re: [PATCH 2/3] drm/i915: extract intel_enable_rc6()

Quoted 6 lines · On Sun, 25 Mar 2012 14:10:59 +0200 Daniel Vetter <[email protected]> wrote:
Quoted 4 lines · Ben Widawsky

nice to have elsewhere

CC Eugeni Dodonov <[email protected]>
Quoted 8 lines

I was momentarily confused with this commit message, until I've noticed that you need this in the next patch (I've assumed Eugeni needs to for something). So please slightly elaborate on the reasons for this.

Also I've wondered whether we shouldn't filter the individual rc6 levels? Or are all counters sane once you enable at least one of the rc6 levels? -Daniel

The only insane counter is rc6 (p and pp work as I would expect). Rc6 seems to always have some random value in it. Eugeni's theory is the BIOS initializes RC6 always, and that's where that value comes from.

The register is read only, unfortunately.

#4 lore raw

PATCH 3/3 drm/i915: rc6 in sysfs

In reply to Ben Widawsky

Merge rc6 information into the power group for our device. Until now the i915 driver has not had any sysfs entries (aside from the connector stuff enabled by libdrm). Since it seems like we're likely to have more in the future I created a new file for sysfs stubs, as well as the rc6 sysfs functions which don't really belong elsewhere (perhaps i915_suspend, but most of the stuff is in intel_display,c).

displays #ms GPU has been in rc6 since boot:
cat /sys/class/drm/card0/power/rc6

displays #ms GPU has been in deep rc6 since boot:
cat /sys/class/drm/card0/power/rc6p

displays #ms GPU has been in deepest rc6 since boot:
cat /sys/class/drm/card0/power/rc6pp

Important note: I've seen on SNB that even when RC6 is *not* enabled the rc6 register seems to have a random value in it. I cannot explain a reason for this. Those writing tools that utilize this value need to be careful and probably want to scrutinize the value very carefully.

Please see intel-gpu-tools patches for sample code.

CC Arjan van de Ven <[email protected]>
---
 drivers/gpu/drm/i915/Makefile       |    1 +
 drivers/gpu/drm/i915/i915_debugfs.c |    2 +-
 drivers/gpu/drm/i915/i915_dma.c     |    4 ++
 drivers/gpu/drm/i915/i915_drv.h     |    4 ++
 drivers/gpu/drm/i915/i915_sysfs.c   |  106 +++++++++++++++++++++++++++++++++++
 5 files changed, 116 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/i915/i915_sysfs.c
drivers/gpu/drm/i915/Makefile +1 -0
index ce7fc77..f801330 100644
@@ -12,6 +12,7 @@ i915-y := i915_drv.o i915_dma.o i915_irq.o \
 	  i915_gem_execbuffer.o \
 	  i915_gem_gtt.o \
 	  i915_gem_tiling.o \
+	  i915_sysfs.o \
 	  i915_trace_points.o \
 	  intel_display.o \
 	  intel_crt.o \
drivers/gpu/drm/i915/i915_debugfs.c +1 -1
index 72457ff..4257151 100644
@@ -1134,9 +1134,9 @@ static int gen6_drpc_info(struct seq_file *m)
 	seq_printf(m, "Core Power Down: %s\n",
 		   yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
 
+	/* Not exactly sure what this is */
 	seq_printf(m, "RC6 \"Locked to RPn\" residency since boot: %d\n",
 		   I915_READ(GEN6_GT_GFX_RC6_LOCKED));
-	/* Not exactly sure what this is */
 	seq_printf(m, "RC6 residency since boot: %d\n",
 		   I915_READ(GEN6_GT_GFX_RC6));
 	seq_printf(m, "RC6+ residency since boot: %d\n",
drivers/gpu/drm/i915/i915_dma.c +4 -0
index fdff009..64dfbb8 100644
@@ -2113,6 +2113,8 @@ int i915_driver_load(struct drm_device *dev, unsigned long flags)
 		}
 	}
 
+	i915_setup_sysfs(dev);
+
 	/* Must be done after probing outputs */
 	intel_opregion_init(dev);
 	acpi_video_register();
@@ -2164,6 +2166,8 @@ int i915_driver_unload(struct drm_device *dev)
 	i915_mch_dev = NULL;
 	spin_unlock(&mchdev_lock);
 
+	i915_teardown_sysfs(dev);
+
 	if (dev_priv->mm.inactive_shrinker.shrink)
 		unregister_shrinker(&dev_priv->mm.inactive_shrinker);
 
drivers/gpu/drm/i915/i915_drv.h +4 -0
index 22ab4db..e267774 100644
@@ -1365,6 +1365,10 @@ extern int i915_restore_state(struct drm_device *dev);
 extern int i915_save_state(struct drm_device *dev);
 extern int i915_restore_state(struct drm_device *dev);
 
+/* i915_sysfs.c */
+void i915_setup_sysfs(struct drm_device *dev_priv);
+void i915_teardown_sysfs(struct drm_device *dev_priv);
+
 /* intel_i2c.c */
 extern int intel_setup_gmbus(struct drm_device *dev);
 extern void intel_teardown_gmbus(struct drm_device *dev);
drivers/gpu/drm/i915/i915_sysfs.c new file +106 -0

106 lines not on this page · raw message

Signature · 6 lines
1.7.9.4

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#5 lore raw

Re: [PATCH 3/3] drm/i915: rc6 in sysfs

I sent stale patches, but this is the only one with a big effect. See inline for what's fixed, and feel free to review the rest.

Quoted 53 lines · On Sat, 24 Mar 2012 19:09:46 -0700 Ben Widawsky <[email protected]> wrote:

Merge rc6 information into the power group for our device. Until now the i915 driver has not had any sysfs entries (aside from the connector stuff enabled by libdrm). Since it seems like we're likely to have more in the future I created a new file for sysfs stubs, as well as the rc6 sysfs functions which don't really belong elsewhere (perhaps i915_suspend, but most of the stuff is in intel_display,c).

displays #ms GPU has been in rc6 since boot:
cat /sys/class/drm/card0/power/rc6

displays #ms GPU has been in deep rc6 since boot:
cat /sys/class/drm/card0/power/rc6p

displays #ms GPU has been in deepest rc6 since boot:
cat /sys/class/drm/card0/power/rc6pp

Important note: I've seen on SNB that even when RC6 is *not* enabled the rc6 register seems to have a random value in it. I cannot explain a reason for this. Those writing tools that utilize this value need to be careful and probably want to scrutinize the value very carefully.

Please see intel-gpu-tools patches for sample code.

CC Arjan van de Ven <[email protected]>
---
 drivers/gpu/drm/i915/Makefile       |    1 +
 drivers/gpu/drm/i915/i915_debugfs.c |    2 +-
 drivers/gpu/drm/i915/i915_dma.c     |    4 ++
 drivers/gpu/drm/i915/i915_drv.h     |    4 ++
 drivers/gpu/drm/i915/i915_sysfs.c   |  106

+++++++++++++++++++++++++++++++++++ 5 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/i915/i915_sysfs.c

(quoted diff) +0 -0

b/drivers/gpu/drm/i915/Makefile index ce7fc77..f801330 100644

drivers/gpu/drm/i915/Makefile +1 -0
@@ -12,6 +12,7 @@ i915-y := i915_drv.o i915_dma.o i915_irq.o \
 	  i915_gem_execbuffer.o \
 	  i915_gem_gtt.o \
 	  i915_gem_tiling.o \
+	  i915_sysfs.o \
 	  i915_trace_points.o \
 	  intel_display.o \
 	  intel_crt.o \
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/i915_debugfs.c index 72457ff..4257151 100644

drivers/gpu/drm/i915/i915_debugfs.c static int gen6_drpc_info(struct seq_file *m) · line 1142

Quoted 10 lines
drivers/gpu/drm/i915/i915_debugfs.c +1 -1
@@ -1134,9 +1134,9 @@ static int gen6_drpc_info(struct seq_file *m)
 	seq_printf(m, "Core Power Down: %s\n",
 		   yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
 
+	/* Not exactly sure what this is */
 	seq_printf(m, "RC6 \"Locked to RPn\" residency since boot:
 %d\n", I915_READ(GEN6_GT_GFX_RC6_LOCKED));
-	/* Not exactly sure what this is */
 	seq_printf(m, "RC6 residency since boot: %d\n",
 		   I915_READ(GEN6_GT_GFX_RC6));
 	seq_printf(m, "RC6+ residency since boot: %d\n",

This hunk should be rebased on patch 1... my bad. I'll fix after waiting on some review.

Quoted 131 lines
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/i915_dma.c index fdff009..64dfbb8 100644

drivers/gpu/drm/i915/i915_dma.c +4 -0
@@ -2113,6 +2113,8 @@ int i915_driver_load(struct drm_device *dev,
 unsigned long flags) }
 	}
 
+	i915_setup_sysfs(dev);
+
 	/* Must be done after probing outputs */
 	intel_opregion_init(dev);
 	acpi_video_register();
@@ -2164,6 +2166,8 @@ int i915_driver_unload(struct drm_device *dev)
 	i915_mch_dev = NULL;
 	spin_unlock(&mchdev_lock);
 
+	i915_teardown_sysfs(dev);
+
 	if (dev_priv->mm.inactive_shrinker.shrink)
 		unregister_shrinker(&dev_priv->mm.inactive_shrinker);
 
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/i915_drv.h index 22ab4db..e267774 100644

drivers/gpu/drm/i915/i915_drv.h +4 -0
@@ -1365,6 +1365,10 @@ extern int i915_restore_state(struct
 drm_device *dev); extern int i915_save_state(struct drm_device *dev);
 extern int i915_restore_state(struct drm_device *dev);
 
+/* i915_sysfs.c */
+void i915_setup_sysfs(struct drm_device *dev_priv);
+void i915_teardown_sysfs(struct drm_device *dev_priv);
+
 /* intel_i2c.c */
 extern int intel_setup_gmbus(struct drm_device *dev);
 extern void intel_teardown_gmbus(struct drm_device *dev);
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/i915_sysfs.c new file mode 100644 index 0000000..a18a955f

drivers/gpu/drm/i915/i915_sysfs.c new file +4 -0
@@ -0,0 +1,106 @@
+/*
+ * Copyright © 2012 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person

obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ * Authors:
+ * Ben Widawsky <[email protected]>
+ *
+ */

drivers/gpu/drm/i915/i915_sysfs.c new file +23 -0
+
+#include <linux/device.h>
+#include <linux/module.h>
+#include <linux/stat.h>
+#include <linux/sysfs.h>
+#include "i915_drv.h"
+
+static u32 calc_residency(struct drm_device *dev, const u32 reg)
+{
+	struct drm_i915_private *dev_priv = dev->dev_private;
+	u64 raw_time;
+	u32 residency;
+
+	if (!intel_enable_rc6(dev))
+		return 0;
+
+	raw_time = I915_READ(reg) * 128ULL;
+	residency = DIV_ROUND_CLOSEST(raw_time, 1000) / 100;
+	return residency;
+}
+
+static ssize_t
+show_rc6pp_ms(struct device *dev, struct device_attribute *attr,

char *buf) +{

drivers/gpu/drm/i915/i915_sysfs.c new file +1 -0
+	struct drm_minor *dminor = container_of(dev, struct

drm_minor, kdev);

drivers/gpu/drm/i915/i915_sysfs.c new file +1 -0
+	u32 rc6pp_residency = calc_residency(dminor->dev,

GEN6_GT_GFX_RC6pp);

drivers/gpu/drm/i915/i915_sysfs.c new file +5 -0
+	return snprintf(buf, PAGE_SIZE, "%u", rc6pp_residency);
+}
+
+static ssize_t
+show_rc6_ms(struct device *dev, struct device_attribute *attr, char

*buf) +{

drivers/gpu/drm/i915/i915_sysfs.c new file +1 -0
+	struct drm_minor *dminor = container_of(dev, struct

drm_minor, kdev);

drivers/gpu/drm/i915/i915_sysfs.c new file +9 -0
+	struct drm_i915_private *dev_priv = dminor->dev->dev_private;
+	/* 32b value may overflow during fixed point math */
+	u64 time = (I915_READ(GEN6_GT_GFX_RC6) * 128);
+	u32 rc6_residency = DIV_ROUND_CLOSEST(time, 1000) / 100;
+	return snprintf(buf, PAGE_SIZE, "%u", rc6_residency);
+}
+
+static ssize_t
+show_rc6p_ms(struct device *dev, struct device_attribute *attr, char

*buf) +{

drivers/gpu/drm/i915/i915_sysfs.c new file +1 -0
+	struct drm_minor *dminor = container_of(dev, struct

drm_minor, kdev);

drivers/gpu/drm/i915/i915_sysfs.c line 76

Quoted 6 lines
drivers/gpu/drm/i915/i915_sysfs.c new file +6 -0
+	struct drm_i915_private *dev_priv = dminor->dev->dev_private;
+	/* 32b value may overflow during fixed point math */
+	u64 time = (I915_READ(GEN6_GT_GFX_RC6p) * 128);
+	u32 rc6p_residency = DIV_ROUND_CLOSEST(time, 1000) / 100;
+	return snprintf(buf, PAGE_SIZE, "%u", rc6p_residency);
+}

These all use calc_residenc() in the newer patch. Again will wait on some review before fixing.

Quoted 30 lines
drivers/gpu/drm/i915/i915_sysfs.c new file +22 -0
+
+static DEVICE_ATTR(rc6, S_IRUGO, show_rc6_ms, NULL);
+static DEVICE_ATTR(rc6p, S_IRUGO, show_rc6p_ms, NULL);
+static DEVICE_ATTR(rc6pp, S_IRUGO, show_rc6pp_ms, NULL);
+
+static struct attribute *rc6_attrs[] = {
+	&dev_attr_rc6.attr,
+	&dev_attr_rc6p.attr,
+	&dev_attr_rc6pp.attr,
+	NULL
+};
+
+static struct attribute_group rc6_attr_group = {
+	.name = power_group_name,
+	.attrs =  rc6_attrs
+};
+
+void i915_setup_sysfs(struct drm_device *dev)
+{
+	int ret;
+
+	ret = sysfs_merge_group(&dev->primary->kdev.kobj,

&rc6_attr_group);

drivers/gpu/drm/i915/i915_sysfs.c new file +7 -0
+	if (ret)
+		DRM_ERROR("sysfs setup failed\n");
+}
+
+void i915_teardown_sysfs(struct drm_device *dev)
+{
+	sysfs_remove_group(&dev->primary->kdev.kobj,
Quoted 1 line

&rc6_attr_group); +}

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#6 lore raw

Re: [PATCH 3/3] drm/i915: rc6 in sysfs

In reply to Ben Widawsky
Quoted 21 lines · Ben Widawsky

Merge rc6 information into the power group for our device. Until now the i915 driver has not had any sysfs entries (aside from the connector stuff enabled by libdrm). Since it seems like we're likely to have more in the future I created a new file for sysfs stubs, as well as the rc6 sysfs functions which don't really belong elsewhere (perhaps i915_suspend, but most of the stuff is in intel_display,c).

displays #ms GPU has been in rc6 since boot:
cat /sys/class/drm/card0/power/rc6

displays #ms GPU has been in deep rc6 since boot:
cat /sys/class/drm/card0/power/rc6p

displays #ms GPU has been in deepest rc6 since boot:
cat /sys/class/drm/card0/power/rc6pp

Important note: I've seen on SNB that even when RC6 is *not* enabled the rc6 register seems to have a random value in it. I cannot explain a reason for this. Those writing tools that utilize this value need to be careful and probably want to scrutinize the value very carefully.

Quoted 4 lines

Please see intel-gpu-tools patches for sample code.

CC Arjan van de Ven <[email protected]>

I like this (with the cleanups you've mentioned). While you dig around in sysfs, can I volunteer you to add another patch to create an official interface for i915_max_freq? Maybe call it max_gpu_freq_MHz (if MHz is an acceptable unit for sysfs files). We have a bug report which might get partially happy with this (there seem to be other issues):

https://bugzilla.kernel.org/show_bug.cgi?id=41392a

Cheers, Daniel

Quoted 192 lines
---
 drivers/gpu/drm/i915/Makefile       |    1 +
 drivers/gpu/drm/i915/i915_debugfs.c |    2 +-
 drivers/gpu/drm/i915/i915_dma.c     |    4 ++
 drivers/gpu/drm/i915/i915_drv.h     |    4 ++
 drivers/gpu/drm/i915/i915_sysfs.c   |  106 +++++++++++++++++++++++++++++++++++
 5 files changed, 116 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/i915/i915_sysfs.c
drivers/gpu/drm/i915/Makefile +1 -0
index ce7fc77..f801330 100644
@@ -12,6 +12,7 @@ i915-y := i915_drv.o i915_dma.o i915_irq.o \
 	  i915_gem_execbuffer.o \
 	  i915_gem_gtt.o \
 	  i915_gem_tiling.o \
+	  i915_sysfs.o \
 	  i915_trace_points.o \
 	  intel_display.o \
 	  intel_crt.o \
drivers/gpu/drm/i915/i915_debugfs.c +1 -1
index 72457ff..4257151 100644
@@ -1134,9 +1134,9 @@ static int gen6_drpc_info(struct seq_file *m)
 	seq_printf(m, "Core Power Down: %s\n",
 		   yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
 
+	/* Not exactly sure what this is */
 	seq_printf(m, "RC6 \"Locked to RPn\" residency since boot: %d\n",
 		   I915_READ(GEN6_GT_GFX_RC6_LOCKED));
-	/* Not exactly sure what this is */
 	seq_printf(m, "RC6 residency since boot: %d\n",
 		   I915_READ(GEN6_GT_GFX_RC6));
 	seq_printf(m, "RC6+ residency since boot: %d\n",
drivers/gpu/drm/i915/i915_dma.c +4 -0
index fdff009..64dfbb8 100644
@@ -2113,6 +2113,8 @@ int i915_driver_load(struct drm_device *dev, unsigned long flags)
 		}
 	}
 
+	i915_setup_sysfs(dev);
+
 	/* Must be done after probing outputs */
 	intel_opregion_init(dev);
 	acpi_video_register();
@@ -2164,6 +2166,8 @@ int i915_driver_unload(struct drm_device *dev)
 	i915_mch_dev = NULL;
 	spin_unlock(&mchdev_lock);
 
+	i915_teardown_sysfs(dev);
+
 	if (dev_priv->mm.inactive_shrinker.shrink)
 		unregister_shrinker(&dev_priv->mm.inactive_shrinker);
 
drivers/gpu/drm/i915/i915_drv.h +4 -0
index 22ab4db..e267774 100644
@@ -1365,6 +1365,10 @@ extern int i915_restore_state(struct drm_device *dev);
 extern int i915_save_state(struct drm_device *dev);
 extern int i915_restore_state(struct drm_device *dev);
 
+/* i915_sysfs.c */
+void i915_setup_sysfs(struct drm_device *dev_priv);
+void i915_teardown_sysfs(struct drm_device *dev_priv);
+
 /* intel_i2c.c */
 extern int intel_setup_gmbus(struct drm_device *dev);
 extern void intel_teardown_gmbus(struct drm_device *dev);
drivers/gpu/drm/i915/i915_sysfs.c new file +106 -0
new file mode 100644
index 0000000..a18a955f
@@ -0,0 +1,106 @@
+/*
+ * Copyright © 2012 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Ben Widawsky <[email protected]>
+ *
+ */
+
+#include <linux/device.h>
+#include <linux/module.h>
+#include <linux/stat.h>
+#include <linux/sysfs.h>
+#include "i915_drv.h"
+
+static u32 calc_residency(struct drm_device *dev, const u32 reg)
+{
+	struct drm_i915_private *dev_priv = dev->dev_private;
+	u64 raw_time;
+	u32 residency;
+
+	if (!intel_enable_rc6(dev))
+		return 0;
+
+	raw_time = I915_READ(reg) * 128ULL;
+	residency = DIV_ROUND_CLOSEST(raw_time, 1000) / 100;
+	return residency;
+}
+
+static ssize_t
+show_rc6pp_ms(struct device *dev, struct device_attribute *attr, char *buf)
+{
+	struct drm_minor *dminor = container_of(dev, struct drm_minor, kdev);
+	u32 rc6pp_residency = calc_residency(dminor->dev, GEN6_GT_GFX_RC6pp);
+	return snprintf(buf, PAGE_SIZE, "%u", rc6pp_residency);
+}
+
+static ssize_t
+show_rc6_ms(struct device *dev, struct device_attribute *attr, char *buf)
+{
+	struct drm_minor *dminor = container_of(dev, struct drm_minor, kdev);
+	struct drm_i915_private *dev_priv = dminor->dev->dev_private;
+	/* 32b value may overflow during fixed point math */
+	u64 time = (I915_READ(GEN6_GT_GFX_RC6) * 128);
+	u32 rc6_residency = DIV_ROUND_CLOSEST(time, 1000) / 100;
+	return snprintf(buf, PAGE_SIZE, "%u", rc6_residency);
+}
+
+static ssize_t
+show_rc6p_ms(struct device *dev, struct device_attribute *attr, char *buf)
+{
+	struct drm_minor *dminor = container_of(dev, struct drm_minor, kdev);
+	struct drm_i915_private *dev_priv = dminor->dev->dev_private;
+	/* 32b value may overflow during fixed point math */
+	u64 time = (I915_READ(GEN6_GT_GFX_RC6p) * 128);
+	u32 rc6p_residency = DIV_ROUND_CLOSEST(time, 1000) / 100;
+	return snprintf(buf, PAGE_SIZE, "%u", rc6p_residency);
+}
+
+static DEVICE_ATTR(rc6, S_IRUGO, show_rc6_ms, NULL);
+static DEVICE_ATTR(rc6p, S_IRUGO, show_rc6p_ms, NULL);
+static DEVICE_ATTR(rc6pp, S_IRUGO, show_rc6pp_ms, NULL);
+
+static struct attribute *rc6_attrs[] = {
+	&dev_attr_rc6.attr,
+	&dev_attr_rc6p.attr,
+	&dev_attr_rc6pp.attr,
+	NULL
+};
+
+static struct attribute_group rc6_attr_group = {
+	.name = power_group_name,
+	.attrs =  rc6_attrs
+};
+
+void i915_setup_sysfs(struct drm_device *dev)
+{
+	int ret;
+
+	ret = sysfs_merge_group(&dev->primary->kdev.kobj, &rc6_attr_group);
+	if (ret)
+		DRM_ERROR("sysfs setup failed\n");
+}
+
+void i915_teardown_sysfs(struct drm_device *dev)
+{
+	sysfs_remove_group(&dev->primary->kdev.kobj, &rc6_attr_group);
+}
Signature · 6 lines
1.7.9.4

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 3 lines
Daniel Vetter
Mail: [email protected]
Mobile: +41 (0)79 365 57 48
#7 lore raw

Re: [PATCH 3/3] drm/i915: rc6 in sysfs

Quoted 36 lines · On Sun, 25 Mar 2012 14:15:56 +0200 Daniel Vetter <[email protected]> wrote:
Quoted 23 lines · Ben Widawsky

Merge rc6 information into the power group for our device. Until now the i915 driver has not had any sysfs entries (aside from the connector stuff enabled by libdrm). Since it seems like we're likely to have more in the future I created a new file for sysfs stubs, as well as the rc6 sysfs functions which don't really belong elsewhere (perhaps i915_suspend, but most of the stuff is in intel_display,c).

displays #ms GPU has been in rc6 since boot:
cat /sys/class/drm/card0/power/rc6

displays #ms GPU has been in deep rc6 since boot:
cat /sys/class/drm/card0/power/rc6p

displays #ms GPU has been in deepest rc6 since boot:
cat /sys/class/drm/card0/power/rc6pp

Important note: I've seen on SNB that even when RC6 is *not* enabled the rc6 register seems to have a random value in it. I cannot explain a reason for this. Those writing tools that utilize this value need to be careful and probably want to scrutinize the value very carefully.

Quoted 4 lines

Please see intel-gpu-tools patches for sample code.

CC Arjan van de Ven <[email protected]>

I like this (with the cleanups you've mentioned). While you dig around in sysfs, can I volunteer you to add another patch to create an official interface for i915_max_freq? Maybe call it max_gpu_freq_MHz (if MHz is an acceptable unit for sysfs files). We have a bug report which might get partially happy with this (there seem to be other issues):

Quoted 4 lines

https://bugzilla.kernel.org/show_bug.cgi?id=41392a

Cheers, Daniel

Yes. From looking at cpureq, it seems MHz is not standard. Simply writing the frequency as a number in the [m|b]illions is the way to go.

I'll get on this once I get an ack from you that you pick up the later versions of my sysfs stuff.

#8 lore raw

PATCH 1/2 build: make sure we have asprintf

In reply to Ben Widawsky
---
 configure.ac |    2 ++
 1 file changed, 2 insertions(+)
configure.ac +2 -0
index f778a9a..567f10d 100644
@@ -32,6 +32,7 @@ AC_CONFIG_MACRO_DIR([m4])
 AC_CONFIG_AUX_DIR([build-aux])
 AC_USE_SYSTEM_EXTENSIONS
 AC_SYS_LARGEFILE
+AC_GNU_SOURCE
 
 AM_INIT_AUTOMAKE([foreign dist-bzip2])
 AM_PATH_PYTHON([3],, [:])
@@ -43,6 +44,7 @@ AC_CHECK_MEMBERS([struct sysinfo.totalram],[],[],[AC_INCLUDES_DEFAULT
 #include <sys/sysinfo.h>
 ])
 AC_CHECK_FUNCS([swapctl])
+AC_CHECK_FUNCS([asprintf])
 
 # Initialize libtool
 AC_DISABLE_STATIC
Signature · 1 line
1.7.9.4
#9 lore raw

PATCH 2/2 tests: rc6 residency test

In reply to Ben Widawsky

This is meant to test the sysfs entry for showing rc6 residency in milliseconds. Remember, sysfs is a permanent interface.

---
 tests/Makefile.am     |    1 +
 tests/rc6_residency.c |   80 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 81 insertions(+)
 create mode 100644 tests/rc6_residency.c
tests/Makefile.am +1 -0
index 6544ec7..a8eed88 100644
@@ -56,6 +56,7 @@ TESTS_progs = \
 	drm_vma_limiter_cpu \
 	drm_vma_limiter_gtt \
 	drm_vma_limiter_cached \
+	rc6_residency \
 	$(NULL)
 
 # IMPORTANT: The ZZ_ tests need to be run last!
tests/rc6_residency.c new file +80 -0

80 lines not on this page · raw message

Signature · 6 lines
1.7.9.4

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#10 lore raw

Re: [PATCH 2/2] tests: rc6 residency test

Quoted 72 lines · Ben Widawsky

This is meant to test the sysfs entry for showing rc6 residency in milliseconds. Remember, sysfs is a permanent interface.

---
 tests/Makefile.am     |    1 +
 tests/rc6_residency.c |   80 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 81 insertions(+)
 create mode 100644 tests/rc6_residency.c
tests/Makefile.am +1 -0
index 6544ec7..a8eed88 100644
@@ -56,6 +56,7 @@ TESTS_progs = \
 	drm_vma_limiter_cpu \
 	drm_vma_limiter_gtt \
 	drm_vma_limiter_cached \
+	rc6_residency \
 	$(NULL)
 
 # IMPORTANT: The ZZ_ tests need to be run last!
tests/rc6_residency.c new file +44 -0
new file mode 100644
index 0000000..8ae6aa4
@@ -0,0 +1,80 @@
+/*
+ * Copyright © 2012 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Ben Widawsky <[email protected]>
+ *
+ */
+
+#include <stdlib.h>
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include "drmtest.h"
+
+static unsigned int readit(const char *path)
+{
+	unsigned int ret;
+
+	FILE *file;
+	file = fopen(path, "r");
+	if (file == NULL) {
+		fprintf(stderr, "Couldn't open %s (%d)\n", path, errno);
+		abort();
+	}

tests/rc6_residency.c line 54

Quoted 10 lines
tests/rc6_residency.c new file +10 -0
+	fscanf(file, "%u", &ret);
+	fclose(file);
+
+	return ret;
+}
+
+int main(int argc, char *argv[])
+{
+	/* TODO: don't always assume 0 */
+	const int device = 0;

Yeah, I'd like to have this, because I have machines with other gpus besides the intel one ;-)

tests/rc6_residency.c line 61

Quoted 7 lines
tests/rc6_residency.c new file +7 -0
+	char *path;
+	int fd, ret;
+	unsigned int value, value2;
+
+	/* Use drm_open_any to verify device existence */
+	fd = drm_open_any();
+	close(fd);

I think we want a gem_quiescent_gpu here to ensure things are _really_ idle.

Quoted 6 lines
tests/rc6_residency.c new file +6 -0
+
+	ret = asprintf(&path, "/sys/class/drm/card%d/power/rc6", device);
+	if (ret == -1 || ret < strlen("/sys/class/drm/card0/power/rc6"))
+		abort();
+
+	value = readit(path);

tests/rc6_residency.c line 77

Quoted 10 lines
tests/rc6_residency.c new file +10 -0
+
+	// Sleep for 3 seconds and compare
+	sleep(3);
+	value2 = readit(path);
+	free(path);
+
+	/* Plenty of fudge */
+	if (((value2 - value) > 3900) ||
+	    ((value2 - value) < 2100))
+		exit(EXIT_FAILURE);

Does that mean that rc6 residency is inclusive of lower-level rc6-resdidency? I.e. on ivb where we enable rc6p, does that include rc6p residency? Othwerwise I think we need to add rc6p and rc6pp in, too.

Cheers, Daniel

Quoted 10 lines
tests/rc6_residency.c new file +3 -0
+
+	exit(EXIT_SUCCESS);
+}
Signature · 6 lines
1.7.9.4

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 3 lines
Daniel Vetter
Mail: [email protected]
Mobile: +41 (0)79 365 57 48
#11 lore raw
In reply to Ben Widawsky
Quoted 32 lines · On Sat, 24 Mar 2012 19:09:44 -0700 Ben Widawsky <[email protected]> wrote:

RC6 residency should be in intervals of 1.28us, and the counter wraps. Here is an example using awk to get the various RC6 and RC6+ residency times in seconds, since boot.

cat /sys/kernel/debug/dri/0/i915_drpc_info | grep residency | awk -F':' -F' ' '{print $5 * 1.28 / 1000000}'

This is primarily for QA, but has other applications as well. An upcoming patch to add interfaces should be more interesting to application developers.

---
 drivers/gpu/drm/i915/i915_debugfs.c |   11 +++++++++++
 drivers/gpu/drm/i915/i915_reg.h     |    5 +++++
 2 files changed, 16 insertions(+)
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/i915_debugfs.c index 66c90d4..72457ff 100644

drivers/gpu/drm/i915/i915_debugfs.c +3 -0
@@ -1133,6 +1133,17 @@ static int gen6_drpc_info(struct seq_file *m)
 
 	seq_printf(m, "Core Power Down: %s\n",
 		   yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
+
+	seq_printf(m, "RC6 \"Locked to RPn\" residency since boot:
 %d\n",
+		   I915_READ(GEN6_GT_GFX_RC6_LOCKED));

drivers/gpu/drm/i915/i915_debugfs.c static int gen6_drpc_info(struct seq_file *m) · line 1149

Quoted 10 lines
drivers/gpu/drm/i915/i915_debugfs.c +8 -0
+	/* Not exactly sure what this is */
+	seq_printf(m, "RC6 residency since boot: %d\n",
+		   I915_READ(GEN6_GT_GFX_RC6));
+	seq_printf(m, "RC6+ residency since boot: %d\n",
+		   I915_READ(GEN6_GT_GFX_RC6p));
+	seq_printf(m, "RC6++ residency since boot: %d\n",
+		   I915_READ(GEN6_GT_GFX_RC6pp));
+
 	return 0;
 }

As noted in patch 3, this was a stale patch, and the comment belongs for the Locked to RPn.

Quoted 17 lines
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/i915_reg.h index f3609f2..b1c3d35 100644

drivers/gpu/drm/i915/i915_reg.h +5 -0
@@ -3799,6 +3799,11 @@
 						 GEN6_PM_RP_DOWN_THRESHOLD
 | \ GEN6_PM_RP_DOWN_TIMEOUT)
 
+#define GEN6_GT_GFX_RC6_LOCKED			0x138104
+#define GEN6_GT_GFX_RC6				0x138108
+#define GEN6_GT_GFX_RC6p			0x13810C
+#define GEN6_GT_GFX_RC6pp			0x138110
+
 #define GEN6_PCODE_MAILBOX			0x138124
 #define   GEN6_PCODE_READY			(1<<31)
 #define   GEN6_READ_OC_PARAMS			0xc