[PATCH v2 09/15] dyndbg: add trace destination field to _ddebug

Łukasz Bartosik posted 15 patches 2 years ago
There is a newer version of this series
[PATCH v2 09/15] dyndbg: add trace destination field to _ddebug
Posted by Łukasz Bartosik 2 years ago
Add trace destination field (trace_dst) to the _ddebug structure.
The trace destination field is used to determine output of debug
logs when +T is set. Setting trace_dst value to TRACE_DST_BITS(63)
enables output to prdbg and devdbg trace events. Setting trace_dst
value to a value in range of [0..62] enables output to trace instance.

Signed-off-by: Łukasz Bartosik <lb@semihalf.com>
---
 include/linux/dynamic_debug.h | 14 ++++++++++++--
 lib/dynamic_debug.c           | 28 +++++++++++++++++++---------
 2 files changed, 31 insertions(+), 11 deletions(-)

diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h
index 684766289bfc..56f152e75604 100644
--- a/include/linux/dynamic_debug.h
+++ b/include/linux/dynamic_debug.h
@@ -60,9 +60,19 @@ struct _ddebug {
 #else
 #define _DPRINTK_FLAGS_DEFAULT 0
 #endif
-	struct {
+	struct dd_ctrl {
 		unsigned int flags:8;
-		unsigned unused:24;
+	/*
+	 * The trace destination field is used to determine output of debug
+	 * logs when +T is set. Setting trace_dst value to TRACE_DST_MAX(63)
+	 * enables output to prdbg and devdbg trace events. Setting trace_dst
+	 * value to a value in range of [0..62] enables output to trace
+	 * instance.
+	 */
+#define TRACE_DST_BITS 6
+		unsigned int trace_dst:TRACE_DST_BITS;
+#define TRACE_DST_MAX	((1 << TRACE_DST_BITS) - 1)
+		unsigned unused:18;
 	} ctrl;
 } __attribute__((aligned(8)));
 
diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index f47cb76e0e3d..0dc9ec76b867 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -80,14 +80,24 @@ module_param(verbose, int, 0644);
 MODULE_PARM_DESC(verbose, " dynamic_debug/control processing "
 		 "( 0 = off (default), 1 = module add/rm, 2 = >control summary, 3 = parsing, 4 = per-site changes)");
 
+static inline struct dd_ctrl *get_ctrl(struct _ddebug *desc)
+{
+	return &desc->ctrl;
+}
+
+static inline void set_ctrl(struct _ddebug *desc, struct dd_ctrl *ctrl)
+{
+	desc->ctrl = *ctrl;
+}
+
 static inline unsigned int get_flags(const struct _ddebug *desc)
 {
 	return desc->ctrl.flags;
 }
 
-static inline void set_flags(struct _ddebug *desc, unsigned int val)
+static inline unsigned int get_trace_dst(const struct _ddebug *desc)
 {
-	desc->ctrl.flags = val;
+	return desc->ctrl.trace_dst;
 }
 
 /* Return the path relative to source root */
@@ -190,8 +200,8 @@ static int ddebug_change(const struct ddebug_query *query,
 {
 	int i;
 	struct ddebug_table *dt;
-	unsigned int newflags;
 	unsigned int nfound = 0;
+	struct dd_ctrl nctrl = {0};
 	struct flagsbuf fbuf, nbuf;
 	struct ddebug_class_map *map = NULL;
 	int __outvar valid_class;
@@ -257,14 +267,14 @@ static int ddebug_change(const struct ddebug_query *query,
 
 			nfound++;
 
-			newflags = (get_flags(dp) & modifiers->mask) | modifiers->flags;
-			if (newflags == get_flags(dp))
+			nctrl.flags = (get_flags(dp) & modifiers->mask) | modifiers->flags;
+			if (!memcmp(&nctrl, get_ctrl(dp), sizeof(struct dd_ctrl)))
 				continue;
 #ifdef CONFIG_JUMP_LABEL
 			if (get_flags(dp) & _DPRINTK_FLAGS_ENABLED) {
-				if (!(newflags & _DPRINTK_FLAGS_ENABLED))
+				if (!(nctrl.flags & _DPRINTK_FLAGS_ENABLED))
 					static_branch_disable(&dp->key.dd_key_true);
-			} else if (newflags & _DPRINTK_FLAGS_ENABLED) {
+			} else if (nctrl.flags & _DPRINTK_FLAGS_ENABLED) {
 				static_branch_enable(&dp->key.dd_key_true);
 			}
 #endif
@@ -272,8 +282,8 @@ static int ddebug_change(const struct ddebug_query *query,
 				  trim_prefix(dp->filename), dp->lineno,
 				  dt->mod_name, dp->function,
 				  ddebug_describe_flags(get_flags(dp), &fbuf),
-				  ddebug_describe_flags(newflags, &nbuf));
-			set_flags(dp, newflags);
+				  ddebug_describe_flags(nctrl.flags, &nbuf));
+			set_ctrl(dp, &nctrl);
 		}
 	}
 	mutex_unlock(&ddebug_lock);
-- 
2.43.0.rc2.451.g8631bc7472-goog

Re: [PATCH v2 09/15] dyndbg: add trace destination field to _ddebug
Posted by jim.cromie@gmail.com 2 years ago
On Thu, Nov 30, 2023 at 4:41 PM Łukasz Bartosik <lb@semihalf.com> wrote:
>
> Add trace destination field (trace_dst) to the _ddebug structure.
> The trace destination field is used to determine output of debug
> logs when +T is set. Setting trace_dst value to TRACE_DST_BITS(63)
> enables output to prdbg and devdbg trace events. Setting trace_dst
> value to a value in range of [0..62] enables output to trace instance.
>

FWIW, I think setting trace_dest = 0  maps naturally to global / event buf.
The reason class_id DFLT is 63 is that DRM_UT_CORE is 0,
and DFLT allowed it to remain unchanged.


> Signed-off-by: Łukasz Bartosik <lb@semihalf.com>
> ---
>  include/linux/dynamic_debug.h | 14 ++++++++++++--
>  lib/dynamic_debug.c           | 28 +++++++++++++++++++---------
>  2 files changed, 31 insertions(+), 11 deletions(-)
>
> diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h
> index 684766289bfc..56f152e75604 100644
> --- a/include/linux/dynamic_debug.h
> +++ b/include/linux/dynamic_debug.h
> @@ -60,9 +60,19 @@ struct _ddebug {
>  #else
>  #define _DPRINTK_FLAGS_DEFAULT 0
>  #endif
> -       struct {
> +       struct dd_ctrl {
>                 unsigned int flags:8;
> -               unsigned unused:24;
> +       /*
> +        * The trace destination field is used to determine output of debug
> +        * logs when +T is set. Setting trace_dst value to TRACE_DST_MAX(63)
> +        * enables output to prdbg and devdbg trace events. Setting trace_dst
> +        * value to a value in range of [0..62] enables output to trace
> +        * instance.
> +        */
> +#define TRACE_DST_BITS 6
> +               unsigned int trace_dst:TRACE_DST_BITS;
> +#define TRACE_DST_MAX  ((1 << TRACE_DST_BITS) - 1)
> +               unsigned unused:18;
>         } ctrl;
>  } __attribute__((aligned(8)));
>
> diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
> index f47cb76e0e3d..0dc9ec76b867 100644
> --- a/lib/dynamic_debug.c
> +++ b/lib/dynamic_debug.c
> @@ -80,14 +80,24 @@ module_param(verbose, int, 0644);
>  MODULE_PARM_DESC(verbose, " dynamic_debug/control processing "
>                  "( 0 = off (default), 1 = module add/rm, 2 = >control summary, 3 = parsing, 4 = per-site changes)");
>
> +static inline struct dd_ctrl *get_ctrl(struct _ddebug *desc)
> +{
> +       return &desc->ctrl;
> +}
> +
> +static inline void set_ctrl(struct _ddebug *desc, struct dd_ctrl *ctrl)
> +{
> +       desc->ctrl = *ctrl;
> +}
> +
>  static inline unsigned int get_flags(const struct _ddebug *desc)
>  {
>         return desc->ctrl.flags;
>  }
>
> -static inline void set_flags(struct _ddebug *desc, unsigned int val)
> +static inline unsigned int get_trace_dst(const struct _ddebug *desc)
>  {
> -       desc->ctrl.flags = val;
> +       return desc->ctrl.trace_dst;
>  }
>
>  /* Return the path relative to source root */
> @@ -190,8 +200,8 @@ static int ddebug_change(const struct ddebug_query *query,
>  {
>         int i;
>         struct ddebug_table *dt;
> -       unsigned int newflags;
>         unsigned int nfound = 0;
> +       struct dd_ctrl nctrl = {0};
>         struct flagsbuf fbuf, nbuf;
>         struct ddebug_class_map *map = NULL;
>         int __outvar valid_class;
> @@ -257,14 +267,14 @@ static int ddebug_change(const struct ddebug_query *query,
>
>                         nfound++;
>
> -                       newflags = (get_flags(dp) & modifiers->mask) | modifiers->flags;
> -                       if (newflags == get_flags(dp))
> +                       nctrl.flags = (get_flags(dp) & modifiers->mask) | modifiers->flags;
> +                       if (!memcmp(&nctrl, get_ctrl(dp), sizeof(struct dd_ctrl)))
>                                 continue;
>  #ifdef CONFIG_JUMP_LABEL
>                         if (get_flags(dp) & _DPRINTK_FLAGS_ENABLED) {
> -                               if (!(newflags & _DPRINTK_FLAGS_ENABLED))
> +                               if (!(nctrl.flags & _DPRINTK_FLAGS_ENABLED))
>                                         static_branch_disable(&dp->key.dd_key_true);
> -                       } else if (newflags & _DPRINTK_FLAGS_ENABLED) {
> +                       } else if (nctrl.flags & _DPRINTK_FLAGS_ENABLED) {
>                                 static_branch_enable(&dp->key.dd_key_true);
>                         }
>  #endif
> @@ -272,8 +282,8 @@ static int ddebug_change(const struct ddebug_query *query,
>                                   trim_prefix(dp->filename), dp->lineno,
>                                   dt->mod_name, dp->function,
>                                   ddebug_describe_flags(get_flags(dp), &fbuf),
> -                                 ddebug_describe_flags(newflags, &nbuf));
> -                       set_flags(dp, newflags);
> +                                 ddebug_describe_flags(nctrl.flags, &nbuf));
> +                       set_ctrl(dp, &nctrl);
>                 }
>         }
>         mutex_unlock(&ddebug_lock);
> --
> 2.43.0.rc2.451.g8631bc7472-goog
>
Re: [PATCH v2 09/15] dyndbg: add trace destination field to _ddebug
Posted by Łukasz Bartosik 2 years ago
czw., 14 gru 2023 o 08:10 <jim.cromie@gmail.com> napisał(a):
>
> On Thu, Nov 30, 2023 at 4:41 PM Łukasz Bartosik <lb@semihalf.com> wrote:
> >
> > Add trace destination field (trace_dst) to the _ddebug structure.
> > The trace destination field is used to determine output of debug
> > logs when +T is set. Setting trace_dst value to TRACE_DST_BITS(63)
> > enables output to prdbg and devdbg trace events. Setting trace_dst
> > value to a value in range of [0..62] enables output to trace instance.
> >
>
> FWIW, I think setting trace_dest = 0  maps naturally to global / event buf.
> The reason class_id DFLT is 63 is that DRM_UT_CORE is 0,
> and DFLT allowed it to remain unchanged.
>

I considered trace_dst value 0 to point to trace events but then I
realized that trace instance table (tr.inst) will be 1-based instead
of 0-based and
based on that I reserved trace destination maximum value (63 when
trace_dst width is 6 bits) for trace events. This simplified the
implementation.

>
> > Signed-off-by: Łukasz Bartosik <lb@semihalf.com>
> > ---
> >  include/linux/dynamic_debug.h | 14 ++++++++++++--
> >  lib/dynamic_debug.c           | 28 +++++++++++++++++++---------
> >  2 files changed, 31 insertions(+), 11 deletions(-)
> >
> > diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h
> > index 684766289bfc..56f152e75604 100644
> > --- a/include/linux/dynamic_debug.h
> > +++ b/include/linux/dynamic_debug.h
> > @@ -60,9 +60,19 @@ struct _ddebug {
> >  #else
> >  #define _DPRINTK_FLAGS_DEFAULT 0
> >  #endif
> > -       struct {
> > +       struct dd_ctrl {
> >                 unsigned int flags:8;
> > -               unsigned unused:24;
> > +       /*
> > +        * The trace destination field is used to determine output of debug
> > +        * logs when +T is set. Setting trace_dst value to TRACE_DST_MAX(63)
> > +        * enables output to prdbg and devdbg trace events. Setting trace_dst
> > +        * value to a value in range of [0..62] enables output to trace
> > +        * instance.
> > +        */
> > +#define TRACE_DST_BITS 6
> > +               unsigned int trace_dst:TRACE_DST_BITS;
> > +#define TRACE_DST_MAX  ((1 << TRACE_DST_BITS) - 1)
> > +               unsigned unused:18;
> >         } ctrl;
> >  } __attribute__((aligned(8)));
> >
> > diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
> > index f47cb76e0e3d..0dc9ec76b867 100644
> > --- a/lib/dynamic_debug.c
> > +++ b/lib/dynamic_debug.c
> > @@ -80,14 +80,24 @@ module_param(verbose, int, 0644);
> >  MODULE_PARM_DESC(verbose, " dynamic_debug/control processing "
> >                  "( 0 = off (default), 1 = module add/rm, 2 = >control summary, 3 = parsing, 4 = per-site changes)");
> >
> > +static inline struct dd_ctrl *get_ctrl(struct _ddebug *desc)
> > +{
> > +       return &desc->ctrl;
> > +}
> > +
> > +static inline void set_ctrl(struct _ddebug *desc, struct dd_ctrl *ctrl)
> > +{
> > +       desc->ctrl = *ctrl;
> > +}
> > +
> >  static inline unsigned int get_flags(const struct _ddebug *desc)
> >  {
> >         return desc->ctrl.flags;
> >  }
> >
> > -static inline void set_flags(struct _ddebug *desc, unsigned int val)
> > +static inline unsigned int get_trace_dst(const struct _ddebug *desc)
> >  {
> > -       desc->ctrl.flags = val;
> > +       return desc->ctrl.trace_dst;
> >  }
> >
> >  /* Return the path relative to source root */
> > @@ -190,8 +200,8 @@ static int ddebug_change(const struct ddebug_query *query,
> >  {
> >         int i;
> >         struct ddebug_table *dt;
> > -       unsigned int newflags;
> >         unsigned int nfound = 0;
> > +       struct dd_ctrl nctrl = {0};
> >         struct flagsbuf fbuf, nbuf;
> >         struct ddebug_class_map *map = NULL;
> >         int __outvar valid_class;
> > @@ -257,14 +267,14 @@ static int ddebug_change(const struct ddebug_query *query,
> >
> >                         nfound++;
> >
> > -                       newflags = (get_flags(dp) & modifiers->mask) | modifiers->flags;
> > -                       if (newflags == get_flags(dp))
> > +                       nctrl.flags = (get_flags(dp) & modifiers->mask) | modifiers->flags;
> > +                       if (!memcmp(&nctrl, get_ctrl(dp), sizeof(struct dd_ctrl)))
> >                                 continue;
> >  #ifdef CONFIG_JUMP_LABEL
> >                         if (get_flags(dp) & _DPRINTK_FLAGS_ENABLED) {
> > -                               if (!(newflags & _DPRINTK_FLAGS_ENABLED))
> > +                               if (!(nctrl.flags & _DPRINTK_FLAGS_ENABLED))
> >                                         static_branch_disable(&dp->key.dd_key_true);
> > -                       } else if (newflags & _DPRINTK_FLAGS_ENABLED) {
> > +                       } else if (nctrl.flags & _DPRINTK_FLAGS_ENABLED) {
> >                                 static_branch_enable(&dp->key.dd_key_true);
> >                         }
> >  #endif
> > @@ -272,8 +282,8 @@ static int ddebug_change(const struct ddebug_query *query,
> >                                   trim_prefix(dp->filename), dp->lineno,
> >                                   dt->mod_name, dp->function,
> >                                   ddebug_describe_flags(get_flags(dp), &fbuf),
> > -                                 ddebug_describe_flags(newflags, &nbuf));
> > -                       set_flags(dp, newflags);
> > +                                 ddebug_describe_flags(nctrl.flags, &nbuf));
> > +                       set_ctrl(dp, &nctrl);
> >                 }
> >         }
> >         mutex_unlock(&ddebug_lock);
> > --
> > 2.43.0.rc2.451.g8631bc7472-goog
> >