From patchwork Tue Feb 2 21:30:52 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Bragg X-Patchwork-Id: 8195911 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 3F7CE9F4DD for ; Tue, 2 Feb 2016 21:31:14 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 44FB22034E for ; Tue, 2 Feb 2016 21:31:13 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 52DC0202EB for ; Tue, 2 Feb 2016 21:31:12 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 994977208E; Tue, 2 Feb 2016 13:31:07 -0800 (PST) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-wm0-f65.google.com (mail-wm0-f65.google.com [74.125.82.65]) by gabe.freedesktop.org (Postfix) with ESMTPS id E0DA97206C; Tue, 2 Feb 2016 13:31:05 -0800 (PST) Received: by mail-wm0-f65.google.com with SMTP id p63so4301031wmp.1; Tue, 02 Feb 2016 13:31:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=WgM/auR490/89u8dOaCC4Go5hFMS0QiiKkZohBxomqk=; b=sYcTr7b2QnXX0783JpQVTQ3kL1YfjFB/W8tB6ISrzrWA6QmcuUp5rPpNn3oBdOhXKo A9ZYYK0LT6/YPwiGy79MebPeMfopG3IuqyTe85l9eM2Cwofkb+F+i23kXMRP8JkeWgiY /kv4rWrRYQInoL2fFuwVgQBFGnExR9KTO6FGguhKL9AAz/IAdywRYJc+fUVfaR1btp13 MSdPOL/Vf9VsYzIiFA3/IQGgHocdVBHcaObi7mYbnNulcjtBz/gs1xGZnIaVtijagrYU +fk1RjQWHuQMY83xCjhPFJaQgSXNh10zXJMNqDe4cdl/Uq9R4IppXKdIsNrdwcK1jsxi 5c/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=WgM/auR490/89u8dOaCC4Go5hFMS0QiiKkZohBxomqk=; b=e/FhIZOISofZOmKzUVUzPELzfHp+9UWHmvBZk2PejeqXN8CZnAhZFxVZDA7WZ9ilVg Hna+d2E/Af2RcDEQ1u2l23Na6qtpmF6pUqBYMvrSJ00szUcUoMshn+vC5oc+bKudjgMC Leb+YHDNjk81Q7VWP+NbXplfUgewrPZ80LCBHIgwO+QZ2kGQcy4G70lhGVz0TgIn9AlO swHDJiJx6kgceSFKkIkV25Wqq60GyinowmKkJMg1+gtrm5fzlaCNIQb/pfd1St8hvXCz bnlDm88FpBoyBXDls2H547E23HEdNOIBoxfPNqKK29Dc2F217YhqD/gmXln6XUSxdJhI rhKQ== X-Gm-Message-State: AG10YORfBk6oYHDl0yhKX5Lh2iFoYLlqle22qHGH7ch1pECJHZPUqDhOEAr0SK7vGFhLIg== X-Received: by 10.194.176.74 with SMTP id cg10mr36460468wjc.169.1454448664697; Tue, 02 Feb 2016 13:31:04 -0800 (PST) Received: from sixbynine.org (cpc26-heme10-2-0-cust305.9-1.cable.virginm.net. [86.3.57.50]) by smtp.gmail.com with ESMTPSA id 17sm4732771wmy.15.2016.02.02.13.31.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Feb 2016 13:31:04 -0800 (PST) From: Robert Bragg To: intel-gfx@lists.freedesktop.org Date: Tue, 2 Feb 2016 21:30:52 +0000 Message-Id: <1454448655-11178-6-git-send-email-robert@sixbynine.org> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1454448655-11178-1-git-send-email-robert@sixbynine.org> References: <1454448655-11178-1-git-send-email-robert@sixbynine.org> Cc: David Airlie , dri-devel@lists.freedesktop.org, Sourab Gupta , Daniel Vetter Subject: [Intel-gfx] [PATCH 5/8] drm/i915: advertise available metrics via sysfs 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-Spam-Status: No, score=-4.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Each metric set is given a sysfs entry like: /sys/class/drm/card0/metrics//id This allows userspace to enumerate the specific sets that are available for the current system. The 'id' file contains an unsigned integer that can be used to open the associated metric set via DRM_IOCTL_I915_PERF_OPEN. The is a globally unique ID for a specific OA unit configuration that can be reliably used as a key to lookup corresponding counter meta data and normalization equations. Signed-off-by: Robert Bragg --- drivers/gpu/drm/i915/i915_drv.h | 2 ++ drivers/gpu/drm/i915/i915_oa_hsw.c | 45 ++++++++++++++++++++++++++++++++++++++ drivers/gpu/drm/i915/i915_oa_hsw.h | 4 ++++ drivers/gpu/drm/i915/i915_perf.c | 18 ++++++++++++++- 4 files changed, 68 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h index aaf1a5b..d51460b 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h @@ -2044,6 +2044,8 @@ struct drm_i915_private { struct { bool initialized; + struct kobject *metrics_kobj; + struct mutex lock; struct list_head streams; diff --git a/drivers/gpu/drm/i915/i915_oa_hsw.c b/drivers/gpu/drm/i915/i915_oa_hsw.c index c05745e..9be5f38 100644 --- a/drivers/gpu/drm/i915/i915_oa_hsw.c +++ b/drivers/gpu/drm/i915/i915_oa_hsw.c @@ -24,6 +24,8 @@ * */ +#include + #include "i915_drv.h" enum metric_set_id { @@ -130,3 +132,46 @@ int i915_oa_select_metric_set_hsw(struct drm_i915_private *dev_priv) return -ENODEV; } } + +static ssize_t +show_render_basic_id(struct device *kdev, struct device_attribute *attr, char *buf) +{ + return sprintf(buf, "%d\n", METRIC_SET_ID_RENDER_BASIC); +} + +static struct device_attribute dev_attr_render_basic_id = { + .attr = { .name = "id", .mode = S_IRUGO }, + .show = show_render_basic_id, + .store = NULL, +}; + +static struct attribute *attrs_render_basic[] = { + &dev_attr_render_basic_id.attr, + NULL, +}; + +static struct attribute_group group_render_basic = { + .name = "403d8832-1a27-4aa6-a64e-f5389ce7b212", + .attrs = attrs_render_basic, +}; + +int +i915_perf_init_sysfs_hsw(struct drm_i915_private *dev_priv) +{ + int ret; + + ret = sysfs_create_group(dev_priv->perf.metrics_kobj, &group_render_basic); + if (ret) + goto error_render_basic; + + return 0; + +error_render_basic: + return ret; +} + +void +i915_perf_deinit_sysfs_hsw(struct drm_i915_private *dev_priv) +{ + sysfs_remove_group(dev_priv->perf.metrics_kobj, &group_render_basic); +} diff --git a/drivers/gpu/drm/i915/i915_oa_hsw.h b/drivers/gpu/drm/i915/i915_oa_hsw.h index b618a1f..e4ba89d 100644 --- a/drivers/gpu/drm/i915/i915_oa_hsw.h +++ b/drivers/gpu/drm/i915/i915_oa_hsw.h @@ -31,4 +31,8 @@ extern int i915_oa_n_builtin_metric_sets_hsw; extern int i915_oa_select_metric_set_hsw(struct drm_i915_private *dev_priv); +extern int i915_perf_init_sysfs_hsw(struct drm_i915_private *dev_priv); + +extern void i915_perf_deinit_sysfs_hsw(struct drm_i915_private *dev_priv); + #endif diff --git a/drivers/gpu/drm/i915/i915_perf.c b/drivers/gpu/drm/i915/i915_perf.c index b54f719..5c08a16 100644 --- a/drivers/gpu/drm/i915/i915_perf.c +++ b/drivers/gpu/drm/i915/i915_perf.c @@ -1164,6 +1164,11 @@ void i915_perf_init(struct drm_device *dev) if (!IS_HASWELL(dev)) return; + dev_priv->perf.metrics_kobj = + kobject_create_and_add("metrics", &dev->primary->kdev->kobj); + if (!dev_priv->perf.metrics_kobj) + return; + hrtimer_init(&dev_priv->perf.oa.poll_check_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); dev_priv->perf.oa.poll_check_timer.function = poll_check_timer_cb; @@ -1187,9 +1192,15 @@ void i915_perf_init(struct drm_device *dev) dev_priv->perf.oa.n_builtin_sets = i915_oa_n_builtin_metric_sets_hsw; - dev_priv->perf.oa.oa_formats = hsw_oa_formats; + if (i915_perf_init_sysfs_hsw(dev_priv)) { + kobject_put(dev_priv->perf.metrics_kobj); + dev_priv->perf.metrics_kobj = NULL; + return; + } dev_priv->perf.initialized = true; + + return; } void i915_perf_fini(struct drm_device *dev) @@ -1199,6 +1210,11 @@ void i915_perf_fini(struct drm_device *dev) if (!dev_priv->perf.initialized) return; + i915_perf_deinit_sysfs_hsw(dev_priv); + + kobject_put(dev_priv->perf.metrics_kobj); + dev_priv->perf.metrics_kobj = NULL; + dev_priv->perf.oa.ops.init_oa_buffer = NULL; dev_priv->perf.initialized = false;