From c9ed5b134b2510e1c9776172e641afc4192ba758 Mon Sep 17 00:00:00 2001 From: Rob Norris Date: Sun, 2 Mar 2025 20:24:12 +1100 Subject: [PATCH] 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 --- config/kernel.m4 | 63 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 45 insertions(+), 18 deletions(-) diff --git a/config/kernel.m4 b/config/kernel.m4 index 9928ead1b6ce..d7d5bada374a 100644 --- a/config/kernel.m4 +++ b/config/kernel.m4 @@ -463,6 +463,11 @@ AC_DEFUN([ZFS_AC_KERNEL], [ AC_SUBST(LINUX) AC_SUBST(LINUX_OBJ) AC_SUBST(LINUX_VERSION) + + dnl # create a relatively unique numeric checksum based on the kernel + dnl # version and path. this is included in the cache key below, + dnl # allowing different cached values for different kernels + _zfs_linux_cache_checksum=$(echo ${kernelsrc} {$kernelbuild} ${kernsrcver} | cksum | cut -f1 -d' ') ]) AC_DEFUN([ZFS_AC_KERNEL_VERSION_WARNING], [ @@ -810,14 +815,18 @@ dnl # must never depend on the results of previous tests. Each test dnl # needs to be entirely independent. dnl # AC_DEFUN([ZFS_LINUX_TEST_SRC], [ - ZFS_LINUX_CONFTEST_C([ZFS_LINUX_TEST_PROGRAM([[$2]], [[$3]], - [["Dual BSD/GPL"]])], [$1]) - ZFS_LINUX_CONFTEST_MAKEFILE([$1], [yes], [$4]) - - AS_IF([ test -n "$5" ], [ - ZFS_LINUX_CONFTEST_C([ZFS_LINUX_TEST_PROGRAM( - [[$2]], [[$3]], [[$5]])], [$1_license]) - ZFS_LINUX_CONFTEST_MAKEFILE([$1_license], [yes], [$4]) + cachevar="zfs_cv_kernel_[$1]_$_zfs_linux_cache_checksum" + eval "cacheval=\$$cachevar" + AS_IF([test "x$cacheval" = "x"], [ + ZFS_LINUX_CONFTEST_C([ZFS_LINUX_TEST_PROGRAM([[$2]], [[$3]], + [["Dual BSD/GPL"]])], [$1]) + ZFS_LINUX_CONFTEST_MAKEFILE([$1], [yes], [$4]) + + AS_IF([ test -n "$5" ], [ + ZFS_LINUX_CONFTEST_C([ZFS_LINUX_TEST_PROGRAM( + [[$2]], [[$3]], [[$5]])], [$1_license]) + ZFS_LINUX_CONFTEST_MAKEFILE([$1_license], [yes], [$4]) + ]) ]) ]) @@ -829,14 +838,23 @@ dnl # $2 - run on success (valid .ko generated) dnl # $3 - run on failure (unable to compile) dnl # AC_DEFUN([ZFS_LINUX_TEST_RESULT], [ - AS_IF([test -d build/$1], [ - AS_IF([test -f build/$1/$1.ko], [$2], [$3]) - ], [ - AC_MSG_ERROR([ + cachevar="zfs_cv_kernel_[$1]_$_zfs_linux_cache_checksum" + AC_CACHE_VAL([$cachevar], [ + AS_IF([test -d build/$1], [ + AS_IF([test -f build/$1/$1.ko], [ + eval "$cachevar=yes" + ], [ + eval "$cachevar=no" + ]) + ], [ + AC_MSG_ERROR([ *** No matching source for the "$1" test, check that *** both the test source and result macros refer to the same name. + ]) ]) ]) + eval "cacheval=\$$cachevar" + AS_IF([test "x$cacheval" = "xyes"], [$2], [$3]) ]) dnl # @@ -865,15 +883,24 @@ dnl # verify symbol exports, unless --enable-linux-builtin was provided to dnl # configure. dnl # AC_DEFUN([ZFS_LINUX_TEST_RESULT_SYMBOL], [ - AS_IF([ ! test -f build/$1/$1.ko], [ - $5 - ], [ - AS_IF([test "x$enable_linux_builtin" != "xyes"], [ - ZFS_CHECK_SYMBOL_EXPORT([$2], [$3], [$4], [$5]) + cachevar="zfs_cv_kernel_[$1]_$_zfs_linux_cache_checksum" + AC_CACHE_VAL([$cachevar], [ + AS_IF([ ! test -f build/$1/$1.ko], [ + eval "$cachevar=no" ], [ - $4 + AS_IF([test "x$enable_linux_builtin" != "xyes"], [ + ZFS_CHECK_SYMBOL_EXPORT([$2], [$3], [ + eval "$cachevar=yes" + ], [ + eval "$cachevar=no" + ]) + ], [ + eval "$cacheval=yes" + ]) ]) ]) + eval "cacheval=\$$cachevar" + AS_IF([test "x$cacheval" = "xyes"], [$4], [$5]) ]) dnl #