Skip to contentSkip to conversation

Improve Coccinelle Parallelisation

PATCH Superseded Sumera Priyadarsini 1 participant 3 messages Oct 7, 2020

Subsystems (3)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover Improve Coccinelle Parallelisation

Coccinelle utilises all available threads to implement parallelisation. However, this results in a decrease in performance.

This patchset aims to improve performance by modifying cocciccheck to use at most one thread per core by default in machines with more than 4 hyperthreads.

Sumera Priyadarsini (2):
scripts: coccicheck: Change default value for parallelism
Documentation: Coccinelle: Modify parallelisation information in docs

 Documentation/dev-tools/coccinelle.rst | 5 +++--
 scripts/coccicheck                     | 5 +++++
 2 files changed, 8 insertions(+), 2 deletions(-)
Signature · 1 line
2.25.1
#1 lore raw

PATCH v3 1/2 scripts: coccicheck: Change default value for parallelism

By default, coccicheck utilizes all available threads to implement parallelisation. However, when all available threads are used, a decrease in performance is noted. The elapsed time is minimum when at most one thread per core is used.

For example, on benchmarking the semantic patch kfree.cocci for usb/serial using hyperfine, the outputs obtained for J=5 and J=2 are 1.32 and 1.90 times faster than those for J=10 and J=9 respectively for two separate runs. For the larger drivers/staging directory, minimium elapsed time is obtained for J=3 which is 1.86 times faster than that for J=12. The optimal J value does not exceed 6 in any of the test runs. The benchmarks are run on a machine with 6 cores, with 2 threads per core, i.e, 12 hyperthreads in all.

To improve performance, modify coccicheck to use at most only one thread per core by default in machines with more than 4 hyperthreads.

---
Changes in V2:
- Change commit message as suggested by Julia Lawall
Changes in V3:
- Use J/2 as optimal value for machines with more than 8 hyperthreads as well.
Changes in V4:
- Use J as optimal value for machines with less than or equal to 4 hyperthreads.

---
 scripts/coccicheck | 5 +++++
 1 file changed, 5 insertions(+)
scripts/coccicheck +5 -0
index e04d328210ac..bafc55141a73 100755
@@ -75,8 +75,13 @@ else
         OPTIONS="--dir $KBUILD_EXTMOD $COCCIINCLUDE"
     fi
 
+    # Use only one thread per core by default if hyperthreading is enabled
+    THREADS_PER_CORE=$(lscpu | grep "Thread(s) per core: " | tr -cd "[:digit:]")
     if [ -z "$J" ]; then
         NPROC=$(getconf _NPROCESSORS_ONLN)
+	if [ $THREADS_PER_CORE -gt 1 -a $NPROC -gt 4 ] ; then
+		NPROC=$((NPROC/2))
+	fi
     else
         NPROC="$J"
     fi
Signature · 1 line
2.25.1
#2 lore raw

PATCH v3 2/2 Documentation: Coccinelle: Modify parallelisation information in docs

In reply to Sumera Priyadarsini

This patchset modifies coccicheck to use at most one thread per core by default in machines with more than 4 hyperthreads for optimal performance. Modify documentation in coccinelle.rst to reflect the same.

---
Changes in V2:
Update scripts/coccicheck to use all available threads in machines with upto 4 hyperthreads.

---
 Documentation/dev-tools/coccinelle.rst | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
Documentation/dev-tools/coccinelle.rst +3 -2
index 74c5e6aeeff5..6fdc462689d5 100644
@@ -130,8 +130,9 @@ To enable verbose messages set the V= variable, for example::
 Coccinelle parallelization
 --------------------------
 
-By default, coccicheck tries to run as parallel as possible. To change
-the parallelism, set the J= variable. For example, to run across 4 CPUs::
+By default, coccicheck uses at most 1 thread per core in a machine with more
+than 4 hyperthreads. In a machine with upto 4 threads, all threads are used.
+To change the parallelism, set the J= variable. For example, to run across 4 CPUs::
 
    make coccicheck MODE=report J=4
 
Signature · 1 line
2.25.1