<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<p style="font-family:Arial;font-size:10pt;color:#0000FF;margin:15pt;" align="Left">
[AMD Official Use Only]<br>
</p>
<br>
<div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
i would like to add a unit marker for the stats that we monitor in the fd, as we discussed currently we are displaying the usage percentage, because we wanted to to provide single query percentages, but this may evolve with time.</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
May I suggest to add two new fields</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
drm-stat-interval: <64 bit> ns</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
drm-stat-timestamp: <64 bit> ns</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
If interval is set, engine utilization is calculated by doing <perc render> = 100*<drm_engine_render>/<drm_stat_interval> </div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
if interval is not set, two reads are needed : <perc render> = 100*<drm_engine_render1 - drm_engine_render0> / <drm-stat-timestamp1 - drm-stat-timestamp0></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
Regards,</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
David</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<br>
</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com><br>
<b>Sent:</b> Thursday, May 20, 2021 8:12 AM<br>
<b>To:</b> Intel-gfx@lists.freedesktop.org <Intel-gfx@lists.freedesktop.org><br>
<b>Cc:</b> dri-devel@lists.freedesktop.org <dri-devel@lists.freedesktop.org>; Tvrtko Ursulin <tvrtko.ursulin@intel.com>; Nieto, David M <David.Nieto@amd.com>; Koenig, Christian <Christian.Koenig@amd.com>; Daniel Vetter <daniel@ffwll.ch><br>
<b>Subject:</b> [RFC 7/7] drm/i915: Expose client engine utilisation via fdinfo</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">From: Tvrtko Ursulin <tvrtko.ursulin@intel.com><br>
<br>
Similar to AMD commit<br>
874442541133 ("drm/amdgpu: Add show_fdinfo() interface"), using the<br>
infrastructure added in previous patches, we add basic client info<br>
and GPU engine utilisation for i915.<br>
<br>
Example of the output:<br>
<br>
  pos:    0<br>
  flags:  0100002<br>
  mnt_id: 21<br>
  drm-driver: i915<br>
  drm-pdev:   0000:00:02.0<br>
  drm-client-id:      7<br>
  drm-engine-render:  9288864723 ns<br>
  drm-engine-copy:    2035071108 ns<br>
  drm-engine-video:   0 ns<br>
  drm-engine-video-enhance:   0 ns<br>
<br>
DRM related fields are appropriately prefixed for easy parsing and<br>
separation from generic fdinfo fields.<br>
<br>
Idea is for some fields to become either fully or partially standardised<br>
in order to enable writting of generic top-like tools.<br>
<br>
Initial proposal for fully standardised common fields:<br>
<br>
 drm-driver: <str><br>
 drm-pdev: <aaaa:bb.cc.d><br>
<br>
Optional fully standardised:<br>
<br>
 drm-client-id: <uint><br>
<br>
Optional partially standardised:<br>
<br>
 engine-<str>: <u64> ns<br>
 memory-<str>: <u64> KiB<br>
<br>
Once agreed the format would need to go to some README or kerneldoc in<br>
DRM core.<br>
<br>
Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com><br>
Cc: David M Nieto <David.Nieto@amd.com><br>
Cc: Christian König <christian.koenig@amd.com><br>
Cc: Daniel Vetter <daniel@ffwll.ch><br>
---<br>
 drivers/gpu/drm/i915/i915_drm_client.c | 68 ++++++++++++++++++++++++++<br>
 drivers/gpu/drm/i915/i915_drm_client.h |  4 ++<br>
 drivers/gpu/drm/i915/i915_drv.c        |  3 ++<br>
 3 files changed, 75 insertions(+)<br>
<br>
diff --git a/drivers/gpu/drm/i915/i915_drm_client.c b/drivers/gpu/drm/i915/i915_drm_client.c<br>
index 1e5db7753276..5e9cfba1116b 100644<br>
--- a/drivers/gpu/drm/i915/i915_drm_client.c<br>
+++ b/drivers/gpu/drm/i915/i915_drm_client.c<br>
@@ -9,6 +9,11 @@<br>
 <br>
 #include <drm/drm_print.h><br>
 <br>
+#include <uapi/drm/i915_drm.h><br>
+<br>
+#include "gem/i915_gem_context.h"<br>
+#include "gt/intel_engine_user.h"<br>
+<br>
 #include "i915_drm_client.h"<br>
 #include "i915_drv.h"<br>
 #include "i915_gem.h"<br>
@@ -168,3 +173,66 @@ void i915_drm_clients_fini(struct i915_drm_clients *clients)<br>
 <br>
         xa_destroy(&clients->xarray);<br>
 }<br>
+<br>
+#ifdef CONFIG_PROC_FS<br>
+static const char * const uabi_class_names[] = {<br>
+       [I915_ENGINE_CLASS_RENDER] = "render",<br>
+       [I915_ENGINE_CLASS_COPY] = "copy",<br>
+       [I915_ENGINE_CLASS_VIDEO] = "video",<br>
+       [I915_ENGINE_CLASS_VIDEO_ENHANCE] = "video-enhance",<br>
+};<br>
+<br>
+static u64 busy_add(struct i915_gem_context *ctx, unsigned int class)<br>
+{<br>
+       struct i915_gem_engines_iter it;<br>
+       struct intel_context *ce;<br>
+       u64 total = 0;<br>
+<br>
+       for_each_gem_engine(ce, rcu_dereference(ctx->engines), it) {<br>
+               if (ce->engine->uabi_class != class)<br>
+                       continue;<br>
+<br>
+               total += intel_context_get_total_runtime_ns(ce);<br>
+       }<br>
+<br>
+       return total;<br>
+}<br>
+<br>
+static void<br>
+show_client_class(struct seq_file *m,<br>
+                 struct i915_drm_client *client,<br>
+                 unsigned int class)<br>
+{<br>
+       const struct list_head *list = &client->ctx_list;<br>
+       u64 total = atomic64_read(&client->past_runtime[class]);<br>
+       struct i915_gem_context *ctx;<br>
+<br>
+       rcu_read_lock();<br>
+       list_for_each_entry_rcu(ctx, list, client_link)<br>
+               total += busy_add(ctx, class);<br>
+       rcu_read_unlock();<br>
+<br>
+       return seq_printf(m, "drm-engine-%s:\t%llu ns\n",<br>
+                         uabi_class_names[class], total);<br>
+}<br>
+<br>
+void i915_drm_client_fdinfo(struct seq_file *m, struct file *f)<br>
+{<br>
+       struct drm_file *file = f->private_data;<br>
+       struct drm_i915_file_private *file_priv = file->driver_priv;<br>
+       struct drm_i915_private *i915 = file_priv->dev_priv;<br>
+       struct i915_drm_client *client = file_priv->client;<br>
+       struct pci_dev *pdev = to_pci_dev(i915->drm.dev);<br>
+       unsigned int i;<br>
+<br>
+       seq_printf(m, "drm-driver:\ti915\n");<br>
+       seq_printf(m, "drm-pdev:\t%04x:%02x:%02x.%d\n",<br>
+                  pci_domain_nr(pdev->bus), pdev->bus->number,<br>
+                  PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn));<br>
+<br>
+       seq_printf(m, "drm-client-id:\t%u\n", client->id);<br>
+<br>
+       for (i = 0; i < ARRAY_SIZE(uabi_class_names); i++)<br>
+               show_client_class(m, client, i);<br>
+}<br>
+#endif<br>
diff --git a/drivers/gpu/drm/i915/i915_drm_client.h b/drivers/gpu/drm/i915/i915_drm_client.h<br>
index b2b69d6985e4..9885002433a0 100644<br>
--- a/drivers/gpu/drm/i915/i915_drm_client.h<br>
+++ b/drivers/gpu/drm/i915/i915_drm_client.h<br>
@@ -98,6 +98,10 @@ i915_drm_client_pid(const struct i915_drm_client *client)<br>
         return __i915_drm_client_name(client)->pid;<br>
 }<br>
 <br>
+#ifdef CONFIG_PROC_FS<br>
+void i915_drm_client_fdinfo(struct seq_file *m, struct file *f);<br>
+#endif<br>
+<br>
 void i915_drm_clients_fini(struct i915_drm_clients *clients);<br>
 <br>
 #endif /* !__I915_DRM_CLIENT_H__ */<br>
diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c<br>
index 33eb7b52b58b..6b63fe4b3c26 100644<br>
--- a/drivers/gpu/drm/i915/i915_drv.c<br>
+++ b/drivers/gpu/drm/i915/i915_drv.c<br>
@@ -1694,6 +1694,9 @@ static const struct file_operations i915_driver_fops = {<br>
         .read = drm_read,<br>
         .compat_ioctl = i915_ioc32_compat_ioctl,<br>
         .llseek = noop_llseek,<br>
+#ifdef CONFIG_PROC_FS<br>
+       .show_fdinfo = i915_drm_client_fdinfo,<br>
+#endif<br>
 };<br>
 <br>
 static int<br>
-- <br>
2.30.2<br>
<br>
</div>
</span></font></div>
</div>
</body>
</html>