Skip to content

Commit dd2a46b

Browse files
authored
config: cache results of kernel checks (openzfs#17106)
Kernel checks are the heaviest part of the configure checks. This allows the results to be cached through the normal autoconf cache. Since we don't want to reuse cached values for different kernels, but don't want to discard the entire cache on every kernel, we instead add a short checksum to kernel config cache keys, based on the version and path, so the cache can hold results for multiple different kernels. Sponsored-by: https://despairlabs.com/sponsor/ Signed-off-by: Rob Norris <[email protected]> Reviewed-by: Tony Hutter <[email protected]>
1 parent 4abc21b commit dd2a46b

File tree

1 file changed

+45
-18
lines changed

1 file changed

+45
-18
lines changed

config/kernel.m4

Lines changed: 45 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,11 @@ AC_DEFUN([ZFS_AC_KERNEL], [
465465
AC_SUBST(LINUX)
466466
AC_SUBST(LINUX_OBJ)
467467
AC_SUBST(LINUX_VERSION)
468+
469+
dnl # create a relatively unique numeric checksum based on the kernel
470+
dnl # version and path. this is included in the cache key below,
471+
dnl # allowing different cached values for different kernels
472+
_zfs_linux_cache_checksum=$(echo ${kernelsrc} {$kernelbuild} ${kernsrcver} | cksum | cut -f1 -d' ')
468473
])
469474

470475
AC_DEFUN([ZFS_AC_KERNEL_VERSION_WARNING], [
@@ -812,14 +817,18 @@ dnl # must never depend on the results of previous tests. Each test
812817
dnl # needs to be entirely independent.
813818
dnl #
814819
AC_DEFUN([ZFS_LINUX_TEST_SRC], [
815-
ZFS_LINUX_CONFTEST_C([ZFS_LINUX_TEST_PROGRAM([[$2]], [[$3]],
816-
[["Dual BSD/GPL"]])], [$1])
817-
ZFS_LINUX_CONFTEST_MAKEFILE([$1], [yes], [$4])
818-
819-
AS_IF([ test -n "$5" ], [
820-
ZFS_LINUX_CONFTEST_C([ZFS_LINUX_TEST_PROGRAM(
821-
[[$2]], [[$3]], [[$5]])], [$1_license])
822-
ZFS_LINUX_CONFTEST_MAKEFILE([$1_license], [yes], [$4])
820+
cachevar="zfs_cv_kernel_[$1]_$_zfs_linux_cache_checksum"
821+
eval "cacheval=\$$cachevar"
822+
AS_IF([test "x$cacheval" = "x"], [
823+
ZFS_LINUX_CONFTEST_C([ZFS_LINUX_TEST_PROGRAM([[$2]], [[$3]],
824+
[["Dual BSD/GPL"]])], [$1])
825+
ZFS_LINUX_CONFTEST_MAKEFILE([$1], [yes], [$4])
826+
827+
AS_IF([ test -n "$5" ], [
828+
ZFS_LINUX_CONFTEST_C([ZFS_LINUX_TEST_PROGRAM(
829+
[[$2]], [[$3]], [[$5]])], [$1_license])
830+
ZFS_LINUX_CONFTEST_MAKEFILE([$1_license], [yes], [$4])
831+
])
823832
])
824833
])
825834

@@ -831,14 +840,23 @@ dnl # $2 - run on success (valid .ko generated)
831840
dnl # $3 - run on failure (unable to compile)
832841
dnl #
833842
AC_DEFUN([ZFS_LINUX_TEST_RESULT], [
834-
AS_IF([test -d build/$1], [
835-
AS_IF([test -f build/$1/$1.ko], [$2], [$3])
836-
], [
837-
AC_MSG_ERROR([
843+
cachevar="zfs_cv_kernel_[$1]_$_zfs_linux_cache_checksum"
844+
AC_CACHE_VAL([$cachevar], [
845+
AS_IF([test -d build/$1], [
846+
AS_IF([test -f build/$1/$1.ko], [
847+
eval "$cachevar=yes"
848+
], [
849+
eval "$cachevar=no"
850+
])
851+
], [
852+
AC_MSG_ERROR([
838853
*** No matching source for the "$1" test, check that
839854
*** both the test source and result macros refer to the same name.
855+
])
840856
])
841857
])
858+
eval "cacheval=\$$cachevar"
859+
AS_IF([test "x$cacheval" = "xyes"], [$2], [$3])
842860
])
843861

844862
dnl #
@@ -867,15 +885,24 @@ dnl # verify symbol exports, unless --enable-linux-builtin was provided to
867885
dnl # configure.
868886
dnl #
869887
AC_DEFUN([ZFS_LINUX_TEST_RESULT_SYMBOL], [
870-
AS_IF([ ! test -f build/$1/$1.ko], [
871-
$5
872-
], [
873-
AS_IF([test "x$enable_linux_builtin" != "xyes"], [
874-
ZFS_CHECK_SYMBOL_EXPORT([$2], [$3], [$4], [$5])
888+
cachevar="zfs_cv_kernel_[$1]_$_zfs_linux_cache_checksum"
889+
AC_CACHE_VAL([$cachevar], [
890+
AS_IF([ ! test -f build/$1/$1.ko], [
891+
eval "$cachevar=no"
875892
], [
876-
$4
893+
AS_IF([test "x$enable_linux_builtin" != "xyes"], [
894+
ZFS_CHECK_SYMBOL_EXPORT([$2], [$3], [
895+
eval "$cachevar=yes"
896+
], [
897+
eval "$cachevar=no"
898+
])
899+
], [
900+
eval "$cacheval=yes"
901+
])
877902
])
878903
])
904+
eval "cacheval=\$$cachevar"
905+
AS_IF([test "x$cacheval" = "xyes"], [$4], [$5])
879906
])
880907

881908
dnl #

0 commit comments

Comments
 (0)