Skip to content

Commit d4dce51

Browse files
committed
config: cache results of kernel checks
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]>
1 parent fc460bf commit d4dce51

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
@@ -463,6 +463,11 @@ AC_DEFUN([ZFS_AC_KERNEL], [
463463
AC_SUBST(LINUX)
464464
AC_SUBST(LINUX_OBJ)
465465
AC_SUBST(LINUX_VERSION)
466+
467+
dnl # create a relatively unique numeric checksum based on the kernel
468+
dnl # version and path. this is included in the cache key below,
469+
dnl # allowing different cached values for different kernels
470+
_zfs_linux_cache_checksum=$(echo ${kernelsrc} {$kernelbuild} ${kernsrcver} | cksum | cut -f1 -d' ')
466471
])
467472

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

@@ -829,14 +838,23 @@ dnl # $2 - run on success (valid .ko generated)
829838
dnl # $3 - run on failure (unable to compile)
830839
dnl #
831840
AC_DEFUN([ZFS_LINUX_TEST_RESULT], [
832-
AS_IF([test -d build/$1], [
833-
AS_IF([test -f build/$1/$1.ko], [$2], [$3])
834-
], [
835-
AC_MSG_ERROR([
841+
cachevar="zfs_cv_kernel_[$1]_$_zfs_linux_cache_checksum"
842+
AC_CACHE_VAL([$cachevar], [
843+
AS_IF([test -d build/$1], [
844+
AS_IF([test -f build/$1/$1.ko], [
845+
eval "$cachevar=yes"
846+
], [
847+
eval "$cachevar=no"
848+
])
849+
], [
850+
AC_MSG_ERROR([
836851
*** No matching source for the "$1" test, check that
837852
*** both the test source and result macros refer to the same name.
853+
])
838854
])
839855
])
856+
eval "cacheval=\$$cachevar"
857+
AS_IF([test "x$cacheval" = "xyes"], [$2], [$3])
840858
])
841859

842860
dnl #
@@ -865,15 +883,24 @@ dnl # verify symbol exports, unless --enable-linux-builtin was provided to
865883
dnl # configure.
866884
dnl #
867885
AC_DEFUN([ZFS_LINUX_TEST_RESULT_SYMBOL], [
868-
AS_IF([ ! test -f build/$1/$1.ko], [
869-
$5
870-
], [
871-
AS_IF([test "x$enable_linux_builtin" != "xyes"], [
872-
ZFS_CHECK_SYMBOL_EXPORT([$2], [$3], [$4], [$5])
886+
cachevar="zfs_cv_kernel_[$1]_$_zfs_linux_cache_checksum"
887+
AC_CACHE_VAL([$cachevar], [
888+
AS_IF([ ! test -f build/$1/$1.ko], [
889+
eval "$cachevar=no"
873890
], [
874-
$4
891+
AS_IF([test "x$enable_linux_builtin" != "xyes"], [
892+
ZFS_CHECK_SYMBOL_EXPORT([$2], [$3], [
893+
eval "$cachevar=yes"
894+
], [
895+
eval "$cachevar=no"
896+
])
897+
], [
898+
eval "$cacheval=yes"
899+
])
875900
])
876901
])
902+
eval "cacheval=\$$cachevar"
903+
AS_IF([test "x$cacheval" = "xyes"], [$4], [$5])
877904
])
878905

879906
dnl #

0 commit comments

Comments
 (0)