From patchwork Mon Dec 16 12:07:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 11293991 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D0FC81593 for ; Mon, 16 Dec 2019 12:07:23 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B8194206D3 for ; Mon, 16 Dec 2019 12:07:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B8194206D3 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4DBF589F55; Mon, 16 Dec 2019 12:07:23 +0000 (UTC) X-Original-To: Intel-gfx@lists.freedesktop.org Delivered-To: Intel-gfx@lists.freedesktop.org Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by gabe.freedesktop.org (Postfix) with ESMTPS id 536AD89EA3 for ; Mon, 16 Dec 2019 12:07:18 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Dec 2019 04:07:18 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,321,1571727600"; d="scan'208";a="416414015" Received: from dtriolet-mobl1.ger.corp.intel.com (HELO localhost.localdomain) ([10.251.84.191]) by fmsmga006.fm.intel.com with ESMTP; 16 Dec 2019 04:07:17 -0800 From: Tvrtko Ursulin To: Intel-gfx@lists.freedesktop.org Date: Mon, 16 Dec 2019 12:07:03 +0000 Message-Id: <20191216120704.958-5-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191216120704.958-1-tvrtko.ursulin@linux.intel.com> References: <20191216120704.958-1-tvrtko.ursulin@linux.intel.com> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH 4/5] drm/i915: Expose per-engine client busyness X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" From: Tvrtko Ursulin 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. v8: Use rcu_read_lock instead of struct_mutext when iterating contexts. (Chris) Signed-off-by: Tvrtko Ursulin --- drivers/gpu/drm/i915/i915_drv.h | 8 +++ drivers/gpu/drm/i915/i915_gem.c | 94 +++++++++++++++++++++++++++++++-- 2 files changed, 98 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h index 1740ce54cb48..e9cefd9b55b5 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h @@ -188,6 +188,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; @@ -232,10 +238,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 59c160534838..2337c4d82ad4 100644 --- a/drivers/gpu/drm/i915/i915_gem.c +++ b/drivers/gpu/drm/i915/i915_gem.c @@ -1541,6 +1541,53 @@ show_client_pid(struct device *kdev, struct device_attribute *attr, char *buf) return snprintf(buf, PAGE_SIZE, "%u", pid_nr(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; + struct i915_gem_engines *engines = rcu_dereference(ctx->engines); + 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, engines, it) { + if (ce->engine->uabi_class == engine_class) + total += ktime_to_ns(intel_context_get_busy_time(ce)); + } + + 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 }; + + rcu_read_lock(); + idr_for_each(&file_priv->context_idr, busy_add, &bc); + rcu_read_unlock(); + + 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, @@ -1550,8 +1597,8 @@ i915_gem_add_client(struct drm_i915_private *i915, struct i915_drm_client *client = &file_priv->client; struct i915_drm_clients *clients = &i915->clients; struct device_attribute *attr; - int ret = -ENOMEM; - char id[32]; + int i, ret = -ENOMEM; + char idstr[32]; if (!clients->root) return 0; /* intel_fbdev_init registers a client before sysfs */ @@ -1560,8 +1607,8 @@ i915_gem_add_client(struct drm_i915_private *i915, if (!client->name) goto err_name; - snprintf(id, sizeof(id), "%u", serial); - client->root = kobject_create_and_add(id, clients->root); + snprintf(idstr, sizeof(idstr), "%u", serial); + client->root = kobject_create_and_add(idstr, clients->root); if (!client->root) goto err_client; @@ -1585,11 +1632,43 @@ i915_gem_add_client(struct drm_i915_private *i915, if (ret) goto err_attr_pid; + client->busy_root = kobject_create_and_add("busy", client->root); + if (!client->busy_root) + goto err_busy_root; + + for (i = 0; i < ARRAY_SIZE(uabi_class_names); i++) { + struct i915_engine_busy_attribute *i915_attr = + &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(client->busy_root, + (struct attribute *)attr); + if (ret) + goto err_attr_busy; + } + client->id = serial; client->pid = get_task_pid(task, PIDTYPE_PID); return 0; +err_attr_busy: + for (--i; i >= 0; i--) + sysfs_remove_file(client->busy_root, + (struct attribute *)&client->attr.busy[i]); + kobject_put(client->busy_root); +err_busy_root: + sysfs_remove_file(client->root, (struct attribute *)&client->attr.pid); err_attr_pid: sysfs_remove_file(client->root, (struct attribute *)&client->attr.name); err_attr_name: @@ -1604,10 +1683,17 @@ void i915_gem_remove_client(struct drm_i915_file_private *file_priv) { struct i915_drm_clients *clients = &file_priv->dev_priv->clients; struct i915_drm_client *client = &file_priv->client; + unsigned int i; if (!client->name) return; /* intel_fbdev_init registers a client before sysfs */ + for (i = 0; i < ARRAY_SIZE(uabi_class_names); i++) + sysfs_remove_file(client->busy_root, + (struct attribute *)&client->attr.busy[i]); + + kobject_put(client->busy_root); + sysfs_remove_file(client->root, (struct attribute *)&client->attr.pid); sysfs_remove_file(client->root, (struct attribute *)&client->attr.name); kobject_put(client->root);