Re: [Cocci] Performance issue with quite simple patch?

2021-01-13 Thread Julia Lawall



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


[Cocci] Performance issue with quite simple patch?

2021-01-13 Thread Maxime Ripard
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


signature.asc
Description: PGP signature
___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci