Skip to content

Commit 90d06a4

Browse files
keesmichal42
authored andcommitted
coccicheck: span checks across CPUs
This adds parallelism by default to the "coccicheck" target using spatch's "-max" and "-index" arguments. Signed-off-by: Kees Cook <keescook@chromium.org> Signed-off-by: Nicolas Palix <nicolas.palix@imag.fr> Signed-off-by: Michal Marek <mmarek@suse.cz>
1 parent 61cb48c commit 90d06a4

2 files changed

Lines changed: 33 additions & 3 deletions

File tree

‎Documentation/coccinelle.txt‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ To enable verbose messages set the V= variable, for example:
9191

9292
make coccicheck MODE=report V=1
9393

94+
By default, coccicheck tries to run as parallel as possible. To change
95+
the parallelism, set the J= variable. For example, to run across 4 CPUs:
96+
97+
make coccicheck MODE=report J=4
98+
9499

95100
Using Coccinelle with a single semantic patch
96101
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

‎scripts/coccicheck‎

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,24 @@
22

33
SPATCH="`which ${SPATCH:=spatch}`"
44

5+
trap kill_running SIGTERM SIGINT
6+
declare -a SPATCH_PID
7+
58
# The verbosity may be set by the environmental parameter V=
69
# as for example with 'make V=1 coccicheck'
710

811
if [ -n "$V" -a "$V" != "0" ]; then
9-
VERBOSE=1
12+
VERBOSE="$V"
1013
else
1114
VERBOSE=0
1215
fi
1316

17+
if [ -z "$J" ]; then
18+
NPROC=$(getconf _NPROCESSORS_ONLN)
19+
else
20+
NPROC="$J"
21+
fi
22+
1423
FLAGS="$SPFLAGS -very_quiet"
1524

1625
# spatch only allows include directories with the syntax "-I include"
@@ -69,12 +78,28 @@ if [ "$ONLINE" = "0" ] ; then
6978
fi
7079

7180
run_cmd() {
81+
local i
7282
if [ $VERBOSE -ne 0 ] ; then
73-
echo "Running: $@"
83+
echo "Running ($NPROC in parallel): $@"
7484
fi
75-
eval $@
85+
for i in $(seq 0 $(( NPROC - 1)) ); do
86+
eval "$@ -max $NPROC -index $i &"
87+
SPATCH_PID[$i]=$!
88+
if [ $VERBOSE -eq 2 ] ; then
89+
echo "${SPATCH_PID[$i]} running"
90+
fi
91+
done
92+
wait
7693
}
7794

95+
kill_running() {
96+
for i in $(seq $(( NPROC - 1 )) ); do
97+
if [ $VERBOSE -eq 2 ] ; then
98+
echo "Killing ${SPATCH_PID[$i]}"
99+
fi
100+
kill ${SPATCH_PID[$i]} 2>/dev/null
101+
done
102+
}
78103

79104
coccinelle () {
80105
COCCI="$1"

0 commit comments

Comments
 (0)