From patchwork Sat Jul 2 18:51:23 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: akash.goel@intel.com X-Patchwork-Id: 9210987 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 AA2DB60571 for ; Sat, 2 Jul 2016 18:38:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9BA2C283F6 for ; Sat, 2 Jul 2016 18:38:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 90B9F28544; Sat, 2 Jul 2016 18:38:28 +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.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 08314283F6 for ; Sat, 2 Jul 2016 18:38:28 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1D2AE6E28E; Sat, 2 Jul 2016 18:38:27 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by gabe.freedesktop.org (Postfix) with ESMTP id 32EB56E28C for ; Sat, 2 Jul 2016 18:38:25 +0000 (UTC) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP; 02 Jul 2016 11:38:25 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.26,564,1459839600"; d="scan'208"; a="1014206484" Received: from akashgoe-desktop.iind.intel.com ([10.223.82.36]) by fmsmga002.fm.intel.com with ESMTP; 02 Jul 2016 11:38:23 -0700 From: akash.goel@intel.com To: intel-gfx@lists.freedesktop.org Date: Sun, 3 Jul 2016 00:21:23 +0530 Message-Id: <1467485491-17247-7-git-send-email-akash.goel@intel.com> X-Mailer: git-send-email 1.9.2 In-Reply-To: <1467485491-17247-1-git-send-email-akash.goel@intel.com> References: <1467485491-17247-1-git-send-email-akash.goel@intel.com> Cc: Akash Goel , Sourab Gupta Subject: [Intel-gfx] [PATCH 06/14] drm/i915: Add a relay backed debugfs interface for capturing GuC logs 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: Akash Goel Added a new debugfs interface '/sys/kernel/debug/dri/guc_log' for the User to capture GuC firmware logs. Availed relay framework to implement the interface, where Driver will have to just use a relay API to store snapshots of the GuC log buffer in the buffer managed by relay. The snapshot will be taken when GuC firmware sends a log buffer flush interrupt and up to four snaphots could be stored in the relay buffer. The relay buffer will be operated in a mode where it will overwrite the data not yet collected by User. Besides mmap method, through which User can directly access the relay buffer contents, relay also supports the 'poll' method. Through the 'poll' call on log file, User can come to know whenever a new snapshot of the log buffer is taken by Driver, so can run in tandem with the Driver and capture the logs in a sustained/streaming manner, without any loss of data. v2: Defer the creation of relay channel & associated debugfs file, as debugfs setup is now done at the end of i915 Driver load. (Chris) Suggested-by: Chris Wilson Signed-off-by: Sourab Gupta Signed-off-by: Akash Goel --- drivers/gpu/drm/i915/i915_drv.c | 2 + drivers/gpu/drm/i915/i915_guc_submission.c | 179 ++++++++++++++++++++++++++++- drivers/gpu/drm/i915/intel_guc.h | 3 + 3 files changed, 183 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c index ec3721c..7a3d821 100644 --- a/drivers/gpu/drm/i915/i915_drv.c +++ b/drivers/gpu/drm/i915/i915_drv.c @@ -1544,6 +1544,7 @@ static void i915_driver_register(struct drm_i915_private *dev_priv) /* Reveal our presence to userspace */ if (drm_dev_register(dev, 0) == 0) { i915_debugfs_register(dev_priv); + i915_guc_register(dev); i915_setup_sysfs(dev); } else DRM_ERROR("Failed to register driver for userspace access!\n"); @@ -1582,6 +1583,7 @@ static void i915_driver_unregister(struct drm_i915_private *dev_priv) intel_opregion_unregister(dev_priv); i915_teardown_sysfs(dev_priv->dev); + i915_guc_unregister(dev_priv->dev); i915_debugfs_unregister(dev_priv); drm_dev_unregister(dev_priv->dev); diff --git a/drivers/gpu/drm/i915/i915_guc_submission.c b/drivers/gpu/drm/i915/i915_guc_submission.c index 425226e..f3831b9 100644 --- a/drivers/gpu/drm/i915/i915_guc_submission.c +++ b/drivers/gpu/drm/i915/i915_guc_submission.c @@ -23,6 +23,8 @@ */ #include #include +#include +#include #include "i915_drv.h" #include "intel_guc.h" @@ -830,7 +832,16 @@ err: static void* guc_get_write_buffer(struct intel_guc *guc) { - return NULL; + /* FIXME: Cover the check under a lock ? */ + if (!guc->log.relay_chan) + return NULL; + + /* Get the pointer to relay sub buffer and copy data into it ourselves. + * Could have used the relay_write() to indirectly copy the data, but + * that would have been bit convoluted, as we also need to update the + * first page containing state data. + */ + return relay_reserve(guc->log.relay_chan, guc->log.obj->base.size); } static void guc_read_update_log_buffer(struct drm_device *dev, bool capture_all) @@ -897,6 +908,152 @@ static void guc_read_update_log_buffer(struct drm_device *dev, bool capture_all) } } +/* + * Sub buffer switch callback. If this callback is not implemented + * relay will operate in non-overwrite mode so will stop accepting + * new data if there are no empty sub buffers left. + */ +static int subbuf_start_callback(struct rchan_buf *buf, + void *subbuf, + void *prev_subbuf, + size_t prev_padding) +{ + /* Always switch to next sub buffer as we don't mind overwriting of + * old data/logs. + */ + return 1; +} + +/* + * file_create() callback. Creates relay file in debugfs. + */ +static struct dentry *create_buf_file_callback(const char *filename, + struct dentry *parent, + umode_t mode, + struct rchan_buf *buf, + int *is_global) +{ + /* + * Not using the channel filename passed as an argument, since for each + * channel relay appends the corresponding CPU number to the filename + * passed in relay_open(). This should be fine as relay just needs a + * dentry of the file associated with the channel buffer and that file's + * name need not be same as the filename passed as an argument. + */ + struct dentry *buf_file = debugfs_create_file("guc_log", mode, + parent, buf, &relay_file_operations); + + /* This to enable the use of a single buffer for the relay channel and + * correspondingly have a single file exposed to User, through which + * it can pull the logs in order without any post-processing. + */ + *is_global = 1; + + return buf_file; +} + +/* + * file_remove() default callback. Removes relay file in debugfs. + */ +static int remove_buf_file_callback(struct dentry *dentry) +{ + debugfs_remove(dentry); + return 0; +} + +/* relay channel callbacks */ +static struct rchan_callbacks relay_callbacks = { + .subbuf_start = subbuf_start_callback, + .create_buf_file = create_buf_file_callback, + .remove_buf_file = remove_buf_file_callback, +}; + +static void guc_remove_log_relay_file(struct intel_guc *guc) +{ + relay_close(guc->log.relay_chan); +} + +static int guc_create_log_relay_file(struct intel_guc *guc) +{ + struct drm_i915_private *dev_priv = guc_to_i915(guc); + struct drm_device *dev = dev_priv->dev; + struct dentry *log_dir; + struct rchan *guc_log_relay_chan; + size_t n_subbufs, subbuf_size; + + if (guc->log.relay_chan) + return 0; + + /* If /sys/kernel/debug/dri/0 location do not exist, then debugfs is + * not mounted and so can't create the relay file. + * The relay API seems to fit well with debugfs only. + */ + if (!dev->primary->debugfs_root) + return -ENODEV; + + /* For now create the log file in /sys/kernel/debug/dri/0 dir */ + log_dir = dev->primary->debugfs_root; + + /* Keep the size of sub buffers same as shared log buffer */ + subbuf_size = guc->log.obj->base.size; + /* TODO: Decide based on the User's input */ + n_subbufs = 4; + + guc_log_relay_chan = relay_open("guc_log", log_dir, + subbuf_size, n_subbufs, &relay_callbacks, dev); + + if (!guc_log_relay_chan) { + DRM_DEBUG_DRIVER("Couldn't create relay chan for guc logs\n"); + return -ENOMEM; + } + + /* FIXME: Cover the update under a lock ? */ + guc->log.relay_chan = guc_log_relay_chan; + return 0; +} + +static void guc_log_cleanup(struct drm_device *dev) +{ + struct drm_i915_private *dev_priv = dev->dev_private; + struct intel_guc *guc = &dev_priv->guc; + + lockdep_assert_held(&dev->struct_mutex); + + if (i915.guc_log_level < 0) + return; + + /* First disable the flush interrupt */ + gen9_disable_guc_interrupts(dev_priv); + + guc_remove_log_relay_file(guc); +} + +static int guc_log_late_setup(struct drm_device *dev) +{ + struct drm_i915_private *dev_priv = dev->dev_private; + struct intel_guc *guc = &dev_priv->guc; + int ret; + + lockdep_assert_held(&dev->struct_mutex); + + if (i915.guc_log_level < 0) + return -EINVAL; + + if (WARN_ON(guc->log.relay_chan)) + return -EINVAL; + + ret = guc_create_log_relay_file(guc); + if (ret) + goto err; + + return 0; +err: + /* logging will remain off */ + i915.guc_log_level = -1; + gen9_disable_guc_interrupts(dev_priv); + return ret; +} + static void guc_create_log(struct intel_guc *guc) { struct drm_i915_private *dev_priv = guc_to_i915(guc); @@ -1165,3 +1322,23 @@ void i915_guc_capture_logs(struct drm_device *dev, bool capture_all) host2guc_logbuffer_flush_complete(&dev_priv->guc); } + +void i915_guc_unregister(struct drm_device *dev) +{ + if (!i915.enable_guc_submission) + return; + + mutex_lock(&dev->struct_mutex); + guc_log_cleanup(dev); + mutex_unlock(&dev->struct_mutex); +} + +void i915_guc_register(struct drm_device *dev) +{ + if (!i915.enable_guc_submission) + return; + + mutex_lock(&dev->struct_mutex); + guc_log_late_setup(dev); + mutex_unlock(&dev->struct_mutex); +} diff --git a/drivers/gpu/drm/i915/intel_guc.h b/drivers/gpu/drm/i915/intel_guc.h index 71aab85..73c9fdf 100644 --- a/drivers/gpu/drm/i915/intel_guc.h +++ b/drivers/gpu/drm/i915/intel_guc.h @@ -126,6 +126,7 @@ struct intel_guc_log { uint32_t flags; struct drm_i915_gem_object *obj; struct workqueue_struct *wq; + struct rchan *relay_chan; }; struct intel_guc { @@ -173,5 +174,7 @@ int i915_guc_submit(struct drm_i915_gem_request *rq); void i915_guc_submission_disable(struct drm_i915_private *dev_priv); void i915_guc_submission_fini(struct drm_i915_private *dev_priv); void i915_guc_capture_logs(struct drm_device *dev, bool capture_all); +void i915_guc_register(struct drm_device *dev); +void i915_guc_unregister(struct drm_device *dev); #endif