From patchwork Tue Apr 17 12:27:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 10344899 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 3CB296039A for ; Tue, 17 Apr 2018 12:28:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 33317286EC for ; Tue, 17 Apr 2018 12:28:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 27C1228A8E; Tue, 17 Apr 2018 12:28:20 +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.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,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 1C659286EC for ; Tue, 17 Apr 2018 12:28:19 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id EA3C26E1E8; Tue, 17 Apr 2018 12:28:15 +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 CF04C6E326 for ; Tue, 17 Apr 2018 12:28:14 +0000 (UTC) Received: by mail-wr0-x241.google.com with SMTP id h3so22366520wrh.5 for ; Tue, 17 Apr 2018 05:28:14 -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=0SH+T9eQuld0y8+MzhFraO5t+5UQ3Bi6pwynH8Jv4VE=; b=v4+8+xrOnbvsUQvwip4aWELRMBFraimITbNBprOmmEWlg6lug/epHeu2tRpqs6VcXX qODShc4lNFkFIhvhBKpapl2EkLGvHXFTl1lRtTBd+A8HjoJufVvBUpGantHrMpnJRaDI GTA41l6TUFmPQpqgzznaNG2VcdcMssb7Yp3p8JgwFPlm6i1Dt8O4ezxTyNKEA7cd8X3B +UxX7ZpiPiFSWCCn+Jgols6HoNWltptZ1vs95usjCLvq5gD9SPQMxgDGvxyX+EAWsbvI jrv/MNafNNJNFqhBH8lmK0jxA+exv76QD7pkU+z6lm50ne68/shdhPLxmu46ds6DBvGm Jz9g== 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=0SH+T9eQuld0y8+MzhFraO5t+5UQ3Bi6pwynH8Jv4VE=; b=uPQ0r8CBfRrtbgijK1fhBnYttnql2tJ+ap+1wjQExnmUCR7gy6YYOMlPlun79ECpwW JOBr9J6+kH6koPpsOEBWQAGEJiDJP0s2MqbFWsCeTRFdit/tj0KosyJwMfeHmrz5DcBL xiYMgKbFdDPCEiuQHlSViq3PnKaRwnHk8jZNk1aZIoEvX15VbsuM3qY4bDeMlLVXFeUb D9VC9PA/48hbTWwl6rhmjlUZLM2ZS6mRmOg0GEISFGNF8AfhorTXyRn93VrBarKC2csJ JziwIGiz63haOzKv10x6qSI8uYUtwi9BhHcU1R1MEnO1C46isEOEMpMpAt2iUcj+ojp8 N8JQ== X-Gm-Message-State: ALQs6tC0fEB3gaAaGonIfoDal0lloG/0U/2gjMCs7+7+23Pi/6MGNfJl 1W1P5qbeEOhRTdaBQWvgZr+g0A== X-Google-Smtp-Source: AIpwx48LtLG0vWjow0kkfNodCzQtTfzZJj2YSq1wCb8+xXFaueisExR+O/YrlsMnGhW2gUfTzR0ocA== X-Received: by 10.28.51.79 with SMTP id z76mr933889wmz.113.1523968093501; Tue, 17 Apr 2018 05:28:13 -0700 (PDT) Received: from localhost.localdomain ([95.146.151.144]) by smtp.gmail.com with ESMTPSA id f22sm9226027wmc.3.2018.04.17.05.28.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Apr 2018 05:28:12 -0700 (PDT) From: Tvrtko Ursulin X-Google-Original-From: Tvrtko Ursulin To: igt-dev@lists.freedesktop.org Date: Tue, 17 Apr 2018 13:27:35 +0100 Message-Id: <20180417122736.11603-7-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180417122736.11603-1-tvrtko.ursulin@linux.intel.com> References: <20180417122736.11603-1-tvrtko.ursulin@linux.intel.com> Subject: [Intel-gfx] [RFC 6/7] drm/i915: Add sysfs toggle to enable per-client engine stats 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: , Cc: Intel-gfx@lists.freedesktop.org MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP From: Tvrtko Ursulin By default we are not collecting any per-engine and per-context statistcs. Add a new sysfs toggle to enable this facility: $ echo 1 >/sys/class/drm/card0/clients/enable_stats v2: Rebase. Signed-off-by: Tvrtko Ursulin --- drivers/gpu/drm/i915/i915_drv.h | 4 +++ drivers/gpu/drm/i915/i915_sysfs.c | 72 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h index f83b8dcac16b..aa82df864dd4 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h @@ -2136,6 +2136,10 @@ struct drm_i915_private { struct i915_drm_clients { struct kobject *root; atomic_t serial; + struct { + bool enabled; + struct device_attribute attr; + } stats; } clients; /* diff --git a/drivers/gpu/drm/i915/i915_sysfs.c b/drivers/gpu/drm/i915/i915_sysfs.c index d809259456ef..70115072d56f 100644 --- a/drivers/gpu/drm/i915/i915_sysfs.c +++ b/drivers/gpu/drm/i915/i915_sysfs.c @@ -576,9 +576,67 @@ static void i915_setup_error_capture(struct device *kdev) {} static void i915_teardown_error_capture(struct device *kdev) {} #endif +static ssize_t +show_client_stats(struct device *kdev, struct device_attribute *attr, char *buf) +{ + struct drm_i915_private *i915 = + container_of(attr, struct drm_i915_private, clients.stats.attr); + + return snprintf(buf, PAGE_SIZE, "%u\n", i915->clients.stats.enabled); +} + +static ssize_t +store_client_stats(struct device *kdev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct drm_i915_private *i915 = + container_of(attr, struct drm_i915_private, clients.stats.attr); + bool disable = false; + bool enable = false; + bool val = false; + struct intel_engine_cs *engine; + enum intel_engine_id id; + int ret; + + /* Use RCS as proxy for all engines. */ + if (!intel_engine_supports_stats(i915->engine[RCS])) + return -EINVAL; + + ret = kstrtobool(buf, &val); + if (ret) + return ret; + + ret = i915_mutex_lock_interruptible(&i915->drm); + if (ret) + return ret; + + if (val && !i915->clients.stats.enabled) + enable = true; + else if (!val && i915->clients.stats.enabled) + disable = true; + + if (!enable && !disable) + goto out; + + for_each_engine(engine, i915, id) { + if (enable) + WARN_ON_ONCE(intel_enable_engine_stats(engine)); + else if (disable) + intel_disable_engine_stats(engine); + } + + i915->clients.stats.enabled = val; + +out: + mutex_unlock(&i915->drm.struct_mutex); + + return count; +} + void i915_setup_sysfs(struct drm_i915_private *dev_priv) { struct device *kdev = dev_priv->drm.primary->kdev; + struct device_attribute *attr; int ret; dev_priv->clients.root = @@ -586,6 +644,17 @@ void i915_setup_sysfs(struct drm_i915_private *dev_priv) if (!dev_priv->clients.root) DRM_ERROR("Per-client sysfs setup failed\n"); + attr = &dev_priv->clients.stats.attr; + attr->attr.name = "enable_stats"; + attr->attr.mode = 0664; + attr->show = show_client_stats; + attr->store = store_client_stats; + + ret = sysfs_create_file(dev_priv->clients.root, + (struct attribute *)attr); + if (ret) + DRM_ERROR("Per-client sysfs setup failed! (%d)\n", ret); + #ifdef CONFIG_PM if (HAS_RC6(dev_priv)) { ret = sysfs_merge_group(&kdev->kobj, @@ -647,6 +716,9 @@ void i915_teardown_sysfs(struct drm_i915_private *dev_priv) sysfs_unmerge_group(&kdev->kobj, &rc6p_attr_group); #endif + sysfs_remove_file(dev_priv->clients.root, + (struct attribute *)&dev_priv->clients.stats.attr); + if (dev_priv->clients.root) kobject_put(dev_priv->clients.root); }