diff options
author | Alp Toker <alp@nuanti.com> | 2014-02-28 09:42:41 +0000 |
---|---|---|
committer | Alp Toker <alp@nuanti.com> | 2014-02-28 09:42:41 +0000 |
commit | 763b93965c9d9da29193cab393cc45eefdcc35d4 (patch) | |
tree | 30314f813e308900e858d48ea5c1a3506bd4d008 /openmp/runtime/src/z_Linux_util.c | |
parent | 6c6af852f924c51b91274b9b52184096bef4677e (diff) | |
download | bcm5719-llvm-763b93965c9d9da29193cab393cc45eefdcc35d4.tar.gz bcm5719-llvm-763b93965c9d9da29193cab393cc45eefdcc35d4.zip |
Add support for FreeBSD
Port the OpenMP runtime to FreeBSD along with associated build system changes.
Also begin to generalize affinity capabilities so they aren't tied explicitly
to Windows and Linux.
The port builds with stock clang and gmake and has no additional runtime
dependencies.
All but a handful of the validation suite tests are now passing on FreeBSD 10
x86_64.
llvm-svn: 202478
Diffstat (limited to 'openmp/runtime/src/z_Linux_util.c')
-rw-r--r-- | openmp/runtime/src/z_Linux_util.c | 59 |
1 files changed, 37 insertions, 22 deletions
diff --git a/openmp/runtime/src/z_Linux_util.c b/openmp/runtime/src/z_Linux_util.c index 40a539fe2e4..664fdeafd42 100644 --- a/openmp/runtime/src/z_Linux_util.c +++ b/openmp/runtime/src/z_Linux_util.c @@ -22,7 +22,9 @@ #include "kmp_i18n.h" #include "kmp_io.h" -#include <alloca.h> +#if !KMP_OS_FREEBSD +# include <alloca.h> +#endif #include <unistd.h> #include <math.h> // HUGE_VAL. #include <sys/time.h> @@ -48,6 +50,9 @@ #elif KMP_OS_DARWIN # include <sys/sysctl.h> # include <mach/mach.h> +#elif KMP_OS_FREEBSD +# include <sys/sysctl.h> +# include <pthread_np.h> #endif @@ -596,7 +601,7 @@ static kmp_int32 __kmp_set_stack_info( int gtid, kmp_info_t *th ) { int stack_data; -#if KMP_OS_LINUX +#if KMP_OS_LINUX || KMP_OS_FREEBSD /* Linux* OS only -- no pthread_getattr_np support on OS X* */ pthread_attr_t attr; int status; @@ -611,8 +616,13 @@ __kmp_set_stack_info( int gtid, kmp_info_t *th ) /* Fetch the real thread attributes */ status = pthread_attr_init( &attr ); KMP_CHECK_SYSFAIL( "pthread_attr_init", status ); +#if KMP_OS_FREEBSD + status = pthread_attr_get_np( pthread_self(), &attr ); + KMP_CHECK_SYSFAIL( "pthread_attr_get_np", status ); +#else status = pthread_getattr_np( pthread_self(), &attr ); KMP_CHECK_SYSFAIL( "pthread_getattr_np", status ); +#endif status = pthread_attr_getstack( &attr, &addr, &size ); KMP_CHECK_SYSFAIL( "pthread_attr_getstack", status ); KA_TRACE( 60, ( "__kmp_set_stack_info: T#%d pthread_attr_getstack returned size: %lu, " @@ -629,16 +639,14 @@ __kmp_set_stack_info( int gtid, kmp_info_t *th ) TCW_PTR(th->th.th_info.ds.ds_stacksize, size); TCW_4(th->th.th_info.ds.ds_stackgrow, FALSE); return TRUE; - } else { -#endif /* KMP_OS_LINUX */ - /* Use incremental refinement starting from initial conservative estimate */ - TCW_PTR(th->th.th_info.ds.ds_stacksize, 0); - TCW_PTR(th -> th.th_info.ds.ds_stackbase, &stack_data); - TCW_4(th->th.th_info.ds.ds_stackgrow, TRUE); - return FALSE; -#if KMP_OS_LINUX } -#endif /* KMP_OS_LINUX */ +#endif /* KMP_OS_LINUX || KMP_OS_FREEBSD */ + + /* Use incremental refinement starting from initial conservative estimate */ + TCW_PTR(th->th.th_info.ds.ds_stacksize, 0); + TCW_PTR(th -> th.th_info.ds.ds_stackbase, &stack_data); + TCW_4(th->th.th_info.ds.ds_stackgrow, TRUE); + return FALSE; } static void* @@ -663,12 +671,8 @@ __kmp_launch_worker( void *thr ) __kmp_itt_thread_name( gtid ); #endif /* USE_ITT_BUILD */ -#if KMP_OS_LINUX +#if KMP_AFFINITY_SUPPORTED __kmp_affinity_set_init_mask( gtid, FALSE ); -#elif KMP_OS_DARWIN - // affinity not supported -#else - #error "Unknown or unsupported OS" #endif #ifdef KMP_CANCEL_THREADS @@ -696,7 +700,7 @@ __kmp_launch_worker( void *thr ) KMP_CHECK_SYSFAIL( "pthread_sigmask", status ); #endif /* KMP_BLOCK_SIGNALS */ -#if KMP_OS_LINUX +#if KMP_OS_LINUX || KMP_OS_FREEBSD if ( __kmp_stkoffset > 0 && gtid > 0 ) { padding = alloca( gtid * __kmp_stkoffset ); } @@ -2000,6 +2004,16 @@ __kmp_get_xproc( void ) { KMP_INFORM( AssumedNumCPU ); }; // if + #elif KMP_OS_FREEBSD + + int mib[] = { CTL_HW, HW_NCPU }; + size_t len = sizeof( r ); + if ( sysctl( mib, 2, &r, &len, NULL, 0 ) < 0 ) { + r = 0; + KMP_WARNING( CantGetNumAvailCPU ); + KMP_INFORM( AssumedNumCPU ); + } + #else #error "Unknown or unsupported OS." @@ -2121,12 +2135,8 @@ __kmp_runtime_destroy( void ) if ( status != 0 && status != EBUSY ) { KMP_SYSFAIL( "pthread_cond_destroy", status ); } - #if KMP_OS_LINUX + #if KMP_AFFINITY_SUPPORTED __kmp_affinity_uninitialize(); - #elif KMP_OS_DARWIN - // affinity not supported - #else - #error "Unknown or unsupported OS" #endif __kmp_init_runtime = FALSE; @@ -2243,6 +2253,11 @@ __kmp_is_address_mapped( void * addr ) { found = 1; }; // if + #elif KMP_OS_FREEBSD + + // FIXME(FreeBSD): Implement this. + found = 1; + #else #error "Unknown or unsupported OS" |