From: Ben Widawsky <ben@bwidawsk.net>
To: Jesse Barnes <jbarnes@virtuousgeek.org>
Cc: intel-gfx@lists.freedesktop.org
Subject: Re: [PATCH] drm/i915: expose energy counter on SNB and IVB
Date: Fri, 22 Jun 2012 19:04:29 -0700 [thread overview]
Message-ID: <20120622190429.63becd32@bwidawsk.net> (raw)
In-Reply-To: <1340228938-16489-1-git-send-email-jbarnes@virtuousgeek.org>
On Wed, 20 Jun 2012 14:48:58 -0700
Jesse Barnes <jbarnes@virtuousgeek.org> wrote:
> 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)
>
> Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
I have some complaints, and a bikeshed - but it's
Acked-by: Ben Widawsky <ben@bwidawsk.net>
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.
> ---
> drivers/gpu/drm/i915/i915_reg.h | 2 +
> drivers/gpu/drm/i915/i915_sysfs.c | 39 +++++++++++++++++++++++++++++++++++++
> 2 files changed, 41 insertions(+), 0 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/i915_reg.h b/drivers/gpu/drm/i915/i915_reg.h
> index 0a61481..ca6a620 100644
> --- a/drivers/gpu/drm/i915/i915_reg.h
> +++ b/drivers/gpu/drm/i915/i915_reg.h
> @@ -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?
> #define TSC1 0x11001
> #define TSE (1<<0)
> #define TR1 0x11006
> diff --git a/drivers/gpu/drm/i915/i915_sysfs.c b/drivers/gpu/drm/i915/i915_sysfs.c
> index 2f5388a..c7fe7bd 100644
> --- a/drivers/gpu/drm/i915/i915_sysfs.c
> +++ b/drivers/gpu/drm/i915/i915_sysfs.c
> @@ -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?
> +
> +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,
> +};
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.
> +
> +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,
> + >_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, >_attr_group);
> }
teardown should occur in reverse of init, so I'd put this on top.
--
Ben Widawsky, Intel Open Source Technology Center
next prev parent reply other threads:[~2012-06-23 2:06 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-20 21:48 [PATCH] drm/i915: expose energy counter on SNB and IVB Jesse Barnes
2012-06-23 2:04 ` Ben Widawsky [this message]
2012-06-24 10:01 ` Daniel Vetter
2012-06-24 23:13 ` Eugeni Dodonov
2012-06-24 23:06 ` Eugeni Dodonov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120622190429.63becd32@bwidawsk.net \
--to=ben@bwidawsk.net \
--cc=intel-gfx@lists.freedesktop.org \
--cc=jbarnes@virtuousgeek.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.