From a91f7b9190bc467aeac5c97b1bbb6e6338be7c5f Mon Sep 17 00:00:00 2001 From: Jeff Squyres Date: Wed, 15 Mar 2017 11:14:30 -0700 Subject: [PATCH 1/4] timer/linux: remove global variable This variable is only used in one file, so make it static. Signed-off-by: Jeff Squyres (cherry picked from commit 290d4598df8f9ba2b6550fa39d6033c4c5dd3cce) --- opal/mca/timer/linux/timer_linux.h | 3 +-- opal/mca/timer/linux/timer_linux_component.c | 5 +++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/opal/mca/timer/linux/timer_linux.h b/opal/mca/timer/linux/timer_linux.h index 6bf05c9f5df..2c2126c6180 100644 --- a/opal/mca/timer/linux/timer_linux.h +++ b/opal/mca/timer/linux/timer_linux.h @@ -9,6 +9,7 @@ * University of Stuttgart. All rights reserved. * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. + * Copyright (c) 2017 Cisco Systems, Inc. All rights reserved * $COPYRIGHT$ * * Additional copyrights may follow @@ -22,8 +23,6 @@ #include "opal_config.h" #include -OPAL_DECLSPEC extern opal_timer_t opal_timer_linux_freq; - OPAL_DECLSPEC extern opal_timer_t (*opal_timer_base_get_cycles)(void); OPAL_DECLSPEC extern opal_timer_t (*opal_timer_base_get_usec)(void); diff --git a/opal/mca/timer/linux/timer_linux_component.c b/opal/mca/timer/linux/timer_linux_component.c index d02a1b11bf7..27542835af3 100644 --- a/opal/mca/timer/linux/timer_linux_component.c +++ b/opal/mca/timer/linux/timer_linux_component.c @@ -14,8 +14,9 @@ * and Technology (RIST). All rights reserved. * Copyright (c) 2015-2017 Los Alamos National Security, LLC. All rights * reserved. - * Copyright (c) 2015 Cisco Systems, Inc. All rights reserved. + * Copyright (c) 2015-2017 Cisco Systems, Inc. All rights reserved * Copyright (c) 2017 IBM Corporation. All rights reserved. + * Copyright (c) 2016 Broadcom Limited. All rights reserved. * $COPYRIGHT$ * * Additional copyrights may follow @@ -46,7 +47,7 @@ opal_timer_t (*opal_timer_base_get_cycles)(void) = opal_timer_base_get_cycles_sy opal_timer_t (*opal_timer_base_get_usec)(void) = opal_timer_base_get_usec_sys_timer; #endif /* OPAL_HAVE_CLOCK_GETTIME */ -opal_timer_t opal_timer_linux_freq = {0}; +static opal_timer_t opal_timer_linux_freq = {0}; static int opal_timer_linux_open(void); From 6d662113313b3141c6533aa6afa90437d8f68c9c Mon Sep 17 00:00:00 2001 From: Jeff Squyres Date: Wed, 15 Mar 2017 11:22:37 -0700 Subject: [PATCH 2/4] timer/linux: rename component-specific functions Several component-specific functions were named with a prefix of "opal_timer_base", which was quite confusing. Rename them to have a prefix "opal_timer_linux" to make it clear that they are here in this component (and different than *actual* opal_timer_base symbols). Signed-off-by: Jeff Squyres (cherry picked from commit 616f20c52cbf695626e747d0cf666e6b02bb2a73) --- opal/mca/timer/linux/timer_linux_component.c | 39 +++++++++++--------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/opal/mca/timer/linux/timer_linux_component.c b/opal/mca/timer/linux/timer_linux_component.c index 27542835af3..18e8b898e19 100644 --- a/opal/mca/timer/linux/timer_linux_component.c +++ b/opal/mca/timer/linux/timer_linux_component.c @@ -34,17 +34,22 @@ #include "opal/constants.h" #include "opal/util/show_help.h" -static opal_timer_t opal_timer_base_get_cycles_sys_timer(void); -static opal_timer_t opal_timer_base_get_usec_sys_timer(void); +static opal_timer_t opal_timer_linux_get_cycles_sys_timer(void); +static opal_timer_t opal_timer_linux_get_usec_sys_timer(void); #if OPAL_HAVE_CLOCK_GETTIME -static opal_timer_t opal_timer_base_get_cycles_clock_gettime(void); -static opal_timer_t opal_timer_base_get_usec_clock_gettime(void); -opal_timer_t (*opal_timer_base_get_cycles)(void) = opal_timer_base_get_cycles_clock_gettime; -opal_timer_t (*opal_timer_base_get_usec)(void) = opal_timer_base_get_usec_clock_gettime; +static opal_timer_t opal_timer_linux_get_cycles_clock_gettime(void); +static opal_timer_t opal_timer_linux_get_usec_clock_gettime(void); + +opal_timer_t (*opal_timer_base_get_cycles)(void) = + opal_timer_linux_get_cycles_clock_gettime; +opal_timer_t (*opal_timer_base_get_usec)(void) = + opal_timer_linux_get_usec_clock_gettime; #else -opal_timer_t (*opal_timer_base_get_cycles)(void) = opal_timer_base_get_cycles_sys_timer; -opal_timer_t (*opal_timer_base_get_usec)(void) = opal_timer_base_get_usec_sys_timer; +opal_timer_t (*opal_timer_base_get_cycles)(void) = + opal_timer_linux_get_cycles_sys_timer; +opal_timer_t (*opal_timer_base_get_usec)(void) = + opal_timer_linux_get_usec_sys_timer; #endif /* OPAL_HAVE_CLOCK_GETTIME */ static opal_timer_t opal_timer_linux_freq = {0}; @@ -165,8 +170,8 @@ int opal_timer_linux_open(void) struct timespec res; if( 0 == clock_getres(CLOCK_MONOTONIC, &res)) { opal_timer_linux_freq = 1.e3; - opal_timer_base_get_cycles = opal_timer_base_get_cycles_clock_gettime; - opal_timer_base_get_usec = opal_timer_base_get_usec_clock_gettime; + opal_timer_base_get_cycles = opal_timer_linux_get_cycles_clock_gettime; + opal_timer_base_get_usec = opal_timer_linux_get_usec_clock_gettime; return ret; } #else @@ -175,13 +180,13 @@ int opal_timer_linux_open(void) #endif /* OPAL_HAVE_CLOCK_GETTIME && (0 == OPAL_TIMER_MONOTONIC) */ } ret = opal_timer_linux_find_freq(); - opal_timer_base_get_cycles = opal_timer_base_get_cycles_sys_timer; - opal_timer_base_get_usec = opal_timer_base_get_usec_sys_timer; + opal_timer_base_get_cycles = opal_timer_linux_get_cycles_sys_timer; + opal_timer_base_get_usec = opal_timer_linux_get_usec_sys_timer; return ret; } #if OPAL_HAVE_CLOCK_GETTIME -opal_timer_t opal_timer_base_get_usec_clock_gettime(void) +opal_timer_t opal_timer_linux_get_usec_clock_gettime(void) { struct timespec tp = {.tv_sec = 0, .tv_nsec = 0}; @@ -190,7 +195,7 @@ opal_timer_t opal_timer_base_get_usec_clock_gettime(void) return (tp.tv_sec * 1e6 + tp.tv_nsec/1000); } -opal_timer_t opal_timer_base_get_cycles_clock_gettime(void) +opal_timer_t opal_timer_linux_get_cycles_clock_gettime(void) { struct timespec tp = {.tv_sec = 0, .tv_nsec = 0}; @@ -200,7 +205,7 @@ opal_timer_t opal_timer_base_get_cycles_clock_gettime(void) } #endif /* OPAL_HAVE_CLOCK_GETTIME */ -opal_timer_t opal_timer_base_get_cycles_sys_timer(void) +opal_timer_t opal_timer_linux_get_cycles_sys_timer(void) { #if OPAL_HAVE_SYS_TIMER_GET_CYCLES return opal_sys_timer_get_cycles(); @@ -210,7 +215,7 @@ opal_timer_t opal_timer_base_get_cycles_sys_timer(void) } -opal_timer_t opal_timer_base_get_usec_sys_timer(void) +opal_timer_t opal_timer_linux_get_usec_sys_timer(void) { #if OPAL_HAVE_SYS_TIMER_GET_CYCLES /* freq is in MHz, so this gives usec */ @@ -224,5 +229,3 @@ opal_timer_t opal_timer_base_get_freq(void) { return opal_timer_linux_freq * 1000000; } - - From ab7dad261452fdd40642be8237acbb780a026f04 Mon Sep 17 00:00:00 2001 From: Joshua Hursey Date: Wed, 15 Mar 2017 21:24:37 -0500 Subject: [PATCH 3/4] mpi/c: Force wtick/wtime to use gettimeofday * See https://github.com/open-mpi/ompi/issues/3003 for a discussion about this patch. Once we get a better version in place we can revert this change. Signed-off-by: Joshua Hursey (cherry picked from commit 48d13aa8ef75a1e2950667687b587b8f1282d15a) Signed-off-by: Jeff Squyres --- ompi/mpi/c/wtick.c | 8 ++++++++ ompi/mpi/c/wtime.c | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/ompi/mpi/c/wtick.c b/ompi/mpi/c/wtick.c index 705f064bbd7..ee0e067477e 100644 --- a/ompi/mpi/c/wtick.c +++ b/ompi/mpi/c/wtick.c @@ -12,6 +12,7 @@ * Copyright (c) 2007-2014 Cisco Systems, Inc. All rights reserved. * Copyright (c) 2015-2016 Research Organization for Information Science * and Technology (RIST). All rights reserved. + * Copyright (c) 2017 IBM Corporation. All rights reserved. * $COPYRIGHT$ * * Additional copyrights may follow @@ -38,6 +39,12 @@ double MPI_Wtick(void) { + /* + * See https://github.com/open-mpi/ompi/issues/3003 + * For now we are forcing the use of gettimeofday() until we find a + * more portable solution. + */ +#if 0 #if OPAL_TIMER_CYCLE_NATIVE { opal_timer_t freq = opal_timer_base_get_freq(); @@ -50,6 +57,7 @@ double MPI_Wtick(void) } #elif OPAL_TIMER_USEC_NATIVE return 0.000001; +#endif #else /* Otherwise, we already return usec precision. */ return 0.000001; diff --git a/ompi/mpi/c/wtime.c b/ompi/mpi/c/wtime.c index 41b01fba884..d20a7943a4b 100644 --- a/ompi/mpi/c/wtime.c +++ b/ompi/mpi/c/wtime.c @@ -12,6 +12,7 @@ * Copyright (c) 2006-2014 Cisco Systems, Inc. All rights reserved. * Copyright (c) 2015 Research Organization for Information Science * and Technology (RIST). All rights reserved. + * Copyright (c) 2017 IBM Corporation. All rights reserved. * $COPYRIGHT$ * * Additional copyrights may follow @@ -40,10 +41,17 @@ double MPI_Wtime(void) { double wtime; + /* + * See https://github.com/open-mpi/ompi/issues/3003 + * For now we are forcing the use of gettimeofday() until we find a + * more portable solution. + */ +#if 0 #if OPAL_TIMER_CYCLE_NATIVE wtime = ((double) opal_timer_base_get_cycles()) / opal_timer_base_get_freq(); #elif OPAL_TIMER_USEC_NATIVE wtime = ((double) opal_timer_base_get_usec()) / 1000000.0; +#endif #else /* Fall back to gettimeofday() if we have nothing else */ struct timeval tv; From 43ab707d96f4aeae5f2b8f22d504544dad2e66da Mon Sep 17 00:00:00 2001 From: Howard Pritchard Date: Fri, 17 Mar 2017 17:01:53 -0600 Subject: [PATCH 4/4] timer: hack use of clock_gettime better solution needed later workaround for #3003 Signed-off-by: Howard Pritchard (cherry picked from commit b9331527f573a4bac060fdde415a6a0015ce8ae3) Signed-off-by: Jeff Squyres --- ompi/mpi/c/wtick.c | 20 ++++++++++++++++++-- ompi/mpi/c/wtime.c | 17 ++++++++++++++--- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/ompi/mpi/c/wtick.c b/ompi/mpi/c/wtick.c index ee0e067477e..f6504dccee2 100644 --- a/ompi/mpi/c/wtick.c +++ b/ompi/mpi/c/wtick.c @@ -13,6 +13,8 @@ * Copyright (c) 2015-2016 Research Organization for Information Science * and Technology (RIST). All rights reserved. * Copyright (c) 2017 IBM Corporation. All rights reserved. + * Copyright (c) 2017 Los Alamos National Security, LLC. All rights + * reserved. * $COPYRIGHT$ * * Additional copyrights may follow @@ -25,6 +27,9 @@ #include #endif #include +#ifdef HAVE_TIME_H +#include +#endif #include MCA_timer_IMPLEMENTATION_HEADER #include "ompi/mpi/c/bindings.h" @@ -41,8 +46,7 @@ double MPI_Wtick(void) { /* * See https://github.com/open-mpi/ompi/issues/3003 - * For now we are forcing the use of gettimeofday() until we find a - * more portable solution. + * to get an idea what's going on here. */ #if 0 #if OPAL_TIMER_CYCLE_NATIVE @@ -58,8 +62,20 @@ double MPI_Wtick(void) #elif OPAL_TIMER_USEC_NATIVE return 0.000001; #endif +#else +#if defined(__linux__) && OPAL_HAVE_CLOCK_GETTIME + struct timespec spec; + double wtick = 0.0; + if (0 == clock_getres(CLOCK_MONOTONIC, &spec)){ + wtick = spec.tv_sec + spec.tv_nsec * 1.0e-09; + } else { + /* guess */ + wtick = 1.0e-09; + } + return wtick; #else /* Otherwise, we already return usec precision. */ return 0.000001; #endif +#endif } diff --git a/ompi/mpi/c/wtime.c b/ompi/mpi/c/wtime.c index d20a7943a4b..73b803c2322 100644 --- a/ompi/mpi/c/wtime.c +++ b/ompi/mpi/c/wtime.c @@ -13,6 +13,8 @@ * Copyright (c) 2015 Research Organization for Information Science * and Technology (RIST). All rights reserved. * Copyright (c) 2017 IBM Corporation. All rights reserved. + * Copyright (c) 2017 Los Alamos National Security, LLC. All rights + * reserved. * $COPYRIGHT$ * * Additional copyrights may follow @@ -25,6 +27,9 @@ #include #endif #include +#ifdef HAVE_TIME_H +#include +#endif /* HAVE_TIME_H */ #include MCA_timer_IMPLEMENTATION_HEADER #include "ompi/mpi/c/bindings.h" @@ -42,9 +47,8 @@ double MPI_Wtime(void) double wtime; /* - * See https://github.com/open-mpi/ompi/issues/3003 - * For now we are forcing the use of gettimeofday() until we find a - * more portable solution. + * See https://github.com/open-mpi/ompi/issues/3003 to find out + * what's happening here. */ #if 0 #if OPAL_TIMER_CYCLE_NATIVE @@ -52,12 +56,19 @@ double MPI_Wtime(void) #elif OPAL_TIMER_USEC_NATIVE wtime = ((double) opal_timer_base_get_usec()) / 1000000.0; #endif +#else +#if defined(__linux__) && OPAL_HAVE_CLOCK_GETTIME + struct timespec tp = {.tv_sec = 0, .tv_nsec = 0}; + (void) clock_gettime(CLOCK_MONOTONIC, &tp); + wtime = tp.tv_sec; + wtime += tp.tv_nsec/1.0e+9; #else /* Fall back to gettimeofday() if we have nothing else */ struct timeval tv; gettimeofday(&tv, NULL); wtime = tv.tv_sec; wtime += (double)tv.tv_usec / 1000000.0; +#endif #endif return wtime;