X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/b266c9f9b644f15f1d397e60f5affa12cf0167d8..8cf6e30af8de6686461b6b1b52ba578df01de985:/src/xbt/xbt_os_time.c diff --git a/src/xbt/xbt_os_time.c b/src/xbt/xbt_os_time.c index 836bd17724..fa6fc2b437 100644 --- a/src/xbt/xbt_os_time.c +++ b/src/xbt/xbt_os_time.c @@ -1,16 +1,17 @@ /* xbt_os_time.c -- portable interface to time-related functions */ -/* Copyright (c) 2007-2010, 2012-2015. The SimGrid Team. - * All rights reserved. */ +/* Copyright (c) 2007-2016. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ +#include "src/internal_config.h" #include "xbt/sysdep.h" -#include "xbt/xbt_os_time.h" /* this module */ #include "xbt/log.h" -#include "src/portable.h" +#include "xbt/xbt_os_time.h" /* this module */ #include /* floor */ +#include +#include #ifdef _WIN32 #include @@ -39,7 +40,7 @@ double xbt_os_time(void) { -#ifdef HAVE_GETTIMEOFDAY +#if HAVE_GETTIMEOFDAY struct timeval tv; gettimeofday(&tv, NULL); #elif defined(_WIN32) @@ -84,20 +85,15 @@ void xbt_os_sleep(double sec) #endif } -/* TSC (tick-level) timers are said to be unreliable on SMP hosts and thus - disabled in SDL source code */ - +/* TSC (tick-level) timers are said to be unreliable on SMP hosts and thus disabled in SDL source code */ /* \defgroup XBT_sysdep All system dependency - * \brief This section describes many macros/functions that can serve as - * an OS abstraction. + * \brief This section describes many macros/functions that can serve as an OS abstraction. */ - - struct s_xbt_os_timer { -#ifdef HAVE_POSIX_GETTIME +#if HAVE_POSIX_GETTIME struct timespec start, stop, elapse; -#elif defined(HAVE_GETTIMEOFDAY) || defined(_WIN32) +#elif HAVE_GETTIMEOFDAY || defined(_WIN32) struct timeval start, stop, elapse; #else unsigned long int start, stop, elapse; @@ -120,29 +116,25 @@ void xbt_os_timer_free(xbt_os_timer_t timer) double xbt_os_timer_elapsed(xbt_os_timer_t timer) { -#ifdef HAVE_POSIX_GETTIME - return ((double) timer->stop.tv_sec) - ((double) timer->start.tv_sec) + - ((double) timer->elapse.tv_sec ) + - ((((double) timer->stop.tv_nsec) - - ((double) timer->start.tv_nsec) + ((double) timer->elapse.tv_nsec )) / 1e9); -#elif defined(HAVE_GETTIMEOFDAY) || defined(_WIN32) - return ((double) timer->stop.tv_sec) - ((double) timer->start.tv_sec) - + ((double) timer->elapse.tv_sec ) + - ((((double) timer->stop.tv_usec) - - ((double) timer->start.tv_usec) + ((double) timer->elapse.tv_usec )) / 1000000.0); +#if HAVE_POSIX_GETTIME + return ((double) timer->stop.tv_sec) - ((double) timer->start.tv_sec) + ((double) timer->elapse.tv_sec ) + + ((((double) timer->stop.tv_nsec) - ((double) timer->start.tv_nsec) + ((double) timer->elapse.tv_nsec )) / 1e9); +#elif HAVE_GETTIMEOFDAY || defined(_WIN32) + return ((double) timer->stop.tv_sec) - ((double) timer->start.tv_sec) + ((double) timer->elapse.tv_sec ) + + ((((double) timer->stop.tv_usec) - ((double) timer->start.tv_usec) + ((double) timer->elapse.tv_usec )) / + 1000000.0); #else - return (double) timer->stop - (double) timer->start + (double) - timer->elapse; + return (double) timer->stop - (double) timer->start + (double) timer->elapse; #endif } void xbt_os_walltimer_start(xbt_os_timer_t timer) { -#ifdef HAVE_POSIX_GETTIME +#if HAVE_POSIX_GETTIME timer->elapse.tv_sec = 0; timer->elapse.tv_nsec = 0; clock_gettime(CLOCK_REALTIME, &(timer->start)); -#elif defined(HAVE_GETTIMEOFDAY) +#elif HAVE_GETTIMEOFDAY timer->elapse.tv_sec = 0; timer->elapse.tv_usec = 0; gettimeofday(&(timer->start), NULL); @@ -168,12 +160,12 @@ void xbt_os_walltimer_start(xbt_os_timer_t timer) void xbt_os_walltimer_resume(xbt_os_timer_t timer) { -#ifdef HAVE_POSIX_GETTIME +#if HAVE_POSIX_GETTIME timer->elapse.tv_sec += timer->stop.tv_sec - timer->start.tv_sec; timer->elapse.tv_nsec += timer->stop.tv_nsec - timer->start.tv_nsec; clock_gettime(CLOCK_REALTIME, &(timer->start)); -#elif defined(HAVE_GETTIMEOFDAY) +#elif HAVE_GETTIMEOFDAY timer->elapse.tv_sec += timer->stop.tv_sec - timer->start.tv_sec; timer->elapse.tv_usec += timer->stop.tv_usec - timer->start.tv_usec; gettimeofday(&(timer->start), NULL); @@ -199,9 +191,9 @@ void xbt_os_walltimer_resume(xbt_os_timer_t timer) void xbt_os_walltimer_stop(xbt_os_timer_t timer) { -#ifdef HAVE_POSIX_GETTIME +#if HAVE_POSIX_GETTIME clock_gettime(CLOCK_REALTIME, &(timer->stop)); -#elif defined(HAVE_GETTIMEOFDAY) +#elif HAVE_GETTIMEOFDAY gettimeofday(&(timer->stop), NULL); #elif defined(_WIN32) FILETIME ft; @@ -222,11 +214,11 @@ void xbt_os_walltimer_stop(xbt_os_timer_t timer) void xbt_os_cputimer_start(xbt_os_timer_t timer) { -#ifdef HAVE_POSIX_GETTIME +#if HAVE_POSIX_GETTIME timer->elapse.tv_sec = 0; timer->elapse.tv_nsec = 0; clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &(timer->start)); -#elif defined(HAVE_GETTIMEOFDAY)//return time and not cputime in this case +#elif HAVE_GETTIMEOFDAY //return time and not cputime in this case timer->elapse.tv_sec = 0; timer->elapse.tv_usec = 0; gettimeofday(&(timer->start), NULL); @@ -250,11 +242,11 @@ void xbt_os_cputimer_start(xbt_os_timer_t timer) void xbt_os_cputimer_resume(xbt_os_timer_t timer) { -#ifdef HAVE_POSIX_GETTIME +#if HAVE_POSIX_GETTIME timer->elapse.tv_sec += timer->stop.tv_sec - timer->start.tv_sec; timer->elapse.tv_nsec += timer->stop.tv_nsec - timer->start.tv_nsec; clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &(timer->start)); -#elif defined(HAVE_GETTIMEOFDAY) +#elif HAVE_GETTIMEOFDAY timer->elapse.tv_sec += timer->stop.tv_sec - timer->start.tv_sec; timer->elapse.tv_usec += timer->stop.tv_usec - timer->start.tv_usec; gettimeofday(&(timer->start), NULL); @@ -278,9 +270,9 @@ void xbt_os_cputimer_resume(xbt_os_timer_t timer) void xbt_os_cputimer_stop(xbt_os_timer_t timer) { -#ifdef HAVE_POSIX_GETTIME +#if HAVE_POSIX_GETTIME clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &(timer->stop)); -#elif defined(HAVE_GETTIMEOFDAY) +#elif HAVE_GETTIMEOFDAY gettimeofday(&(timer->stop), NULL); #elif defined(_WIN32) HANDLE h = GetCurrentProcess(); @@ -300,11 +292,11 @@ void xbt_os_cputimer_stop(xbt_os_timer_t timer) void xbt_os_threadtimer_start(xbt_os_timer_t timer) { -#ifdef HAVE_POSIX_GETTIME +#if HAVE_POSIX_GETTIME timer->elapse.tv_sec = 0; timer->elapse.tv_nsec = 0; clock_gettime(CLOCK_THREAD_CPUTIME_ID, &(timer->start)); -#elif defined(HAVE_GETTIMEOFDAY) && defined(__MACH__) && defined(__APPLE__) +#elif HAVE_GETTIMEOFDAY && defined(__MACH__) && defined(__APPLE__) timer->elapse.tv_sec = 0; timer->elapse.tv_usec = 0; mach_msg_type_number_t count = THREAD_BASIC_INFO_COUNT; @@ -313,7 +305,7 @@ void xbt_os_threadtimer_start(xbt_os_timer_t timer) thread_info(mach_thread_self(), THREAD_BASIC_INFO, (thread_info_t)thi, &count); timer->start.tv_usec = thi->system_time.microseconds + thi->user_time.microseconds; timer->start.tv_sec = thi->system_time.seconds + thi->user_time.seconds; -#elif defined(HAVE_GETTIMEOFDAY)//return time and not cputime in this case +#elif HAVE_GETTIMEOFDAY //return time and not cputime in this case timer->elapse.tv_sec = 0; timer->elapse.tv_usec = 0; gettimeofday(&(timer->start), NULL); @@ -335,11 +327,11 @@ void xbt_os_threadtimer_start(xbt_os_timer_t timer) void xbt_os_threadtimer_resume(xbt_os_timer_t timer) { -#ifdef HAVE_POSIX_GETTIME +#if HAVE_POSIX_GETTIME timer->elapse.tv_sec += timer->stop.tv_sec - timer->start.tv_sec; timer->elapse.tv_nsec += timer->stop.tv_nsec - timer->start.tv_nsec; clock_gettime(CLOCK_THREAD_CPUTIME_ID, &(timer->start)); -#elif defined(HAVE_GETTIMEOFDAY) && defined(__MACH__) && defined(__APPLE__) +#elif HAVE_GETTIMEOFDAY && defined(__MACH__) && defined(__APPLE__) timer->elapse.tv_sec += timer->stop.tv_sec - timer->start.tv_sec; timer->elapse.tv_usec += timer->stop.tv_usec - timer->start.tv_usec; mach_msg_type_number_t count = THREAD_BASIC_INFO_COUNT; @@ -348,7 +340,7 @@ void xbt_os_threadtimer_resume(xbt_os_timer_t timer) thread_info(mach_thread_self(), THREAD_BASIC_INFO, (thread_info_t)thi, &count); timer->start.tv_usec = thi->system_time.microseconds + thi->user_time.microseconds; timer->start.tv_sec = thi->system_time.seconds + thi->user_time.seconds; -#elif defined(HAVE_GETTIMEOFDAY) +#elif HAVE_GETTIMEOFDAY timer->elapse.tv_sec += timer->stop.tv_sec - timer->start.tv_sec; timer->elapse.tv_usec += timer->stop.tv_usec - timer->start.tv_usec; gettimeofday(&(timer->start), NULL); @@ -372,16 +364,16 @@ void xbt_os_threadtimer_resume(xbt_os_timer_t timer) void xbt_os_threadtimer_stop(xbt_os_timer_t timer) { -#ifdef HAVE_POSIX_GETTIME +#if HAVE_POSIX_GETTIME clock_gettime(CLOCK_THREAD_CPUTIME_ID, &(timer->stop)); -#elif defined(HAVE_GETTIMEOFDAY) && defined(__MACH__) && defined(__APPLE__) +#elif HAVE_GETTIMEOFDAY && defined(__MACH__) && defined(__APPLE__) mach_msg_type_number_t count = THREAD_BASIC_INFO_COUNT; thread_basic_info_data_t thi_data; thread_basic_info_t thi = &thi_data; thread_info(mach_thread_self(), THREAD_BASIC_INFO, (thread_info_t)thi, &count); timer->stop.tv_usec = thi->system_time.microseconds + thi->user_time.microseconds; timer->stop.tv_sec = thi->system_time.seconds + thi->user_time.seconds; -#elif defined(HAVE_GETTIMEOFDAY)//if nothing else is available, return just time +#elif HAVE_GETTIMEOFDAY //if nothing else is available, return just time gettimeofday(&(timer->stop), NULL); #elif defined(_WIN32) HANDLE h = GetCurrentThread();