[v4] devtools: parallelize ABI check

Message ID 20230111195345.1275693-1-thomas@monjalon.net (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series [v4] devtools: parallelize ABI check |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/github-robot: build success github build: passed
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-testing fail Testing issues
ci/iol-x86_64-unit-testing fail Testing issues
ci/iol-abi-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS

Commit Message

Thomas Monjalon Jan. 11, 2023, 7:53 p.m. UTC
  Generation and comparison of ABI dumps are done on multiple cores
thanks to xargs -P0.
It can accelerate this long step by 5 in my tests.

xargs reports a global error if one of the process has an error.

Running a shell function with xargs requires to export it.
POSIX shell does not support function export except using an "eval trick".
Required variables are also exported.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
Tested-by: Ferruh Yigit <ferruh.yigit@amd.com>
---
v2:
	- find dump2 inside the function
	- force bash because of export -f
v3:
	- revert to POSIX sh
	- use POSIX eval instead of export -f (issues on Ubuntu)
v4:
	- export all required variables
	- remove useless stdout echo calls
---
 devtools/check-abi.sh | 23 +++++++++++++----------
 devtools/gen-abi.sh   |  5 +++--
 2 files changed, 16 insertions(+), 12 deletions(-)
  

Comments

David Marchand Jan. 12, 2023, 10:53 a.m. UTC | #1
On Wed, Jan 11, 2023 at 8:53 PM Thomas Monjalon <thomas@monjalon.net> wrote:
>
> Generation and comparison of ABI dumps are done on multiple cores
> thanks to xargs -P0.
> It can accelerate this long step by 5 in my tests.
>
> xargs reports a global error if one of the process has an error.
>
> Running a shell function with xargs requires to export it.
> POSIX shell does not support function export except using an "eval trick".
> Required variables are also exported.
>
> Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
> Tested-by: Ferruh Yigit <ferruh.yigit@amd.com>
> diff --git a/devtools/check-abi.sh b/devtools/check-abi.sh
> index c583eae2fd..31eceb42e6 100755
> --- a/devtools/check-abi.sh
> +++ b/devtools/check-abi.sh
> @@ -34,20 +34,18 @@ else
>         ABIDIFF_OPTIONS="$ABIDIFF_OPTIONS --headers-dir2 $incdir2"
>  fi
>
> -error=
> -for dump in $(find $refdir -name "*.dump"); do
> +export newdir ABIDIFF_OPTIONS
> +export diff_func='run_diff() {
> +       dump=$1
>         name=$(basename $dump)
>         dump2=$(find $newdir -name $name)
>         if [ -z "$dump2" ] || [ ! -e "$dump2" ]; then
>                 echo "Error: cannot find $name in $newdir" >&2
> -               error=1
> -               continue
> -       fi
> +               return 1
> +       fi;

No need for ; here.
This can be fixed when applying (I tested both your patch and with
this small fix).


>         abidiff $ABIDIFF_OPTIONS $dump $dump2 || {
>                 abiret=$?
> -               echo "Error: ABI issue reported for 'abidiff $ABIDIFF_OPTIONS $dump $dump2'" >&2
> -               error=1
> -               echo
> +               echo "Error: ABI issue reported for abidiff $ABIDIFF_OPTIONS $dump $dump2" >&2
>                 if [ $(($abiret & 3)) -ne 0 ]; then
>                         echo "ABIDIFF_ERROR|ABIDIFF_USAGE_ERROR, this could be a script or environment issue." >&2
>                 fi
> @@ -57,8 +55,13 @@ for dump in $(find $refdir -name "*.dump"); do
>                 if [ $(($abiret & 8)) -ne 0 ]; then
>                         echo "ABIDIFF_ABI_INCOMPATIBLE_CHANGE, this change breaks the ABI." >&2
>                 fi
> -               echo
> +               return 1
>         }
> -done
> +}'
> +
> +error=
> +find $refdir -name "*.dump" |
> +xargs -n1 -P0 sh -c 'eval "$diff_func"; run_diff $0' ||
> +error=1
>
>  [ -z "$error" ] || [ -n "$warnonly" ]

For the record, on my system, calling this script is ~5 times faster:
- before
real    0m5,447s
user    0m4,497s
sys    0m0,937s

- after
real    0m1,202s
user    0m10,784s
sys    0m2,027s


> diff --git a/devtools/gen-abi.sh b/devtools/gen-abi.sh
> index f15a3b9aaf..61f7510ea1 100755
> --- a/devtools/gen-abi.sh
> +++ b/devtools/gen-abi.sh
> @@ -22,5 +22,6 @@ for f in $(find $installdir -name "*.so.*"); do
>         fi
>
>         libname=$(basename $f)
> -       abidw --out-file $dumpdir/${libname%.so*}.dump $f
> -done
> +       echo $dumpdir/${libname%.so*}.dump $f
> +done |
> +xargs -n2 -P0 abidw --out-file
> --
> 2.39.0
>

- before
real    0m8,237s
user    0m7,704s
sys    0m0,504s

- after
real    0m2,517s
user    0m14,145s
sys    0m0,766s


Ferruh, I am seeing quite different numbers for running those scripts
(clearly not of the minute order).
I switched to testing/building in tmpfs some time ago.
It requires a good amount of memory (I empirically allocated 40G), but
maybe worth a try for you?


In any case, this patch lgtm.
Acked-by: David Marchand <david.marchand@redhat.com>
  
Ferruh Yigit Jan. 12, 2023, 2:14 p.m. UTC | #2
On 1/12/2023 10:53 AM, David Marchand wrote:
> On Wed, Jan 11, 2023 at 8:53 PM Thomas Monjalon <thomas@monjalon.net> wrote:
>>
>> Generation and comparison of ABI dumps are done on multiple cores
>> thanks to xargs -P0.
>> It can accelerate this long step by 5 in my tests.
>>
>> xargs reports a global error if one of the process has an error.
>>
>> Running a shell function with xargs requires to export it.
>> POSIX shell does not support function export except using an "eval trick".
>> Required variables are also exported.
>>
>> Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
>> Tested-by: Ferruh Yigit <ferruh.yigit@amd.com>
>> diff --git a/devtools/check-abi.sh b/devtools/check-abi.sh
>> index c583eae2fd..31eceb42e6 100755
>> --- a/devtools/check-abi.sh
>> +++ b/devtools/check-abi.sh
>> @@ -34,20 +34,18 @@ else
>>         ABIDIFF_OPTIONS="$ABIDIFF_OPTIONS --headers-dir2 $incdir2"
>>  fi
>>
>> -error=
>> -for dump in $(find $refdir -name "*.dump"); do
>> +export newdir ABIDIFF_OPTIONS
>> +export diff_func='run_diff() {
>> +       dump=$1
>>         name=$(basename $dump)
>>         dump2=$(find $newdir -name $name)
>>         if [ -z "$dump2" ] || [ ! -e "$dump2" ]; then
>>                 echo "Error: cannot find $name in $newdir" >&2
>> -               error=1
>> -               continue
>> -       fi
>> +               return 1
>> +       fi;
> 
> No need for ; here.
> This can be fixed when applying (I tested both your patch and with
> this small fix).
> 
> 
>>         abidiff $ABIDIFF_OPTIONS $dump $dump2 || {
>>                 abiret=$?
>> -               echo "Error: ABI issue reported for 'abidiff $ABIDIFF_OPTIONS $dump $dump2'" >&2
>> -               error=1
>> -               echo
>> +               echo "Error: ABI issue reported for abidiff $ABIDIFF_OPTIONS $dump $dump2" >&2
>>                 if [ $(($abiret & 3)) -ne 0 ]; then
>>                         echo "ABIDIFF_ERROR|ABIDIFF_USAGE_ERROR, this could be a script or environment issue." >&2
>>                 fi
>> @@ -57,8 +55,13 @@ for dump in $(find $refdir -name "*.dump"); do
>>                 if [ $(($abiret & 8)) -ne 0 ]; then
>>                         echo "ABIDIFF_ABI_INCOMPATIBLE_CHANGE, this change breaks the ABI." >&2
>>                 fi
>> -               echo
>> +               return 1
>>         }
>> -done
>> +}'
>> +
>> +error=
>> +find $refdir -name "*.dump" |
>> +xargs -n1 -P0 sh -c 'eval "$diff_func"; run_diff $0' ||
>> +error=1
>>
>>  [ -z "$error" ] || [ -n "$warnonly" ]
> 
> For the record, on my system, calling this script is ~5 times faster:
> - before
> real    0m5,447s
> user    0m4,497s
> sys    0m0,937s
> 
> - after
> real    0m1,202s
> user    0m10,784s
> sys    0m2,027s
> 
> 
>> diff --git a/devtools/gen-abi.sh b/devtools/gen-abi.sh
>> index f15a3b9aaf..61f7510ea1 100755
>> --- a/devtools/gen-abi.sh
>> +++ b/devtools/gen-abi.sh
>> @@ -22,5 +22,6 @@ for f in $(find $installdir -name "*.so.*"); do
>>         fi
>>
>>         libname=$(basename $f)
>> -       abidw --out-file $dumpdir/${libname%.so*}.dump $f
>> -done
>> +       echo $dumpdir/${libname%.so*}.dump $f
>> +done |
>> +xargs -n2 -P0 abidw --out-file
>> --
>> 2.39.0
>>
> 
> - before
> real    0m8,237s
> user    0m7,704s
> sys    0m0,504s
> 
> - after
> real    0m2,517s
> user    0m14,145s
> sys    0m0,766s
> 
> 
> Ferruh, I am seeing quite different numbers for running those scripts
> (clearly not of the minute order).
> I switched to testing/building in tmpfs some time ago.
> It requires a good amount of memory (I empirically allocated 40G), but
> maybe worth a try for you?
> 

I run 'test-meson-builds.sh' script directly and yes I am getting
different numbers although there is still improvement, not in scale with
what you are getting, with v4 I have following:

- before
real    10m3.248s
user    39m8.664s
sys     14m52.870s

- after
real    7m49.086s
user    39m59.507s
sys     15m0.598s


What I am running exactly is:
time DPDK_ABI_REF_VERSION=v22.11.1 DPDK_ABI_REF_DIR=/tmp/dpdk-abiref
DPDK_ABI_REF_SRC=.../dpdk-stable/ ./devtools/test-meson-builds.sh

> 
> In any case, this patch lgtm.
> Acked-by: David Marchand <david.marchand@redhat.com>
> 
>
  
David Marchand Jan. 18, 2023, 10:45 a.m. UTC | #3
On Thu, Jan 12, 2023 at 3:15 PM Ferruh Yigit <ferruh.yigit@amd.com> wrote:
> >>         abidiff $ABIDIFF_OPTIONS $dump $dump2 || {
> >>                 abiret=$?
> >> -               echo "Error: ABI issue reported for 'abidiff $ABIDIFF_OPTIONS $dump $dump2'" >&2
> >> -               error=1
> >> -               echo
> >> +               echo "Error: ABI issue reported for abidiff $ABIDIFF_OPTIONS $dump $dump2" >&2
> >>                 if [ $(($abiret & 3)) -ne 0 ]; then
> >>                         echo "ABIDIFF_ERROR|ABIDIFF_USAGE_ERROR, this could be a script or environment issue." >&2
> >>                 fi
> >> @@ -57,8 +55,13 @@ for dump in $(find $refdir -name "*.dump"); do
> >>                 if [ $(($abiret & 8)) -ne 0 ]; then
> >>                         echo "ABIDIFF_ABI_INCOMPATIBLE_CHANGE, this change breaks the ABI." >&2
> >>                 fi
> >> -               echo
> >> +               return 1
> >>         }
> >> -done
> >> +}'
> >> +
> >> +error=
> >> +find $refdir -name "*.dump" |
> >> +xargs -n1 -P0 sh -c 'eval "$diff_func"; run_diff $0' ||
> >> +error=1
> >>
> >>  [ -z "$error" ] || [ -n "$warnonly" ]
> >
> > For the record, on my system, calling this script is ~5 times faster:
> > - before
> > real    0m5,447s
> > user    0m4,497s
> > sys    0m0,937s
> >
> > - after
> > real    0m1,202s
> > user    0m10,784s
> > sys    0m2,027s
> >
> >
> >> diff --git a/devtools/gen-abi.sh b/devtools/gen-abi.sh
> >> index f15a3b9aaf..61f7510ea1 100755
> >> --- a/devtools/gen-abi.sh
> >> +++ b/devtools/gen-abi.sh
> >> @@ -22,5 +22,6 @@ for f in $(find $installdir -name "*.so.*"); do
> >>         fi
> >>
> >>         libname=$(basename $f)
> >> -       abidw --out-file $dumpdir/${libname%.so*}.dump $f
> >> -done
> >> +       echo $dumpdir/${libname%.so*}.dump $f
> >> +done |
> >> +xargs -n2 -P0 abidw --out-file
> >> --
> >> 2.39.0
> >>
> >
> > - before
> > real    0m8,237s
> > user    0m7,704s
> > sys    0m0,504s
> >
> > - after
> > real    0m2,517s
> > user    0m14,145s
> > sys    0m0,766s
> >
> >
> > Ferruh, I am seeing quite different numbers for running those scripts
> > (clearly not of the minute order).
> > I switched to testing/building in tmpfs some time ago.
> > It requires a good amount of memory (I empirically allocated 40G), but
> > maybe worth a try for you?
> >
>
> I run 'test-meson-builds.sh' script directly and yes I am getting
> different numbers although there is still improvement, not in scale with
> what you are getting, with v4 I have following:
>
> - before
> real    10m3.248s
> user    39m8.664s
> sys     14m52.870s
>
> - after
> real    7m49.086s
> user    39m59.507s
> sys     15m0.598s

Well, yes, I did not realise which apples you were looking at :-).
The change looks good in any case.
  
Ferruh Yigit Jan. 18, 2023, 11:43 a.m. UTC | #4
On 1/18/2023 10:45 AM, David Marchand wrote:
> On Thu, Jan 12, 2023 at 3:15 PM Ferruh Yigit <ferruh.yigit@amd.com> wrote:
>>>>         abidiff $ABIDIFF_OPTIONS $dump $dump2 || {
>>>>                 abiret=$?
>>>> -               echo "Error: ABI issue reported for 'abidiff $ABIDIFF_OPTIONS $dump $dump2'" >&2
>>>> -               error=1
>>>> -               echo
>>>> +               echo "Error: ABI issue reported for abidiff $ABIDIFF_OPTIONS $dump $dump2" >&2
>>>>                 if [ $(($abiret & 3)) -ne 0 ]; then
>>>>                         echo "ABIDIFF_ERROR|ABIDIFF_USAGE_ERROR, this could be a script or environment issue." >&2
>>>>                 fi
>>>> @@ -57,8 +55,13 @@ for dump in $(find $refdir -name "*.dump"); do
>>>>                 if [ $(($abiret & 8)) -ne 0 ]; then
>>>>                         echo "ABIDIFF_ABI_INCOMPATIBLE_CHANGE, this change breaks the ABI." >&2
>>>>                 fi
>>>> -               echo
>>>> +               return 1
>>>>         }
>>>> -done
>>>> +}'
>>>> +
>>>> +error=
>>>> +find $refdir -name "*.dump" |
>>>> +xargs -n1 -P0 sh -c 'eval "$diff_func"; run_diff $0' ||
>>>> +error=1
>>>>
>>>>  [ -z "$error" ] || [ -n "$warnonly" ]
>>>
>>> For the record, on my system, calling this script is ~5 times faster:
>>> - before
>>> real    0m5,447s
>>> user    0m4,497s
>>> sys    0m0,937s
>>>
>>> - after
>>> real    0m1,202s
>>> user    0m10,784s
>>> sys    0m2,027s
>>>
>>>
>>>> diff --git a/devtools/gen-abi.sh b/devtools/gen-abi.sh
>>>> index f15a3b9aaf..61f7510ea1 100755
>>>> --- a/devtools/gen-abi.sh
>>>> +++ b/devtools/gen-abi.sh
>>>> @@ -22,5 +22,6 @@ for f in $(find $installdir -name "*.so.*"); do
>>>>         fi
>>>>
>>>>         libname=$(basename $f)
>>>> -       abidw --out-file $dumpdir/${libname%.so*}.dump $f
>>>> -done
>>>> +       echo $dumpdir/${libname%.so*}.dump $f
>>>> +done |
>>>> +xargs -n2 -P0 abidw --out-file
>>>> --
>>>> 2.39.0
>>>>
>>>
>>> - before
>>> real    0m8,237s
>>> user    0m7,704s
>>> sys    0m0,504s
>>>
>>> - after
>>> real    0m2,517s
>>> user    0m14,145s
>>> sys    0m0,766s
>>>
>>>
>>> Ferruh, I am seeing quite different numbers for running those scripts
>>> (clearly not of the minute order).
>>> I switched to testing/building in tmpfs some time ago.
>>> It requires a good amount of memory (I empirically allocated 40G), but
>>> maybe worth a try for you?
>>>
>>
>> I run 'test-meson-builds.sh' script directly and yes I am getting
>> different numbers although there is still improvement, not in scale with
>> what you are getting, with v4 I have following:
>>
>> - before
>> real    10m3.248s
>> user    39m8.664s
>> sys     14m52.870s
>>
>> - after
>> real    7m49.086s
>> user    39m59.507s
>> sys     15m0.598s
> 
> Well, yes, I did not realise which apples you were looking at :-).
> The change looks good in any case.
> 

Ack
  
David Marchand Jan. 18, 2023, 2:29 p.m. UTC | #5
On Wed, Jan 11, 2023 at 8:53 PM Thomas Monjalon <thomas@monjalon.net> wrote:
>
> Generation and comparison of ABI dumps are done on multiple cores
> thanks to xargs -P0.
> It can accelerate this long step by 5 in my tests.
>
> xargs reports a global error if one of the process has an error.
>
> Running a shell function with xargs requires to export it.
> POSIX shell does not support function export except using an "eval trick".
> Required variables are also exported.
>
> Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
> Tested-by: Ferruh Yigit <ferruh.yigit@amd.com>

Reviewed-by: David Marchand <david.marchand@redhat.com>

Applied, thanks.
  

Patch

diff --git a/devtools/check-abi.sh b/devtools/check-abi.sh
index c583eae2fd..31eceb42e6 100755
--- a/devtools/check-abi.sh
+++ b/devtools/check-abi.sh
@@ -34,20 +34,18 @@  else
 	ABIDIFF_OPTIONS="$ABIDIFF_OPTIONS --headers-dir2 $incdir2"
 fi
 
-error=
-for dump in $(find $refdir -name "*.dump"); do
+export newdir ABIDIFF_OPTIONS
+export diff_func='run_diff() {
+	dump=$1
 	name=$(basename $dump)
 	dump2=$(find $newdir -name $name)
 	if [ -z "$dump2" ] || [ ! -e "$dump2" ]; then
 		echo "Error: cannot find $name in $newdir" >&2
-		error=1
-		continue
-	fi
+		return 1
+	fi;
 	abidiff $ABIDIFF_OPTIONS $dump $dump2 || {
 		abiret=$?
-		echo "Error: ABI issue reported for 'abidiff $ABIDIFF_OPTIONS $dump $dump2'" >&2
-		error=1
-		echo
+		echo "Error: ABI issue reported for abidiff $ABIDIFF_OPTIONS $dump $dump2" >&2
 		if [ $(($abiret & 3)) -ne 0 ]; then
 			echo "ABIDIFF_ERROR|ABIDIFF_USAGE_ERROR, this could be a script or environment issue." >&2
 		fi
@@ -57,8 +55,13 @@  for dump in $(find $refdir -name "*.dump"); do
 		if [ $(($abiret & 8)) -ne 0 ]; then
 			echo "ABIDIFF_ABI_INCOMPATIBLE_CHANGE, this change breaks the ABI." >&2
 		fi
-		echo
+		return 1
 	}
-done
+}'
+
+error=
+find $refdir -name "*.dump" |
+xargs -n1 -P0 sh -c 'eval "$diff_func"; run_diff $0' ||
+error=1
 
 [ -z "$error" ] || [ -n "$warnonly" ]
diff --git a/devtools/gen-abi.sh b/devtools/gen-abi.sh
index f15a3b9aaf..61f7510ea1 100755
--- a/devtools/gen-abi.sh
+++ b/devtools/gen-abi.sh
@@ -22,5 +22,6 @@  for f in $(find $installdir -name "*.so.*"); do
 	fi
 
 	libname=$(basename $f)
-	abidw --out-file $dumpdir/${libname%.so*}.dump $f
-done
+	echo $dumpdir/${libname%.so*}.dump $f
+done |
+xargs -n2 -P0 abidw --out-file