[PATCH v9 30/52] drm-dyndbg: adapt drm core to use dyndbg classmaps-v2

Jim Cromie posted 53 patches 1 year, 5 months ago
[PATCH v9 30/52] drm-dyndbg: adapt drm core to use dyndbg classmaps-v2
Posted by Jim Cromie 1 year, 5 months ago
dyndbg's CLASSMAP-v1 api was broken; DECLARE_DYNDBG_CLASSMAP tried to
do too much.  Its replaced by DRM_CLASSMAP_DEFINE, which creates &
EXPORTs the classmap when CONFIG_DRM_USE_DYNAMIC_DEBUG=y, for direct
reference by drivers.

The drivers still use DECLARE_DYNDBG_CLASSMAP for now, so they still
redundantly re-declare the classmap, but we can convert the drivers
later to DYNDBG_CLASSMAP_USE

Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
---
 drivers/gpu/drm/drm_print.c | 25 +++++++++++++------------
 include/drm/drm_print.h     |  8 ++++++++
 2 files changed, 21 insertions(+), 12 deletions(-)

diff --git a/drivers/gpu/drm/drm_print.c b/drivers/gpu/drm/drm_print.c
index 699b7dbffd7b..4a5f2317229b 100644
--- a/drivers/gpu/drm/drm_print.c
+++ b/drivers/gpu/drm/drm_print.c
@@ -55,18 +55,19 @@ MODULE_PARM_DESC(debug, "Enable debug output, where each bit enables a debug cat
 #if !defined(CONFIG_DRM_USE_DYNAMIC_DEBUG)
 module_param_named(debug, __drm_debug, ulong, 0600);
 #else
-/* classnames must match vals of enum drm_debug_category */
-DECLARE_DYNDBG_CLASSMAP(drm_debug_classes, DD_CLASS_TYPE_DISJOINT_BITS, 0,
-			"DRM_UT_CORE",
-			"DRM_UT_DRIVER",
-			"DRM_UT_KMS",
-			"DRM_UT_PRIME",
-			"DRM_UT_ATOMIC",
-			"DRM_UT_VBL",
-			"DRM_UT_STATE",
-			"DRM_UT_LEASE",
-			"DRM_UT_DP",
-			"DRM_UT_DRMRES");
+/* classnames must match value-symbols of enum drm_debug_category */
+DRM_CLASSMAP_DEFINE(drm_debug_classes, DD_CLASS_TYPE_DISJOINT_BITS,
+		    DRM_UT_CORE,
+		    "DRM_UT_CORE",
+		    "DRM_UT_DRIVER",
+		    "DRM_UT_KMS",
+		    "DRM_UT_PRIME",
+		    "DRM_UT_ATOMIC",
+		    "DRM_UT_VBL",
+		    "DRM_UT_STATE",
+		    "DRM_UT_LEASE",
+		    "DRM_UT_DP",
+		    "DRM_UT_DRMRES");
 
 static struct ddebug_class_param drm_debug_bitmap = {
 	.bits = &__drm_debug,
diff --git a/include/drm/drm_print.h b/include/drm/drm_print.h
index 9cc473e5d353..905fc25bf65a 100644
--- a/include/drm/drm_print.h
+++ b/include/drm/drm_print.h
@@ -140,6 +140,14 @@ enum drm_debug_category {
 	DRM_UT_DRMRES
 };
 
+#ifdef CONFIG_DRM_USE_DYNAMIC_DEBUG
+#define DRM_CLASSMAP_DEFINE(...) DYNDBG_CLASSMAP_DEFINE(__VA_ARGS__)
+#define DRM_CLASSMAP_USE(name)   DYNDBG_CLASSMAP_USE(name)
+#else
+#define DRM_CLASSMAP_DEFINE(...)
+#define DRM_CLASSMAP_USE(name)
+#endif
+
 static inline bool drm_debug_enabled_raw(enum drm_debug_category category)
 {
 	return unlikely(__drm_debug & BIT(category));
-- 
2.45.2
Re: [PATCH v9 30/52] drm-dyndbg: adapt drm core to use dyndbg classmaps-v2
Posted by Ville Syrjälä 1 year, 5 months ago
On Tue, Jul 02, 2024 at 03:57:20PM -0600, Jim Cromie wrote:
> dyndbg's CLASSMAP-v1 api was broken; DECLARE_DYNDBG_CLASSMAP tried to
> do too much.  Its replaced by DRM_CLASSMAP_DEFINE, which creates &
> EXPORTs the classmap when CONFIG_DRM_USE_DYNAMIC_DEBUG=y, for direct
> reference by drivers.
> 
> The drivers still use DECLARE_DYNDBG_CLASSMAP for now, so they still
> redundantly re-declare the classmap, but we can convert the drivers
> later to DYNDBG_CLASSMAP_USE
> 
> Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
> ---
>  drivers/gpu/drm/drm_print.c | 25 +++++++++++++------------
>  include/drm/drm_print.h     |  8 ++++++++
>  2 files changed, 21 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_print.c b/drivers/gpu/drm/drm_print.c
> index 699b7dbffd7b..4a5f2317229b 100644
> --- a/drivers/gpu/drm/drm_print.c
> +++ b/drivers/gpu/drm/drm_print.c
> @@ -55,18 +55,19 @@ MODULE_PARM_DESC(debug, "Enable debug output, where each bit enables a debug cat
>  #if !defined(CONFIG_DRM_USE_DYNAMIC_DEBUG)
>  module_param_named(debug, __drm_debug, ulong, 0600);
>  #else
> -/* classnames must match vals of enum drm_debug_category */
> -DECLARE_DYNDBG_CLASSMAP(drm_debug_classes, DD_CLASS_TYPE_DISJOINT_BITS, 0,
> -			"DRM_UT_CORE",
> -			"DRM_UT_DRIVER",
> -			"DRM_UT_KMS",
> -			"DRM_UT_PRIME",
> -			"DRM_UT_ATOMIC",
> -			"DRM_UT_VBL",
> -			"DRM_UT_STATE",
> -			"DRM_UT_LEASE",
> -			"DRM_UT_DP",
> -			"DRM_UT_DRMRES");
> +/* classnames must match value-symbols of enum drm_debug_category */
> +DRM_CLASSMAP_DEFINE(drm_debug_classes, DD_CLASS_TYPE_DISJOINT_BITS,
> +		    DRM_UT_CORE,
> +		    "DRM_UT_CORE",
> +		    "DRM_UT_DRIVER",
> +		    "DRM_UT_KMS",
> +		    "DRM_UT_PRIME",
> +		    "DRM_UT_ATOMIC",
> +		    "DRM_UT_VBL",
> +		    "DRM_UT_STATE",
> +		    "DRM_UT_LEASE",
> +		    "DRM_UT_DP",
> +		    "DRM_UT_DRMRES");

Looks like this stuff just ends up in an array, so presumably
it should be possible to use designated initializers to make this
less fragile?

-- 
Ville Syrjälä
Intel
Re: [PATCH v9 30/52] drm-dyndbg: adapt drm core to use dyndbg classmaps-v2
Posted by jim.cromie@gmail.com 1 year, 5 months ago
On Tue, Jul 2, 2024 at 5:33 PM Ville Syrjälä
<ville.syrjala@linux.intel.com> wrote:
>
> On Tue, Jul 02, 2024 at 03:57:20PM -0600, Jim Cromie wrote:
> > dyndbg's CLASSMAP-v1 api was broken; DECLARE_DYNDBG_CLASSMAP tried to
> > do too much.  Its replaced by DRM_CLASSMAP_DEFINE, which creates &
> > EXPORTs the classmap when CONFIG_DRM_USE_DYNAMIC_DEBUG=y, for direct
> > reference by drivers.
> >
> > The drivers still use DECLARE_DYNDBG_CLASSMAP for now, so they still
> > redundantly re-declare the classmap, but we can convert the drivers
> > later to DYNDBG_CLASSMAP_USE
> >
> > Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
> > ---
> >  drivers/gpu/drm/drm_print.c | 25 +++++++++++++------------
> >  include/drm/drm_print.h     |  8 ++++++++
> >  2 files changed, 21 insertions(+), 12 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/drm_print.c b/drivers/gpu/drm/drm_print.c
> > index 699b7dbffd7b..4a5f2317229b 100644
> > --- a/drivers/gpu/drm/drm_print.c
> > +++ b/drivers/gpu/drm/drm_print.c
> > @@ -55,18 +55,19 @@ MODULE_PARM_DESC(debug, "Enable debug output, where each bit enables a debug cat
> >  #if !defined(CONFIG_DRM_USE_DYNAMIC_DEBUG)
> >  module_param_named(debug, __drm_debug, ulong, 0600);
> >  #else
> > -/* classnames must match vals of enum drm_debug_category */
> > -DECLARE_DYNDBG_CLASSMAP(drm_debug_classes, DD_CLASS_TYPE_DISJOINT_BITS, 0,
> > -                     "DRM_UT_CORE",
> > -                     "DRM_UT_DRIVER",
> > -                     "DRM_UT_KMS",
> > -                     "DRM_UT_PRIME",
> > -                     "DRM_UT_ATOMIC",
> > -                     "DRM_UT_VBL",
> > -                     "DRM_UT_STATE",
> > -                     "DRM_UT_LEASE",
> > -                     "DRM_UT_DP",
> > -                     "DRM_UT_DRMRES");
> > +/* classnames must match value-symbols of enum drm_debug_category */
> > +DRM_CLASSMAP_DEFINE(drm_debug_classes, DD_CLASS_TYPE_DISJOINT_BITS,
> > +                 DRM_UT_CORE,
> > +                 "DRM_UT_CORE",
> > +                 "DRM_UT_DRIVER",
> > +                 "DRM_UT_KMS",
> > +                 "DRM_UT_PRIME",
> > +                 "DRM_UT_ATOMIC",
> > +                 "DRM_UT_VBL",
> > +                 "DRM_UT_STATE",
> > +                 "DRM_UT_LEASE",
> > +                 "DRM_UT_DP",
> > +                 "DRM_UT_DRMRES");
>
> Looks like this stuff just ends up in an array, so presumably
> it should be possible to use designated initializers to make this
> less fragile?

Im not sure I got your whole point, but:

the fragility is the repetitive re-statement of the map,
in those un-modified DECLARE_s,
once replaced, the USEs just ref the struct built by the _DEFINE
(once, and exported)

I dont really like the _DEFINEs restatement of the enum-values: DRM_UT_*
especially as "strings".
I can automate the stringification with an APPLY_FN_(__stringify, ...)
but the enum-list DRM_UT_* (w.o quotes) is still needed as args.

unless there is something C can do thats like Enum.values() ?



>
> --
> Ville Syrjälä
> Intel
Re: [PATCH v9 30/52] drm-dyndbg: adapt drm core to use dyndbg classmaps-v2
Posted by Ville Syrjälä 1 year, 5 months ago
On Tue, Jul 02, 2024 at 08:34:39PM -0600, jim.cromie@gmail.com wrote:
> On Tue, Jul 2, 2024 at 5:33 PM Ville Syrjälä
> <ville.syrjala@linux.intel.com> wrote:
> >
> > On Tue, Jul 02, 2024 at 03:57:20PM -0600, Jim Cromie wrote:
> > > dyndbg's CLASSMAP-v1 api was broken; DECLARE_DYNDBG_CLASSMAP tried to
> > > do too much.  Its replaced by DRM_CLASSMAP_DEFINE, which creates &
> > > EXPORTs the classmap when CONFIG_DRM_USE_DYNAMIC_DEBUG=y, for direct
> > > reference by drivers.
> > >
> > > The drivers still use DECLARE_DYNDBG_CLASSMAP for now, so they still
> > > redundantly re-declare the classmap, but we can convert the drivers
> > > later to DYNDBG_CLASSMAP_USE
> > >
> > > Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
> > > ---
> > >  drivers/gpu/drm/drm_print.c | 25 +++++++++++++------------
> > >  include/drm/drm_print.h     |  8 ++++++++
> > >  2 files changed, 21 insertions(+), 12 deletions(-)
> > >
> > > diff --git a/drivers/gpu/drm/drm_print.c b/drivers/gpu/drm/drm_print.c
> > > index 699b7dbffd7b..4a5f2317229b 100644
> > > --- a/drivers/gpu/drm/drm_print.c
> > > +++ b/drivers/gpu/drm/drm_print.c
> > > @@ -55,18 +55,19 @@ MODULE_PARM_DESC(debug, "Enable debug output, where each bit enables a debug cat
> > >  #if !defined(CONFIG_DRM_USE_DYNAMIC_DEBUG)
> > >  module_param_named(debug, __drm_debug, ulong, 0600);
> > >  #else
> > > -/* classnames must match vals of enum drm_debug_category */
> > > -DECLARE_DYNDBG_CLASSMAP(drm_debug_classes, DD_CLASS_TYPE_DISJOINT_BITS, 0,
> > > -                     "DRM_UT_CORE",
> > > -                     "DRM_UT_DRIVER",
> > > -                     "DRM_UT_KMS",
> > > -                     "DRM_UT_PRIME",
> > > -                     "DRM_UT_ATOMIC",
> > > -                     "DRM_UT_VBL",
> > > -                     "DRM_UT_STATE",
> > > -                     "DRM_UT_LEASE",
> > > -                     "DRM_UT_DP",
> > > -                     "DRM_UT_DRMRES");
> > > +/* classnames must match value-symbols of enum drm_debug_category */
> > > +DRM_CLASSMAP_DEFINE(drm_debug_classes, DD_CLASS_TYPE_DISJOINT_BITS,
> > > +                 DRM_UT_CORE,
> > > +                 "DRM_UT_CORE",
> > > +                 "DRM_UT_DRIVER",
> > > +                 "DRM_UT_KMS",
> > > +                 "DRM_UT_PRIME",
> > > +                 "DRM_UT_ATOMIC",
> > > +                 "DRM_UT_VBL",
> > > +                 "DRM_UT_STATE",
> > > +                 "DRM_UT_LEASE",
> > > +                 "DRM_UT_DP",
> > > +                 "DRM_UT_DRMRES");
> >
> > Looks like this stuff just ends up in an array, so presumably
> > it should be possible to use designated initializers to make this
> > less fragile?
> 
> Im not sure I got your whole point, but:

I mean using
 [DRM_UT_CORE] = "DRM_UT_CORE"
instead of
 "DRM_UT_CORE"
so there is no chance of screwing up the order.
Or maybe the order doesn't even matter here?

Could also stringify to avoid accidental of typos.

> 
> the fragility is the repetitive re-statement of the map,
> in those un-modified DECLARE_s,
> once replaced, the USEs just ref the struct built by the _DEFINE
> (once, and exported)
> 
> I dont really like the _DEFINEs restatement of the enum-values: DRM_UT_*
> especially as "strings".
> I can automate the stringification with an APPLY_FN_(__stringify, ...)
> but the enum-list DRM_UT_* (w.o quotes) is still needed as args.
> 
> unless there is something C can do thats like Enum.values() ?
> 
> 
> 
> >
> > --
> > Ville Syrjälä
> > Intel

-- 
Ville Syrjälä
Intel
Re: [PATCH v9 30/52] drm-dyndbg: adapt drm core to use dyndbg classmaps-v2
Posted by jim.cromie@gmail.com 1 year, 5 months ago
Got it.
I had some mental block about passing designated intializers as macro args.
it just worked, I needed to eyeball the .i file just to be sure.
thanks.
I have a fixup patch.
whats the best thing to do with it, squash it in for later ? send in
reply here ?

On Wed, Jul 3, 2024 at 5:52 AM Ville Syrjälä
<ville.syrjala@linux.intel.com> wrote:
>
> On Tue, Jul 02, 2024 at 08:34:39PM -0600, jim.cromie@gmail.com wrote:
> > On Tue, Jul 2, 2024 at 5:33 PM Ville Syrjälä
> > <ville.syrjala@linux.intel.com> wrote:
> > >
> > > On Tue, Jul 02, 2024 at 03:57:20PM -0600, Jim Cromie wrote:
> > > > dyndbg's CLASSMAP-v1 api was broken; DECLARE_DYNDBG_CLASSMAP tried to
> > > > do too much.  Its replaced by DRM_CLASSMAP_DEFINE, which creates &
> > > > EXPORTs the classmap when CONFIG_DRM_USE_DYNAMIC_DEBUG=y, for direct
> > > > reference by drivers.
> > > >
> > > > The drivers still use DECLARE_DYNDBG_CLASSMAP for now, so they still
> > > > redundantly re-declare the classmap, but we can convert the drivers
> > > > later to DYNDBG_CLASSMAP_USE
> > > >
> > > > Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
> > > > ---
> > > >  drivers/gpu/drm/drm_print.c | 25 +++++++++++++------------
> > > >  include/drm/drm_print.h     |  8 ++++++++
> > > >  2 files changed, 21 insertions(+), 12 deletions(-)
> > > >
> > > > diff --git a/drivers/gpu/drm/drm_print.c b/drivers/gpu/drm/drm_print.c
> > > > index 699b7dbffd7b..4a5f2317229b 100644
> > > > --- a/drivers/gpu/drm/drm_print.c
> > > > +++ b/drivers/gpu/drm/drm_print.c
> > > > @@ -55,18 +55,19 @@ MODULE_PARM_DESC(debug, "Enable debug output, where each bit enables a debug cat
> > > >  #if !defined(CONFIG_DRM_USE_DYNAMIC_DEBUG)
> > > >  module_param_named(debug, __drm_debug, ulong, 0600);
> > > >  #else
> > > > -/* classnames must match vals of enum drm_debug_category */
> > > > -DECLARE_DYNDBG_CLASSMAP(drm_debug_classes, DD_CLASS_TYPE_DISJOINT_BITS, 0,
> > > > -                     "DRM_UT_CORE",
> > > > -                     "DRM_UT_DRIVER",
> > > > -                     "DRM_UT_KMS",
> > > > -                     "DRM_UT_PRIME",
> > > > -                     "DRM_UT_ATOMIC",
> > > > -                     "DRM_UT_VBL",
> > > > -                     "DRM_UT_STATE",
> > > > -                     "DRM_UT_LEASE",
> > > > -                     "DRM_UT_DP",
> > > > -                     "DRM_UT_DRMRES");
> > > > +/* classnames must match value-symbols of enum drm_debug_category */
> > > > +DRM_CLASSMAP_DEFINE(drm_debug_classes, DD_CLASS_TYPE_DISJOINT_BITS,
> > > > +                 DRM_UT_CORE,
> > > > +                 "DRM_UT_CORE",
> > > > +                 "DRM_UT_DRIVER",
> > > > +                 "DRM_UT_KMS",
> > > > +                 "DRM_UT_PRIME",
> > > > +                 "DRM_UT_ATOMIC",
> > > > +                 "DRM_UT_VBL",
> > > > +                 "DRM_UT_STATE",
> > > > +                 "DRM_UT_LEASE",
> > > > +                 "DRM_UT_DP",
> > > > +                 "DRM_UT_DRMRES");
> > >
> > > Looks like this stuff just ends up in an array, so presumably
> > > it should be possible to use designated initializers to make this
> > > less fragile?
> >
> > Im not sure I got your whole point, but:
>
> I mean using
>  [DRM_UT_CORE] = "DRM_UT_CORE"
> instead of
>  "DRM_UT_CORE"
> so there is no chance of screwing up the order.
> Or maybe the order doesn't even matter here?
>
> Could also stringify to avoid accidental of typos.
>
> >
> > the fragility is the repetitive re-statement of the map,
> > in those un-modified DECLARE_s,
> > once replaced, the USEs just ref the struct built by the _DEFINE
> > (once, and exported)
> >
> > I dont really like the _DEFINEs restatement of the enum-values: DRM_UT_*
> > especially as "strings".
> > I can automate the stringification with an APPLY_FN_(__stringify, ...)
> > but the enum-list DRM_UT_* (w.o quotes) is still needed as args.
> >
> > unless there is something C can do thats like Enum.values() ?
> >
> >
> >
> > >
> > > --
> > > Ville Syrjälä
> > > Intel
>
> --
> Ville Syrjälä
> Intel
Re: [PATCH v9 30/52] drm-dyndbg: adapt drm core to use dyndbg classmaps-v2
Posted by jim.cromie@gmail.com 1 year, 5 months ago
On Wed, Jul 3, 2024 at 10:11 AM <jim.cromie@gmail.com> wrote:
>
> Got it.
> I had some mental block about passing designated intializers as macro args.
> it just worked, I needed to eyeball the .i file just to be sure.
> thanks.
> I have a fixup patch.
> whats the best thing to do with it, squash it in for later ? send in
> reply here ?
>

I have to retract on designated-initializers into DYNDBG_CLASSMAP_DEFINE

While it works for DRM, and looks good, and self-documenting,
it only works cuz DRM_UT_CORE = 0,
and breaks when I used it 2x in test-dynamic-debug.ko.
the 2nd _DEFINE needs a _base > DRM_UT_LAST.


With designated-init exprs passed in thru the macro, I get:

    1st classmap below is bad - the length should be 8, but is 28 cuz
init started at 20.

    (gdb) p *di->classes@di->num_classes
    $2 = {{mod = 0xffffffffc0203740, mod_name = 0xffffffffc0206220
"test_dynamic_debug",
        class_names = 0xffffffffc0203080, length = 28, base = 20,
map_type = DD_CLASS_TYPE_LEVEL_NUM}, {
        mod = 0xffffffffc0203740, mod_name = 0xffffffffc0206220
"test_dynamic_debug",
        class_names = 0xffffffffc0203160, length = 10, base = 0,
map_type = DD_CLASS_TYPE_DISJOINT_BITS}}
    (gdb)

    so 1st 20 classnames are empty, and classnames -> index -> classid
translation fails later.

    (gdb) p *di->classes[0]->class_names@di->classes[0]->length
    $4 = {0x0 <fixed_percpu_data> <repeats 20 times>,
0xffffffffc0206356 "V0", 0xffffffffc0206359 "V1",
      0xffffffffc020635c "V2", 0xffffffffc020635f "V3",
0xffffffffc0206362 "V4", 0xffffffffc0206365 "V5",
      0xffffffffc0206368 "V6", 0xffffffffc020636b "V7"}
    (gdb)

Basically, when designated-inits are passed in, the _base param is redundant,
and the once guaranteed contiguous 0-based classnames list is now
guaranteed sparse.

the macro could be altered to expect designated-inits,
but I couldnt distinguish between the 2 different uses,
so theres a mis-use potential either way.

Id prefer to keep the _DEFINE the way it is,
and better kdoc & howto this to explain away the potential.

BTW: Im aware I failed to delete some v9*patch files before git send-email,
Im considering my penance, will resend soon.