Message ID | 20210721175526.22020-11-sean@poorly.run (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | drm/trace: Mirror DRM debug logs to tracefs | expand |
On 2021-07-21 10:55, Sean Paul wrote: > From: Sean Paul <seanpaul@chromium.org> > > This patch adds a new printer which will select the appropriate output > for a given debug category. Currently there is only one output target, > which is syslog. However in the future we'll have tracefs and it will > be > useful to print to syslog, tracefs, or both. Drivers just need to > create > the printer for the appropriate category and the printer will decide > where to send the output. > > Signed-off-by: Sean Paul <seanpaul@chromium.org> Reviewed-by: Abhinav Kumar <abhinavk@codeaurora.org> > Link: > https://patchwork.freedesktop.org/patch/msgid/20200608210505.48519-11-sean@poorly.run > #v5 > > Changes in v5: > -Added to the set > Changes in v6: > -None > --- > drivers/gpu/drm/drm_print.c | 5 +++++ > include/drm/drm_print.h | 28 ++++++++++++++++++++++++++++ > 2 files changed, 33 insertions(+) > > diff --git a/drivers/gpu/drm/drm_print.c b/drivers/gpu/drm/drm_print.c > index 2ff7a6ecc632..4d984a01b3a3 100644 > --- a/drivers/gpu/drm/drm_print.c > +++ b/drivers/gpu/drm/drm_print.c > @@ -172,6 +172,11 @@ void __drm_printfn_err(struct drm_printer *p, > struct va_format *vaf) > } > EXPORT_SYMBOL(__drm_printfn_err); > > +void __drm_printfn_noop(struct drm_printer *p, struct va_format *vaf) > +{ > +} > +EXPORT_SYMBOL(__drm_printfn_noop); > + > /** > * drm_puts - print a const string to a &drm_printer stream > * @p: the &drm printer > diff --git a/include/drm/drm_print.h b/include/drm/drm_print.h > index 2ea0ffd9c1ce..af31beeb82a1 100644 > --- a/include/drm/drm_print.h > +++ b/include/drm/drm_print.h > @@ -87,6 +87,7 @@ void __drm_puts_seq_file(struct drm_printer *p, > const char *str); > void __drm_printfn_info(struct drm_printer *p, struct va_format *vaf); > void __drm_printfn_debug_syslog(struct drm_printer *p, struct > va_format *vaf); > void __drm_printfn_err(struct drm_printer *p, struct va_format *vaf); > +void __drm_printfn_noop(struct drm_printer *p, struct va_format *vaf); > > __printf(2, 3) > void drm_printf(struct drm_printer *p, const char *f, ...); > @@ -329,6 +330,33 @@ static inline bool drm_debug_enabled(enum > drm_debug_category category) > return drm_debug_syslog_enabled(category); > } > > +/** > + * drm_debug_category_printer - construct a &drm_printer that outputs > to > + * pr_debug() if enabled for the given category. > + * @category: the DRM_UT_* message category this message belongs to > + * @prefix: trace output prefix > + * > + * RETURNS: > + * The &drm_printer object > + */ > +static inline struct drm_printer > +drm_debug_category_printer(enum drm_debug_category category, > + const char *prefix) > +{ > + struct drm_printer p = { > + .prefix = prefix > + }; > + > + if (drm_debug_syslog_enabled(category)) { > + p.printfn = __drm_printfn_debug_syslog; > + } else { > + WARN(1, "Debug category %d is inactive.", category); > + p.printfn = __drm_printfn_noop; > + } > + > + return p; > +} > + > /* > * struct device based logging > *
diff --git a/drivers/gpu/drm/drm_print.c b/drivers/gpu/drm/drm_print.c index 2ff7a6ecc632..4d984a01b3a3 100644 --- a/drivers/gpu/drm/drm_print.c +++ b/drivers/gpu/drm/drm_print.c @@ -172,6 +172,11 @@ void __drm_printfn_err(struct drm_printer *p, struct va_format *vaf) } EXPORT_SYMBOL(__drm_printfn_err); +void __drm_printfn_noop(struct drm_printer *p, struct va_format *vaf) +{ +} +EXPORT_SYMBOL(__drm_printfn_noop); + /** * drm_puts - print a const string to a &drm_printer stream * @p: the &drm printer diff --git a/include/drm/drm_print.h b/include/drm/drm_print.h index 2ea0ffd9c1ce..af31beeb82a1 100644 --- a/include/drm/drm_print.h +++ b/include/drm/drm_print.h @@ -87,6 +87,7 @@ void __drm_puts_seq_file(struct drm_printer *p, const char *str); void __drm_printfn_info(struct drm_printer *p, struct va_format *vaf); void __drm_printfn_debug_syslog(struct drm_printer *p, struct va_format *vaf); void __drm_printfn_err(struct drm_printer *p, struct va_format *vaf); +void __drm_printfn_noop(struct drm_printer *p, struct va_format *vaf); __printf(2, 3) void drm_printf(struct drm_printer *p, const char *f, ...); @@ -329,6 +330,33 @@ static inline bool drm_debug_enabled(enum drm_debug_category category) return drm_debug_syslog_enabled(category); } +/** + * drm_debug_category_printer - construct a &drm_printer that outputs to + * pr_debug() if enabled for the given category. + * @category: the DRM_UT_* message category this message belongs to + * @prefix: trace output prefix + * + * RETURNS: + * The &drm_printer object + */ +static inline struct drm_printer +drm_debug_category_printer(enum drm_debug_category category, + const char *prefix) +{ + struct drm_printer p = { + .prefix = prefix + }; + + if (drm_debug_syslog_enabled(category)) { + p.printfn = __drm_printfn_debug_syslog; + } else { + WARN(1, "Debug category %d is inactive.", category); + p.printfn = __drm_printfn_noop; + } + + return p; +} + /* * struct device based logging *