From: Sitsofe Wheeler Date: Sun, 26 Feb 2017 11:47:28 +0000 (+0000) Subject: configure: add generic pshared mutex test X-Git-Tag: fio-2.19~30 X-Git-Url: https://git.kernel.dk/?p=fio.git;a=commitdiff_plain;h=06eac6b2318da7759a055c4a3ac01c2c1e8aa764 configure: add generic pshared mutex test Add a feature test to configure to determine if a platform has interprocess synchronization primitives that work with threads and remove the hardcoded enablement in the individual os/os-* headers. This should work better for platforms where support was overlooked or didn't exist at some point in the past but has since been added. Also update the README to not single out FreeBSD for being thread only as this might change... This is based off work by the Boost project (https://github.com/boostorg/interprocess/blob/boost-1.63.0/include/boost/interprocess/detail/workaround.hpp#L45 ) that found that OSX 10.6 and Cygwin are buggy even though _POSIX_THREAD_PROCESS_SHARED says this feature should be work on them. Signed-off-by: Sitsofe Wheeler --- diff --git a/README b/README index 9493c2a5..951550b8 100644 --- a/README +++ b/README @@ -205,10 +205,10 @@ implemented, I'd be happy to take patches for that. An example of that is disk utility statistics and (I think) huge page support, support for that does exist in FreeBSD/Solaris. -Fio uses pthread mutexes for signalling and locking and FreeBSD does not -support process shared pthread mutexes. As a result, only threads are -supported on FreeBSD. This could be fixed with sysv ipc locking or -other locking alternatives. +Fio uses pthread mutexes for signalling and locking and some platforms do not +support process shared pthread mutexes. As a result, on such platforms only +threads are supported. This could be fixed with sysv ipc locking or other +locking alternatives. Other \*BSD platforms are untested, but fio should work there almost out of the box. Since I don't do test runs or even compiles on those platforms, your diff --git a/configure b/configure index a7610b15..93351242 100755 --- a/configure +++ b/configure @@ -604,6 +604,34 @@ EOF fi echo "POSIX AIO fsync $posix_aio_fsync" +########################################## +# POSIX pshared attribute probe +posix_pshared="no" +cat > $TMPC < +int main(void) +{ +#if defined(_POSIX_THREAD_PROCESS_SHARED) && ((_POSIX_THREAD_PROCESS_SHARED + 0) > 0) +# if defined(__CYGWIN__) +# error "_POSIX_THREAD_PROCESS_SHARED is buggy on Cygwin" +# elif defined(__APPLE__) +# include +# include +# if TARGET_OS_MAC && MAC_OS_X_VERSION_MIN_REQUIRED < 1070 +# error "_POSIX_THREAD_PROCESS_SHARED is buggy/unsupported prior to OSX 10.7" +# endif +# endif +#else +# error "_POSIX_THREAD_PROCESS_SHARED is unsupported" +#endif + return 0; +} +EOF +if compile_prog "" "$LIBS" "posix_pshared" ; then + posix_pshared=yes +fi +echo "POSIX pshared support $posix_pshared" + ########################################## # solaris aio probe if test "$solaris_aio" != "yes" ; then @@ -1986,6 +2014,9 @@ fi if test "$posix_aio_fsync" = "yes" ; then output_sym "CONFIG_POSIXAIO_FSYNC" fi +if test "$posix_pshared" = "yes" ; then + output_sym "CONFIG_PSHARED" +fi if test "$linux_fallocate" = "yes" ; then output_sym "CONFIG_LINUX_FALLOCATE" fi diff --git a/init.c b/init.c index 18538de1..54fdb92a 100644 --- a/init.c +++ b/init.c @@ -586,7 +586,7 @@ static int fixup_options(struct thread_data *td) struct thread_options *o = &td->o; int ret = 0; -#ifndef FIO_HAVE_PSHARED_MUTEX +#ifndef CONFIG_PSHARED if (!o->use_thread) { log_info("fio: this platform does not support process shared" " mutexes, forcing use of threads. Use the 'thread'" diff --git a/mutex.c b/mutex.c index 5e5a0648..d8c48251 100644 --- a/mutex.c +++ b/mutex.c @@ -47,7 +47,7 @@ int cond_init_pshared(pthread_cond_t *cond) return ret; } -#ifdef FIO_HAVE_PSHARED_MUTEX +#ifdef CONFIG_PSHARED ret = pthread_condattr_setpshared(&cattr, PTHREAD_PROCESS_SHARED); if (ret) { log_err("pthread_condattr_setpshared: %s\n", strerror(ret)); @@ -77,7 +77,7 @@ int mutex_init_pshared(pthread_mutex_t *mutex) /* * Not all platforms support process shared mutexes (FreeBSD) */ -#ifdef FIO_HAVE_PSHARED_MUTEX +#ifdef CONFIG_PSHARED ret = pthread_mutexattr_setpshared(&mattr, PTHREAD_PROCESS_SHARED); if (ret) { log_err("pthread_mutexattr_setpshared: %s\n", strerror(ret)); @@ -287,7 +287,7 @@ struct fio_rwlock *fio_rwlock_init(void) log_err("pthread_rwlockattr_init: %s\n", strerror(ret)); goto err; } -#ifdef FIO_HAVE_PSHARED_MUTEX +#ifdef CONFIG_PSHARED ret = pthread_rwlockattr_setpshared(&attr, PTHREAD_PROCESS_SHARED); if (ret) { log_err("pthread_rwlockattr_setpshared: %s\n", strerror(ret)); diff --git a/os/os-aix.h b/os/os-aix.h index bdc190a9..e204d6f2 100644 --- a/os/os-aix.h +++ b/os/os-aix.h @@ -14,8 +14,6 @@ #define FIO_USE_GENERIC_RAND #define FIO_USE_GENERIC_INIT_RANDOM_STATE -#define FIO_HAVE_PSHARED_MUTEX - #define OS_MAP_ANON MAP_ANON #define OS_MSG_DONTWAIT 0 diff --git a/os/os-android.h b/os/os-android.h index cdae7030..b59fac15 100644 --- a/os/os-android.h +++ b/os/os-android.h @@ -27,7 +27,6 @@ #define FIO_HAVE_ODIRECT #define FIO_HAVE_HUGETLB #define FIO_HAVE_BLKTRACE -#define FIO_HAVE_PSHARED_MUTEX #define FIO_HAVE_CL_SIZE #define FIO_HAVE_FS_STAT #define FIO_HAVE_TRIM diff --git a/os/os-freebsd.h b/os/os-freebsd.h index 3d7dbe65..c7863b5e 100644 --- a/os/os-freebsd.h +++ b/os/os-freebsd.h @@ -24,10 +24,6 @@ #define FIO_HAVE_CPU_AFFINITY #define FIO_HAVE_SHM_ATTACH_REMOVED -#if _POSIX_THREAD_PROCESS_SHARED > 0 -#define FIO_HAVE_PSHARED_MUTEX -#endif - #define OS_MAP_ANON MAP_ANON #define fio_swap16(x) bswap16(x) diff --git a/os/os-hpux.h b/os/os-hpux.h index 1707ddd8..6a240b0d 100644 --- a/os/os-hpux.h +++ b/os/os-hpux.h @@ -22,7 +22,6 @@ #define FIO_HAVE_ODIRECT #define FIO_USE_GENERIC_RAND #define FIO_USE_GENERIC_INIT_RANDOM_STATE -#define FIO_HAVE_PSHARED_MUTEX #define FIO_HAVE_CHARDEV_SIZE #define OS_MAP_ANON MAP_ANONYMOUS diff --git a/os/os-linux.h b/os/os-linux.h index 7be833bf..7b328dc0 100644 --- a/os/os-linux.h +++ b/os/os-linux.h @@ -32,7 +32,6 @@ #define FIO_HAVE_HUGETLB #define FIO_HAVE_RAWBIND #define FIO_HAVE_BLKTRACE -#define FIO_HAVE_PSHARED_MUTEX #define FIO_HAVE_CL_SIZE #define FIO_HAVE_CGROUPS #define FIO_HAVE_FS_STAT diff --git a/os/os-solaris.h b/os/os-solaris.h index 73ad84a3..8f8f53b6 100644 --- a/os/os-solaris.h +++ b/os/os-solaris.h @@ -16,7 +16,6 @@ #include "../file.h" #define FIO_HAVE_CPU_AFFINITY -#define FIO_HAVE_PSHARED_MUTEX #define FIO_HAVE_CHARDEV_SIZE #define FIO_USE_GENERIC_BDEV_SIZE #define FIO_USE_GENERIC_INIT_RANDOM_STATE