diff mbox series

[v1,6/8] drm/print: add drm_dev_* logging functions

Message ID 20191221095553.13332-7-sam@ravnborg.org (mailing list archive)
State New, archived
Headers show
Series drm: add more new-style logging functions | expand

Commit Message

Sam Ravnborg Dec. 21, 2019, 9:55 a.m. UTC
There are a lot of cases where we have a device * but no drm_device *.
Add drm_dev_* variants of the logging functions to cover these cases.

Include brief documentation.

Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
Cc: Jani Nikula <jani.nikula@intel.com>
Cc: Sean Paul <sean@poorly.run>
Cc: Daniel Vetter <daniel@ffwll.ch>
---
 include/drm/drm_print.h | 99 ++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 98 insertions(+), 1 deletion(-)

Comments

Joe Perches Dec. 21, 2019, 1:56 p.m. UTC | #1
On Sat, 2019-12-21 at 10:55 +0100, Sam Ravnborg wrote:
> There are a lot of cases where we have a device * but no drm_device *.
> Add drm_dev_* variants of the logging functions to cover these cases.
[]
> diff --git a/include/drm/drm_print.h b/include/drm/drm_print.h
[]
> @@ -468,6 +511,60 @@ static inline bool drm_debug_enabled(enum drm_debug_category category)
>  #define drm_dbg_dp(drm, fmt, ...)					\
>  	__drm_cat_printk((drm), DRM_UT_DP, fmt, ##__VA_ARGS__)
>  
> +/* struct device based logging. */
> +#define __drm_dev_printk(dev, level, type, fmt, ...)			\
> +	dev_##level##type(dev, "[drm] " fmt, ##__VA_ARGS__)
> +
> +#define __drm_dev_cat_printk(dev, cat, type, fmt, ...)			\
> +({									\
> +	if (drm_debug_enabled(cat))					\
> +		dev_dbg##type((dev), "[drm] " fmt, ##__VA_ARGS__);	\

trivia:  The parentheses around dev aren't necessary.

> +})
> +
> +#define drm_dev_info(dev, fmt, ...)					\
> +	__drm_dev_printk((dev), info,, fmt, ##__VA_ARGS__)

etc...
Sam Ravnborg Dec. 21, 2019, 2:48 p.m. UTC | #2
Hi Joe.

> > +#define __drm_dev_cat_printk(dev, cat, type, fmt, ...)			\
> > +({									\
> > +	if (drm_debug_enabled(cat))					\
> > +		dev_dbg##type((dev), "[drm] " fmt, ##__VA_ARGS__);	\
> 
> trivia:  The parentheses around dev aren't necessary.
> 
> > +})
> > +
> > +#define drm_dev_info(dev, fmt, ...)					\
> > +	__drm_dev_printk((dev), info,, fmt, ##__VA_ARGS__)
> 
> etc...

I was not really sure so I just added them.
Will remove in v2 in all relevent patches - thanks!

	Sam
Jani Nikula Dec. 23, 2019, 11:21 a.m. UTC | #3
On Sat, 21 Dec 2019, Sam Ravnborg <sam@ravnborg.org> wrote:
> Hi Joe.
>
>> > +#define __drm_dev_cat_printk(dev, cat, type, fmt, ...)			\
>> > +({									\
>> > +	if (drm_debug_enabled(cat))					\
>> > +		dev_dbg##type((dev), "[drm] " fmt, ##__VA_ARGS__);	\
>> 
>> trivia:  The parentheses around dev aren't necessary.
>> 
>> > +})
>> > +
>> > +#define drm_dev_info(dev, fmt, ...)					\
>> > +	__drm_dev_printk((dev), info,, fmt, ##__VA_ARGS__)
>> 
>> etc...
>
> I was not really sure so I just added them.
> Will remove in v2 in all relevent patches - thanks!

FWIW, they are necessary in the drm_device variants due to the macros
doing the dereferencing.

BR,
Jani.


>
> 	Sam
Jani Nikula Dec. 23, 2019, 11:29 a.m. UTC | #4
On Sat, 21 Dec 2019, Sam Ravnborg <sam@ravnborg.org> wrote:
> There are a lot of cases where we have a device * but no drm_device *.
> Add drm_dev_* variants of the logging functions to cover these cases.

So I know there are some valid cases where we only have struct device *,
and instead of passing struct drm_device * will need the distinction
between multiple struct device *.

Not all current uses of DRM_DEV_* meet that criteria, however. I think
I'd like to have those converted over to the drm_device based logging
first, and then see what's left. Because I fear adding these will just
lead to mass conversion from DRM_DEV_* to drm_dev_*, and the ball gets
dropped there.

I feel a bit similar about the drm_pr_* logging functions. I want to
promote switching to drm_device based logging, not switching to the same
old thing with just new names.

BR,
Jani.


>
> Include brief documentation.
>
> Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
> Cc: Jani Nikula <jani.nikula@intel.com>
> Cc: Sean Paul <sean@poorly.run>
> Cc: Daniel Vetter <daniel@ffwll.ch>
> ---
>  include/drm/drm_print.h | 99 ++++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 98 insertions(+), 1 deletion(-)
>
> diff --git a/include/drm/drm_print.h b/include/drm/drm_print.h
> index 7c0b93e6cb80..b2e5d0209010 100644
> --- a/include/drm/drm_print.h
> +++ b/include/drm/drm_print.h
> @@ -337,7 +337,50 @@ static inline struct drm_printer drm_err_printer(const char *prefix)
>   *
>   * Logging when a &device * is available, but no &drm_device *
>   * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> - * TODO
> + *
> + * Adding a device pointer (if no &drm_device * is available) is always a good
> + * idea as it add more information in the logging message thus making it easier
> + * to determine the source of the logging.
> + *
> + * All logging functions in this block share the same prototype:
> + *
> + * .. code-block:: c
> + *
> + *   void drm_dev_xxx(struct device *, char * fmt, ...)
> + *
> + * The following functions are available:
> + *
> + * .. code-block:: none
> + *
> + *   # Plain logging
> + *   drm_dev_dbg()
> + *   drm_dev_info()
> + *   drm_dev_notice()
> + *   drm_dev_warn()
> + *   drm_dev_err()
> + *
> + *   # Log only once
> + *   drm_dev_info_once()
> + *   drm_dev_notice_once()
> + *   drm_dev_warn_once()
> + *   drm_dev_err_once()
> + *
> + *   # Ratelimited - do not flood the logs
> + *   drm_dev_err_ratelimited()
> + *   drm_dev_dbg_ratelimited()
> + *   drm_dev_dbg_kms_ratelimited()
> + *
> + *   # Logging with a specific category
> + *   drm_dev_dbg_core()
> + *   drm_dev_dbg()		# Uses the DRIVER category
> + *   drm_dev_dbg_kms()
> + *   drm_dev_dbg_prime()
> + *   drm_dev_dbg_atomic()
> + *   drm_dev_dbg_vbl()
> + *   drm_dev_dbg_state()
> + *   drm_dev_dbg_lease()
> + *   drm_dev_dbg_dp()
> + *
>   *
>   * Logging when no &device * nor &drm_device * is available
>   * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> @@ -468,6 +511,60 @@ static inline bool drm_debug_enabled(enum drm_debug_category category)
>  #define drm_dbg_dp(drm, fmt, ...)					\
>  	__drm_cat_printk((drm), DRM_UT_DP, fmt, ##__VA_ARGS__)
>  
> +/* struct device based logging. */
> +#define __drm_dev_printk(dev, level, type, fmt, ...)			\
> +	dev_##level##type(dev, "[drm] " fmt, ##__VA_ARGS__)
> +
> +#define __drm_dev_cat_printk(dev, cat, type, fmt, ...)			\
> +({									\
> +	if (drm_debug_enabled(cat))					\
> +		dev_dbg##type((dev), "[drm] " fmt, ##__VA_ARGS__);	\
> +})
> +
> +#define drm_dev_info(dev, fmt, ...)					\
> +	__drm_dev_printk((dev), info,, fmt, ##__VA_ARGS__)
> +#define drm_dev_notice(dev, fmt, ...)					\
> +	__drm_dev_printk((dev), notice,, fmt, ##__VA_ARGS__)
> +#define drm_dev_warn(dev, fmt, ...)					\
> +	__drm_dev_printk((dev), warn,, fmt, ##__VA_ARGS__)
> +#define drm_dev_err(dev, fmt, ...)					\
> +	__drm_dev_printk((dev), err,, "*ERROR* " fmt, ##__VA_ARGS__)
> +
> +#define drm_dev_info_once(dev, fmt, ...)				\
> +	__drm_dev_printk((dev), info, _once, fmt, ##__VA_ARGS__)
> +#define drm_dev_notice_once(dev, fmt, ...)				\
> +	__drm_dev_printk((dev), notice, _once, fmt, ##__VA_ARGS__)
> +#define drm_dev_warn_once(dev, fmt, ...)				\
> +	__drm_dev_printk((dev), warn, _once, fmt, ##__VA_ARGS__)
> +#define drm_dev_err_once(dev, fmt, ...)					\
> +	__drm_dev_printk((dev), err, _once, "*ERROR* " fmt, ##__VA_ARGS__)
> +
> +#define drm_dev_err_ratelimited(dev, fmt, ...)				\
> +	__drm_dev_printk((dev), err, _ratelimited, "*ERROR* " fmt, ##__VA_ARGS__)
> +#define drm_dev_dbg_ratelimited(dev, fmt, ...)				\
> +	__drm_dev_cat_printk((dev), DRM_UT_DRIVER,_ratelimited, fmt, ##__VA_ARGS__)
> +#define drm_dev_dbg_kms_ratelimited(dev, fmt, ...)			\
> +	__drm_dev_cat_printk((dev), DRM_UT_KMS,_ratelimited, fmt, ##__VA_ARGS__)
> +
> +#define drm_dev_dbg_core(dev, fmt, ...)					\
> +	__drm_dev_cat_printk((dev), DRM_UT_CORE,, fmt, ##__VA_ARGS__)
> +#define drm_dev_dbg(dev, fmt, ...)					\
> +	__drm_dev_cat_printk((dev), DRM_UT_DRIVER,, fmt, ##__VA_ARGS__)
> +#define drm_dev_dbg_kms(dev, fmt, ...)					\
> +	__drm_dev_cat_printk((dev), DRM_UT_KMS,, fmt, ##__VA_ARGS__)
> +#define drm_dev_dbg_prime(dev, fmt, ...)				\
> +	__drm_dev_cat_printk((dev), DRM_UT_PRIME,, fmt, ##__VA_ARGS__)
> +#define drm_dev_dbg_atomic(dev, fmt, ...)				\
> +	__drm_dev_cat_printk((dev), DRM_UT_ATOMIC,, fmt, ##__VA_ARGS__)
> +#define drm_dev_dbg_vbl(dev, fmt, ...)					\
> +	__drm_dev_cat_printk((dev), DRM_UT_VBL,, fmt, ##__VA_ARGS__)
> +#define drm_dev_dbg_state(dev, fmt, ...)				\
> +	__drm_dev_cat_printk((dev), DRM_UT_STATE,, fmt, ##__VA_ARGS__)
> +#define drm_dev_dbg_lease(dev, fmt, ...)				\
> +	__drm_dev_cat_printk((dev), DRM_UT_LEASE,, fmt, ##__VA_ARGS__)
> +#define drm_dev_dbg_dp(dev, fmt, ...)					\
> +	__drm_dev_cat_printk((dev), DRM_UT_DP,, fmt, ##__VA_ARGS__)
> +
>  /*
>   * LEGACY logging support - do not use in new code
>   */
Sam Ravnborg Dec. 23, 2019, 12:35 p.m. UTC | #5
Hi Jani.

On Mon, Dec 23, 2019 at 01:29:19PM +0200, Jani Nikula wrote:
> On Sat, 21 Dec 2019, Sam Ravnborg <sam@ravnborg.org> wrote:
> > There are a lot of cases where we have a device * but no drm_device *.
> > Add drm_dev_* variants of the logging functions to cover these cases.
> 
> So I know there are some valid cases where we only have struct device *,
> and instead of passing struct drm_device * will need the distinction
> between multiple struct device *.
> 
> Not all current uses of DRM_DEV_* meet that criteria, however. I think
> I'd like to have those converted over to the drm_device based logging
> first, and then see what's left. Because I fear adding these will just
> lead to mass conversion from DRM_DEV_* to drm_dev_*, and the ball gets
> dropped there.

Hmm...
$ git grep -E '(DRM_DEV_ERROR|DRM_DEV_INFO|DRM_DEV_WARN|DRM_DEV_DEBUG)'
953
There are 4 hits in drm/* - the rest is in drivers (no suprise).


$ git grep -E '(DRM_ERROR|DRM_INFO|DRM_WARN|DRM_DEBUG)' | wc -l
8380
There are 626 hits in drm/* - the rest in drivers.


So moving over all DRM_DEV looks doable with a lot of effort. It touches
all drivers.
But the non-DEV variants - thats just too much.
This is a lot of effort required before we can offer new drivers
a simple a logical logging solution.

On top of this - there is today no gain using drm_device * versus device *.
The output is exactly the same.

We should discuss what is required before we can offer the full solution
for new drivers. And how much the existing usage should hold this back.

	Sam
Jani Nikula Dec. 31, 2019, 2:35 p.m. UTC | #6
On Mon, 23 Dec 2019, Sam Ravnborg <sam@ravnborg.org> wrote:
> Hi Jani.
>
> On Mon, Dec 23, 2019 at 01:29:19PM +0200, Jani Nikula wrote:
>> On Sat, 21 Dec 2019, Sam Ravnborg <sam@ravnborg.org> wrote:
>> > There are a lot of cases where we have a device * but no drm_device *.
>> > Add drm_dev_* variants of the logging functions to cover these cases.
>> 
>> So I know there are some valid cases where we only have struct device *,
>> and instead of passing struct drm_device * will need the distinction
>> between multiple struct device *.
>> 
>> Not all current uses of DRM_DEV_* meet that criteria, however. I think
>> I'd like to have those converted over to the drm_device based logging
>> first, and then see what's left. Because I fear adding these will just
>> lead to mass conversion from DRM_DEV_* to drm_dev_*, and the ball gets
>> dropped there.
>
> Hmm...
> $ git grep -E '(DRM_DEV_ERROR|DRM_DEV_INFO|DRM_DEV_WARN|DRM_DEV_DEBUG)'
> 953
> There are 4 hits in drm/* - the rest is in drivers (no suprise).
>
>
> $ git grep -E '(DRM_ERROR|DRM_INFO|DRM_WARN|DRM_DEBUG)' | wc -l
> 8380
> There are 626 hits in drm/* - the rest in drivers.
>
>
> So moving over all DRM_DEV looks doable with a lot of effort. It touches
> all drivers.
> But the non-DEV variants - thats just too much.
> This is a lot of effort required before we can offer new drivers
> a simple a logical logging solution.

I guess that's part of the point. Do we even want to offer new non-dev
based alternatives for (DRM_ERROR|DRM_INFO|DRM_WARN|DRM_DEBUG)? We'll
end up carrying the alternatives for years. And face tons of churn for
no real benefit. Why not just stick to the old ones when you're not
using a drm device based alternative?

Switching from non-dev based logging to drm device based logging, OTOH,
is worth the churn.

> On top of this - there is today no gain using drm_device * versus device *.
> The output is exactly the same.

For me and i915 the gain is in not having to do the dereference
everywhere. Having drm device available is the more common case.

If you go through the current DRM_DEV_* uses, a significant portion of
them use drm->dev or have drm device readily available. Again, I'd
prefer converting them over to drm device instead of just changing the
call to another struct device based version. And then see how big the
demand really is for struct device based logging before adding all
possible variations of it. Could they do with less?

Using drm device gives us the benefit that we can also add drm device
based debug control if we want, for example to enable debug only for a
certain device in a multi-GPU system. That option is not easily
available with struct device based logging.

> We should discuss what is required before we can offer the full solution
> for new drivers. And how much the existing usage should hold this back.

I guess I'm more concerned about existing drivers and the conversion
than new drivers...


BR,
Jani.
diff mbox series

Patch

diff --git a/include/drm/drm_print.h b/include/drm/drm_print.h
index 7c0b93e6cb80..b2e5d0209010 100644
--- a/include/drm/drm_print.h
+++ b/include/drm/drm_print.h
@@ -337,7 +337,50 @@  static inline struct drm_printer drm_err_printer(const char *prefix)
  *
  * Logging when a &device * is available, but no &drm_device *
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- * TODO
+ *
+ * Adding a device pointer (if no &drm_device * is available) is always a good
+ * idea as it add more information in the logging message thus making it easier
+ * to determine the source of the logging.
+ *
+ * All logging functions in this block share the same prototype:
+ *
+ * .. code-block:: c
+ *
+ *   void drm_dev_xxx(struct device *, char * fmt, ...)
+ *
+ * The following functions are available:
+ *
+ * .. code-block:: none
+ *
+ *   # Plain logging
+ *   drm_dev_dbg()
+ *   drm_dev_info()
+ *   drm_dev_notice()
+ *   drm_dev_warn()
+ *   drm_dev_err()
+ *
+ *   # Log only once
+ *   drm_dev_info_once()
+ *   drm_dev_notice_once()
+ *   drm_dev_warn_once()
+ *   drm_dev_err_once()
+ *
+ *   # Ratelimited - do not flood the logs
+ *   drm_dev_err_ratelimited()
+ *   drm_dev_dbg_ratelimited()
+ *   drm_dev_dbg_kms_ratelimited()
+ *
+ *   # Logging with a specific category
+ *   drm_dev_dbg_core()
+ *   drm_dev_dbg()		# Uses the DRIVER category
+ *   drm_dev_dbg_kms()
+ *   drm_dev_dbg_prime()
+ *   drm_dev_dbg_atomic()
+ *   drm_dev_dbg_vbl()
+ *   drm_dev_dbg_state()
+ *   drm_dev_dbg_lease()
+ *   drm_dev_dbg_dp()
+ *
  *
  * Logging when no &device * nor &drm_device * is available
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -468,6 +511,60 @@  static inline bool drm_debug_enabled(enum drm_debug_category category)
 #define drm_dbg_dp(drm, fmt, ...)					\
 	__drm_cat_printk((drm), DRM_UT_DP, fmt, ##__VA_ARGS__)
 
+/* struct device based logging. */
+#define __drm_dev_printk(dev, level, type, fmt, ...)			\
+	dev_##level##type(dev, "[drm] " fmt, ##__VA_ARGS__)
+
+#define __drm_dev_cat_printk(dev, cat, type, fmt, ...)			\
+({									\
+	if (drm_debug_enabled(cat))					\
+		dev_dbg##type((dev), "[drm] " fmt, ##__VA_ARGS__);	\
+})
+
+#define drm_dev_info(dev, fmt, ...)					\
+	__drm_dev_printk((dev), info,, fmt, ##__VA_ARGS__)
+#define drm_dev_notice(dev, fmt, ...)					\
+	__drm_dev_printk((dev), notice,, fmt, ##__VA_ARGS__)
+#define drm_dev_warn(dev, fmt, ...)					\
+	__drm_dev_printk((dev), warn,, fmt, ##__VA_ARGS__)
+#define drm_dev_err(dev, fmt, ...)					\
+	__drm_dev_printk((dev), err,, "*ERROR* " fmt, ##__VA_ARGS__)
+
+#define drm_dev_info_once(dev, fmt, ...)				\
+	__drm_dev_printk((dev), info, _once, fmt, ##__VA_ARGS__)
+#define drm_dev_notice_once(dev, fmt, ...)				\
+	__drm_dev_printk((dev), notice, _once, fmt, ##__VA_ARGS__)
+#define drm_dev_warn_once(dev, fmt, ...)				\
+	__drm_dev_printk((dev), warn, _once, fmt, ##__VA_ARGS__)
+#define drm_dev_err_once(dev, fmt, ...)					\
+	__drm_dev_printk((dev), err, _once, "*ERROR* " fmt, ##__VA_ARGS__)
+
+#define drm_dev_err_ratelimited(dev, fmt, ...)				\
+	__drm_dev_printk((dev), err, _ratelimited, "*ERROR* " fmt, ##__VA_ARGS__)
+#define drm_dev_dbg_ratelimited(dev, fmt, ...)				\
+	__drm_dev_cat_printk((dev), DRM_UT_DRIVER,_ratelimited, fmt, ##__VA_ARGS__)
+#define drm_dev_dbg_kms_ratelimited(dev, fmt, ...)			\
+	__drm_dev_cat_printk((dev), DRM_UT_KMS,_ratelimited, fmt, ##__VA_ARGS__)
+
+#define drm_dev_dbg_core(dev, fmt, ...)					\
+	__drm_dev_cat_printk((dev), DRM_UT_CORE,, fmt, ##__VA_ARGS__)
+#define drm_dev_dbg(dev, fmt, ...)					\
+	__drm_dev_cat_printk((dev), DRM_UT_DRIVER,, fmt, ##__VA_ARGS__)
+#define drm_dev_dbg_kms(dev, fmt, ...)					\
+	__drm_dev_cat_printk((dev), DRM_UT_KMS,, fmt, ##__VA_ARGS__)
+#define drm_dev_dbg_prime(dev, fmt, ...)				\
+	__drm_dev_cat_printk((dev), DRM_UT_PRIME,, fmt, ##__VA_ARGS__)
+#define drm_dev_dbg_atomic(dev, fmt, ...)				\
+	__drm_dev_cat_printk((dev), DRM_UT_ATOMIC,, fmt, ##__VA_ARGS__)
+#define drm_dev_dbg_vbl(dev, fmt, ...)					\
+	__drm_dev_cat_printk((dev), DRM_UT_VBL,, fmt, ##__VA_ARGS__)
+#define drm_dev_dbg_state(dev, fmt, ...)				\
+	__drm_dev_cat_printk((dev), DRM_UT_STATE,, fmt, ##__VA_ARGS__)
+#define drm_dev_dbg_lease(dev, fmt, ...)				\
+	__drm_dev_cat_printk((dev), DRM_UT_LEASE,, fmt, ##__VA_ARGS__)
+#define drm_dev_dbg_dp(dev, fmt, ...)					\
+	__drm_dev_cat_printk((dev), DRM_UT_DP,, fmt, ##__VA_ARGS__)
+
 /*
  * LEGACY logging support - do not use in new code
  */