Skip to content

Commit

Permalink
Support parallel testing in libgomp: fallback Perl 'flock' [PR66005]
Browse files Browse the repository at this point in the history
Follow-up to commit 6c3b30e
"Support parallel testing in libgomp, part II [PR66005]"
("..., and enable if 'flock' is available for serializing execution testing"),
where we saw:

> On my Dell Precision 7530 laptop:
>
>     $ uname -srvi
>     Linux 5.15.0-71-generic gcc-mirror#78-Ubuntu SMP Tue Apr 18 09:00:29 UTC 2023 x86_64
>     $ grep '^model name' < /proc/cpuinfo | uniq -c
>          12 model name      : Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
>     $ nvidia-smi -L
>     GPU 0: Quadro P1000 (UUID: GPU-e043973b-b52a-d02b-c066-a8fdbf64e8ea)
>
> ... [...]: case (c) standard configuration, no offloading
> configured, [...]

>     $ \time make check-target-libgomp
>
> Case (c), baseline; [...]:
>
>     1180.98user 110.80system 19:36.40elapsed 109%CPU (0avgtext+0avgdata 505148maxresident)k
>     1133.22user 111.08system 19:35.75elapsed 105%CPU (0avgtext+0avgdata 505212maxresident)k
>
> Case (c), parallelized [using 'flock']:
>
> [...]
>     -j12 GCC_TEST_PARALLEL_SLOTS=12
>     2591.04user 192.64system 4:44.98elapsed 976%CPU (0avgtext+0avgdata 505216maxresident)k
>     2581.23user 195.21system 4:47.51elapsed 965%CPU (0avgtext+0avgdata 505212maxresident)k

Quite the same when instead of 'flock' using this fallback Perl 'flock':

    2565.23user 194.35system 4:46.77elapsed 962%CPU (0avgtext+0avgdata 505216maxresident)k
    2549.38user 200.20system 4:46.08elapsed 961%CPU (0avgtext+0avgdata 505216maxresident)k

	PR testsuite/66005
	gcc/
	* doc/install.texi: Document (optional) Perl usage for parallel
	testing of libgomp.
	libgomp/
	* testsuite/lib/libgomp.exp: 'flock' through stdout.
	* testsuite/flock: New.
	* configure.ac (FLOCK): Point to that if no 'flock' available, but
	'perl' is.
	* configure: Regenerate.

(cherry picked from commit 04abe19)
  • Loading branch information
tschwinge committed Jun 28, 2023
1 parent 5c65150 commit b4561b7
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 1 deletion.
3 changes: 3 additions & 0 deletions gcc/doc/install.texi
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,9 @@ tables.

Used by @command{automake}.

If available, enables parallel testing of @samp{libgomp} in case that
@command{flock} is not available.

@end table

Several support libraries are necessary to build GCC, some are required,
Expand Down
42 changes: 42 additions & 0 deletions libgomp/configure
Original file line number Diff line number Diff line change
Expand Up @@ -16664,6 +16664,8 @@ $as_echo "unable to detect (assuming 1)" >&6; }
fi


{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for flock implementation" >&5
$as_echo "$as_me: checking for flock implementation" >&6;}
for ac_prog in flock
do
# Extract the first word of "$ac_prog", so it can be a program name with args.
Expand Down Expand Up @@ -16706,6 +16708,46 @@ fi
test -n "$FLOCK" && break
done

# Fallback if 'perl' is available.
if test -z "$FLOCK"; then
# Extract the first word of "perl", so it can be a program name with args.
set dummy perl; ac_word=$2
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
if ${ac_cv_prog_FLOCK+:} false; then :
$as_echo_n "(cached) " >&6
else
if test -n "$FLOCK"; then
ac_cv_prog_FLOCK="$FLOCK" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
IFS=$as_save_IFS
test -z "$as_dir" && as_dir=.
for ac_exec_ext in '' $ac_executable_extensions; do
if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
ac_cv_prog_FLOCK="$srcdir/testsuite/flock"
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
break 2
fi
done
done
IFS=$as_save_IFS

fi
fi
FLOCK=$ac_cv_prog_FLOCK
if test -n "$FLOCK"; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $FLOCK" >&5
$as_echo "$FLOCK" >&6; }
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
fi


fi

# Get target configury.
. ${srcdir}/configure.tgt
Expand Down
5 changes: 5 additions & 0 deletions libgomp/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,12 @@ fi
AX_COUNT_CPUS
AC_SUBST(CPU_COUNT)

AC_MSG_NOTICE([checking for flock implementation])
AC_CHECK_PROGS(FLOCK, flock)
# Fallback if 'perl' is available.
if test -z "$FLOCK"; then
AC_CHECK_PROG(FLOCK, perl, $srcdir/testsuite/flock)
fi

# Get target configury.
. ${srcdir}/configure.tgt
Expand Down
17 changes: 17 additions & 0 deletions libgomp/testsuite/flock
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env perl

use strict;
use warnings;

# Only arguments '--exclusive 1' exactly are supported.
(@ARGV == 2) or die;
my $mode = shift;
($mode eq "--exclusive") or die;
my $fd = shift;
($fd eq "1") or die;

use Fcntl ':flock';

open(my $fh, '>&=', 1) or die "open: $!";

flock($fh, LOCK_EX) or die "flock: $!";
4 changes: 3 additions & 1 deletion libgomp/testsuite/lib/libgomp.exp
Original file line number Diff line number Diff line change
Expand Up @@ -335,12 +335,14 @@ if ![info exists ::env(GCC_RUNTEST_PARALLELIZE_DIR)] {
rename libgomp_load standard_libgomp_load
proc libgomp_load { program args } {
# ... in order to serialize execution testing via an exclusive lock.
# We use stdout, as per <https://perldoc.perl.org/functions/flock>
# "[...] FILEHANDLE [...] be open with write intent to use LOCK_EX".
set lock_file ../lock
set lock_kind --exclusive
set lock_fd [open $lock_file a+]
set lock_clock_begin [clock seconds]
global FLOCK
exec $FLOCK $lock_kind 0 <@ $lock_fd
exec $FLOCK $lock_kind 1 >@ $lock_fd
set lock_clock_end [clock seconds]
verbose -log "Got ${FLOCK}('$lock_file', '$lock_kind') at [clock format $lock_clock_end] after [expr $lock_clock_end - $lock_clock_begin] s" 2

Expand Down

0 comments on commit b4561b7

Please sign in to comment.