From f510626d20b164f5cc6cfd495eb51fcf0f3ec314 Mon Sep 17 00:00:00 2001 From: degomme Date: Sat, 18 Jun 2016 20:25:15 +0200 Subject: [PATCH] We intercept sleep, usleep and gettimeofday. Add clock_gettime and nanoslepp, also --- include/smpi/mpi.h | 8 +++++++- include/smpi/smpi.h | 8 ++++++++ src/smpi/smpi_bench.cpp | 23 +++++++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/include/smpi/mpi.h b/include/smpi/mpi.h index f5ff19fbe9..ee9e433c69 100644 --- a/include/smpi/mpi.h +++ b/include/smpi/mpi.h @@ -10,6 +10,10 @@ #define SEED 221238 #define sleep(x) smpi_sleep(x) +#if _POSIX_TIMERS +#define nanosleep(x,y) smpi_nanosleep(x,NULL) +#endif +#define usleep(x) smpi_usleep(x) #include #include @@ -19,7 +23,9 @@ #include /* Load it before the define next line to not mess with the system headers */ #define gettimeofday(x, y) smpi_gettimeofday(x, NULL) - +#if _POSIX_TIMERS +#define clock_gettime(x, y) smpi_clock_gettime(x, y) +#endif #if HAVE_MC #undef assert #define assert(x) MC_assert(x) diff --git a/include/smpi/smpi.h b/include/smpi/smpi.h index 3f7245b823..73fdb682d8 100644 --- a/include/smpi/smpi.h +++ b/include/smpi/smpi.h @@ -9,6 +9,9 @@ #include #include +#if _POSIX_TIMERS +#include +#endif #include #include @@ -803,6 +806,11 @@ XBT_PUBLIC(int) smpi_get_host_pstate(void); XBT_PUBLIC(double) smpi_get_host_consumed_energy(void); XBT_PUBLIC(int) smpi_usleep(useconds_t usecs); +#if _POSIX_TIMERS + +XBT_PUBLIC(int) smpi_nanosleep(struct timespec *tp, void* t); +XBT_PUBLIC(int) smpi_clock_gettime(clockid_t clk_id, struct timespec *tp); +#endif XBT_PUBLIC(unsigned int) smpi_sleep(unsigned int secs); XBT_PUBLIC(int) smpi_gettimeofday(struct timeval *tv, void* tz); XBT_PUBLIC(unsigned long long) smpi_rastro_resolution (void); diff --git a/src/smpi/smpi_bench.cpp b/src/smpi/smpi_bench.cpp index dfc02f1424..91be166949 100644 --- a/src/smpi/smpi_bench.cpp +++ b/src/smpi/smpi_bench.cpp @@ -307,6 +307,13 @@ int smpi_usleep(useconds_t usecs) return static_cast(private_sleep(static_cast(usecs) / 1000000.0)); } +#if _POSIX_TIMERS +int smpi_nanosleep(struct timespec *tp, void* t) +{ + return static_cast(private_sleep(static_cast(tp->tv_sec + tp->tv_nsec / 1000000000.0))); +} +#endif + int smpi_gettimeofday(struct timeval *tv, void* tz) { double now; @@ -324,6 +331,22 @@ int smpi_gettimeofday(struct timeval *tv, void* tz) return 0; } +#if _POSIX_TIMERS +int smpi_clock_gettime(clockid_t clk_id, struct timespec *tp) +{ + //there is only one time in SMPI, so clk_id is ignored. + double now; + smpi_bench_end(); + now = SIMIX_get_clock(); + if (tp) { + tp->tv_sec = static_cast(now); + tp->tv_nsec = static_cast((now - tp->tv_sec) * 1e9); + } + smpi_bench_begin(); + return 0; +} +#endif + extern double sg_surf_precision; unsigned long long smpi_rastro_resolution (void) { -- 2.20.1