mirror of
git://git.code.sf.net/p/sbcl/sbcl
synced 2026-09-10 07:26:40 -04:00
FreeBSD and Linux have added the close_range syscall (in April 2020 and 5.9,
respectively). This allows for a range of fds to be closed using a single
syscall. The behavior of closefrom can be emulated using ~0U as the end fd.
FreeBSD immediately added it to their libc, but Linux libcs have lagged
behind. To support Linux systems running kernel 5.9+ without a libc wrapper for
close_range, we test for the presence of a wrapper at build time and use it if
it exists. Otherwise, fall back to the syscall directly (if the number of the
syscall can be determined at build time).
If close_range can't be found at build time, or the run time kernel does not
support it, fall back to close() in a for loop.
Linux tests were run on an x86-64 machine with ulimit -n 524288, using
(time (dotimes (i 100) (sb-ext:run-program "/bin/true" nil)))
Typical "slow" path (no use of close_range) results were:
Evaluation took:
11.630 seconds of real time
0.088556 seconds of total run time (0.013697 user, 0.074859 system)
0.77% CPU
1,491 forms interpreted
26,799,410,672 processor cycles
425,376 bytes consed
Typical "fast" path results were:
Evaluation took:
0.153 seconds of real time
0.055602 seconds of total run time (0.002995 user, 0.052607 system)
36.60% CPU
1,491 forms interpreted
351,242,436 processor cycles
424,192 bytes consed
This was tested with a 5.4 kernel and a 5.13 kernel, using Ubuntu 20.04, 21.04,
and 21.10 userspaces. The 5.4 kernel has no close_range support. Ubuntu 20.04
has neither a close_range wrapper (-os-provides-close-range-wrapper) nor a
version of Linux headers with __NR_close_range defined. Ubuntu 21.04 has no
wrapper, but does have __NR_close_range defined. Ubuntu 21.10 has both a
wrapper (+os-provides-close-range-wrapper) and __NR_close_range.
The results for which path was taken are summarized below. The top row of each
table states which kernel was used at build time, the left-most column states
which kernel was used at run time.
| 20.04 | 5.4 | 5.13 |
|-------|------|------|
| 5.4 | slow | slow |
| 5.13 | slow | slow |
| 21.04 | 5.4 | 5.13 |
|-------|------|------|
| 5.4 | slow | slow |
| 5.13 | fast | fast |
| 21.10 | 5.4 | 5.13 |
|-------|------|------|
| 5.4 | slow | slow |
| 5.13 | fast | fast |
This was additionally tested on FreeBSD amd64 13.0-RELEASE. All easily
available versions of FreeBSD have close_range support. So lack of close_range
was emulated by building with --without-os-provides-close-range-wrapper.
Additionally, FreeBSD has closefrom(2), so a slightly more complicated test was
needed to force the use of close_range.
(time (dotimes (i 100) (sb-ext:run-program "/bin/true" nil :preserve-fds (list 100000))))
As expected, the test took less time to run with
+os-provides-close-range-wrapper as opposed to
-os-provides-close-range-wrapper.
50 lines
1.4 KiB
Bash
50 lines
1.4 KiB
Bash
# Automated platform feature testing
|
|
cd ./tools-for-build > /dev/null
|
|
|
|
# FIXME: Use this to test for dlopen presence and hence
|
|
# load-shared-object buildability
|
|
|
|
# Assumes the presence of $1-test.c, which when built and
|
|
# run should return with 104 if the feature is present.
|
|
# We presumes that the build machine matches the target machine
|
|
# in terms of a whether each feature presence test should pass.
|
|
featurep() {
|
|
bin="$1-test"
|
|
featurename=${2:-$1}
|
|
rm -f $bin
|
|
$GNUMAKE $bin -I ../src/runtime > /dev/null 2>&1 && echo "input" | ./$bin> /dev/null 2>&1
|
|
if [ "$?" -eq 104 ]
|
|
then
|
|
printf " :$featurename"
|
|
fi
|
|
rm -f $bin
|
|
}
|
|
|
|
# Adding a nonexistent link library to Config.*-win32 will fail,
|
|
# so we pass -lSynchronization to the featurep test specifically
|
|
# and not in the general make rule.
|
|
# It will get added in by Config.*-win32 only if LISP_FEATURE_SB_FUTEX.
|
|
if [ "$sbcl_os" = win32 ] ; then
|
|
LOADLIBES=-lSynchronization featurep os-provides-wakebyaddr sb-futex
|
|
fi
|
|
|
|
# KLUDGE: ppc/darwin dlopen is special cased in make-config.sh, as
|
|
# we fake it with a shim.
|
|
featurep os-provides-dlopen
|
|
|
|
featurep os-provides-dladdr
|
|
|
|
featurep os-provides-blksize-t
|
|
|
|
featurep os-provides-suseconds-t
|
|
|
|
featurep os-provides-getprotoby-r
|
|
|
|
featurep os-provides-poll
|
|
|
|
featurep os-provides-close-range-wrapper
|
|
|
|
if [ "$sbcl_arch" = arm ] ; then
|
|
featurep arm-softfp
|
|
fi
|