All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
To: Intel-gfx@lists.freedesktop.org
Subject: [Intel-gfx] [RFC 10/10] drm/i915: Prefer software tracked context busyness
Date: Wed, 11 Mar 2020 18:26:18 +0000	[thread overview]
Message-ID: <20200311182618.21513-11-tvrtko.ursulin@linux.intel.com> (raw)
In-Reply-To: <20200311182618.21513-1-tvrtko.ursulin@linux.intel.com>

From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>

When available prefer context tracked context busyness because it provides
visibility into currently executing contexts as well.

Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
---
 drivers/gpu/drm/i915/i915_drm_client.c | 68 ++++++++++++++++++++++++--
 1 file changed, 63 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_drm_client.c b/drivers/gpu/drm/i915/i915_drm_client.c
index e7a9f0f767aa..a711db8e91bc 100644
--- a/drivers/gpu/drm/i915/i915_drm_client.c
+++ b/drivers/gpu/drm/i915/i915_drm_client.c
@@ -98,6 +98,61 @@ show_client_busy(struct device *kdev, struct device_attribute *attr, char *buf)
 	return snprintf(buf, PAGE_SIZE, "%llu\n", total);
 }
 
+static u64
+sw_busy_add(struct i915_gem_context *ctx, unsigned int class)
+{
+	struct i915_gem_engines *engines = rcu_dereference(ctx->engines);
+	u32 period_ns = RUNTIME_INFO(ctx->i915)->cs_timestamp_period_ns;
+	struct i915_gem_engines_iter it;
+	struct intel_context *ce;
+	u64 total = 0;
+
+	for_each_gem_engine(ce, engines, it) {
+		struct intel_context_stats *stats;
+		unsigned int seq;
+		u64 t;
+
+		if (ce->engine->uabi_class != class)
+			continue;
+
+		stats = &ce->stats;
+
+		do {
+			seq = read_seqbegin(&stats->lock);
+			t = ce->stats.runtime.total * period_ns;
+			t += intel_context_get_active_time(ce);
+		} while (read_seqretry(&stats->lock, seq));
+
+		total += t;
+	}
+
+	return total;
+}
+
+static ssize_t
+show_client_sw_busy(struct device *kdev,
+		    struct device_attribute *attr,
+		    char *buf)
+{
+	struct i915_engine_busy_attribute *i915_attr =
+		container_of(attr, typeof(*i915_attr), attr);
+	unsigned int class = i915_attr->engine_class;
+	struct i915_drm_client *client = i915_attr->client;
+	u32 period_ns = RUNTIME_INFO(i915_attr->i915)->cs_timestamp_period_ns;
+	u64 total = atomic64_read(&client->past_runtime[class]) * period_ns;
+	struct list_head *list = &client->ctx_list;
+	struct i915_gem_context *ctx;
+
+	rcu_read_lock();
+	list_for_each_entry_rcu(ctx, list, client_link) {
+		total += atomic64_read(&ctx->past_runtime[class]) * period_ns +
+			 sw_busy_add(ctx, class);
+	}
+	rcu_read_unlock();
+
+	return snprintf(buf, PAGE_SIZE, "%llu\n", total);
+}
+
 static const char *uabi_class_names[] = {
 	[I915_ENGINE_CLASS_RENDER] = "0",
 	[I915_ENGINE_CLASS_COPY] = "1",
@@ -111,6 +166,8 @@ __client_register_sysfs_busy(struct i915_drm_client *client)
 	struct i915_drm_clients *clients = client->clients;
 	struct drm_i915_private *i915 =
 		container_of(clients, typeof(*i915), clients);
+	bool sw_stats = i915->caps.scheduler &
+			I915_SCHEDULER_CAP_ENGINE_BUSY_STATS;
 	unsigned int i;
 	int ret = 0;
 
@@ -137,18 +194,19 @@ __client_register_sysfs_busy(struct i915_drm_client *client)
 
 		attr->attr.name = uabi_class_names[i];
 		attr->attr.mode = 0444;
-		attr->show = show_client_busy;
+		attr->show = sw_stats ?
+			     show_client_sw_busy : show_client_busy;
 
 		ret = sysfs_create_file(client->busy_root,
 					(struct attribute *)attr);
 		if (ret)
-			goto err;
+			goto out;
 	}
 
-	return 0;
+out:
+	if (ret)
+		kobject_put(client->busy_root);
 
-err:
-	kobject_put(client->busy_root);
 	return ret;
 }
 
-- 
2.20.1

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

  parent reply	other threads:[~2020-03-11 18:26 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-11 18:26 [Intel-gfx] [RFC 00/12] Per client engine busyness Tvrtko Ursulin
2020-03-11 18:26 ` [Intel-gfx] [RFC 01/10] drm/i915: Expose list of clients in sysfs Tvrtko Ursulin
2020-03-13 10:36   ` Chris Wilson
2020-03-11 18:26 ` [Intel-gfx] [RFC 02/10] drm/i915: Update client name on context create Tvrtko Ursulin
2020-03-13 10:41   ` Chris Wilson
2020-03-11 18:26 ` [Intel-gfx] [RFC 03/10] drm/i915: Make GEM contexts track DRM clients Tvrtko Ursulin
2020-03-13 11:00   ` Chris Wilson
2020-03-11 18:26 ` [Intel-gfx] [RFC 04/10] drm/i915: Use explicit flag to mark unreachable intel_context Tvrtko Ursulin
2020-03-13 11:03   ` Chris Wilson
2020-03-11 18:26 ` [Intel-gfx] [RFC 05/10] drm/i915: Track runtime spent in unreachable intel_contexts Tvrtko Ursulin
2020-03-11 18:26 ` [Intel-gfx] [RFC 06/10] drm/i915: Track runtime spent in closed GEM contexts Tvrtko Ursulin
2020-03-11 18:26 ` [Intel-gfx] [RFC 07/10] drm/i915: Track all user contexts per client Tvrtko Ursulin
2020-03-11 18:26 ` [Intel-gfx] [RFC 08/10] drm/i915: Expose per-engine client busyness Tvrtko Ursulin
2020-03-11 18:26 ` [Intel-gfx] [RFC 09/10] drm/i915: Track context current active time Tvrtko Ursulin
2020-03-11 18:26 ` Tvrtko Ursulin [this message]
2020-03-12  2:08 ` [Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for Per client engine busyness (rev6) Patchwork
2020-03-12  2:14 ` [Intel-gfx] ✗ Fi.CI.SPARSE: " Patchwork
2020-03-12  2:33 ` [Intel-gfx] ✗ Fi.CI.BAT: failure " Patchwork
2020-03-13 10:28 ` [Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for Per client engine busyness (rev7) Patchwork
2020-03-13 10:34 ` [Intel-gfx] ✗ Fi.CI.SPARSE: " Patchwork
2020-03-13 10:54 ` [Intel-gfx] ✓ Fi.CI.BAT: success " Patchwork
2020-03-13 17:26 ` [Intel-gfx] ✓ 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=20200311182618.21513-11-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 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.