From patchwork Wed Oct 3 12:04:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 10624709 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6767313BB for ; Wed, 3 Oct 2018 12:04:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 59D7028944 for ; Wed, 3 Oct 2018 12:04:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4EACC28952; Wed, 3 Oct 2018 12:04:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id CE03A28944 for ; Wed, 3 Oct 2018 12:04:30 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C88656E458; Wed, 3 Oct 2018 12:04:28 +0000 (UTC) X-Original-To: Intel-gfx@lists.freedesktop.org Delivered-To: Intel-gfx@lists.freedesktop.org Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4D9B66E454 for ; Wed, 3 Oct 2018 12:04:26 +0000 (UTC) Received: by mail-wm1-x330.google.com with SMTP id z204-v6so4537013wmc.5 for ; Wed, 03 Oct 2018 05:04:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=kDW9MxfsvU36c4/lfYrKTjbxkOvjGw3J0TEh0fv9vIY=; b=ewpcQE7fbt9kS0IAW8Zx1+IIRepsPr9FTAf4RpS2hfgyjGQf6Es7mt9d4aT7UxwjLu U3q79kRUzjst5rE71ObXwx3xcmdECKAc6gnvJUAc2NGbYPIGSa2Ix0DZoWYd5TvtMdVZ 4VzOxKIKm3pufwPpvkbYZAxpe9zslO1WJgBdS4ii/lZ1Tpra9TJ7V88zadbEN4JLkIR7 /jQ2gh/hxgS9GmWiF0Is074eA0uoQgzeFTOZaiGZckccMappEOTIkzFAVBdfZ4ATRaVy txnCppn1D5oRaFiuyH6VrIjaqekv7qVxm71O4KkE3JEMk/fnPtfQlsTrJmo3Z342rF4s v/mA== X-Gm-Message-State: ABuFfoiWLwy410vSrbEpxchiwT7EKO6d88PidUv2xHlpn7SfIiN0XT25 63uGphZ8UQkBVP2zyshBoo/9jGI/aOE= X-Google-Smtp-Source: ACcGV63nuKyo/QG/ZKRb/2cwVpPA66aEMQ5VrVjciLgiCbYSf1V8RFRAPo+6MRz/b9hH/y9GvChRBQ== X-Received: by 2002:a1c:7dce:: with SMTP id y197-v6mr1317433wmc.78.1538568264624; Wed, 03 Oct 2018 05:04:24 -0700 (PDT) Received: from localhost.localdomain ([95.144.165.37]) by smtp.gmail.com with ESMTPSA id f69-v6sm866657wmf.34.2018.10.03.05.04.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Oct 2018 05:04:23 -0700 (PDT) From: Tvrtko Ursulin X-Google-Original-From: Tvrtko Ursulin To: Intel-gfx@lists.freedesktop.org Date: Wed, 3 Oct 2018 13:04:05 +0100 Message-Id: <20181003120406.6784-13-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181003120406.6784-1-tvrtko.ursulin@linux.intel.com> References: <20181003120406.6784-1-tvrtko.ursulin@linux.intel.com> Subject: [Intel-gfx] [RFC 12/13] drm/i915: Expose per-engine client busyness X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP 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. $ cat /sys/class/drm/card0/clients/5/busy/rcs0 32516602 This data can serve as an interface to implement a top like utility for GPU jobs. For instance I have prototyped a tool in IGT which produces periodic output like: neverball[ 6011]: rcs0: 41.01% bcs0: 0.00% vcs0: 0.00% vecs0: 0.00% Xorg[ 5664]: rcs0: 31.16% bcs0: 0.00% vcs0: 0.00% vecs0: 0.00% xfwm4[ 5727]: rcs0: 0.00% bcs0: 0.00% vcs0: 0.00% vecs0: 0.00% This tools can also be extended to use the i915 PMU and show overall engine busyness, and engine loads using the queue depth metric. v2: Use intel_context_engine_get_busy_time. v3: New directory structure. v4: Rebase. v5: sysfs_attr_init. Signed-off-by: Tvrtko Ursulin --- drivers/gpu/drm/i915/i915_drv.h | 8 ++++ drivers/gpu/drm/i915/i915_gem.c | 81 +++++++++++++++++++++++++++++++-- 2 files changed, 86 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h index 075a600e066f..a75f8345db27 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h @@ -330,6 +330,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; + struct intel_engine_cs *engine; +}; + struct drm_i915_file_private { struct drm_i915_private *dev_priv; struct drm_file *file; @@ -375,10 +381,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[I915_NUM_ENGINES]; } attr; } client; }; diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c index fe684d04be22..7a1a1279f39b 100644 --- a/drivers/gpu/drm/i915/i915_gem.c +++ b/drivers/gpu/drm/i915/i915_gem.c @@ -5908,6 +5908,37 @@ 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 { + struct intel_engine_cs *engine; + u64 total; +}; + +static int busy_add(int _id, void *p, void *data) +{ + struct busy_ctx *bc = data; + struct i915_gem_context *ctx = p; + struct intel_context *ce = to_intel_context(ctx, bc->engine); + + bc->total += ktime_to_ns(intel_context_get_busy_time(ce)); + + 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 = i915_attr->engine }; + + 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); +} + int i915_gem_add_client(struct drm_i915_private *i915, struct drm_i915_file_private *file_priv, @@ -5915,8 +5946,10 @@ i915_gem_add_client(struct drm_i915_private *i915, unsigned int serial) { int ret = -ENOMEM; + struct intel_engine_cs *engine; struct device_attribute *attr; - char id[32]; + enum intel_engine_id id, id2; + char idstr[32]; if (!i915->clients.root) goto err_name; @@ -5925,8 +5958,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; @@ -5953,10 +5986,42 @@ 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_each_engine(engine, i915, id) { + file_priv->client.attr.busy[id].file_priv = file_priv; + file_priv->client.attr.busy[id].engine = engine; + attr = &file_priv->client.attr.busy[id].attr; + sysfs_attr_init(&attr->attr); + attr->attr.name = engine->name; + 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_each_engine(engine, i915, id2) { + if (id2 == id) + break; + + sysfs_remove_file(file_priv->client.busy_root, + (struct attribute *)&file_priv->client.attr.busy[id2]); + } + 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); @@ -5970,10 +6035,20 @@ i915_gem_add_client(struct drm_i915_private *i915, void i915_gem_remove_client(struct drm_i915_file_private *file_priv) { + struct intel_engine_cs *engine; + enum intel_engine_id id; + + for_each_engine(engine, file_priv->dev_priv, id) + sysfs_remove_file(file_priv->client.busy_root, + (struct attribute *)&file_priv->client.attr.busy[id]); + + 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, (struct attribute *)&file_priv->client.attr.name); + kobject_put(file_priv->client.root); kfree(file_priv->client.name); }