[v3] devtools: parallelize ABI check

Message ID 20230111131652.1265058-1-thomas@monjalon.net (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series [v3] 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/github-robot: build success github build: passed
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS

Commit Message

Thomas Monjalon Jan. 11, 2023, 1:16 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 with -f,
and that is a specific capability of bash.

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)
---
 devtools/check-abi.sh | 21 +++++++++++++--------
 devtools/gen-abi.sh   |  5 +++--
 2 files changed, 16 insertions(+), 10 deletions(-)
  

Comments

Bruce Richardson Jan. 11, 2023, 2:10 p.m. UTC | #1
On Wed, Jan 11, 2023 at 02:16:52PM +0100, Thomas Monjalon 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 with -f,
> and that is a specific capability of bash.
> 
Commit-log needs update based on changes in v3.

> 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)
> ---
>  devtools/check-abi.sh | 21 +++++++++++++--------
>  devtools/gen-abi.sh   |  5 +++--
>  2 files changed, 16 insertions(+), 10 deletions(-)
  
David Marchand Jan. 11, 2023, 2:11 p.m. UTC | #2
On Wed, Jan 11, 2023 at 2:16 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 with -f,
> and that is a specific capability of bash.
>
> 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)
> ---
>  devtools/check-abi.sh | 21 +++++++++++++--------
>  devtools/gen-abi.sh   |  5 +++--
>  2 files changed, 16 insertions(+), 10 deletions(-)
>
> diff --git a/devtools/check-abi.sh b/devtools/check-abi.sh
> index c583eae2fd..d58c867c60 100755
> --- a/devtools/check-abi.sh
> +++ b/devtools/check-abi.sh
> @@ -34,19 +34,18 @@ else
>         ABIDIFF_OPTIONS="$ABIDIFF_OPTIONS --headers-dir2 $incdir2"
>  fi
>
> -error=
> -for dump in $(find $refdir -name "*.dump"); do
> +export diff_func='run_diff() {
> +       dump=$1
> +       newdir=$2
>         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 "Error: ABI issue reported for abidiff $ABIDIFF_OPTIONS $dump $dump2" >&2
>                 echo
>                 if [ $(($abiret & 3)) -ne 0 ]; then
>                         echo "ABIDIFF_ERROR|ABIDIFF_USAGE_ERROR, this could be a script or environment issue." >&2
> @@ -58,7 +57,13 @@ for dump in $(find $refdir -name "*.dump"); do
>                         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 '$newdir ||
> +error=1

Do we need to pass $newdir ?
Like, for example, ABIDIFF_OPTIONS seems inherited, right?

Otherwise this trick looks to work.
  
Thomas Monjalon Jan. 11, 2023, 5:04 p.m. UTC | #3
11/01/2023 15:11, David Marchand:
> On Wed, Jan 11, 2023 at 2:16 PM Thomas Monjalon <thomas@monjalon.net> wrote:
> > +find $refdir -name "*.dump" |
> > +xargs -n1 -P0 sh -c 'eval "$diff_func"; run_diff $0 '$newdir ||
> > +error=1
> 
> Do we need to pass $newdir ?
> Like, for example, ABIDIFF_OPTIONS seems inherited, right?

Actually ABIDIFF_OPTIONS was empty when calling the function.
I'll pass it as well.
  

Patch

diff --git a/devtools/check-abi.sh b/devtools/check-abi.sh
index c583eae2fd..d58c867c60 100755
--- a/devtools/check-abi.sh
+++ b/devtools/check-abi.sh
@@ -34,19 +34,18 @@  else
 	ABIDIFF_OPTIONS="$ABIDIFF_OPTIONS --headers-dir2 $incdir2"
 fi
 
-error=
-for dump in $(find $refdir -name "*.dump"); do
+export diff_func='run_diff() {
+	dump=$1
+	newdir=$2
 	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 "Error: ABI issue reported for abidiff $ABIDIFF_OPTIONS $dump $dump2" >&2
 		echo
 		if [ $(($abiret & 3)) -ne 0 ]; then
 			echo "ABIDIFF_ERROR|ABIDIFF_USAGE_ERROR, this could be a script or environment issue." >&2
@@ -58,7 +57,13 @@  for dump in $(find $refdir -name "*.dump"); do
 			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 '$newdir ||
+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