Coccinelle: null: Optimise disjunctions in SmPL script “eno.cocci”
Subsystems (2)
PATCH 1/1 Coccinelle: null: Optimise disjunctions in SmPL script “eno.cocci”
From: Markus Elfring <[email protected]>
Date: Sun, 25 Oct 2020 18:54:36 +0100
A disjunction is applied by this script for the semantic patch language. This construct uses short-circuit evaluation. It has got the consequence that the last element of the specified condition will only be checked if all previous parts did not match. Such a technical detail leads to a recommended ordering of condition parts if you would like to care for optimal run time characteristics of SmPL code.
An usage incidence was determined for the specified identifiers in source files from the software “Linux next-20201023” by another SmPL script.
See also:
Determination of an usage statistic for memory allocation calls
https://lore.kernel.org/cocci/2774601.u91sIFNy1E@sonne/
This analysis result indicates a clear ranking for such function calls. Thus reorder the SmPL disjunction items according to their usage incidence.
--- scripts/coccinelle/null/eno.cocci | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
scripts/coccinelle/null/eno.cocci +11 -4
@@ -17,8 +17,16 @@ virtual report @depends on patch@ expression x,E; @@ - -x = \(kmalloc\|kzalloc\|kcalloc\|kmem_cache_alloc\|kmem_cache_zalloc\|kmem_cache_alloc_node\|kmalloc_node\|kzalloc_node\)(...) + x = +(kzalloc +|kmalloc +|kcalloc +|kmem_cache_alloc +|kmem_cache_zalloc +|kzalloc_node +|kmalloc_node +|kmem_cache_alloc_node +)(...) ... when != x = E - IS_ERR(x) + !x
@@ -27,8 +35,7 @@ x = \(kmalloc\|kzalloc\|kcalloc\|kmem_cache_alloc\|kmem_cache_zalloc\|kmem_cache expression x,E; position p1,p2; @@ - -*x = \(kmalloc@p1\|kzalloc@p1\|kcalloc@p1\|kmem_cache_alloc@p1\|kmem_cache_zalloc@p1\|kmem_cache_alloc_node@p1\|kmalloc_node@p1\|kzalloc_node@p1\)(...) +*x = \(kzalloc@p1\|kmalloc@p1\|kcalloc@p1\|kmem_cache_alloc@p1\|kmem_cache_zalloc@p1\|kzalloc_node@p1\|kmalloc_node@p1\|kmem_cache_alloc_node@p1\)(...) ... when != x = E * IS_ERR@p2(x)
--
2.29.1
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
Julia Lawall
maintainerQuoted 13 lines · Markus Elfring
From: Markus Elfring <[email protected]>
Date: Sun, 25 Oct 2020 18:54:36 +0100A disjunction is applied by this script for the semantic patch language. This construct uses short-circuit evaluation. It has got the consequence that the last element of the specified condition will only be checked if all previous parts did not match. Such a technical detail leads to a recommended ordering of condition parts if you would like to care for optimal run time characteristics of SmPL code.
An usage incidence was determined for the specified identifiers in source files from the software “Linux next-20201023” by another SmPL script.
Quoted 6 lines
See also:
Determination of an usage statistic for memory allocation calls
https://lore.kernel.org/cocci/2774601.u91sIFNy1E@sonne/This analysis result indicates a clear ranking for such function calls. Thus reorder the SmPL disjunction items according to their usage incidence.
Did you actually test this before and after the change and see a difference in performance? On my laptop, I see absolutely no difference, for the patch mode and for the context mode. I didn't try the other cases.
Before the change:
patch: 440.182u 2.049s 1:53.12 390.9% 0+0k 0+232io 4pf+0w
context: 392.931u 2.164s 1:41.53 389.1% 0+0k 432+360io 5pf+0w
After the change:
patch: 442.182u 2.090s 1:54.13 389.2% 0+0k 0+240io 4pf+0w
context: 392.742u 2.035s 1:41.37 389.4% 0+0k 0+360io 4pf+0w
julia
Quoted 47 lines
Signed-off-by Markus Elfring <[email protected]>--- scripts/coccinelle/null/eno.cocci | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)scripts/coccinelle/null/eno.cocci +11
-5@@ -17,8 +17,16 @@ virtual report @depends on patch@ expression x,E; @@ - -x = \(kmalloc\|kzalloc\|kcalloc\|kmem_cache_alloc\|kmem_cache_zalloc\|kmem_cache_alloc_node\|kmalloc_node\|kzalloc_node\)(...) + x = +(kzalloc +|kmalloc +|kcalloc +|kmem_cache_alloc +|kmem_cache_zalloc +|kzalloc_node +|kmalloc_node +|kmem_cache_alloc_node +)(...) ... when != x = E - IS_ERR(x) + !x@@ -27,8 +35,7 @@ x = \(kmalloc\|kzalloc\|kcalloc\|kmem_cache_alloc\|kmem_cache_zalloc\|kmem_cache expression x,E; position p1,p2; @@ - -*x = \(kmalloc@p1\|kzalloc@p1\|kcalloc@p1\|kmem_cache_alloc@p1\|kmem_cache_zalloc@p1\|kmem_cache_alloc_node@p1\|kmalloc_node@p1\|kzalloc_node@p1\)(...) +*x = \(kzalloc@p1\|kmalloc@p1\|kcalloc@p1\|kmem_cache_alloc@p1\|kmem_cache_zalloc@p1\|kzalloc_node@p1\|kmalloc_node@p1\|kmem_cache_alloc_node@p1\)(...) ... when != x = E * IS_ERR@p2(x) --2.29.1
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
Quoted 5 lines
Quoted 2 lines
This analysis result indicates a clear ranking for such function calls. Thus reorder the SmPL disjunction items according to their usage incidence.
Did you actually test this before and after the change and see a difference in performance?
Would you become interested to configure a representative test environment for safe comparisons of corresponding run time characteristics of the affected software?
Quoted 2 lines
On my laptop, I see absolutely no difference,
for the patch mode and for the context mode.
Does such information trigger a desire to clarify involved aspects in more detail?
Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
Julia Lawall
maintainerQuoted 9 lines · Markus Elfring
Quoted 5 lines
Quoted 2 lines
This analysis result indicates a clear ranking for such function calls. Thus reorder the SmPL disjunction items according to their usage incidence.
Did you actually test this before and after the change and see a difference in performance?
Would you become interested to configure a representative test environment for safe comparisons of corresponding run time characteristics of the affected software?
In what sense could the comparison possibly be unsafe?
Just use time and run spatch on whatever machine you want. It's not that complicated.
Quoted 4 lines
Quoted 2 lines
On my laptop, I see absolutely no difference,
for the patch mode and for the context mode.Does such information trigger a desire to clarify involved aspects in more detail?
Intel(R) Core(TM) i5-6200U CPU @ 2.30GHz
julia
Quoted 5 lines
Quoted 3 lines
Would you become interested to configure a representative test environment for safe comparisons of corresponding run time characteristics of the affected software?
In what sense could the comparison possibly be unsafe?
* Our test systems are obviously different.
Thus concerns can be considered for reproducibility of test results on other possible configurations.
* We share only a tiny fraction of technical information which would probably be needed for “benchmarks”.
Quoted 1 line
Just use time and run spatch on whatever machine you want.
fring@Sonne:~/Projekte/Linux/next-patched>
elfring@Sonne:~/Projekte/Linux/next-patched> git checkout next-20201023 && XX=$(date) && time spatch -D patch --timeout 9 --jobs 4 --chunksize 1 --include-headers --no-includes --dir . scripts/coccinelle/null/eno.cocci > ~/Projekte/Bau/Linux/scripts/Coccinelle/call_checks/20201023/eno1.diff 2> ~/Projekte/Bau/Linux/scripts/Coccinelle/call_checks/20201023/eno1-errors.txt; YY=$(date) && echo "$XX | $YY" …
real 2m54,266s
user 10m15,553s
sys 0m4,004s
So 25. Okt 20:53:56 CET 2020 | So 25. Okt 20:56:51 CET 2020
elfring@Sonne:~/Projekte/Linux/next-patched> git checkout next-20201023 && XX=$(date) && time spatch -D context --timeout 9 --jobs 4 --chunksize 1 --include-headers --no-includes --dir . scripts/coccinelle/null/eno.cocci > ~/Projekte/Bau/Linux/scripts/Coccinelle/call_checks/20201023/eno2.txt 2> ~/Projekte/Bau/Linux/scripts/Coccinelle/call_checks/20201023/eno2-errors.txt; YY=$(date) && echo "$XX | $YY" …
real 2m38,494s
user 9m39,364s
sys 0m4,094s
So 25. Okt 20:58:05 CET 2020 | So 25. Okt 21:00:44 CET 2020
elfring@Sonne:~/Projekte/Linux/next-patched> git checkout optimise_disjunction_in_eno.cocci-1 && XX=$(date) && time spatch -D patch --timeout 9 --jobs 4 --chunksize 1 --include-headers --no-includes --dir . scripts/coccinelle/null/eno.cocci > ~/Projekte/Bau/Linux/scripts/Coccinelle/call_checks/20201023/eno3.diff 2> ~/Projekte/Bau/Linux/scripts/Coccinelle/call_checks/20201023/eno3-errors.txt; YY=$(date) && echo "$XX | $YY" …
real 2m46,097s
user 10m15,467s
sys 0m3,984s
So 25. Okt 21:00:56 CET 2020 | So 25. Okt 21:03:42 CET 2020
elfring@Sonne:~/Projekte/Linux/next-patched> git checkout optimise_disjunction_in_eno.cocci-1 && XX=$(date) && time spatch -D context --timeout 9 --jobs 4 --chunksize 1 --include-headers --no-includes --dir . scripts/coccinelle/null/eno.cocci > ~/Projekte/Bau/Linux/scripts/Coccinelle/call_checks/20201023/eno4.txt 2> ~/Projekte/Bau/Linux/scripts/Coccinelle/call_checks/20201023/eno4-errors.txt; YY=$(date) && echo "$XX | $YY" …
real 2m41,472s
user 9m37,492s
sys 0m3,834s
So 25. Okt 21:03:56 CET 2020 | So 25. Okt 21:06:37 CET 2020
Quoted 1 line
Intel(R) Core(TM) i5-6200U CPU @ 2.30GHz
AMD Phenom(tm) II X4 850 Processor
Will any other aspects become relevant?
Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
Julia Lawall
maintainerQuoted 32 lines · Markus Elfring
Quoted 5 lines
Quoted 3 lines
Would you become interested to configure a representative test environment for safe comparisons of corresponding run time characteristics of the affected software?
In what sense could the comparison possibly be unsafe?
* Our test systems are obviously different.
Thus concerns can be considered for reproducibility of test results on other possible configurations.* We share only a tiny fraction of technical information which would probably be needed for “benchmarks”.
Quoted 1 line
Just use time and run spatch on whatever machine you want.
fring@Sonne:~/Projekte/Linux/next-patched>
elfring@Sonne:~/Projekte/Linux/next-patched> git checkout next-20201023 && XX=$(date) && time spatch -D patch --timeout 9 --jobs 4 --chunksize 1 --include-headers --no-includes --dir .scripts/coccinelle/null/eno.cocci>~/Projekte/Bau/Linux/scripts/Coccinelle/call_checks/20201023/eno1.diff2>~/Projekte/Bau/Linux/scripts/Coccinelle/call_checks/20201023/eno1-errors.txt; YY=$(date) && echo "$XX | $YY" …
real 2m54,266s
user 10m15,553s
sys 0m4,004s
So 25. Okt 20:53:56 CET 2020 | So 25. Okt 20:56:51 CET 2020
elfring@Sonne:~/Projekte/Linux/next-patched> git checkout next-20201023 && XX=$(date) && time spatch -D context --timeout 9 --jobs 4 --chunksize 1 --include-headers --no-includes --dir .scripts/coccinelle/null/eno.cocci>~/Projekte/Bau/Linux/scripts/Coccinelle/call_checks/20201023/eno2.txt2>~/Projekte/Bau/Linux/scripts/Coccinelle/call_checks/20201023/eno2-errors.txt; YY=$(date) && echo "$XX | $YY" …
real 2m38,494s
user 9m39,364s
sys 0m4,094s
So 25. Okt 20:58:05 CET 2020 | So 25. Okt 21:00:44 CET 2020
elfring@Sonne:~/Projekte/Linux/next-patched> git checkout optimise_disjunction_in_eno.cocci-1 && XX=$(date) && time spatch -D patch --timeout 9 --jobs 4 --chunksize 1 --include-headers --no-includes --dir .scripts/coccinelle/null/eno.cocci>~/Projekte/Bau/Linux/scripts/Coccinelle/call_checks/20201023/eno3.diff2>~/Projekte/Bau/Linux/scripts/Coccinelle/call_checks/20201023/eno3-errors.txt; YY=$(date) && echo "$XX | $YY" …
real 2m46,097s
Quoted 8 lines
user 10m15,467s
sys 0m3,984s
So 25. Okt 21:00:56 CET 2020 | So 25. Okt 21:03:42 CET 2020
elfring@Sonne:~/Projekte/Linux/next-patched> git checkout optimise_disjunction_in_eno.cocci-1 && XX=$(date) && time spatch -D context --timeout 9 --jobs 4 --chunksize 1 --include-headers --no-includes --dir .scripts/coccinelle/null/eno.cocci>~/Projekte/Bau/Linux/scripts/Coccinelle/call_checks/20201023/eno4.txt2>~/Projekte/Bau/Linux/scripts/Coccinelle/call_checks/20201023/eno4-errors.txt; YY=$(date) && echo "$XX | $YY" …
real 2m41,472s
user 9m37,492s
sys 0m3,834s
In the patch case, the user and system time are essentially identical. In the context case, the difference in user time is 2 seconds out of 9.5 minutes, 0.3%.
In the patch case, the real time is a bit slower. But I believe that this is due to the time to read in the data from the file system. I also had a number like that, but the difference disappeared when I reran it afterwards, which meant running that case in the same conditions as the others.
In the context case, the real time is slightly slower with your patch.
So I see no compelling evidence for making the change.
julia
Quoted 12 lines
So 25. Okt 21:03:56 CET 2020 | So 25. Okt 21:06:37 CET 2020
Quoted 1 line
Intel(R) Core(TM) i5-6200U CPU @ 2.30GHz
AMD Phenom(tm) II X4 850 Processor
Will any other aspects become relevant?
Regards,
Markus
Quoted 3 lines
In the patch case, the user and system time are essentially identical. In the context case, the difference in user time is 2 seconds out of 9.5 minutes, 0.3%.
This was just a single test run example.
Quoted 1 line
In the patch case, the real time is a bit slower.
I wonder about such an interpretation.
Quoted 1 line
But I believe that this is due to the time to read in the data from the file system.
I assume that I could reduce such an influence a bit if I would put (my) Linux repository into a RAM disk.
Quoted 5 lines
I also had a number like that, but the difference disappeared
when I reran it afterwards, which meant running that case in the same conditions as the others.In the context case, the real time is slightly slower with your patch.
I guess that the small variations from such a test approach can eventually become more interesting.
Quoted 1 line
So I see no compelling evidence for making the change.
This can be.
Should any other differences become more significant?
Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci