From patchwork Tue Dec 1 09:07:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 11942341 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0CC3CC8301F for ; Tue, 1 Dec 2020 09:07:56 +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 907BC20656 for ; Tue, 1 Dec 2020 09:07:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 907BC20656 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=chris-wilson.co.uk 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 597B36E51A; Tue, 1 Dec 2020 09:07:47 +0000 (UTC) Received: from fireflyinternet.com (unknown [77.68.26.236]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7734989F3C for ; Tue, 1 Dec 2020 09:07:41 +0000 (UTC) X-Default-Received-SPF: pass (skip=forwardok (res=PASS)) x-ip-name=78.156.65.138; Received: from build.alporthouse.com (unverified [78.156.65.138]) by fireflyinternet.com (Firefly Internet (M1)) with ESMTP id 23172174-1500050 for multiple; Tue, 01 Dec 2020 09:07:32 +0000 From: Chris Wilson To: intel-gfx@lists.freedesktop.org Date: Tue, 1 Dec 2020 09:07:26 +0000 Message-Id: <20201201090729.24777-9-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201201090729.24777-1-chris@chris-wilson.co.uk> References: <20201201090729.24777-1-chris@chris-wilson.co.uk> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH 09/12] drm/i915: Prefer software tracked context 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 When available prefer context tracked context busyness because it provides visibility into currently executing contexts as well. Signed-off-by: Tvrtko Ursulin --- drivers/gpu/drm/i915/i915_drm_client.c | 66 ++++++++++++++++++++++++-- 1 file changed, 61 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_drm_client.c b/drivers/gpu/drm/i915/i915_drm_client.c index 49bbbc7b7fbf..8a5594819f9a 100644 --- a/drivers/gpu/drm/i915/i915_drm_client.c +++ b/drivers/gpu/drm/i915/i915_drm_client.c @@ -96,6 +96,59 @@ 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; + const u32 period_ns = + RUNTIME_INFO(client->clients->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 += sw_busy_add(ctx, class); + rcu_read_unlock(); + + return snprintf(buf, PAGE_SIZE, "%llu\n", total); +} + static const char * const uabi_class_names[] = { [I915_ENGINE_CLASS_RENDER] = "0", [I915_ENGINE_CLASS_COPY] = "1", @@ -106,6 +159,8 @@ static const char * const uabi_class_names[] = { static int __client_register_sysfs_busy(struct i915_drm_client *client) { struct i915_drm_clients *clients = client->clients; + bool sw_stats = clients->i915->caps.scheduler & + I915_SCHEDULER_CAP_ENGINE_BUSY_STATS; unsigned int i; int ret = 0; @@ -131,18 +186,19 @@ static int __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; }