From patchwork Fri May 27 19:42:56 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: 9138895 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 313A96075A for ; Fri, 27 May 2016 19:30:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2391E27CF9 for ; Fri, 27 May 2016 19:30:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 18B5F28294; Fri, 27 May 2016 19:30:19 +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 A683427CF9 for ; Fri, 27 May 2016 19:30:18 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CE4A16ED1A; Fri, 27 May 2016 19:30:13 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by gabe.freedesktop.org (Postfix) with ESMTP id D29CB6E0DF for ; Fri, 27 May 2016 19:30:04 +0000 (UTC) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga103.fm.intel.com with ESMTP; 27 May 2016 12:30:05 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.26,375,1459839600"; d="scan'208";a="986117428" Received: from akashgoe-desktop.iind.intel.com ([10.223.82.36]) by orsmga002.jf.intel.com with ESMTP; 27 May 2016 12:30:02 -0700 From: akash.goel@intel.com To: intel-gfx@lists.freedesktop.org Date: Sat, 28 May 2016 01:12:56 +0530 Message-Id: <1464378183-9433-6-git-send-email-akash.goel@intel.com> X-Mailer: git-send-email 1.9.2 In-Reply-To: <1464378183-9433-1-git-send-email-akash.goel@intel.com> References: <1464378183-9433-1-git-send-email-akash.goel@intel.com> Cc: sourab.gupta@intel.com, Akash Goel Subject: [Intel-gfx] [RFC 05/12] 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 ukernel logs. Availed relay framework to implement the interface, so Driver will just use a relay API to copy the contents of GuC log buffer into relay's buffer. Suggested-by: Chris Wilson Signed-off-by: Sourab Gupta Signed-off-by: Akash Goel --- drivers/gpu/drm/i915/i915_guc_submission.c | 125 +++++++++++++++++++++++++++++ drivers/gpu/drm/i915/intel_guc.h | 1 + 2 files changed, 126 insertions(+) diff --git a/drivers/gpu/drm/i915/i915_guc_submission.c b/drivers/gpu/drm/i915/i915_guc_submission.c index f7f29f6..379e2843 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" @@ -837,6 +839,124 @@ static void guc_read_update_log_buffer(struct drm_device *dev) guc_move_to_next_buf(guc); } +#ifdef CONFIG_DEBUG_FS +/* + * 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) +{ + /* The relay API seems to fit well with debugfs only. + * There are 3 requirements to associate a file with relay channel, + * a) Need the associated dentry pointer of the file while opening + * the relay channel. + * b) Should use 'relay_file_operations' fops for the file. + * c) The private field of file's inode should be set to the pointer + * of relay channel buffer. + * All the above 3 requirements can be met for a debugfs file in a + * straightforward manner, but not for a file created inside the + * sysfs or for a file created as a character device file. + */ + struct dentry *buf_file = debugfs_create_file(filename, 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 void 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; + + /* For now create the log file in /sys/kernel/debug/dri dir. */ + log_dir = dev->primary->debugfs_root->d_parent; + + /* 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_ERROR("Couldn't create relay chan for guc logs\n"); + return; + } + + guc->log_relay_chan = guc_log_relay_chan; + + /* Enable interrupt to start capturing of the logs inside the + * relay channel's buffer. + */ + if (i915.guc_log_level >= 0) + gen8_enable_guc_interrupts(dev); +} +#endif + +static void guc_logging_fini(struct intel_guc *guc) +{ +#ifdef CONFIG_DEBUG_FS + guc_remove_log_relay_file(guc); +#endif +} + +static void guc_logging_init(struct intel_guc *guc) +{ +#ifdef CONFIG_DEBUG_FS + guc_create_log_relay_file(guc); +#endif +} + static void guc_create_log(struct intel_guc *guc) { struct drm_i915_private *dev_priv = guc_to_i915(guc); @@ -873,6 +993,7 @@ static void guc_create_log(struct intel_guc *guc) offset = i915_gem_obj_ggtt_offset(obj) >> PAGE_SHIFT; /* in pages */ guc->log_flags = (offset << GUC_LOG_BUF_ADDR_SHIFT) | flags; + guc_logging_init(guc); } static void init_guc_policies(struct guc_policies *policies) @@ -1037,6 +1158,7 @@ void i915_guc_submission_fini(struct drm_device *dev) gem_release_guc_obj(dev_priv->guc.log_obj); guc->log_obj = NULL; + guc_logging_fini(guc); if (guc->ctx_pool_obj) ida_destroy(&guc->ctx_ids); @@ -1086,6 +1208,9 @@ int intel_guc_resume(struct drm_device *dev) if (guc->guc_fw.guc_fw_load_status != GUC_FIRMWARE_SUCCESS) return 0; + if (i915.guc_log_level >= 0 && guc->log_relay_chan) + gen8_enable_guc_interrupts(dev); + ctx = dev_priv->kernel_context; data[0] = HOST2GUC_ACTION_EXIT_S_STATE; diff --git a/drivers/gpu/drm/i915/intel_guc.h b/drivers/gpu/drm/i915/intel_guc.h index 92d70d8..bf61925 100644 --- a/drivers/gpu/drm/i915/intel_guc.h +++ b/drivers/gpu/drm/i915/intel_guc.h @@ -125,6 +125,7 @@ struct intel_guc { struct intel_guc_fw guc_fw; uint32_t log_flags; struct drm_i915_gem_object *log_obj; + struct rchan *log_relay_chan; /* * work, interrupts_enabled are protected by dev_priv->irq_lock */