mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-12-24 03:24:55 +08:00
f3a45709d2
HMM selftests are incredibly useful, but they are only effective if people actually build and run them. All the other tests in selftests/vm can be built with very standard, always-available libraries: libpthread, librt. The hmm-tests.c program, on the other hand, requires something that is (much) less readily available: libhugetlbfs. And so the build will typically fail for many developers. A simple attempt to install libhugetlbfs will also run into complications on some common distros these days: Fedora and Arch Linux (yes, Arch AUR has it, but that's fragile, as always with AUR). The library is not maintained actively enough at the moment, for distros to deal with it. I had to build it from source, for Fedora, and that didn't go too smoothly either. It turns out that, out of 21 tests in hmm-tests.c, only 2 actually require functionality from libhugetlbfs. Therefore, if libhugetlbfs is missing, simply ifdef those two tests out and allow the developer to at least have the other 19 tests, if they don't want to pause to work through the above issues. Also issue a warning, so that it's clear that there is an imperfection in the build. In order to do that, a tiny shell script (check_config.sh) runs a quick compile (not link, that's too prone to false failures with library paths), and basically, if the compiler doesn't find hugetlbfs.h in its standard locations, then the script concludes that libhugetlbfs is not available. The output is in two files, one for inclusion in hmm-test.c (local_config.h), and one for inclusion in the Makefile (local_config.mk). Link: https://lkml.kernel.org/r/20201026064021.3545418-9-jhubbard@nvidia.com Signed-off-by: John Hubbard <jhubbard@nvidia.com> Cc: Ralph Campbell <rcampbell@nvidia.com> Cc: Jérôme Glisse <jglisse@redhat.com> Cc: Jonathan Corbet <corbet@lwn.net> Cc: Shuah Khan <shuah@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
32 lines
967 B
Bash
32 lines
967 B
Bash
#!/bin/sh
|
|
# SPDX-License-Identifier: GPL-2.0
|
|
#
|
|
# Probe for libraries and create header files to record the results. Both C
|
|
# header files and Makefile include fragments are created.
|
|
|
|
OUTPUT_H_FILE=local_config.h
|
|
OUTPUT_MKFILE=local_config.mk
|
|
|
|
# libhugetlbfs
|
|
tmpname=$(mktemp)
|
|
tmpfile_c=${tmpname}.c
|
|
tmpfile_o=${tmpname}.o
|
|
|
|
echo "#include <sys/types.h>" > $tmpfile_c
|
|
echo "#include <hugetlbfs.h>" >> $tmpfile_c
|
|
echo "int func(void) { return 0; }" >> $tmpfile_c
|
|
|
|
CC=${1:?"Usage: $0 <compiler> # example compiler: gcc"}
|
|
$CC -c $tmpfile_c -o $tmpfile_o >/dev/null 2>&1
|
|
|
|
if [ -f $tmpfile_o ]; then
|
|
echo "#define LOCAL_CONFIG_HAVE_LIBHUGETLBFS 1" > $OUTPUT_H_FILE
|
|
echo "HMM_EXTRA_LIBS = -lhugetlbfs" > $OUTPUT_MKFILE
|
|
else
|
|
echo "// No libhugetlbfs support found" > $OUTPUT_H_FILE
|
|
echo "# No libhugetlbfs support found, so:" > $OUTPUT_MKFILE
|
|
echo "HMM_EXTRA_LIBS = " >> $OUTPUT_MKFILE
|
|
fi
|
|
|
|
rm ${tmpname}.*
|