]> granicus.if.org Git - zfs/commitdiff
Add autoconf checks for atomic64_cmpxchg + atomic64_xchg
authorBrian Behlendorf <behlendorf1@llnl.gov>
Fri, 30 Oct 2009 20:53:17 +0000 (13:53 -0700)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Fri, 30 Oct 2009 20:53:17 +0000 (13:53 -0700)
These functions didn't exist for all archs prior to 2.6.24.  This
patch addes an autoconf test to detect this and add them when needed.
The autoconf check is needed instead of just an #ifndef because in
the most modern kernels atomic64_{cmp}xchg are implemented as in
inline function and not a #define.

config/spl-build.m4
configure
include/asm/atomic_compat.h
include/sys/atomic.h
spl_config.h.in

index 15d10841b28569b35d2d3399bd1e076874ee395b..9d81ccc8e1b433cd97991504ae73d140880f28f3 100644 (file)
@@ -28,6 +28,8 @@ AC_DEFUN([SPL_AC_CONFIG_KERNEL], [
        SPL_AC_ATOMIC_SPINLOCK
        SPL_AC_TYPE_UINTPTR_T
        SPL_AC_TYPE_ATOMIC64_T
+       SPL_AC_TYPE_ATOMIC64_CMPXCHG
+       SPL_AC_TYPE_ATOMIC64_XCHG
        SPL_AC_3ARGS_INIT_WORK
        SPL_AC_2ARGS_REGISTER_SYSCTL
        SPL_AC_SET_SHRINKER
@@ -488,6 +490,44 @@ AC_DEFUN([SPL_AC_TYPE_ATOMIC64_T],
        ])
 ])
 
+dnl #
+dnl # 2.6.24 API change,
+dnl # check if atomic64_cmpxchg is defined
+dnl #
+AC_DEFUN([SPL_AC_TYPE_ATOMIC64_CMPXCHG],
+       [AC_MSG_CHECKING([whether kernel defines atomic64_cmpxchg])
+       SPL_LINUX_TRY_COMPILE([
+               #include <asm/atomic.h>
+       ],[
+               atomic64_cmpxchg((atomic64_t *)NULL, 0, 0);
+       ],[
+               AC_MSG_RESULT([yes])
+               AC_DEFINE(HAVE_ATOMIC64_CMPXCHG, 1,
+                         [kernel defines atomic64_cmpxchg])
+       ],[
+               AC_MSG_RESULT([no])
+       ])
+])
+
+dnl #
+dnl # 2.6.24 API change,
+dnl # check if atomic64_xchg is defined
+dnl #
+AC_DEFUN([SPL_AC_TYPE_ATOMIC64_XCHG],
+       [AC_MSG_CHECKING([whether kernel defines atomic64_xchg])
+       SPL_LINUX_TRY_COMPILE([
+               #include <asm/atomic.h>
+       ],[
+               atomic64_xchg((atomic64_t *)NULL, 0);
+       ],[
+               AC_MSG_RESULT([yes])
+               AC_DEFINE(HAVE_ATOMIC64_XCHG, 1,
+                         [kernel defines atomic64_xchg])
+       ],[
+               AC_MSG_RESULT([no])
+       ])
+])
+
 dnl #
 dnl # 2.6.20 API change,
 dnl # INIT_WORK use 2 args and not store data inside
index bcbd0fb54afd43858f5ac0e7f4aadb1203b069f9..b03faa8c9c8e8e5e1b54f4c515e6d35830f8c361 100755 (executable)
--- a/configure
+++ b/configure
@@ -19350,6 +19350,134 @@ echo "${ECHO_T}no" >&6
 
 
 
+fi
+
+       rm -Rf build
+
+
+
+       echo "$as_me:$LINENO: checking whether kernel defines atomic64_cmpxchg" >&5
+echo $ECHO_N "checking whether kernel defines atomic64_cmpxchg... $ECHO_C" >&6
+
+
+cat >conftest.c <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+
+               #include <asm/atomic.h>
+
+int
+main (void)
+{
+
+               atomic64_cmpxchg((atomic64_t *)NULL, 0, 0);
+
+  ;
+  return 0;
+}
+
+_ACEOF
+
+
+       rm -Rf build && mkdir -p build
+       echo "obj-m := conftest.o" >build/Makefile
+       if { ac_try='cp conftest.c build && make modules -C $LINUX_OBJ EXTRA_CFLAGS="-Werror-implicit-function-declaration $EXTRA_KCFLAGS" $ARCH_UM M=$PWD/build'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } >/dev/null && { ac_try='test -s build/conftest.o'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+
+               echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6
+
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_ATOMIC64_CMPXCHG 1
+_ACEOF
+
+
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+               echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+
+
+
+fi
+
+       rm -Rf build
+
+
+
+       echo "$as_me:$LINENO: checking whether kernel defines atomic64_xchg" >&5
+echo $ECHO_N "checking whether kernel defines atomic64_xchg... $ECHO_C" >&6
+
+
+cat >conftest.c <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+
+               #include <asm/atomic.h>
+
+int
+main (void)
+{
+
+               atomic64_xchg((atomic64_t *)NULL, 0);
+
+  ;
+  return 0;
+}
+
+_ACEOF
+
+
+       rm -Rf build && mkdir -p build
+       echo "obj-m := conftest.o" >build/Makefile
+       if { ac_try='cp conftest.c build && make modules -C $LINUX_OBJ EXTRA_CFLAGS="-Werror-implicit-function-declaration $EXTRA_KCFLAGS" $ARCH_UM M=$PWD/build'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } >/dev/null && { ac_try='test -s build/conftest.o'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+
+               echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6
+
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_ATOMIC64_XCHG 1
+_ACEOF
+
+
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+               echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+
+
+
 fi
 
        rm -Rf build
@@ -22521,6 +22649,134 @@ echo "${ECHO_T}no" >&6
 
 
 
+fi
+
+       rm -Rf build
+
+
+
+       echo "$as_me:$LINENO: checking whether kernel defines atomic64_cmpxchg" >&5
+echo $ECHO_N "checking whether kernel defines atomic64_cmpxchg... $ECHO_C" >&6
+
+
+cat >conftest.c <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+
+               #include <asm/atomic.h>
+
+int
+main (void)
+{
+
+               atomic64_cmpxchg((atomic64_t *)NULL, 0, 0);
+
+  ;
+  return 0;
+}
+
+_ACEOF
+
+
+       rm -Rf build && mkdir -p build
+       echo "obj-m := conftest.o" >build/Makefile
+       if { ac_try='cp conftest.c build && make modules -C $LINUX_OBJ EXTRA_CFLAGS="-Werror-implicit-function-declaration $EXTRA_KCFLAGS" $ARCH_UM M=$PWD/build'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } >/dev/null && { ac_try='test -s build/conftest.o'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+
+               echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6
+
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_ATOMIC64_CMPXCHG 1
+_ACEOF
+
+
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+               echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+
+
+
+fi
+
+       rm -Rf build
+
+
+
+       echo "$as_me:$LINENO: checking whether kernel defines atomic64_xchg" >&5
+echo $ECHO_N "checking whether kernel defines atomic64_xchg... $ECHO_C" >&6
+
+
+cat >conftest.c <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+
+               #include <asm/atomic.h>
+
+int
+main (void)
+{
+
+               atomic64_xchg((atomic64_t *)NULL, 0);
+
+  ;
+  return 0;
+}
+
+_ACEOF
+
+
+       rm -Rf build && mkdir -p build
+       echo "obj-m := conftest.o" >build/Makefile
+       if { ac_try='cp conftest.c build && make modules -C $LINUX_OBJ EXTRA_CFLAGS="-Werror-implicit-function-declaration $EXTRA_KCFLAGS" $ARCH_UM M=$PWD/build'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } >/dev/null && { ac_try='test -s build/conftest.o'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+
+               echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6
+
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_ATOMIC64_XCHG 1
+_ACEOF
+
+
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+               echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+
+
+
 fi
 
        rm -Rf build
index 2f7376925a5d84d7360af3ee0a25165e75dbf3d9..c769d62482456f981b2e5a7c900b718a3fe68c10 100644 (file)
@@ -55,5 +55,13 @@ static inline void atomic64_set(atomic64_t *v, __s64 i)
 
 #endif /* HAVE_ATOMIC64_T */
 
+#ifndef HAVE_ATOMIC64_CMPXCHG
+#define atomic64_cmpxchg(v, o, n)      (cmpxchg(&((v)->counter), (o), (n)))
+#endif
+
+#ifndef HAVE_ATOMIC64_XCHG
+#define atomic64_xchg(v, n)            (xchg(&((v)->counter), n))
+#endif
+
 #endif /* _SPL_ATOMIC_COMPAT_H */
 
index 4f4a1e058e08d7587898bd90267876b2784340c7..7a741de175937e0e8e82a8e826b711e80c0f4902 100644 (file)
@@ -30,6 +30,7 @@
 #include <linux/module.h>
 #include <linux/spinlock.h>
 #include <sys/types.h>
+#include <asm/atomic_compat.h>
 
 /*
  * Two approaches to atomic operations are implemented each with its
index feb09a865ef1c56fcb48ab32d1b0be4439fbd214..409ee372da93c6de834e09fb1991705bd0d917a5 100644 (file)
 /* device_create wants 5 args */
 #undef HAVE_5ARGS_DEVICE_CREATE
 
+/* kernel defines atomic64_cmpxchg */
+#undef HAVE_ATOMIC64_CMPXCHG
+
 /* kernel defines atomic64_t */
 #undef HAVE_ATOMIC64_T
 
+/* kernel defines atomic64_xchg */
+#undef HAVE_ATOMIC64_XCHG
+
 /* class_device_create() is available */
 #undef HAVE_CLASS_DEVICE_CREATE