Coccinelle Archive on lore.kernel.org
 help / color / Atom feed
* [Cocci] Performance issue with quite simple patch?
@ 2021-01-13  9:48 Maxime Ripard
  2021-01-13 10:58 ` Julia Lawall
  0 siblings, 1 reply; 3+ messages in thread
From: Maxime Ripard @ 2021-01-13  9:48 UTC (permalink / raw)
  To: cocci

[-- Attachment #1.1: Type: text/plain, Size: 1088 bytes --]

Hi!

I've been trying to get a patch to rename any variable called "state" in
a given set of callbacks.

This is the patch that I've come up with:

@ plane_atomic_func @
identifier helpers;
identifier func;
@@

(
 static const struct drm_plane_helper_funcs helpers = {
 	...,
 	.atomic_check = func,
	...,
 };
|
 static const struct drm_plane_helper_funcs helpers = {
 	...,
 	.atomic_disable = func,
	...,
 };
|
 static const struct drm_plane_helper_funcs helpers = {
 	...,
 	.atomic_update = func,
	...,
 };
)

@@
identifier plane_atomic_func.func;
symbol state;
expression e;
type T;
@@

 func(...)
 {
 	...
-	T state = e;
+	T plane_state = e;
 	<+...
-	state
+	plane_state
 	...+>
 }

However, it seems like at least on a file (in Linux,
drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c), it takes quite big
performance hit with one CPU running at 100% until the timeout is hit.

Replacing <+... by ... makes it work instantly, but doesn't really do
what I'm expecting, so I guess it's a matter of the patch being
subobtimal?

Is there a more optimal way of doing it?

Thanks!
Maxime

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

[-- Attachment #2: Type: text/plain, Size: 136 bytes --]

_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Cocci] Performance issue with quite simple patch?
  2021-01-13  9:48 [Cocci] Performance issue with quite simple patch? Maxime Ripard
@ 2021-01-13 10:58 ` Julia Lawall
  2021-01-14 13:24   ` Maxime Ripard
  0 siblings, 1 reply; 3+ messages in thread
From: Julia Lawall @ 2021-01-13 10:58 UTC (permalink / raw)
  To: Maxime Ripard; +Cc: cocci



On Wed, 13 Jan 2021, Maxime Ripard wrote:

> Hi!
>
> I've been trying to get a patch to rename any variable called "state" in
> a given set of callbacks.
>
> This is the patch that I've come up with:
>
> @ plane_atomic_func @
> identifier helpers;
> identifier func;
> @@
>
> (
>  static const struct drm_plane_helper_funcs helpers = {
>  	...,
>  	.atomic_check = func,
> 	...,
>  };
> |
>  static const struct drm_plane_helper_funcs helpers = {
>  	...,
>  	.atomic_disable = func,
> 	...,
>  };
> |
>  static const struct drm_plane_helper_funcs helpers = {
>  	...,
>  	.atomic_update = func,
> 	...,
>  };
> )

You don't need the ...s in the above.  For structure declarations
Coccinelle is happy as long as what you specify is a subset of what is
present.  The static and const aren't essential either.  If you remove
them, the pattern will match whethe thy are present or not.

>
> @@
> identifier plane_atomic_func.func;
> symbol state;
> expression e;
> type T;
> @@
>
>  func(...)
>  {
>  	...
> -	T state = e;
> +	T plane_state = e;
>  	<+...
> -	state
> +	plane_state
>  	...+>
>  }
>
> However, it seems like at least on a file (in Linux,
> drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c), it takes quite big
> performance hit with one CPU running at 100% until the timeout is hit.
>
> Replacing <+... by ... makes it work instantly, but doesn't really do
> what I'm expecting, so I guess it's a matter of the patch being
> subobtimal?
>
> Is there a more optimal way of doing it?

In your rule, I donkt think that there is really any essential connection
between the declaration and the use?  You just want to change state to
plane_state when it occurs in one of the functions that you detected.  So
you could at least try the following and see if it gives any false
positives:

@@
identifier plane_atomic_func.func;
symbol state;
expression e;
type T;
@@

 func(...)
 {
      <...
(
-     T state = e;
+     T plane_state = e;
|
-     state
+     plane_state
)
      ...>
 }
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Cocci] Performance issue with quite simple patch?
  2021-01-13 10:58 ` Julia Lawall
@ 2021-01-14 13:24   ` Maxime Ripard
  0 siblings, 0 replies; 3+ messages in thread
From: Maxime Ripard @ 2021-01-14 13:24 UTC (permalink / raw)
  To: Julia Lawall; +Cc: cocci

[-- Attachment #1.1: Type: text/plain, Size: 3374 bytes --]

Hi Julia,

On Wed, Jan 13, 2021 at 11:58:41AM +0100, Julia Lawall wrote:
> On Wed, 13 Jan 2021, Maxime Ripard wrote:
> 
> > Hi!
> >
> > I've been trying to get a patch to rename any variable called "state" in
> > a given set of callbacks.
> >
> > This is the patch that I've come up with:
> >
> > @ plane_atomic_func @
> > identifier helpers;
> > identifier func;
> > @@
> >
> > (
> >  static const struct drm_plane_helper_funcs helpers = {
> >  	...,
> >  	.atomic_check = func,
> > 	...,
> >  };
> > |
> >  static const struct drm_plane_helper_funcs helpers = {
> >  	...,
> >  	.atomic_disable = func,
> > 	...,
> >  };
> > |
> >  static const struct drm_plane_helper_funcs helpers = {
> >  	...,
> >  	.atomic_update = func,
> > 	...,
> >  };
> > )
> 
> You don't need the ...s in the above.  For structure declarations
> Coccinelle is happy as long as what you specify is a subset of what is
> present.  The static and const aren't essential either.  If you remove
> them, the pattern will match whethe thy are present or not.

Oh, that's good to know, thanks!

> >
> > @@
> > identifier plane_atomic_func.func;
> > symbol state;
> > expression e;
> > type T;
> > @@
> >
> >  func(...)
> >  {
> >  	...
> > -	T state = e;
> > +	T plane_state = e;
> >  	<+...
> > -	state
> > +	plane_state
> >  	...+>
> >  }
> >
> > However, it seems like at least on a file (in Linux,
> > drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c), it takes quite big
> > performance hit with one CPU running at 100% until the timeout is hit.
> >
> > Replacing <+... by ... makes it work instantly, but doesn't really do
> > what I'm expecting, so I guess it's a matter of the patch being
> > subobtimal?
> >
> > Is there a more optimal way of doing it?
> 
> In your rule, I donkt think that there is really any essential connection
> between the declaration and the use?  You just want to change state to
> plane_state when it occurs in one of the functions that you detected.

I'm sorry, I forgot to mention that I only want the change to occur if
it's a variable declared in the function, not an argument to it

> So you could at least try the following and see if it gives any false positives:
>
> @@
> identifier plane_atomic_func.func;
> symbol state;
> expression e;
> type T;
> @@
> 
>  func(...)
>  {
>       <...
> (
> -     T state = e;
> +     T plane_state = e;
> |
> -     state
> +     plane_state
> )
>       ...>
>  }

I would never have thought of that, thanks :)

I tried to adjust it to match only on functions that have such a
variable defined:

@ plane_atomic_func @
identifier helpers;
identifier func;
@@

 struct drm_plane_helper_funcs helpers = {
 	.atomic_check = func,
 };

@ has_variable_state @
identifier plane_atomic_func.func;
symbol state;
expression e;
type T;
@@

 func(...)
 {
 	...
	T state = e;
 	...
 }

@ depends on has_variable_state @
identifier plane_atomic_func.func;
symbol state;
expression e;
type T;
@@

 func(...)
 {
 	<...
(
-	T state = e;
+	T plane_state = e;
|
-	state
+	plane_state
)
 	...>
 }

But it's still choking on that same file
(drivers/gpu/drm//atmel-hlcdc/atmel_hlcdc_plane.c). Every other file
that matches takes at most a few seconds though, so it seems a bit weird

Maxime

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

[-- Attachment #2: Type: text/plain, Size: 136 bytes --]

_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-13  9:48 [Cocci] Performance issue with quite simple patch? Maxime Ripard
2021-01-13 10:58 ` Julia Lawall
2021-01-14 13:24   ` Maxime Ripard

Coccinelle Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/cocci/0 cocci/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 cocci cocci/ https://lore.kernel.org/cocci \
		cocci@systeme.lip6.fr
	public-inbox-index cocci

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/fr.lip6.systeme.cocci


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git