From: Daniel Vetter <daniel@ffwll.ch>
To: Rob Clark <robdclark@gmail.com>
Cc: "dri-devel@lists.freedesktop.org"
<dri-devel@lists.freedesktop.org>,
freedreno@lists.freedesktop.org
Subject: Re: [PATCH 2/6] drm: add helper for printing to log or seq_file
Date: Mon, 17 Oct 2016 14:30:24 +0200 [thread overview]
Message-ID: <20161017123024.GJ20761@phenom.ffwll.local> (raw)
In-Reply-To: <CAF6AEGvQdWcOyvYSTm0Ne3dq0MuSYLjUzZ7WY1_qYcTqj5KbNA@mail.gmail.com>
On Mon, Oct 17, 2016 at 07:59:51AM -0400, Rob Clark wrote:
> On Mon, Oct 17, 2016 at 2:38 AM, Daniel Vetter <daniel@ffwll.ch> wrote:
> > On Fri, Oct 14, 2016 at 07:55:49PM -0400, Rob Clark wrote:
> >> Sometimes it is nice not to duplicate equivalent printk() and
> >> seq_printf() code.
> >>
> >> Signed-off-by: Rob Clark <robdclark@gmail.com>
> >
> > Ok, maybe I should wait for coffee to kick in before commenting on patches
> > ;-)
> >
> > Two bits:
> > - kerneldoc for this pls, plus pulling into drm-internals.rst.
> > - Would be awesome to de-dupe the existing dumping code in drm_mm.c with
> > this.
>
> I have a couple things in drm/msm that I want to de-dup.. and I guess
> most drivers probably do as well..
>
> I'm toying with the idea to convert drm_info_list::show over to take a
> drm_print ptr instead of seq_file, then we could just re-use the
> debugfs fxns directly without having extra wrappers fxns.. question is
> best way to do that in a non-flag-day way..
One idea I had in the other reply is to create a seq_file which can dump
to debugfs. Not sure how feasible that is ...
-Daniel
>
> BR,
> -R
>
> > -Daniel
> >
> >> ---
> >> drivers/gpu/drm/Makefile | 3 ++-
> >> drivers/gpu/drm/drm_print.c | 54 +++++++++++++++++++++++++++++++++++++++
> >> include/drm/drm_print.h | 62 +++++++++++++++++++++++++++++++++++++++++++++
> >> 3 files changed, 118 insertions(+), 1 deletion(-)
> >> create mode 100644 drivers/gpu/drm/drm_print.c
> >> create mode 100644 include/drm/drm_print.h
> >>
> >> diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
> >> index e3dba6f..4894ebb 100644
> >> --- a/drivers/gpu/drm/Makefile
> >> +++ b/drivers/gpu/drm/Makefile
> >> @@ -12,7 +12,8 @@ drm-y := drm_auth.o drm_bufs.o drm_cache.o \
> >> drm_info.o drm_debugfs.o drm_encoder_slave.o \
> >> drm_trace_points.o drm_global.o drm_prime.o \
> >> drm_rect.o drm_vma_manager.o drm_flip_work.o \
> >> - drm_modeset_lock.o drm_atomic.o drm_bridge.o
> >> + drm_modeset_lock.o drm_atomic.o drm_bridge.o \
> >> + drm_print.o
> >>
> >> drm-$(CONFIG_COMPAT) += drm_ioc32.o
> >> drm-$(CONFIG_DRM_GEM_CMA_HELPER) += drm_gem_cma_helper.o
> >> diff --git a/drivers/gpu/drm/drm_print.c b/drivers/gpu/drm/drm_print.c
> >> new file mode 100644
> >> index 0000000..ddcb437
> >> --- /dev/null
> >> +++ b/drivers/gpu/drm/drm_print.c
> >> @@ -0,0 +1,54 @@
> >> +/*
> >> + * Copyright (C) 2016 Red Hat
> >> + *
> >> + * Permission is hereby granted, free of charge, to any person obtaining a
> >> + * copy of this software and associated documentation files (the "Software"),
> >> + * to deal in the Software without restriction, including without limitation
> >> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> >> + * and/or sell copies of the Software, and to permit persons to whom the
> >> + * Software is furnished to do so, subject to the following conditions:
> >> + *
> >> + * The above copyright notice and this permission notice shall be included in
> >> + * all copies or substantial portions of the Software.
> >> + *
> >> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> >> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> >> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
> >> + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
> >> + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
> >> + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
> >> + * OTHER DEALINGS IN THE SOFTWARE.
> >> + *
> >> + * Authors:
> >> + * Rob Clark <robdclark@gmail.com>
> >> + */
> >> +
> >> +#include <linux/seq_file.h>
> >> +#include <drm/drmP.h>
> >> +#include <drm/drm_print.h>
> >> +
> >> +void __drm_printfn_seq_file(struct drm_print *p, const char *f, va_list args)
> >> +{
> >> + seq_vprintf(p->arg, f, args);
> >> +}
> >> +
> >> +void __drm_printfn_info(struct drm_print *p, const char *f, va_list args)
> >> +{
> >> + const char *hdr = KERN_INFO "[" DRM_NAME "] ";
> >> + char fmt[strlen(hdr) + strlen(f) + 1];
> >> +
> >> + memcpy(fmt, hdr, strlen(hdr));
> >> + memcpy(fmt + strlen(hdr), f, strlen(f));
> >> + fmt[strlen(hdr) + strlen(f)] = 0;
> >> +
> >> + vprintk(fmt, args);
> >> +}
> >> +
> >> +void drm_printf(struct drm_print *p, const char *f, ...)
> >> +{
> >> + va_list args;
> >> +
> >> + va_start(args, f);
> >> + p->printfn(p, f, args);
> >> + va_end(args);
> >> +}
> >> diff --git a/include/drm/drm_print.h b/include/drm/drm_print.h
> >> new file mode 100644
> >> index 0000000..f294a9a
> >> --- /dev/null
> >> +++ b/include/drm/drm_print.h
> >> @@ -0,0 +1,62 @@
> >> +/*
> >> + * Copyright (C) 2016 Red Hat
> >> + *
> >> + * Permission is hereby granted, free of charge, to any person obtaining a
> >> + * copy of this software and associated documentation files (the "Software"),
> >> + * to deal in the Software without restriction, including without limitation
> >> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> >> + * and/or sell copies of the Software, and to permit persons to whom the
> >> + * Software is furnished to do so, subject to the following conditions:
> >> + *
> >> + * The above copyright notice and this permission notice shall be included in
> >> + * all copies or substantial portions of the Software.
> >> + *
> >> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> >> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> >> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
> >> + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
> >> + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
> >> + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
> >> + * OTHER DEALINGS IN THE SOFTWARE.
> >> + *
> >> + * Authors:
> >> + * Rob Clark <robdclark@gmail.com>
> >> + */
> >> +
> >> +#ifndef DRM_PRINT_H_
> >> +#define DRM_PRINT_H_
> >> +
> >> +#include <stdarg.h>
> >> +#include <linux/seq_file.h>
> >> +
> >> +/* A simple wrapper to abstract seq_file vs printk, so same logging code
> >> + * does not have to be duplicated.
> >> + */
> >> +struct drm_print {
> >> + void (*printfn)(struct drm_print *p, const char *f, va_list args);
> >> + void *arg;
> >> +};
> >> +
> >> +void __drm_printfn_seq_file(struct drm_print *p, const char *f, va_list args);
> >> +void __drm_printfn_info(struct drm_print *p, const char *f, va_list args);
> >> +
> >> +void drm_printf(struct drm_print *p, const char *f, ...);
> >> +
> >> +static inline struct drm_print drm_print_seq_file(struct seq_file *f)
> >> +{
> >> + struct drm_print p = {
> >> + .printfn = __drm_printfn_seq_file,
> >> + .arg = f,
> >> + };
> >> + return p;
> >> +}
> >> +
> >> +static inline struct drm_print drm_print_info(void)
> >> +{
> >> + struct drm_print p = {
> >> + .printfn = __drm_printfn_info,
> >> + };
> >> + return p;
> >> +}
> >> +
> >> +#endif /* DRM_PRINT_H_ */
> >> --
> >> 2.7.4
> >>
> >
> > --
> > Daniel Vetter
> > Software Engineer, Intel Corporation
> > http://blog.ffwll.ch
--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
next prev parent reply other threads:[~2016-10-17 12:30 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-14 23:55 [PATCH 0/6] drm: add atomic state logging and debugfs Rob Clark
[not found] ` <1476489353-16261-1-git-send-email-robdclark-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-10-14 23:55 ` [PATCH 1/6] drm: helper macros to print composite types Rob Clark
2016-10-17 17:00 ` Sean Paul
2016-10-14 23:55 ` [PATCH 2/6] drm: add helper for printing to log or seq_file Rob Clark
2016-10-17 6:38 ` Daniel Vetter
2016-10-17 11:59 ` Rob Clark
2016-10-17 12:30 ` Daniel Vetter [this message]
2016-10-17 12:35 ` Rob Clark
[not found] ` <1476489353-16261-3-git-send-email-robdclark-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-10-17 17:00 ` Sean Paul
2016-10-24 17:05 ` Rob Clark
2016-10-14 23:55 ` [PATCH 3/6] drm: add helpers to go from plane state to drm_rect Rob Clark
2016-10-17 17:00 ` Sean Paul
2016-10-14 23:55 ` [PATCH 5/6] drm/atomic: add debugfs file to dump out atomic state Rob Clark
2016-10-17 17:00 ` Sean Paul
2016-10-14 23:55 ` [PATCH 6/6] drm/msm/mdp5: add atomic_print_state support Rob Clark
[not found] ` <1476489353-16261-7-git-send-email-robdclark-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-10-17 17:00 ` Sean Paul
2016-10-14 23:55 ` [PATCH 4/6] drm/atomic: add new drm_debug bit to dump atomic state before commit Rob Clark
2016-10-17 6:31 ` Daniel Vetter
2016-10-17 17:00 ` Sean Paul
2016-10-15 0:19 ` [PATCH 0/6] drm: add atomic state logging and debugfs Rob Clark
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20161017123024.GJ20761@phenom.ffwll.local \
--to=daniel@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=freedreno@lists.freedesktop.org \
--cc=robdclark@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.