From: Tvrtko Ursulin <tursulin@ursulin.net>
To: Intel-gfx@lists.freedesktop.org
Cc: Peter Zijlstra <peterz@infradead.org>
Subject: [RFC 08/11] drm/i915: Export engine busy stats in debugfs
Date: Mon, 11 Sep 2017 16:25:56 +0100 [thread overview]
Message-ID: <20170911152559.7077-9-tvrtko.ursulin@linux.intel.com> (raw)
In-Reply-To: <20170911152559.7077-1-tvrtko.ursulin@linux.intel.com>
From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Export the stats added in the previous patch in debugfs.
Number of active clients reading this data is tracked and the
static key is only enabled whilst there are some.
Userspace is intended to keep the file descriptor open, seeking
to the beginning of the file periodically, and re-reading the
stats.
This is because the underlying implementation is costly on every
first open/last close transition, and also, because the stats
exported mostly make sense when they are considered relative to
the previous sample.
File lists nanoseconds each engine was active since the tracking
has started.
v2: Rebase.
v3: Rebase.
Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
---
drivers/gpu/drm/i915/i915_debugfs.c | 92 +++++++++++++++++++++++++++++++++++++
1 file changed, 92 insertions(+)
diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
index 1fd777fb5e9e..4bb3970204a1 100644
--- a/drivers/gpu/drm/i915/i915_debugfs.c
+++ b/drivers/gpu/drm/i915/i915_debugfs.c
@@ -4811,6 +4811,92 @@ static const struct file_operations i915_hpd_storm_ctl_fops = {
.write = i915_hpd_storm_ctl_write
};
+struct i915_engine_stats_buf {
+ unsigned int len;
+ size_t available;
+ char buf[0];
+};
+
+static int i915_engine_stats_open(struct inode *inode, struct file *file)
+{
+ struct drm_i915_private *i915 = file->f_inode->i_private;
+ const unsigned int engine_name_len =
+ sizeof(((struct intel_engine_cs *)0)->name);
+ struct i915_engine_stats_buf *buf;
+ const unsigned int buf_size =
+ (engine_name_len + 2 + 19 + 1) * I915_NUM_ENGINES + 1 +
+ sizeof(*buf);
+ int ret;
+
+ buf = kzalloc(buf_size, GFP_KERNEL);
+ if (!buf)
+ return -ENOMEM;
+
+ ret = intel_enable_engines_stats(i915);
+ if (ret) {
+ kfree(buf);
+ return ret;
+ }
+
+ buf->len = buf_size;
+ file->private_data = buf;
+
+ return 0;
+}
+
+static int i915_engine_stats_release(struct inode *inode, struct file *file)
+{
+ struct drm_i915_private *i915 = file->f_inode->i_private;
+
+ intel_disable_engines_stats(i915);
+ kfree(file->private_data);
+
+ return 0;
+}
+
+static ssize_t i915_engine_stats_read(struct file *file, char __user *ubuf,
+ size_t count, loff_t *pos)
+{
+ struct i915_engine_stats_buf *buf =
+ (struct i915_engine_stats_buf *)file->private_data;
+
+ if (*pos == 0) {
+ struct drm_i915_private *dev_priv = file->f_inode->i_private;
+ char *ptr = &buf->buf[0];
+ int left = buf->len;
+ struct intel_engine_cs *engine;
+ enum intel_engine_id id;
+
+ buf->available = 0;
+
+ for_each_engine(engine, dev_priv, id) {
+ u64 total =
+ ktime_to_ns(intel_engine_get_busy_time(engine));
+ int len;
+
+ len = snprintf(ptr, left, "%s: %llu\n",
+ engine->name, total);
+ buf->available += len;
+ left -= len;
+ ptr += len;
+
+ if (len == 0)
+ return -EFBIG;
+ }
+ }
+
+ return simple_read_from_buffer(ubuf, count, pos, &buf->buf[0],
+ buf->available);
+}
+
+static const struct file_operations i915_engine_stats_fops = {
+ .owner = THIS_MODULE,
+ .open = i915_engine_stats_open,
+ .release = i915_engine_stats_release,
+ .read = i915_engine_stats_read,
+ .llseek = default_llseek,
+};
+
static const struct drm_info_list i915_debugfs_list[] = {
{"i915_capabilities", i915_capabilities, 0},
{"i915_gem_objects", i915_gem_object_info, 0},
@@ -4901,6 +4987,12 @@ int i915_debugfs_register(struct drm_i915_private *dev_priv)
struct dentry *ent;
int ret, i;
+ ent = debugfs_create_file("i915_engine_stats", S_IRUGO,
+ minor->debugfs_root, to_i915(minor->dev),
+ &i915_engine_stats_fops);
+ if (!ent)
+ return -ENOMEM;
+
ent = debugfs_create_file("i915_forcewake_user", S_IRUSR,
minor->debugfs_root, to_i915(minor->dev),
&i915_forcewake_fops);
--
2.9.5
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
next prev parent reply other threads:[~2017-09-11 15:26 UTC|newest]
Thread overview: 56+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-11 15:25 [RFC v3 00/11] i915 PMU and engine busy stats Tvrtko Ursulin
2017-09-11 15:25 ` [RFC 01/11] drm/i915: Convert intel_rc6_residency_us to ns Tvrtko Ursulin
2017-09-14 19:48 ` Chris Wilson
2017-09-11 15:25 ` [RFC 02/11] drm/i915: Add intel_energy_uJ Tvrtko Ursulin
2017-09-14 19:49 ` Chris Wilson
2017-09-15 9:18 ` Tvrtko Ursulin
2017-09-14 20:36 ` Ville Syrjälä
2017-09-15 6:56 ` Tvrtko Ursulin
2017-09-15 8:51 ` Chris Wilson
2017-09-15 10:07 ` Tvrtko Ursulin
2017-09-15 10:34 ` Ville Syrjälä
2017-09-15 10:38 ` Chris Wilson
2017-09-15 11:16 ` Tvrtko Ursulin
2017-09-11 15:25 ` [RFC 03/11] drm/i915: Extract intel_get_cagf Tvrtko Ursulin
2017-09-14 19:51 ` Chris Wilson
2017-09-11 15:25 ` [RFC 04/11] drm/i915/pmu: Expose a PMU interface for perf queries Tvrtko Ursulin
2017-09-12 2:06 ` Rogozhkin, Dmitry V
2017-09-12 14:59 ` Tvrtko Ursulin
2017-09-13 8:57 ` [RFC v6 " Tvrtko Ursulin
2017-09-13 10:34 ` [RFC v7 " Tvrtko Ursulin
2017-09-15 0:00 ` Rogozhkin, Dmitry V
2017-09-15 7:57 ` Tvrtko Ursulin
2017-09-14 19:46 ` [RFC " Chris Wilson
2017-09-11 15:25 ` [RFC 05/11] drm/i915/pmu: Suspend sampling when GPU is idle Tvrtko Ursulin
2017-09-13 10:34 ` [RFC v5 " Tvrtko Ursulin
2017-09-14 19:57 ` Chris Wilson
2017-09-15 9:22 ` Tvrtko Ursulin
2017-09-11 15:25 ` [RFC 06/11] drm/i915: Wrap context schedule notification Tvrtko Ursulin
2017-09-11 15:25 ` [RFC 07/11] drm/i915: Engine busy time tracking Tvrtko Ursulin
2017-09-14 20:16 ` Chris Wilson
2017-09-15 9:45 ` Tvrtko Ursulin
2017-09-11 15:25 ` Tvrtko Ursulin [this message]
2017-09-14 20:17 ` [RFC 08/11] drm/i915: Export engine busy stats in debugfs Chris Wilson
2017-09-15 9:46 ` Tvrtko Ursulin
2017-09-11 15:25 ` [RFC 09/11] drm/i915/pmu: Wire up engine busy stats to PMU Tvrtko Ursulin
2017-09-11 15:25 ` [RFC 10/11] drm/i915: Export engine stats API to other users Tvrtko Ursulin
2017-09-12 18:35 ` Ben Widawsky
2017-09-14 20:26 ` Chris Wilson
2017-09-15 9:49 ` Tvrtko Ursulin
2017-09-19 19:50 ` Ben Widawsky
2017-09-19 20:11 ` Rogozhkin, Dmitry V
2017-09-29 10:59 ` Joonas Lahtinen
2017-09-11 15:25 ` [RFC 11/11] drm/i915: Gate engine stats collection with a static key Tvrtko Ursulin
2017-09-13 12:18 ` [RFC v3 " Tvrtko Ursulin
2017-09-14 20:22 ` Chris Wilson
2017-09-15 9:51 ` Tvrtko Ursulin
2017-09-11 15:50 ` ✗ Fi.CI.BAT: warning for i915 PMU and engine busy stats (rev3) Patchwork
2017-09-12 2:03 ` [RFC v3 00/11] i915 PMU and engine busy stats Rogozhkin, Dmitry V
2017-09-12 14:54 ` Tvrtko Ursulin
2017-09-12 22:01 ` Rogozhkin, Dmitry V
2017-09-13 8:54 ` [RFC v6 04/11] drm/i915/pmu: Expose a PMU interface for perf queries Tvrtko Ursulin
2017-09-13 9:01 ` [RFC v3 00/11] i915 PMU and engine busy stats Tvrtko Ursulin
2017-09-13 9:34 ` ✗ Fi.CI.BAT: warning for i915 PMU and engine busy stats (rev4) Patchwork
2017-09-13 10:46 ` ✗ Fi.CI.BAT: failure for i915 PMU and engine busy stats (rev6) Patchwork
2017-09-13 13:27 ` ✓ Fi.CI.BAT: success for i915 PMU and engine busy stats (rev7) Patchwork
2017-09-13 21:24 ` ✓ Fi.CI.IGT: " Patchwork
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=20170911152559.7077-9-tvrtko.ursulin@linux.intel.com \
--to=tursulin@ursulin.net \
--cc=Intel-gfx@lists.freedesktop.org \
--cc=peterz@infradead.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox