From patchwork Wed Oct 3 12:04:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 10624717 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 C570A14BD for ; Wed, 3 Oct 2018 12:04:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B75E028944 for ; Wed, 3 Oct 2018 12:04:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ABB3028957; Wed, 3 Oct 2018 12:04:37 +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 4F62D28944 for ; Wed, 3 Oct 2018 12:04:37 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 809636E463; Wed, 3 Oct 2018 12:04:35 +0000 (UTC) X-Original-To: Intel-gfx@lists.freedesktop.org Delivered-To: Intel-gfx@lists.freedesktop.org Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by gabe.freedesktop.org (Postfix) with ESMTPS id 90B636E457 for ; Wed, 3 Oct 2018 12:04:27 +0000 (UTC) Received: by mail-wm1-x341.google.com with SMTP id 206-v6so5458401wmb.5 for ; Wed, 03 Oct 2018 05:04:27 -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=/T4ebmMPIaYE24eQQCZU579FLhm27hm865zllosBzug=; b=inu/QJUfxWIGC8JE1q1hWVdxZPzYqH7KQaksszc9k+qgcq7Pr/0O3ZgNVJdwr8CWKW 5r7ZaJ1eHJKL0lR0cFwzuGP4proxZGAUKWllF1TD+2z7rzW7/564QxGVmYFD+2Z61ddU H//X0W3O6v9BD3sNaa3ze03PBeYGkP1bJJyO5Cg9ynMKu9fjnlVS2T302PLs8twvCsP7 d4vH/1Ty6R3Hhrei2jIRoanh9ihtFvOuyBtNeiheVQhAbrk6bt4/z0v+uNCtHxtdBdLs 61Lwt0CRkEpG8QCFZl/ft+aGthHpppE7FNPISeCJMxzaMKNrTwdy2aR08D2TrbDXjYVC YF4A== X-Gm-Message-State: ABuFfoiq+Xctc9eCebA4b+qXh7QBL2EJRiEpUsdlfEkGdYImo7tooq1B KnJhQK8CujsTouRovcGvaOhFCRyEOf8= X-Google-Smtp-Source: ACcGV61hK2rgRIyGfiSrMS3WK4WhGkB5F154cjDl8zuvoQFM2Icm9phk0Zn6XUAY3KcIUy2B7kzw/g== X-Received: by 2002:a1c:48d:: with SMTP id 135-v6mr1228956wme.102.1538568265665; Wed, 03 Oct 2018 05:04:25 -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.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Oct 2018 05:04:24 -0700 (PDT) From: Tvrtko Ursulin X-Google-Original-From: Tvrtko Ursulin To: Intel-gfx@lists.freedesktop.org Date: Wed, 3 Oct 2018 13:04:06 +0100 Message-Id: <20181003120406.6784-14-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 13/13] 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: , 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. v3: sysfs_attr_init. Signed-off-by: Tvrtko Ursulin --- drivers/gpu/drm/i915/i915_drv.h | 4 ++ drivers/gpu/drm/i915/i915_sysfs.c | 73 +++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h index a75f8345db27..2d611335d367 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h @@ -2196,6 +2196,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..bf33b0cab7c8 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,18 @@ 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; + sysfs_attr_init(&attr->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 +717,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); }