From: Tvrtko Ursulin <tvrtko.ursulin@xxxxxxxxx> When available prefer context tracked context busyness because it provides visibility into currently executing contexts as well. Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@xxxxxxxxx> --- drivers/gpu/drm/i915/i915_drm_client.c | 83 +++++++++++++++++++++++++- drivers/gpu/drm/i915/i915_drm_client.h | 2 + 2 files changed, 84 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/i915/i915_drm_client.c b/drivers/gpu/drm/i915/i915_drm_client.c index 6df5a21f5d4e..c6b463650ba2 100644 --- a/drivers/gpu/drm/i915/i915_drm_client.c +++ b/drivers/gpu/drm/i915/i915_drm_client.c @@ -91,6 +91,46 @@ 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); + struct i915_gem_engines_iter it; + struct intel_context *ce; + ktime_t total = 0; + + for_each_gem_engine(ce, engines, it) { + if (ce->engine->uabi_class == class) + total = ktime_add(total, + intel_context_get_busy_time(ce)); + } + + return ktime_to_ns(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; + u64 total = atomic64_read(&client->past_sw_runtime[class]); + 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_sw_runtime[class]); + total += 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", @@ -146,11 +186,39 @@ __i915_drm_client_register(struct i915_drm_client *client, goto err_attr; if (HAS_LOGICAL_RING_CONTEXTS(i915)) { + struct intel_engine_cs *engine; + bool sw_stats = true; + client->busy_root = kobject_create_and_add("busy", client->root); if (!client->busy_root) goto err_attr; + /* Enable busy stats on all engines. */ + i = 0; + for_each_uabi_engine(engine, i915) { + ret = intel_enable_engine_stats(engine); + if (ret) { + int j; + + /* Unwind if not available. */ + j = 0; + for_each_uabi_engine(engine, i915) { + if (j++ == i) + break; + + intel_disable_engine_stats(engine); + } + + sw_stats = false; + dev_notice_once(i915->drm.dev, + "Engine busy stats not available! (%d)", + ret); + break; + } + i++; + } + for (i = 0; i < ARRAY_SIZE(uabi_class_names); i++) { struct i915_engine_busy_attribute *i915_attr = &client->attr.busy[i]; @@ -168,13 +236,17 @@ __i915_drm_client_register(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_busy; } + + client->sw_busy = sw_stats; } return 0; @@ -200,6 +272,15 @@ __i915_drm_client_unregister(struct i915_drm_client *client) if (!client->root) return; /* fbdev client or error during drm open */ + if (client->busy_root && client->sw_busy) { + struct drm_i915_private *i915 = + container_of(client->clients, typeof(*i915), clients); + struct intel_engine_cs *engine; + + for_each_uabi_engine(engine, i915) + intel_disable_engine_stats(engine); + } + kobject_put(fetch_and_zero(&client->busy_root)); kobject_put(fetch_and_zero(&client->root)); } diff --git a/drivers/gpu/drm/i915/i915_drm_client.h b/drivers/gpu/drm/i915/i915_drm_client.h index aa1e446d0376..bc15f371715f 100644 --- a/drivers/gpu/drm/i915/i915_drm_client.h +++ b/drivers/gpu/drm/i915/i915_drm_client.h @@ -62,6 +62,8 @@ struct i915_drm_client { struct i915_engine_busy_attribute busy[MAX_ENGINE_CLASS + 1]; } attr; + bool sw_busy; + /** * @past_runtime: Accumulation of pphwsp runtimes from closed contexts. */ -- 2.20.1 _______________________________________________ Intel-gfx mailing list Intel-gfx@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/intel-gfx