Skip to contentSkip to conversation

drm/i915: expose energy counter on SNB and IVB

PATCH In review Jesse Barnes 4 participants 5 messages Jun 20, 2012 – Jun 24, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/i915: expose energy counter on SNB and IVB

On SNB and IVB, there's an MSR (also exposed through MCHBAR) we can use to read out the amount of energy used over time. Expose this in sysfs to make it easy to do power comparisons with different configurations.

If the platform supports it, the file will show up under the drm/card0/power subdirectory of the PCI device in sysfs as gt_energy_uJ. The value in the file is a running total of energy (in microjoules) consumed by the graphics device.

v2: move to sysfs (Ben, Daniel)
expose a simple value (Chris)
drop unrelated hunk (Ben)

---
 drivers/gpu/drm/i915/i915_reg.h   |    2 +
 drivers/gpu/drm/i915/i915_sysfs.c |   39 +++++++++++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+), 0 deletions(-)
drivers/gpu/drm/i915/i915_reg.h +2 -0
index 0a61481..ca6a620 100644
@@ -1224,6 +1224,8 @@
 #define CLKCFG_MEM_800					(3 << 4)
 #define CLKCFG_MEM_MASK					(7 << 4)
 
+#define SECP_NRG_STTS			(MCHBAR_MIRROR_BASE_SNB + 0x592c)
+
 #define TSC1			0x11001
 #define   TSE			(1<<0)
 #define TR1			0x11006
drivers/gpu/drm/i915/i915_sysfs.c +39 -0
index 2f5388a..c7fe7bd 100644
@@ -93,6 +93,37 @@ static struct attribute_group rc6_attr_group = {
 	.attrs =  rc6_attrs
 };
 
+#define MSR_IA32_PACKAGE_POWER_SKU_UNIT		0x00000606
+
+static ssize_t
+show_gt_energy_uJ(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;
+	u64 ppsu;
+	u32 val, units;
+
+	rdmsrl(MSR_IA32_PACKAGE_POWER_SKU_UNIT, ppsu);
+
+	ppsu = (ppsu & 0x1f00) >> 8;
+	units = 1000000 / (1 << ppsu); /* convert to uJ */
+	val = I915_READ(SECP_NRG_STTS);
+
+	return snprintf(buf, PAGE_SIZE, "%u", val * units);
+}
+
+static DEVICE_ATTR(gt_energy_uJ, S_IRUGO, show_gt_energy_uJ, NULL);
+
+static struct attribute *gt_attrs[] = {
+	&dev_attr_gt_energy_uJ.attr,
+	NULL,
+};
+
+static struct attribute_group gt_attr_group = {
+	.name = power_group_name,
+	.attrs = gt_attrs,
+};
+
 static int l3_access_valid(struct drm_device *dev, loff_t offset)
 {
 	if (!IS_IVYBRIDGE(dev))
@@ -217,10 +248,18 @@ void i915_setup_sysfs(struct drm_device *dev)
 		if (ret)
 			DRM_ERROR("l3 parity sysfs setup failed\n");
 	}
+
+	if (IS_GEN6(dev) || IS_IVYBRIDGE(dev)) {
+		ret = sysfs_merge_group(&dev->primary->kdev.kobj,
+					&gt_attr_group);
+		if (ret)
+			DRM_ERROR("GT energy sysfs setup failed\n");
+	}
 }
 
 void i915_teardown_sysfs(struct drm_device *dev)
 {
 	device_remove_bin_file(&dev->primary->kdev,  &dpf_attrs);
 	sysfs_unmerge_group(&dev->primary->kdev.kobj, &rc6_attr_group);
+	sysfs_unmerge_group(&dev->primary->kdev.kobj, &gt_attr_group);
 }
Signature · 1 line
1.7.4.1
Acked-by on v1 1/1
#1 lore raw
Quoted 9 lines · On Wed, 20 Jun 2012 14:48:58 -0700 Jesse Barnes <[email protected]>…

On SNB and IVB, there's an MSR (also exposed through MCHBAR) we can use to read out the amount of energy used over time. Expose this in sysfs to make it easy to do power comparisons with different configurations.

If the platform supports it, the file will show up under the drm/card0/power subdirectory of the PCI device in sysfs as gt_energy_uJ. The value in the file is a running total of energy (in microjoules) consumed by the graphics device.

Quoted 5 lines

v2: move to sysfs (Ben, Daniel)
expose a simple value (Chris)
drop unrelated hunk (Ben)

I have some complaints, and a bikeshed - but it's

either way.

And color-me-danvet, but I kind of get why review is so mean on ABI stuff.

I don't really care whether you address the other complaints, but I won't do a a proper reviewed-by until the doc complaints are addressed.

Quoted 10 lines
---
 drivers/gpu/drm/i915/i915_reg.h   |    2 +
 drivers/gpu/drm/i915/i915_sysfs.c |   39 +++++++++++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+), 0 deletions(-)
drivers/gpu/drm/i915/i915_reg.h +0 -0
index 0a61481..ca6a620 100644

drivers/gpu/drm/i915/i915_reg.h line 1228

Quoted 5 lines
drivers/gpu/drm/i915/i915_reg.h +2 -0
@@ -1224,6 +1224,8 @@
 #define CLKCFG_MEM_800					(3 << 4)
 #define CLKCFG_MEM_MASK					(7 << 4)
 
+#define SECP_NRG_STTS			(MCHBAR_MIRROR_BASE_SNB + 0x592c)
+

I can't find where this is defined, so it's hard to review. Could you please point me to the docs for this?

drivers/gpu/drm/i915/i915_sysfs.c static struct attribute_group rc6_attr_group = { · line 96

Quoted 12 lines
drivers/gpu/drm/i915/i915_reg.h +0 -0
 #define TSC1			0x11001
 #define   TSE			(1<<0)
 #define TR1			0x11006
drivers/gpu/drm/i915/i915_sysfs.c +1 -0
index 2f5388a..c7fe7bd 100644
@@ -93,6 +93,37 @@ static struct attribute_group rc6_attr_group = {
 	.attrs =  rc6_attrs
 };
 
+#define MSR_IA32_PACKAGE_POWER_SKU_UNIT		0x00000606

I honestly didn't try to look for this definition, but let's assume I can't find it. Where is this one?

Quoted 14 lines
drivers/gpu/drm/i915/i915_sysfs.c +14 -0
+
+static ssize_t
+show_gt_energy_uJ(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;
+	u64 ppsu;
+	u32 val, units;
+
+	rdmsrl(MSR_IA32_PACKAGE_POWER_SKU_UNIT, ppsu);
+
+	ppsu = (ppsu & 0x1f00) >> 8;
+	units = 1000000 / (1 << ppsu); /* convert to uJ */
+	val = I915_READ(SECP_NRG_STTS);

drivers/gpu/drm/i915/i915_sysfs.c static struct attribute_group rc6_attr_group = { · line 120

Quoted 10 lines
drivers/gpu/drm/i915/i915_sysfs.c +10 -0
+
+	return snprintf(buf, PAGE_SIZE, "%u", val * units);
+}
+
+static DEVICE_ATTR(gt_energy_uJ, S_IRUGO, show_gt_energy_uJ, NULL);
+
+static struct attribute *gt_attrs[] = {
+	&dev_attr_gt_energy_uJ.attr,
+	NULL,
+};

I think convention dictates it should be all lowercase. And while on that, gt_energy_uJ is about as descriptive a name as rc6 (what jerk named that anyway?). I think something like consumed_microjoules is better.

Quoted 18 lines
drivers/gpu/drm/i915/i915_sysfs.c +11 -0
+
+static struct attribute_group gt_attr_group = {
+	.name = power_group_name,
+	.attrs = gt_attrs,
+};
+
 static int l3_access_valid(struct drm_device *dev, loff_t offset)
 {
 	if (!IS_IVYBRIDGE(dev))
@@ -217,10 +248,18 @@ void i915_setup_sysfs(struct drm_device *dev)
 		if (ret)
 			DRM_ERROR("l3 parity sysfs setup failed\n");
 	}
+
+	if (IS_GEN6(dev) || IS_IVYBRIDGE(dev)) {
+		ret = sysfs_merge_group(&dev->primary->kdev.kobj,
+					&gt_attr_group);
+		if (ret)

drivers/gpu/drm/i915/i915_sysfs.c void i915_setup_sysfs(struct drm_device *dev) · line 265

Quoted 10 lines
drivers/gpu/drm/i915/i915_sysfs.c +3 -0
+			DRM_ERROR("GT energy sysfs setup failed\n");
+	}
 }
 
 void i915_teardown_sysfs(struct drm_device *dev)
 {
 	device_remove_bin_file(&dev->primary->kdev,  &dpf_attrs);
 	sysfs_unmerge_group(&dev->primary->kdev.kobj, &rc6_attr_group);
+	sysfs_unmerge_group(&dev->primary->kdev.kobj, &gt_attr_group);
 }

teardown should occur in reverse of init, so I'd put this on top.

Signature · 1 line
Ben Widawsky, Intel Open Source Technology Center
#2 lore raw
Quoted 11 lines · Ben Widawsky

drivers/gpu/drm/i915/i915_sysfs.c static struct attribute_group rc6_attr_group = { · line 120

Quoted 4 lines · On Wed, 20 Jun 2012 14:48:58 -0700 Jesse Barnes <[email protected]>…
drivers/gpu/drm/i915/i915_sysfs.c +4 -0
+static struct attribute *gt_attrs[] = {
+	&dev_attr_gt_energy_uJ.attr,
+	NULL,
+};

I think convention dictates it should be all lowercase. And while on that, gt_energy_uJ is about as descriptive a name as rc6 (what jerk named that anyway?). I think something like consumed_microjoules is better.

I admit that the uJ makes tons of sense for me - J is the official SI abbrev. for joules (I'm a bit unsure about u for \mu, but it seems to be customary). Adding consumed makes some sense I think, but otherwise it's imo good if we stick with the names vpg ppl have come up. So gt_consumed_energy_uJ anyone? I can bikeshed this name while applying ... -Daniel

Quoted 40 lines
Quoted 19 lines
drivers/gpu/drm/i915/i915_sysfs.c +11 -0
+
+static struct attribute_group gt_attr_group = {
+	.name = power_group_name,
+	.attrs = gt_attrs,
+};
+
 static int l3_access_valid(struct drm_device *dev, loff_t offset)
 {
 	if (!IS_IVYBRIDGE(dev))
@@ -217,10 +248,18 @@ void i915_setup_sysfs(struct drm_device *dev)
 		if (ret)
 			DRM_ERROR("l3 parity sysfs setup failed\n");
 	}
+
+	if (IS_GEN6(dev) || IS_IVYBRIDGE(dev)) {
+		ret = sysfs_merge_group(&dev->primary->kdev.kobj,
+					&gt_attr_group);
+		if (ret)

drivers/gpu/drm/i915/i915_sysfs.c void i915_setup_sysfs(struct drm_device *dev) · line 265

Quoted 10 lines
drivers/gpu/drm/i915/i915_sysfs.c +3 -0
+			DRM_ERROR("GT energy sysfs setup failed\n");
+	}
 }
 
 void i915_teardown_sysfs(struct drm_device *dev)
 {
 	device_remove_bin_file(&dev->primary->kdev,  &dpf_attrs);
 	sysfs_unmerge_group(&dev->primary->kdev.kobj, &rc6_attr_group);
+	sysfs_unmerge_group(&dev->primary->kdev.kobj, &gt_attr_group);
 }

teardown should occur in reverse of init, so I'd put this on top.

Signature · 5 lines
Ben Widawsky, Intel Open Source Technology Center
_______________________________________________
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
Quoted 13 lines · Daniel Vetter
Quoted 11 lines · Ben Widawsky

drivers/gpu/drm/i915/i915_sysfs.c static struct attribute_group rc6_attr_group = { · line 120

Quoted 4 lines · On Wed, 20 Jun 2012 14:48:58 -0700 Jesse Barnes <[email protected]>…
drivers/gpu/drm/i915/i915_sysfs.c +4 -0
+static struct attribute *gt_attrs[] = {
+	&dev_attr_gt_energy_uJ.attr,
+	NULL,
+};

I think convention dictates it should be all lowercase. And while on that, gt_energy_uJ is about as descriptive a name as rc6 (what jerk named that anyway?). I think something like consumed_microjoules is better.

Quoted 6 lines

I admit that the uJ makes tons of sense for me - J is the official SI abbrev. for joules (I'm a bit unsure about u for \mu, but it seems to be customary). Adding consumed makes some sense I think, but otherwise it's imo good if we stick with the names vpg ppl have come up. So gt_consumed_energy_uJ anyone? I can bikeshed this name while applying ... -Daniel

<bikeshed>
I'd vote for gt_energy or gt_consumed_energy, which would provide results in plain J instead of mJ or uJ. This would result in a smaller name + power readings which are standardized.
</bikeshed>

But if we settle on uJ values, gt_consumed_energy_uJ seems to be more self-explainable to me.

Eugeni

Reviewed-by on v1 1/1
#4 lore raw
In reply to Jesse Barnes
Quoted 9 lines · Jesse Barnes

On SNB and IVB, there's an MSR (also exposed through MCHBAR) we can use to read out the amount of energy used over time. Expose this in sysfs to make it easy to do power comparisons with different configurations.

If the platform supports it, the file will show up under the drm/card0/power subdirectory of the PCI device in sysfs as gt_energy_uJ. The value in the file is a running total of energy (in microjoules) consumed by the graphics device.

Quoted 5 lines

v2: move to sysfs (Ben, Daniel)
expose a simple value (Chris)
drop unrelated hunk (Ben)

(Assuming I haven't checked all the magic register values but I trust that they work):

Eugeni