From 7cabd2131f953de23e7015d760b0ddfda51b1251 Mon Sep 17 00:00:00 2001 From: Devin Matthews Date: Thu, 3 Mar 2016 11:43:07 -0600 Subject: [PATCH 1/3] Use clock_gettime(CLOCK_MONOTONIC) and mach_absolute_time instead of gettimeofday. --- frame/base/bli_clock.c | 102 +++++++++++++++++++++---------------- frame/include/bli_system.h | 27 +++++++++- 2 files changed, 83 insertions(+), 46 deletions(-) diff --git a/frame/base/bli_clock.c b/frame/base/bli_clock.c index 1b4fb3b76..5fcdf1765 100644 --- a/frame/base/bli_clock.c +++ b/frame/base/bli_clock.c @@ -65,60 +65,74 @@ double bli_clock_min_diff( double time_min, double time_start ) return time_min; } - -// --- Begin Linux build definitions ------------------------------------------- -#ifndef BLIS_ENABLE_WINDOWS_BUILD +#if BLIS_OS_WINDOWS +// --- Begin Windows build definitions ----------------------------------------- double bli_clock_helper() { - double the_time, norm_sec; - struct timeval tv; + LARGE_INTEGER clock_freq = {0}; + LARGE_INTEGER clock_val; + BOOL r_val; - gettimeofday( &tv, NULL ); + r_val = QueryPerformanceFrequency( &clock_freq ); - if ( gtod_ref_time_sec == 0.0 ) - gtod_ref_time_sec = ( double ) tv.tv_sec; + if ( r_val == 0 ) + { + bli_print_msg( "QueryPerformanceFrequency() failed", __FILE__, __LINE__ ); + bli_abort(); + } - norm_sec = ( double ) tv.tv_sec - gtod_ref_time_sec; + r_val = QueryPerformanceCounter( &clock_val ); - the_time = norm_sec + tv.tv_usec * 1.0e-6; + if ( r_val == 0 ) + { + bli_print_msg( "QueryPerformanceCounter() failed", __FILE__, __LINE__ ); + bli_abort(); + } - return the_time; + return ( ( double) clock_val.QuadPart / ( double) clock_freq.QuadPart ); +} + +// --- End Windows build definitions ------------------------------------------- +#elif BLIS_OS_OSX +// --- Begin OSX build definitions ------------------------------------------- + +double bli_clock_helper() +{ + mach_timebase_info_data_t timebase; + mach_timebase_info( &timebase ); + + uint64_t nsec = mach_absolute_time(); + + double the_time = (double) nsec * 1.0e-9 * timebase.numer / timebase.denom; + + if ( gtod_ref_time_sec == 0.0 ) + gtod_ref_time_sec = the_time; + + return the_time - gtod_ref_time_sec; +} + +// --- End OSX build definitions --------------------------------------------- +#else +// --- Begin Linux build definitions ------------------------------------------- + +double bli_clock_helper() +{ + double the_time, norm_sec; + struct timespec ts; + + clock_gettime( CLOCK_MONOTONIC, &ts ); + + if ( gtod_ref_time_sec == 0.0 ) + gtod_ref_time_sec = ( double ) ts.tv_sec; + + norm_sec = ( double ) ts.tv_sec - gtod_ref_time_sec; + + the_time = norm_sec + ts.tv_nsec * 1.0e-9; + + return the_time; } // --- End Linux build definitions --------------------------------------------- -#else -// --- Begin Windows build definitions ----------------------------------------- - -#define WIN32_LEAN_AND_MEAN -#define VC_EXTRALEAN -#include - -double bli_clock_helper() -{ - LARGE_INTEGER clock_freq = {0}; - LARGE_INTEGER clock_val; - BOOL r_val; - - r_val = QueryPerformanceFrequency( &clock_freq ); - - if ( r_val == 0 ) - { - bli_print_msg( "QueryPerformanceFrequency() failed", __FILE__, __LINE__ ); - bli_abort(); - } - - r_val = QueryPerformanceCounter( &clock_val ); - - if ( r_val == 0 ) - { - bli_print_msg( "QueryPerformanceCounter() failed", __FILE__, __LINE__ ); - bli_abort(); - } - - return ( ( double) clock_val.QuadPart / ( double) clock_freq.QuadPart ); -} - #endif -// --- End Windows build definitions ------------------------------------------- diff --git a/frame/include/bli_system.h b/frame/include/bli_system.h index b2098d504..f3502417d 100644 --- a/frame/include/bli_system.h +++ b/frame/include/bli_system.h @@ -40,9 +40,30 @@ #include #include -#ifdef BLIS_ENABLE_WINDOWS_BUILD +#if defined(_WIN32) || defined(__CYGWIN__) +#define BLIS_OS_WINDOWS 1 +#elif defined(__APPLE__) || defined(__MACH__) +#define BLIS_OS_OSX 1 +#elif defined(__ANDROID__) +#define BLIS_OS_ANDROID 1 +#elif defined(__linux__) +#define BLIS_OS_LINUX 1 +#elif defined(__bgq__) +#define BLIS_OS_BGQ 1 +#elif defined(__bg__) +#define BLIS_OS_BGP 1 +#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || + defined(__bsdi__) || defined(__DragonFly__) +#define BLIS_OS_BSD 1 +#else +#error "Cannot determine operating system" +#endif + +#if BLIS_OS_WINDOWS // Include Windows header file. + #define WIN32_LEAN_AND_MEAN + #define VC_EXTRALEAN #include // Undefine attribute specifiers in Windows. @@ -54,8 +75,10 @@ #endif // gettimeofday() needs this. -#ifdef BLIS_ENABLE_WINDOWS_BUILD +#if BLIS_OS_WINDOWS #include +#elif BLIS_OS_OSX + #include #else #include #include From 44fddd48dc1708a956803d1948f04429ec0d8700 Mon Sep 17 00:00:00 2001 From: Devin Matthews Date: Fri, 4 Mar 2016 12:36:38 -0600 Subject: [PATCH 2/3] Add missing \. --- frame/include/bli_system.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/include/bli_system.h b/frame/include/bli_system.h index f3502417d..88038d201 100644 --- a/frame/include/bli_system.h +++ b/frame/include/bli_system.h @@ -52,7 +52,7 @@ #define BLIS_OS_BGQ 1 #elif defined(__bg__) #define BLIS_OS_BGP 1 -#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || +#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \ defined(__bsdi__) || defined(__DragonFly__) #define BLIS_OS_BSD 1 #else From 63e264239053b913164a849dd8a45829087eaddc Mon Sep 17 00:00:00 2001 From: Devin Matthews Date: Fri, 4 Mar 2016 13:17:50 -0600 Subject: [PATCH 3/3] Make sure that -lrt is linked on Linux. --- Makefile | 10 ++++++++++ build/config.mk.in | 3 +++ 2 files changed, 13 insertions(+) diff --git a/Makefile b/Makefile index c9fe957b5..ba4df5981 100644 --- a/Makefile +++ b/Makefile @@ -159,6 +159,16 @@ endif +# +# --- Append OS-specific libraries to LDFLAGS ---------------------------------- +# + +ifeq ($(OS_NAME),Linux) +LDFLAGS += -lrt +endif + + + # # --- Main target variable definitions ----------------------------------------- # diff --git a/build/config.mk.in b/build/config.mk.in index 595cf0192..3766437f5 100644 --- a/build/config.mk.in +++ b/build/config.mk.in @@ -39,6 +39,9 @@ CONFIG_MK_INCLUDED := yes # The name of the configuration sub-directory. CONFIG_NAME := @config_name@ +# The operating system name, which should be either 'Linux' or 'Darwin'. +OS_NAME := $(shell uname -s) + # The directory path to the top level of the source distribution. DIST_PATH := @dist_path@