From: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
To: Intel-gfx@lists.freedesktop.org
Subject: [RFC 4/5] drm/i915: Expose per-engine client busyness
Date: Fri, 25 Oct 2019 15:21:30 +0100 [thread overview]
Message-ID: <20191025142131.17378-5-tvrtko.ursulin@linux.intel.com> (raw)
In-Reply-To: <20191025142131.17378-1-tvrtko.ursulin@linux.intel.com>
From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Expose per-client and per-engine busyness under the previously added sysfs
client root.
The new files are one per-engine instance and located under the 'busy'
directory. Each contains a monotonically increasing nano-second resolution
times each client's jobs were executing on the GPU.
This enables userspace to create a top-like tool for GPU utilization:
==========================================================================
intel-gpu-top - 935/ 935 MHz; 0% RC6; 14.73 Watts; 1097 irqs/s
IMC reads: 1401 MiB/s
IMC writes: 4 MiB/s
ENGINE BUSY MI_SEMA MI_WAIT
Render/3D/0 63.73% |███████████████████ | 3% 0%
Blitter/0 9.53% |██▊ | 6% 0%
Video/0 39.32% |███████████▊ | 16% 0%
Video/1 15.62% |████▋ | 0% 0%
VideoEnhance/0 0.00% | | 0% 0%
PID NAME RCS BCS VCS VECS
4084 gem_wsim |█████▌ ||█ || || |
4086 gem_wsim |█▌ || ||███ || |
==========================================================================
v2: Use intel_context_engine_get_busy_time.
v3: New directory structure.
v4: Rebase.
v5: sysfs_attr_init.
v6: Small tidy in i915_gem_add_client.
v7: Rebase to be engine class based.
Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
---
drivers/gpu/drm/i915/i915_drv.h | 8 +++
drivers/gpu/drm/i915/i915_gem.c | 102 ++++++++++++++++++++++++++++++--
2 files changed, 106 insertions(+), 4 deletions(-)
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index b8f7b0637224..45f0e2455322 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -186,6 +186,12 @@ struct drm_i915_private;
struct i915_mm_struct;
struct i915_mmu_object;
+struct i915_engine_busy_attribute {
+ struct device_attribute attr;
+ struct drm_i915_file_private *file_priv;
+ unsigned int engine_class;
+};
+
struct drm_i915_file_private {
struct drm_i915_private *dev_priv;
@@ -230,10 +236,12 @@ struct drm_i915_file_private {
char *name;
struct kobject *root;
+ struct kobject *busy_root;
struct {
struct device_attribute pid;
struct device_attribute name;
+ struct i915_engine_busy_attribute busy[MAX_ENGINE_CLASS];
} attr;
} client;
};
diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index 54a00c954066..b3d21b6b570c 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -1512,15 +1512,67 @@ show_client_pid(struct device *kdev, struct device_attribute *attr, char *buf)
return snprintf(buf, PAGE_SIZE, "%u", file_priv->client.pid);
}
+struct busy_ctx {
+ unsigned int engine_class;
+ u64 total;
+};
+
+static int busy_add(int id, void *p, void *data)
+{
+ struct busy_ctx *bc = data;
+ struct i915_gem_context *ctx = p;
+ unsigned int engine_class = bc->engine_class;
+ struct i915_gem_engines_iter it;
+ struct intel_context *ce;
+ uint64_t total = bc->total;
+
+ for_each_gem_engine(ce, i915_gem_context_lock_engines(ctx), it) {
+ if (ce->engine->uabi_class == engine_class)
+ total += ktime_to_ns(intel_context_get_busy_time(ce));
+ }
+ i915_gem_context_unlock_engines(ctx);
+
+ bc->total = total;
+
+ return 0;
+}
+
+static ssize_t
+show_client_busy(struct device *kdev, struct device_attribute *attr, char *buf)
+{
+ struct i915_engine_busy_attribute *i915_attr =
+ container_of(attr, typeof(*i915_attr), attr);
+ struct drm_i915_file_private *file_priv = i915_attr->file_priv;
+ struct busy_ctx bc = { .engine_class = i915_attr->engine_class };
+ int ret;
+
+ ret = mutex_lock_interruptible(&file_priv->context_idr_lock);
+ if (ret)
+ return ret;
+
+ idr_for_each(&file_priv->context_idr, busy_add, &bc);
+
+ mutex_unlock(&file_priv->context_idr_lock);
+
+ return snprintf(buf, PAGE_SIZE, "%llu\n", bc.total);
+}
+
+static const char *uabi_class_names[] = {
+ [I915_ENGINE_CLASS_RENDER] = "0",
+ [I915_ENGINE_CLASS_COPY] = "1",
+ [I915_ENGINE_CLASS_VIDEO] = "2",
+ [I915_ENGINE_CLASS_VIDEO_ENHANCE] = "3",
+};
+
int
i915_gem_add_client(struct drm_i915_private *i915,
struct drm_i915_file_private *file_priv,
struct task_struct *task,
unsigned int serial)
{
- int ret = -ENOMEM;
+ int i, ret = -ENOMEM;
struct device_attribute *attr;
- char id[32];
+ char idstr[32];
if (!i915->clients.root)
return 0; /* intel_fbdev_init registers a client before sysfs */
@@ -1529,8 +1581,8 @@ i915_gem_add_client(struct drm_i915_private *i915,
if (!file_priv->client.name)
goto err_name;
- snprintf(id, sizeof(id), "%u", serial);
- file_priv->client.root = kobject_create_and_add(id,
+ snprintf(idstr, sizeof(idstr), "%u", serial);
+ file_priv->client.root = kobject_create_and_add(idstr,
i915->clients.root);
if (!file_priv->client.root)
goto err_client;
@@ -1557,10 +1609,44 @@ i915_gem_add_client(struct drm_i915_private *i915,
if (ret)
goto err_attr_pid;
+ file_priv->client.busy_root =
+ kobject_create_and_add("busy", file_priv->client.root);
+ if (!file_priv->client.busy_root)
+ goto err_busy_root;
+
+ for (i = 0; i < ARRAY_SIZE(uabi_class_names); i++) {
+ struct i915_engine_busy_attribute *i915_attr =
+ &file_priv->client.attr.busy[i];
+
+ i915_attr->file_priv = file_priv;
+ i915_attr->engine_class = i;
+
+ attr = &i915_attr->attr;
+
+ sysfs_attr_init(&attr->attr);
+
+ attr->attr.name = uabi_class_names[i];
+ attr->attr.mode = 0444;
+ attr->show = show_client_busy;
+
+ ret = sysfs_create_file(file_priv->client.busy_root,
+ (struct attribute *)attr);
+ if (ret)
+ goto err_attr_busy;
+ }
+
file_priv->client.pid = pid_nr(get_task_pid(task, PIDTYPE_PID));
return 0;
+err_attr_busy:
+ for (--i; i >= 0; i--)
+ sysfs_remove_file(file_priv->client.busy_root,
+ (struct attribute *)&file_priv->client.attr.busy[i]);
+ kobject_put(file_priv->client.busy_root);
+err_busy_root:
+ sysfs_remove_file(file_priv->client.root,
+ (struct attribute *)&file_priv->client.attr.pid);
err_attr_pid:
sysfs_remove_file(file_priv->client.root,
(struct attribute *)&file_priv->client.attr.name);
@@ -1574,9 +1660,17 @@ i915_gem_add_client(struct drm_i915_private *i915,
void i915_gem_remove_client(struct drm_i915_file_private *file_priv)
{
+ unsigned int i;
+
if (!file_priv->client.name)
return; /* intel_fbdev_init registers a client before sysfs */
+ for (i = 0; i < ARRAY_SIZE(uabi_class_names); i++)
+ sysfs_remove_file(file_priv->client.busy_root,
+ (struct attribute *)&file_priv->client.attr.busy[i]);
+
+ kobject_put(file_priv->client.busy_root);
+
sysfs_remove_file(file_priv->client.root,
(struct attribute *)&file_priv->client.attr.pid);
sysfs_remove_file(file_priv->client.root,
--
2.20.1
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
WARNING: multiple messages have this Message-ID (diff)
From: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
To: Intel-gfx@lists.freedesktop.org
Subject: [Intel-gfx] [RFC 4/5] drm/i915: Expose per-engine client busyness
Date: Fri, 25 Oct 2019 15:21:30 +0100 [thread overview]
Message-ID: <20191025142131.17378-5-tvrtko.ursulin@linux.intel.com> (raw)
Message-ID: <20191025142130.9XryPyAfqRfDK_98vQ8ohMwtlbgmhx_8zhNak640RN8@z> (raw)
In-Reply-To: <20191025142131.17378-1-tvrtko.ursulin@linux.intel.com>
From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Expose per-client and per-engine busyness under the previously added sysfs
client root.
The new files are one per-engine instance and located under the 'busy'
directory. Each contains a monotonically increasing nano-second resolution
times each client's jobs were executing on the GPU.
This enables userspace to create a top-like tool for GPU utilization:
==========================================================================
intel-gpu-top - 935/ 935 MHz; 0% RC6; 14.73 Watts; 1097 irqs/s
IMC reads: 1401 MiB/s
IMC writes: 4 MiB/s
ENGINE BUSY MI_SEMA MI_WAIT
Render/3D/0 63.73% |███████████████████ | 3% 0%
Blitter/0 9.53% |██▊ | 6% 0%
Video/0 39.32% |███████████▊ | 16% 0%
Video/1 15.62% |████▋ | 0% 0%
VideoEnhance/0 0.00% | | 0% 0%
PID NAME RCS BCS VCS VECS
4084 gem_wsim |█████▌ ||█ || || |
4086 gem_wsim |█▌ || ||███ || |
==========================================================================
v2: Use intel_context_engine_get_busy_time.
v3: New directory structure.
v4: Rebase.
v5: sysfs_attr_init.
v6: Small tidy in i915_gem_add_client.
v7: Rebase to be engine class based.
Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
---
drivers/gpu/drm/i915/i915_drv.h | 8 +++
drivers/gpu/drm/i915/i915_gem.c | 102 ++++++++++++++++++++++++++++++--
2 files changed, 106 insertions(+), 4 deletions(-)
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index b8f7b0637224..45f0e2455322 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -186,6 +186,12 @@ struct drm_i915_private;
struct i915_mm_struct;
struct i915_mmu_object;
+struct i915_engine_busy_attribute {
+ struct device_attribute attr;
+ struct drm_i915_file_private *file_priv;
+ unsigned int engine_class;
+};
+
struct drm_i915_file_private {
struct drm_i915_private *dev_priv;
@@ -230,10 +236,12 @@ struct drm_i915_file_private {
char *name;
struct kobject *root;
+ struct kobject *busy_root;
struct {
struct device_attribute pid;
struct device_attribute name;
+ struct i915_engine_busy_attribute busy[MAX_ENGINE_CLASS];
} attr;
} client;
};
diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index 54a00c954066..b3d21b6b570c 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -1512,15 +1512,67 @@ show_client_pid(struct device *kdev, struct device_attribute *attr, char *buf)
return snprintf(buf, PAGE_SIZE, "%u", file_priv->client.pid);
}
+struct busy_ctx {
+ unsigned int engine_class;
+ u64 total;
+};
+
+static int busy_add(int id, void *p, void *data)
+{
+ struct busy_ctx *bc = data;
+ struct i915_gem_context *ctx = p;
+ unsigned int engine_class = bc->engine_class;
+ struct i915_gem_engines_iter it;
+ struct intel_context *ce;
+ uint64_t total = bc->total;
+
+ for_each_gem_engine(ce, i915_gem_context_lock_engines(ctx), it) {
+ if (ce->engine->uabi_class == engine_class)
+ total += ktime_to_ns(intel_context_get_busy_time(ce));
+ }
+ i915_gem_context_unlock_engines(ctx);
+
+ bc->total = total;
+
+ return 0;
+}
+
+static ssize_t
+show_client_busy(struct device *kdev, struct device_attribute *attr, char *buf)
+{
+ struct i915_engine_busy_attribute *i915_attr =
+ container_of(attr, typeof(*i915_attr), attr);
+ struct drm_i915_file_private *file_priv = i915_attr->file_priv;
+ struct busy_ctx bc = { .engine_class = i915_attr->engine_class };
+ int ret;
+
+ ret = mutex_lock_interruptible(&file_priv->context_idr_lock);
+ if (ret)
+ return ret;
+
+ idr_for_each(&file_priv->context_idr, busy_add, &bc);
+
+ mutex_unlock(&file_priv->context_idr_lock);
+
+ return snprintf(buf, PAGE_SIZE, "%llu\n", bc.total);
+}
+
+static const char *uabi_class_names[] = {
+ [I915_ENGINE_CLASS_RENDER] = "0",
+ [I915_ENGINE_CLASS_COPY] = "1",
+ [I915_ENGINE_CLASS_VIDEO] = "2",
+ [I915_ENGINE_CLASS_VIDEO_ENHANCE] = "3",
+};
+
int
i915_gem_add_client(struct drm_i915_private *i915,
struct drm_i915_file_private *file_priv,
struct task_struct *task,
unsigned int serial)
{
- int ret = -ENOMEM;
+ int i, ret = -ENOMEM;
struct device_attribute *attr;
- char id[32];
+ char idstr[32];
if (!i915->clients.root)
return 0; /* intel_fbdev_init registers a client before sysfs */
@@ -1529,8 +1581,8 @@ i915_gem_add_client(struct drm_i915_private *i915,
if (!file_priv->client.name)
goto err_name;
- snprintf(id, sizeof(id), "%u", serial);
- file_priv->client.root = kobject_create_and_add(id,
+ snprintf(idstr, sizeof(idstr), "%u", serial);
+ file_priv->client.root = kobject_create_and_add(idstr,
i915->clients.root);
if (!file_priv->client.root)
goto err_client;
@@ -1557,10 +1609,44 @@ i915_gem_add_client(struct drm_i915_private *i915,
if (ret)
goto err_attr_pid;
+ file_priv->client.busy_root =
+ kobject_create_and_add("busy", file_priv->client.root);
+ if (!file_priv->client.busy_root)
+ goto err_busy_root;
+
+ for (i = 0; i < ARRAY_SIZE(uabi_class_names); i++) {
+ struct i915_engine_busy_attribute *i915_attr =
+ &file_priv->client.attr.busy[i];
+
+ i915_attr->file_priv = file_priv;
+ i915_attr->engine_class = i;
+
+ attr = &i915_attr->attr;
+
+ sysfs_attr_init(&attr->attr);
+
+ attr->attr.name = uabi_class_names[i];
+ attr->attr.mode = 0444;
+ attr->show = show_client_busy;
+
+ ret = sysfs_create_file(file_priv->client.busy_root,
+ (struct attribute *)attr);
+ if (ret)
+ goto err_attr_busy;
+ }
+
file_priv->client.pid = pid_nr(get_task_pid(task, PIDTYPE_PID));
return 0;
+err_attr_busy:
+ for (--i; i >= 0; i--)
+ sysfs_remove_file(file_priv->client.busy_root,
+ (struct attribute *)&file_priv->client.attr.busy[i]);
+ kobject_put(file_priv->client.busy_root);
+err_busy_root:
+ sysfs_remove_file(file_priv->client.root,
+ (struct attribute *)&file_priv->client.attr.pid);
err_attr_pid:
sysfs_remove_file(file_priv->client.root,
(struct attribute *)&file_priv->client.attr.name);
@@ -1574,9 +1660,17 @@ i915_gem_add_client(struct drm_i915_private *i915,
void i915_gem_remove_client(struct drm_i915_file_private *file_priv)
{
+ unsigned int i;
+
if (!file_priv->client.name)
return; /* intel_fbdev_init registers a client before sysfs */
+ for (i = 0; i < ARRAY_SIZE(uabi_class_names); i++)
+ sysfs_remove_file(file_priv->client.busy_root,
+ (struct attribute *)&file_priv->client.attr.busy[i]);
+
+ kobject_put(file_priv->client.busy_root);
+
sysfs_remove_file(file_priv->client.root,
(struct attribute *)&file_priv->client.attr.pid);
sysfs_remove_file(file_priv->client.root,
--
2.20.1
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
next prev parent reply other threads:[~2019-10-25 14:21 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-25 14:21 [RFC 0/5] Per client engine busyness (all aboard the sysfs train!) Tvrtko Ursulin
2019-10-25 14:21 ` [Intel-gfx] " Tvrtko Ursulin
2019-10-25 14:21 ` [RFC 1/5] drm/i915: Track per-context engine busyness Tvrtko Ursulin
2019-10-25 14:21 ` [Intel-gfx] " Tvrtko Ursulin
2019-10-25 14:21 ` [RFC 2/5] drm/i915: Expose list of clients in sysfs Tvrtko Ursulin
2019-10-25 14:21 ` [Intel-gfx] " Tvrtko Ursulin
2019-10-25 14:35 ` Chris Wilson
2019-10-25 14:35 ` [Intel-gfx] " Chris Wilson
2019-10-25 14:21 ` [RFC 3/5] drm/i915: Update client name on context create Tvrtko Ursulin
2019-10-25 14:21 ` [Intel-gfx] " Tvrtko Ursulin
2019-10-25 14:39 ` Chris Wilson
2019-10-25 14:39 ` [Intel-gfx] " Chris Wilson
2019-10-25 14:21 ` Tvrtko Ursulin [this message]
2019-10-25 14:21 ` [Intel-gfx] [RFC 4/5] drm/i915: Expose per-engine client busyness Tvrtko Ursulin
2019-10-25 14:42 ` Chris Wilson
2019-10-25 14:42 ` [Intel-gfx] " Chris Wilson
2019-10-25 14:21 ` [RFC 5/5] drm/i915: Add sysfs toggle to enable per-client engine stats Tvrtko Ursulin
2019-10-25 14:21 ` [Intel-gfx] " Tvrtko Ursulin
2019-10-25 14:49 ` Chris Wilson
2019-10-25 14:49 ` [Intel-gfx] " Chris Wilson
2019-10-25 19:45 ` ✗ Fi.CI.CHECKPATCH: warning for Per client engine busyness (all aboard the sysfs train!) Patchwork
2019-10-25 19:45 ` [Intel-gfx] " Patchwork
2019-10-25 20:12 ` ✗ Fi.CI.BAT: failure " Patchwork
2019-10-25 20:12 ` [Intel-gfx] " Patchwork
-- strict thread matches above, loose matches on Subject: below --
2018-02-14 18:50 [RFC 0/5] Per-client engine stats Tvrtko Ursulin
2018-02-14 18:50 ` [RFC 4/5] drm/i915: Expose per-engine client busyness Tvrtko Ursulin
2018-02-14 19:17 ` Chris Wilson
2018-02-15 9:41 ` Tvrtko Ursulin
2018-02-15 9:44 ` Chris Wilson
2018-02-15 15:13 ` Tvrtko Ursulin
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=20191025142131.17378-5-tvrtko.ursulin@linux.intel.com \
--to=tvrtko.ursulin@linux.intel.com \
--cc=Intel-gfx@lists.freedesktop.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