[PATCH v3 1/2] drm: Move debug macros out of drmP.h

Sean Paul seanpaul at chromium.org
Tue Oct 17 19:54:13 UTC 2017


On Tue, Oct 17, 2017 at 02:43:38AM -0600, Haneen Mohammed wrote:
> This patch extract DRM_* debug macros from drmP.h to drm_print.h and
> move printing related functions used by these macros from drm_drv.[hc]
> to drm_print.[hc].
> 
> Signed-off-by: Haneen Mohammed <hamohammed.sa at gmail.com>
> ---
> Changes in v3:
> - Move debug macros and print functions into drm_print.[hc] instead of
> introducing drm_debug.[hc].
> 
>  drivers/gpu/drm/drm_drv.c   |  47 -------------
>  drivers/gpu/drm/drm_print.c |  47 +++++++++++++
>  include/drm/drmP.h          | 150 +-----------------------------------------
>  include/drm/drm_drv.h       |   7 --
>  include/drm/drm_print.h     | 156 ++++++++++++++++++++++++++++++++++++++++++++
>  5 files changed, 204 insertions(+), 203 deletions(-)
> 

<snip />

> diff --git a/include/drm/drmP.h b/include/drm/drmP.h
> index 7277783a..2ba73ff4 100644
> --- a/include/drm/drmP.h
> +++ b/include/drm/drmP.h
> @@ -75,6 +75,7 @@
>  #include <drm/drm_sarea.h>
>  #include <drm/drm_drv.h>
>  #include <drm/drm_prime.h>
> +#include <drm/drm_print.h>
>  #include <drm/drm_pci.h>
>  #include <drm/drm_file.h>
>  #include <drm/drm_debugfs.h>
> @@ -142,160 +143,11 @@ struct pci_controller;
>  /*@{*/
>  

Any reason why you didn't move the DRM_UT_* defines as well? They're sprinkled
through a couple drivers, but it's all related to debug messaging.

Sean

>  /***********************************************************************/
> -/** \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_INFO(fmt, ...)						\
> -	_DRM_PRINTK(, INFO, fmt, ##__VA_ARGS__)
> -#define DRM_NOTE(fmt, ...)						\
> -	_DRM_PRINTK(, NOTICE, fmt, ##__VA_ARGS__)
> -#define DRM_WARN(fmt, ...)						\
> -	_DRM_PRINTK(, WARNING, fmt, ##__VA_ARGS__)
> -
> -#define DRM_INFO_ONCE(fmt, ...)						\
> -	_DRM_PRINTK(_once, INFO, fmt, ##__VA_ARGS__)
> -#define DRM_NOTE_ONCE(fmt, ...)						\
> -	_DRM_PRINTK(_once, NOTICE, fmt, ##__VA_ARGS__)
> -#define DRM_WARN_ONCE(fmt, ...)						\
> -	_DRM_PRINTK(_once, WARNING, fmt, ##__VA_ARGS__)
> -
> -/**
> - * Error output.
> - *
> - * \param fmt printf() like format string.
> - * \param arg arguments
> - */
> -#define DRM_DEV_ERROR(dev, fmt, ...)					\
> -	drm_dev_printk(dev, KERN_ERR, DRM_UT_NONE, __func__, " *ERROR*",\
> -		       fmt, ##__VA_ARGS__)
> -#define DRM_ERROR(fmt, ...)						\
> -	drm_printk(KERN_ERR, DRM_UT_NONE, fmt,	##__VA_ARGS__)
> -
> -/**
> - * Rate limited error output.  Like DRM_ERROR() but won't flood the log.
> - *
> - * \param fmt printf() like format string.
> - * \param arg arguments
> - */
> -#define DRM_DEV_ERROR_RATELIMITED(dev, fmt, ...)			\
> -({									\
> -	static DEFINE_RATELIMIT_STATE(_rs,				\
> -				      DEFAULT_RATELIMIT_INTERVAL,	\
> -				      DEFAULT_RATELIMIT_BURST);		\
> -									\
> -	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_DEV_INFO(dev, fmt, ...)					\
> -	drm_dev_printk(dev, KERN_INFO, DRM_UT_NONE, __func__, "", fmt,	\
> -		       ##__VA_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__);			\
> -	}								\
> -})
> -
> -/**
> - * Debug output.
> - *
> - * \param fmt printf() like format string.
> - * \param arg arguments
> - */
> -#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__)
> -
> -#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__)
> -
> -#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__)
> -
> -#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__)
> -
> -#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__)
> -
> -#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__)
> -
> -#define _DRM_DEV_DEFINE_DEBUG_RATELIMITED(dev, level, 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);		\
> -})
> -
> -/**
> - * Rate limited debug output. Like DRM_DEBUG() but won't flood the log.
> - *
> - * \param fmt printf() like format string.
> - * \param arg arguments
> - */
> -#define DRM_DEV_DEBUG_RATELIMITED(dev, fmt, args...)			\
> -	DEV__DRM_DEFINE_DEBUG_RATELIMITED(dev, CORE, fmt, ##args)
> -#define DRM_DEBUG_RATELIMITED(fmt, args...)				\
> -	DRM_DEV_DEBUG_RATELIMITED(NULL, 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)
> -#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)
> -#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)
> -
> -/* Format strings and argument splitters to simplify printing
> - * various "complex" objects
> - */
> -
> -/*@}*/
> -
> -/***********************************************************************/
>  /** \name Internal types and structures */
>  /*@{*/
>  
>  #define DRM_IF_VERSION(maj, min) (maj << 16 | min)
>  
> -
>  /**
>   * drm_drv_uses_atomic_modeset - check if the driver implements
>   * atomic_commit()
> diff --git a/include/drm/drm_drv.h b/include/drm/drm_drv.h
> index 71bbaae..4f3cc25 100644
> --- a/include/drm/drm_drv.h
> +++ b/include/drm/drm_drv.h
> @@ -592,13 +592,6 @@ struct drm_driver {
>  	int dev_priv_size;
>  };
>  
> -__printf(6, 7)
> -void drm_dev_printk(const struct device *dev, const char *level,
> -		    unsigned int category, const char *function_name,
> -		    const char *prefix, const char *format, ...);
> -__printf(3, 4)
> -void drm_printk(const char *level, unsigned int category,
> -		const char *format, ...);
>  extern unsigned int drm_debug;
>  
>  int drm_dev_init(struct drm_device *dev,
> diff --git a/include/drm/drm_print.h b/include/drm/drm_print.h
> index ca4d7c6..9dacc5e 100644
> --- a/include/drm/drm_print.h
> +++ b/include/drm/drm_print.h
> @@ -128,4 +128,160 @@ static inline struct drm_printer drm_debug_printer(const char *prefix)
>  	};
>  	return p;
>  }
> +
> +__printf(6, 7)
> +void drm_dev_printk(const struct device *dev, const char *level,
> +		    unsigned int category, const char *function_name,
> +		    const char *prefix, const char *format, ...);
> +__printf(3, 4)
> +void drm_printk(const char *level, unsigned int category,
> +		const char *format, ...);
> +/***********************************************************************/
> +/** \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_INFO(fmt, ...)						\
> +	_DRM_PRINTK(, INFO, fmt, ##__VA_ARGS__)
> +#define DRM_NOTE(fmt, ...)						\
> +	_DRM_PRINTK(, NOTICE, fmt, ##__VA_ARGS__)
> +#define DRM_WARN(fmt, ...)						\
> +	_DRM_PRINTK(, WARNING, fmt, ##__VA_ARGS__)
> +
> +#define DRM_INFO_ONCE(fmt, ...)						\
> +	_DRM_PRINTK(_once, INFO, fmt, ##__VA_ARGS__)
> +#define DRM_NOTE_ONCE(fmt, ...)						\
> +	_DRM_PRINTK(_once, NOTICE, fmt, ##__VA_ARGS__)
> +#define DRM_WARN_ONCE(fmt, ...)						\
> +	_DRM_PRINTK(_once, WARNING, fmt, ##__VA_ARGS__)
> +
> +/**
> + * Error output.
> + *
> + * \param fmt printf() like format string.
> + * \param arg arguments
> + */
> +#define DRM_DEV_ERROR(dev, fmt, ...)					\
> +	drm_dev_printk(dev, KERN_ERR, DRM_UT_NONE, __func__, " *ERROR*",\
> +		       fmt, ##__VA_ARGS__)
> +#define DRM_ERROR(fmt, ...)						\
> +	drm_printk(KERN_ERR, DRM_UT_NONE, fmt,	##__VA_ARGS__)
> +
> +/**
> + * Rate limited error output.  Like DRM_ERROR() but won't flood the log.
> + *
> + * \param fmt printf() like format string.
> + * \param arg arguments
> + */
> +#define DRM_DEV_ERROR_RATELIMITED(dev, fmt, ...)			\
> +({									\
> +	static DEFINE_RATELIMIT_STATE(_rs,				\
> +				      DEFAULT_RATELIMIT_INTERVAL,	\
> +				      DEFAULT_RATELIMIT_BURST);		\
> +									\
> +	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_DEV_INFO(dev, fmt, ...)					\
> +	drm_dev_printk(dev, KERN_INFO, DRM_UT_NONE, __func__, "", fmt,	\
> +		       ##__VA_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__);			\
> +	}								\
> +})
> +
> +/**
> + * Debug output.
> + *
> + * \param fmt printf() like format string.
> + * \param arg arguments
> + */
> +#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__)
> +
> +#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__)
> +
> +#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__)
> +
> +#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__)
> +
> +#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__)
> +
> +#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__)
> +
> +#define _DRM_DEV_DEFINE_DEBUG_RATELIMITED(dev, level, 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);		\
> +})
> +
> +/**
> + * Rate limited debug output. Like DRM_DEBUG() but won't flood the log.
> + *
> + * \param fmt printf() like format string.
> + * \param arg arguments
> + */
> +#define DRM_DEV_DEBUG_RATELIMITED(dev, fmt, args...)			\
> +	DEV__DRM_DEFINE_DEBUG_RATELIMITED(dev, CORE, fmt, ##args)
> +#define DRM_DEBUG_RATELIMITED(fmt, args...)				\
> +	DRM_DEV_DEBUG_RATELIMITED(NULL, 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)
> +#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)
> +#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)
> +
> +/* Format strings and argument splitters to simplify printing
> + * various "complex" objects
> + */
> +
> +/*@}*/
> +
>  #endif /* DRM_PRINT_H_ */
> -- 
> 2.7.4
> 

-- 
Sean Paul, Software Engineer, Google / Chromium OS


More information about the dri-devel mailing list