From patchwork Tue May 9 14:09:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 9718031 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D12B660364 for ; Tue, 9 May 2017 14:09:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C77E028405 for ; Tue, 9 May 2017 14:09:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BC5B72842A; Tue, 9 May 2017 14:09:54 +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=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID 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 4A5B828405 for ; Tue, 9 May 2017 14:09:54 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1AD286E193; Tue, 9 May 2017 14:09:53 +0000 (UTC) X-Original-To: Intel-gfx@lists.freedesktop.org Delivered-To: Intel-gfx@lists.freedesktop.org Received: from mail-wr0-x241.google.com (mail-wr0-x241.google.com [IPv6:2a00:1450:400c:c0c::241]) by gabe.freedesktop.org (Postfix) with ESMTPS id 27DAA6E193 for ; Tue, 9 May 2017 14:09:51 +0000 (UTC) Received: by mail-wr0-x241.google.com with SMTP id g12so385866wrg.2 for ; Tue, 09 May 2017 07:09:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ursulin-net.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=MURhASvyxHpLzNf2JbaTAXq7MqR5/ePM2wsTq1I+oRc=; b=D1/75dIIp5CFDieepH5HSP6YB8cIsevN0xL7pv2BhAlmV6cUmqqn/PWlZPusbfVCd5 ajdyjsVnmunAwQNROFRdSNFUTojtF6TqxdLIMgS3gf1NGNsV7h6QAHUBZOSTKodqqIFg KsjHS7Et475m3cE8ZCElA1XK00hBcr2njDapwwPcqdpfkGFs/e3ZVfOPFD/dFptJAHI/ Ie1hPJsj56mTjYxD0Gnl4qiNBjY8XFm5GTci1GrzcPyCJIc9ZTz3KVR/DgRHbnIZKtrQ rloSOZfnWIFWVjltnlqFSYNJcvbSgnifRQPb3GODNQZFX+pBj4lhcNblwl7OLhiPsehD 4lOA== 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=MURhASvyxHpLzNf2JbaTAXq7MqR5/ePM2wsTq1I+oRc=; b=uG7+Ry8HDK9MaQ4j71hOdgFbQm9dywUA4lwJLhgn9WWoGTcqBtCHng5ywyNnKEzKnt 0HNz1bBCH2/eON3aCLqviVhXz95ICsex+qtpAvUgp/Eb3hE+7n00T7QHFX6vbq5t01Yu /UJewieB6sLDYhgYwptRzMMsYswp/vpW41xENVn8kaSQEJIDoOuOQsSYDnebjzJBEgRr OJ2uxoP7eSP0iS7V2eiTdy/qF9F10BVmRBLuAQKt2zSlVP06uFa6SjfsI3MUYKquxU4R FFYzjmNM+QRbGbtyVmVVo7UaZ0lptEyHC2zrNTxDaju7OvbDo0oVNrB7OMySBXoc+aLB jBOw== X-Gm-Message-State: AODbwcBq3GBSErtrPNNodelcRwI7ZUfJNt/aqJFXRb+3Ot7Bh+boVUSU rMdmDYSOmLPaa4J/ X-Received: by 10.223.172.105 with SMTP id v96mr187133wrc.1.1494338989552; Tue, 09 May 2017 07:09:49 -0700 (PDT) Received: from t460p.intel ([94.15.199.60]) by smtp.gmail.com with ESMTPSA id a197sm85577wma.1.2017.05.09.07.09.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 09 May 2017 07:09:49 -0700 (PDT) From: Tvrtko Ursulin X-Google-Original-From: Tvrtko Ursulin To: Intel-gfx@lists.freedesktop.org Date: Tue, 9 May 2017 15:09:36 +0100 Message-Id: <20170509140936.19060-4-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170509140936.19060-1-tvrtko.ursulin@linux.intel.com> References: <20170509140936.19060-1-tvrtko.ursulin@linux.intel.com> Subject: [Intel-gfx] [RFC 3/3] drm/i915: Export engine busy stats in debugfs X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 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 Export the stats added in the previous patch in debugfs. Number of active clients reading this data is tracked and the static key is only enabled whilst there are some. Userspace is intended to keep the file descriptor open, seeking to the beginning of the file periodically, and re-reading the stats. This is because the underlying implementation is costly on every first open/last close transition, and also, because the stats exported mostly make sense when they are considered relative to the previous sample. File lists nanoseconds each engine was active since the tracking has started. Signed-off-by: Tvrtko Ursulin --- drivers/gpu/drm/i915/i915_debugfs.c | 120 ++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c index 1003511f28cc..db588ef858cb 100644 --- a/drivers/gpu/drm/i915/i915_debugfs.c +++ b/drivers/gpu/drm/i915/i915_debugfs.c @@ -4752,6 +4752,120 @@ static const struct file_operations i915_hpd_storm_ctl_fops = { .write = i915_hpd_storm_ctl_write }; +DECLARE_STATIC_KEY_FALSE(i915_engine_stats_key); +static DEFINE_MUTEX(i915_engine_stats_mutex); +static int i915_engine_stats_ref; + +struct i915_engine_stats_buf { + unsigned int len; + size_t available; + char buf[0]; +}; + +static int i915_engine_stats_open(struct inode *inode, struct file *file) +{ + const unsigned int engine_name_len = + sizeof(((struct intel_engine_cs *)0)->name); + struct i915_engine_stats_buf *buf; + const unsigned int buf_size = + (engine_name_len + 2 + 19 + 1) * I915_NUM_ENGINES + 1 + + sizeof(*buf); + int ret; + + buf = kzalloc(buf_size, GFP_KERNEL); + if (!buf) + return -ENOMEM; + + buf->len = buf_size; + file->private_data = buf; + + ret = mutex_lock_interruptible(&i915_engine_stats_mutex); + if (ret) + return ret; + + if (i915_engine_stats_ref++ == 0) { + struct drm_i915_private *dev_priv = file->f_inode->i_private; + struct intel_engine_cs *engine; + enum intel_engine_id id; + + for_each_engine(engine, dev_priv, id) { + memset(&engine->stats, 0, sizeof(engine->stats)); + spin_lock_init(&engine->stats.lock); + } + + static_branch_enable(&i915_engine_stats_key); + } + + mutex_unlock(&i915_engine_stats_mutex); + + return 0; +} + +static int i915_engine_stats_release(struct inode *inode, struct file *file) +{ + mutex_lock(&i915_engine_stats_mutex); + if (--i915_engine_stats_ref == 0) + static_branch_disable(&i915_engine_stats_key); + mutex_unlock(&i915_engine_stats_mutex); + + kfree(file->private_data); + + return 0; +} + +static ssize_t i915_engine_stats_read(struct file *file, char __user *ubuf, + size_t count, loff_t *pos) +{ + struct i915_engine_stats_buf *buf = + (struct i915_engine_stats_buf *)file->private_data; + + if (*pos == 0) { + struct drm_i915_private *dev_priv = file->f_inode->i_private; + char *ptr = &buf->buf[0]; + int left = buf->len; + struct intel_engine_cs *engine; + enum intel_engine_id id; + + buf->available = 0; + + for_each_engine(engine, dev_priv, id) { + u64 total; + int len; + + spin_lock_irq(&engine->stats.lock); + total = engine->stats.total; + /* + * If the engine is executing something at the moment + * add it to the total. + */ + if (engine->stats.ref) + total += ktime_get_real_ns() - + engine->stats.start; + spin_unlock_irq(&engine->stats.lock); + + len = snprintf(ptr, left, "%s: %llu\n", + engine->name, total); + buf->available += len; + left -= len; + ptr += len; + + if (len == 0) + return -EFBIG; + } + } + + return simple_read_from_buffer(ubuf, count, pos, &buf->buf[0], + buf->available); +} + +static const struct file_operations i915_engine_stats_fops = { + .owner = THIS_MODULE, + .open = i915_engine_stats_open, + .release = i915_engine_stats_release, + .read = i915_engine_stats_read, + .llseek = default_llseek, +}; + static const struct drm_info_list i915_debugfs_list[] = { {"i915_capabilities", i915_capabilities, 0}, {"i915_gem_objects", i915_gem_object_info, 0}, @@ -4839,6 +4953,12 @@ int i915_debugfs_register(struct drm_i915_private *dev_priv) struct dentry *ent; int ret, i; + ent = debugfs_create_file("i915_engine_stats", S_IRUGO, + minor->debugfs_root, to_i915(minor->dev), + &i915_engine_stats_fops); + if (!ent) + return -ENOMEM; + ent = debugfs_create_file("i915_forcewake_user", S_IRUSR, minor->debugfs_root, to_i915(minor->dev), &i915_forcewake_fops);