From patchwork Thu Dec 1 17:18:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Bragg X-Patchwork-Id: 9456613 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 3AA8060756 for ; Thu, 1 Dec 2016 17:18:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 26F3628520 for ; Thu, 1 Dec 2016 17:18:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1A4F928522; Thu, 1 Dec 2016 17:18:30 +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.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, 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 C2C7A28520 for ; Thu, 1 Dec 2016 17:18:25 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 58B6C6E819; Thu, 1 Dec 2016 17:18:21 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-wm0-x243.google.com (mail-wm0-x243.google.com [IPv6:2a00:1450:400c:c09::243]) by gabe.freedesktop.org (Postfix) with ESMTPS id 51A096E819 for ; Thu, 1 Dec 2016 17:18:19 +0000 (UTC) Received: by mail-wm0-x243.google.com with SMTP id u144so35146007wmu.0 for ; Thu, 01 Dec 2016 09:18:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:subject:date:message-id; bh=y0PlPwlTrgivhl/sAp6VFwEfde9xkno9+kQX/kT5eh8=; b=W+Vz31LH8OF+nNPJVc8Xwv46Dv1f7/qZrAEISZfoYWrlKNwE1zA5J6ldc7UlyWZ4wy iPqP9WKiSpgaT7kN4FO9vZCqqyRniJfbf7tDSkOX72XNazt1wS8GpzPhvQj3/clsgv4S /XwKtNGAiL5VqNfCtwtdKNh4/kXOxZukODPc9Ml42xkxS2uUvp8XSikmeKGHO5eiLM5X E/gZbnksXZCjsF30ii3Lm2vQfZf1JLQ97wsTh8GDRfHnpsKDaiJcHDMPhuUSuQffovpe +8W7ftrgkMXrkmXbg29fK99q1UZ5WE+njESjRg9uVUmx9S/XTCYX9zEDOpX0neTgMe80 +dfA== 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:subject:date:message-id; bh=y0PlPwlTrgivhl/sAp6VFwEfde9xkno9+kQX/kT5eh8=; b=iA1zkl7CjeKDvemfj0ZYNf/G00FQ9tvtvvqqNhndJZU6LUHW6MdKW6w9q7WCMTpb5W gkeO69aGblFHXU8Z7337zZuNfQbwNnxhC57H8CZqNkF2uNMzGaAs+gKjxqA5Uo3xYKJ4 paHYAoYfEC1e0wloJrYMRw/7dV726AFe5AhJWuUggEMGspxOJTtlHLRMfguURsmjO9RD 92doamKc5cqJM3ztF+YcyZ/KFZVpxDT3Me0BxRzx7E7MPcIQMtI3AZHotPjnqInfMVjo WXvwQ8fZo8q+KmOfP49IxlMz5ZDFJSMXdltSC0ZaTY3e2cyz6sZiWuO8fEbYMA+gNQye Ld2Q== X-Gm-Message-State: AKaTC02JUssKyE1IGr5e2SJhpKVd9w3bFyw7tKN8+pZoLn/INya6p+zRbc+cseY+omMrCw== X-Received: by 10.28.68.195 with SMTP id r186mr15028800wma.105.1480612697342; Thu, 01 Dec 2016 09:18:17 -0800 (PST) Received: from sixbynine.org ([82.132.185.173]) by smtp.gmail.com with ESMTPSA id ba10sm1232393wjb.32.2016.12.01.09.18.13 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 01 Dec 2016 09:18:16 -0800 (PST) From: Robert Bragg To: intel-gfx@lists.freedesktop.org Date: Thu, 1 Dec 2016 17:18:00 +0000 Message-Id: <20161201171800.10770-1-robert@sixbynine.org> X-Mailer: git-send-email 2.10.2 Subject: [Intel-gfx] [RFC] drm: Enable dynamic debug for DRM_[DEV]_DEBUG* 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 I'm currently considering the use of DRM_ERROR in i915 perf for steam config validation errors (i.e. userspace misconfigurations) that should be changed so that i-g-t tests aren't treated as failures when triggering these. I initially proposed changing these to DRM_INFO messages and intentionally wanted to avoid DRM_DEBUG since in my limited experience DRM_DEBUG messages aren't practical to work with. I thought I'd see if DRM_DEBUG could be updated to have a bit more fine grained control in case that might help sway my view. Tbh, although I think something like this could be nice to have, I'm still not really convinced that debug messages are a great fit for helping userspace developers hitting EINVAL errors. Such developers don't need to be drm/i915 developers and imho shouldn't be expected to know of the existence of optional debug messages, and if you don't know of there existence then the control interface isn't important and they won't help anyone. --- >8 --- (git am --scissors) Dynamic debug messages (ref: Documentation/dynamic-debug-howto.txt) allow fine grained control over which debug messages are enabled with runtime control through /sysfs/kernel/debug/dynamic_debug/control This provides more control than the current drm.drm_debug parameter which for some use cases is impractical to use given how chatty some drm debug categories are. For example all debug messages in i915_drm.c can be enabled with: echo "file i915_perf.c +p" > dynamic_debug/control This aims to maintain compatibility with controlling debug messages using the drm_debug parameter. The new dynamic debug macros are called by default but conditionally calling [dev_]printk if the category flag is set (side stepping the dynamic debug condition in that case) This removes the drm_[dev_]printk wrappers considering that the dynamic debug macros are only useful if they can track the __FILE__, __func__ and __LINE__ where they are called. The wrapper didn't seem necessary in the DRM_UT_NONE case with no category flag. The output format should be compatible, unless the _DEV macros are passed a NULL dev pointer considering how the core.c dev_printk implementation adds "(NULL device *)" to the message in that case while the drm wrapper would fallback to a plain printk in this case. Previously some of non-dev drm debug macros were defined in terms of passing NULL to a dev version but that's avoided now due to this difference. I haven't so far looked to see what affect these have on linked object sizes. Signed-off-by: Robert Bragg Cc: Chris Wilson --- drivers/gpu/drm/drm_drv.c | 47 ------------- include/drm/drmP.h | 168 +++++++++++++++++++++++++++++----------------- 2 files changed, 108 insertions(+), 107 deletions(-) diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c index cc6c253..5b2dbcd 100644 --- a/drivers/gpu/drm/drm_drv.c +++ b/drivers/gpu/drm/drm_drv.c @@ -65,53 +65,6 @@ static struct idr drm_minors_idr; static struct dentry *drm_debugfs_root; -#define DRM_PRINTK_FMT "[" DRM_NAME ":%s]%s %pV" - -void drm_dev_printk(const struct device *dev, const char *level, - unsigned int category, const char *function_name, - const char *prefix, const char *format, ...) -{ - struct va_format vaf; - va_list args; - - if (category != DRM_UT_NONE && !(drm_debug & category)) - return; - - va_start(args, format); - vaf.fmt = format; - vaf.va = &args; - - if (dev) - dev_printk(level, dev, DRM_PRINTK_FMT, function_name, prefix, - &vaf); - else - printk("%s" DRM_PRINTK_FMT, level, function_name, prefix, &vaf); - - va_end(args); -} -EXPORT_SYMBOL(drm_dev_printk); - -void drm_printk(const char *level, unsigned int category, - const char *format, ...) -{ - struct va_format vaf; - va_list args; - - if (category != DRM_UT_NONE && !(drm_debug & category)) - return; - - va_start(args, format); - vaf.fmt = format; - vaf.va = &args; - - printk("%s" "[" DRM_NAME ":%ps]%s %pV", - level, __builtin_return_address(0), - strcmp(level, KERN_ERR) == 0 ? " *ERROR*" : "", &vaf); - - va_end(args); -} -EXPORT_SYMBOL(drm_printk); - /* * DRM Minors * A DRM device can provide several char-dev interfaces on the DRM-Major. Each diff --git a/include/drm/drmP.h b/include/drm/drmP.h index b352a7b..d61d937 100644 --- a/include/drm/drmP.h +++ b/include/drm/drmP.h @@ -58,6 +58,7 @@ #include #include #include +#include #include #include @@ -129,7 +130,6 @@ struct dma_buf_attachment; * run-time by echoing the debug value in its sysfs node: * # echo 0xf > /sys/module/drm/parameters/debug */ -#define DRM_UT_NONE 0x00 #define DRM_UT_CORE 0x01 #define DRM_UT_DRIVER 0x02 #define DRM_UT_KMS 0x04 @@ -146,25 +146,22 @@ struct dma_buf_attachment; /** \name Macros to make printk easier */ /*@{*/ -#define _DRM_PRINTK(once, level, fmt, ...) \ - do { \ - printk##once(KERN_##level "[" DRM_NAME "] " fmt, \ - ##__VA_ARGS__); \ - } while (0) +#define _DRM_FMT_PREFIX "[" DRM_NAME "] " +#define _DRM_FMT_FUNC_PREFIX "[" DRM_NAME ":%s] " #define DRM_INFO(fmt, ...) \ - _DRM_PRINTK(, INFO, fmt, ##__VA_ARGS__) + pr_info(_DRM_FMT_PREFIX fmt, ##__VA_ARGS__) #define DRM_NOTE(fmt, ...) \ - _DRM_PRINTK(, NOTICE, fmt, ##__VA_ARGS__) + pr_notice(_DRM_FMT_PREFIX fmt, ##__VA_ARGS__) #define DRM_WARN(fmt, ...) \ - _DRM_PRINTK(, WARNING, fmt, ##__VA_ARGS__) + pr_warn(_DRM_FMT_PREFIX fmt, ##__VA_ARGS__) #define DRM_INFO_ONCE(fmt, ...) \ - _DRM_PRINTK(_once, INFO, fmt, ##__VA_ARGS__) + pr_info_once(_DRM_FMT_PREFIX fmt, ##__VA_ARGS__) #define DRM_NOTE_ONCE(fmt, ...) \ - _DRM_PRINTK(_once, NOTICE, fmt, ##__VA_ARGS__) + pr_notice_once(_DRM_FMT_PREFIX fmt, ##__VA_ARGS__) #define DRM_WARN_ONCE(fmt, ...) \ - _DRM_PRINTK(_once, WARNING, fmt, ##__VA_ARGS__) + pr_warn_once(_DRM_FMT_PREFIX fmt, ##__VA_ARGS__) /** * Error output. @@ -173,10 +170,11 @@ struct dma_buf_attachment; * \param arg arguments */ #define DRM_DEV_ERROR(dev, fmt, ...) \ - drm_dev_printk(dev, KERN_ERR, DRM_UT_NONE, __func__, " *ERROR*",\ - fmt, ##__VA_ARGS__) + dev_err(dev, _DRM_FMT_FUNC_PREFIX "*ERROR*" fmt, __func__, \ + ##__VA_ARGS__) #define DRM_ERROR(fmt, ...) \ - drm_printk(KERN_ERR, DRM_UT_NONE, fmt, ##__VA_ARGS__) + pr_err(_DRM_FMT_FUNC_PREFIX "*ERROR*" fmt, __func__, \ + ##__VA_ARGS__) /** * Rate limited error output. Like DRM_ERROR() but won't flood the log. @@ -193,21 +191,14 @@ struct dma_buf_attachment; if (__ratelimit(&_rs)) \ DRM_DEV_ERROR(dev, fmt, ##__VA_ARGS__); \ }) -#define DRM_ERROR_RATELIMITED(fmt, ...) \ - DRM_DEV_ERROR_RATELIMITED(NULL, fmt, ##__VA_ARGS__) +#define DRM_ERROR_RATELIMITED(fmt, args...) \ + DRM_DEV_ERROR_RATELIMITED(NULL, fmt, ##args) -#define DRM_DEV_INFO(dev, fmt, ...) \ - drm_dev_printk(dev, KERN_INFO, DRM_UT_NONE, __func__, "", fmt, \ - ##__VA_ARGS__) +#define DRM_DEV_INFO(dev, fmt, args...) \ + dev_info(dev, _DRM_FMT_FUNC_PREFIX fmt, __func__, ##args) -#define DRM_DEV_INFO_ONCE(dev, fmt, ...) \ -({ \ - static bool __print_once __read_mostly; \ - if (!__print_once) { \ - __print_once = true; \ - DRM_DEV_INFO(dev, fmt, ##__VA_ARGS__); \ - } \ -}) +#define DRM_DEV_INFO_ONCE(dev, fmt, args...) \ + dev_info_once(dev, _DRM_FMT_FUNC_PREFIX fmt, __func__, ##args) /** * Debug output. @@ -215,50 +206,104 @@ struct dma_buf_attachment; * \param fmt printf() like format string. * \param arg arguments */ + +#if defined(CONFIG_DYNAMIC_DEBUG) +/* We don't use pr_debug and dev_dbg directly since we want to + * maintain format compatibility with non-dynamic drm debug messages + */ +#define _DRM_DYNAMIC_DEV_DEBUG(dev, fmt, args...) \ +({ \ + DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \ + if (DYNAMIC_DEBUG_BRANCH(descriptor)) \ + dev_printk(KERN_DEBUG, dev, fmt, ##args); \ +}) +#define _DRM_DYNAMIC_DEBUG(fmt, args...) \ +({ \ + DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \ + if (DYNAMIC_DEBUG_BRANCH(descriptor)) \ + printk(KERN_DEBUG fmt, ##args); \ +}) +#else +#define _DRM_DYNAMIC_DEV_DEBUG(dev, fmt, args...) \ + no_printk(fmt, ##args) +#define _DRM_DYNAMIC_DEBUG(fmt, args...) \ + no_printk(fmt, ##args) +#endif + +/* The conditional use of pr_debug/dev_dbg here allows us to take + * advantage of the kernel's dynamic debug feature by default (ref + * Documentation/dynamic-debug-howto.txt) while maintaining + * compatibility with using drm.drm_debug to turn on sets of messages + * + * Note: pr_debug and dev_dbg can't be called by a wrapper function + * otherwise they can't track the __FILE__, __func__ and __LINE__ + * where they are called. + */ +#define _DRM_DEV_DEBUG(dev, category, fmt, args...) \ +({ \ + if (unlikely(drm_debug & category)) { \ + dev_printk(KERN_DEBUG, dev, _DRM_FMT_FUNC_PREFIX fmt, \ + __func__, ##args); \ + } else { \ + _DRM_DYNAMIC_DEV_DEBUG(dev, _DRM_FMT_FUNC_PREFIX fmt, \ + __func__, ##args); \ + } \ +}) +#define _DRM_DEBUG(category, fmt, args...) \ +({ \ + if (unlikely(drm_debug & category)) { \ + printk(KERN_DEBUG _DRM_FMT_FUNC_PREFIX fmt, \ + __func__, ##args); \ + } else \ + _DRM_DYNAMIC_DEBUG(_DRM_FMT_FUNC_PREFIX fmt, \ + __func__, ##args); \ +}) + #define DRM_DEV_DEBUG(dev, fmt, args...) \ - drm_dev_printk(dev, KERN_DEBUG, DRM_UT_CORE, __func__, "", fmt, \ - ##args) -#define DRM_DEBUG(fmt, ...) \ - drm_printk(KERN_DEBUG, DRM_UT_CORE, fmt, ##__VA_ARGS__) + _DRM_DEV_DEBUG(dev, DRM_UT_CORE, fmt, ##args) +#define DRM_DEBUG(fmt, args...) \ + _DRM_DEBUG(DRM_UT_CORE, fmt, ##args) #define DRM_DEV_DEBUG_DRIVER(dev, fmt, args...) \ - drm_dev_printk(dev, KERN_DEBUG, DRM_UT_DRIVER, __func__, "", \ - fmt, ##args) -#define DRM_DEBUG_DRIVER(fmt, ...) \ - drm_printk(KERN_DEBUG, DRM_UT_DRIVER, fmt, ##__VA_ARGS__) + _DRM_DEV_DEBUG(dev, DRM_UT_DRIVER, fmt, ##args) +#define DRM_DEBUG_DRIVER(fmt, args...) \ + _DRM_DEBUG(DRM_UT_DRIVER, fmt, ##args) #define DRM_DEV_DEBUG_KMS(dev, fmt, args...) \ - drm_dev_printk(dev, KERN_DEBUG, DRM_UT_KMS, __func__, "", fmt, \ - ##args) -#define DRM_DEBUG_KMS(fmt, ...) \ - drm_printk(KERN_DEBUG, DRM_UT_KMS, fmt, ##__VA_ARGS__) + _DRM_DEV_DEBUG(dev, DRM_UT_KMS, fmt, ##args) +#define DRM_DEBUG_KMS(fmt, args...) \ + _DRM_DEBUG(DRM_UT_KMS, fmt, ##args) #define DRM_DEV_DEBUG_PRIME(dev, fmt, args...) \ - drm_dev_printk(dev, KERN_DEBUG, DRM_UT_PRIME, __func__, "", \ - fmt, ##args) -#define DRM_DEBUG_PRIME(fmt, ...) \ - drm_printk(KERN_DEBUG, DRM_UT_PRIME, fmt, ##__VA_ARGS__) + _DRM_DEV_DEBUG(dev, DRM_UT_PRIME, fmt, ##args) +#define DRM_DEBUG_PRIME(fmt, args...) \ + _DRM_DEBUG(DRM_UT_PRIME, fmt, ##args) #define DRM_DEV_DEBUG_ATOMIC(dev, fmt, args...) \ - drm_dev_printk(dev, KERN_DEBUG, DRM_UT_ATOMIC, __func__, "", \ - fmt, ##args) -#define DRM_DEBUG_ATOMIC(fmt, ...) \ - drm_printk(KERN_DEBUG, DRM_UT_ATOMIC, fmt, ##__VA_ARGS__) + _DRM_DEV_DEBUG(dev, DRM_UT_ATOMIC, fmt, ##args) +#define DRM_DEBUG_ATOMIC(fmt, args...) \ + _DRM_DEBUG(DRM_UT_ATOMIC, fmt, ##args) #define DRM_DEV_DEBUG_VBL(dev, fmt, args...) \ - drm_dev_printk(dev, KERN_DEBUG, DRM_UT_VBL, __func__, "", fmt, \ - ##args) -#define DRM_DEBUG_VBL(fmt, ...) \ - drm_printk(KERN_DEBUG, DRM_UT_VBL, fmt, ##__VA_ARGS__) + _DRM_DEV_DEBUG(dev, DRM_UT_VBL, fmt, ##args) +#define DRM_DEBUG_VBL(fmt, args...) \ + _DRM_DEBUG(DRM_UT_VBL, fmt, ##args) -#define _DRM_DEV_DEFINE_DEBUG_RATELIMITED(dev, level, fmt, args...) \ +#define _DRM_DEV_DEFINE_DEBUG_RATELIMITED(dev, category, fmt, args...) \ +({ \ + static DEFINE_RATELIMIT_STATE(_rs, \ + DEFAULT_RATELIMIT_INTERVAL, \ + DEFAULT_RATELIMIT_BURST); \ + if (__ratelimit(&_rs)) \ + _DRM_DEV_DEBUG(dev, DRM_UT_ ## category, fmt, ##args); \ +}) +#define _DRM_DEFINE_DEBUG_RATELIMITED(category, fmt, args...) \ ({ \ static DEFINE_RATELIMIT_STATE(_rs, \ DEFAULT_RATELIMIT_INTERVAL, \ DEFAULT_RATELIMIT_BURST); \ if (__ratelimit(&_rs)) \ - drm_dev_printk(dev, KERN_DEBUG, DRM_UT_ ## level, \ - __func__, "", fmt, ##args); \ + _DRM_DEBUG(DRM_UT_ ## category, fmt, ##args); \ }) /** @@ -268,21 +313,24 @@ struct dma_buf_attachment; * \param arg arguments */ #define DRM_DEV_DEBUG_RATELIMITED(dev, fmt, args...) \ - DEV__DRM_DEFINE_DEBUG_RATELIMITED(dev, CORE, fmt, ##args) + _DRM_DEFINE_DEBUG_RATELIMITED(dev, CORE, fmt, ##args) #define DRM_DEBUG_RATELIMITED(fmt, args...) \ - DRM_DEV_DEBUG_RATELIMITED(NULL, fmt, ##args) + _DRM_DEFINE_DEBUG_RATELIMITED(CORE, fmt, ##args) + #define DRM_DEV_DEBUG_DRIVER_RATELIMITED(dev, fmt, args...) \ _DRM_DEV_DEFINE_DEBUG_RATELIMITED(dev, DRIVER, fmt, ##args) #define DRM_DEBUG_DRIVER_RATELIMITED(fmt, args...) \ - DRM_DEV_DEBUG_DRIVER_RATELIMITED(NULL, fmt, ##args) + _DRM_DEV_DEFINE_DEBUG_RATELIMITED(DRIVER, fmt, ##args) + #define DRM_DEV_DEBUG_KMS_RATELIMITED(dev, fmt, args...) \ _DRM_DEV_DEFINE_DEBUG_RATELIMITED(dev, KMS, fmt, ##args) #define DRM_DEBUG_KMS_RATELIMITED(fmt, args...) \ - DRM_DEV_DEBUG_KMS_RATELIMITED(NULL, fmt, ##args) + _DRM_DEFINE_DEBUG_RATELIMITED(KMS, fmt, ##args) + #define DRM_DEV_DEBUG_PRIME_RATELIMITED(dev, fmt, args...) \ _DRM_DEV_DEFINE_DEBUG_RATELIMITED(dev, PRIME, fmt, ##args) #define DRM_DEBUG_PRIME_RATELIMITED(fmt, args...) \ - DRM_DEV_DEBUG_PRIME_RATELIMITED(NULL, fmt, ##args) + _DRM_DEFINE_DEBUG_RATELIMITED(PRIME, fmt, ##args) /* Format strings and argument splitters to simplify printing * various "complex" objects