From 91ca39d79fbd3e53ea3cc5fdff3a7ec0348cfcfc Mon Sep 17 00:00:00 2001 From: =?utf8?q?Guillaume=20Serri=C3=A8re?= Date: Fri, 14 Jun 2013 15:02:19 +0200 Subject: [PATCH] Change xbt_os_timer interface to handle cpu time, thread time and wall time distinctly. Windows section isn't test. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Guillaume Serrière --- examples/msg/pmm/msg_pmm.c | 6 +- examples/simdag/goal/goal_test.c | 4 +- src/include/xbt/xbt_os_time.h | 15 +- src/mc/mc_compare.c | 68 ++--- src/simix/smx_context_raw.c | 6 +- src/simix/smx_global.c | 12 +- src/smpi/smpi_bench.c | 6 +- src/xbt/xbt_os_time.c | 287 ++++++++++++++++-- .../platforms/Evaluate_get_route_time.c | 4 +- .../simdag/platforms/Evaluate_parse_time.c | 4 +- teshsuite/simdag/platforms/flatifier.c | 4 +- 11 files changed, 328 insertions(+), 88 deletions(-) diff --git a/examples/msg/pmm/msg_pmm.c b/examples/msg/pmm/msg_pmm.c index ba8a65c1c4..ee45fec5d5 100644 --- a/examples/msg/pmm/msg_pmm.c +++ b/examples/msg/pmm/msg_pmm.c @@ -271,7 +271,7 @@ static void task_cleanup(void *arg){ int main(int argc, char *argv[]) { #ifdef BENCH_THIS_CODE - xbt_os_timer_t timer = xbt_os_timer_new(); + xbt_os_cputimer_t timer = xbt_os_timer_new(); #endif MSG_init(&argc, argv); @@ -286,11 +286,11 @@ int main(int argc, char *argv[]) MSG_launch_application(application_file); #ifdef BENCH_THIS_CODE - xbt_os_timer_start(timer); + xbt_os_cputimer_start(timer); #endif msg_error_t res = MSG_main(); #ifdef BENCH_THIS_CODE - xbt_os_timer_stop(timer); + xbt_os_cputimer_stop(timer); #endif XBT_CRITICAL("Simulated time: %g", MSG_get_clock()); diff --git a/examples/simdag/goal/goal_test.c b/examples/simdag/goal/goal_test.c index be7b99e7e6..299c0b5106 100644 --- a/examples/simdag/goal/goal_test.c +++ b/examples/simdag/goal/goal_test.c @@ -71,7 +71,7 @@ int main(int argc, char **argv) { reclaimed = xbt_dynar_new(sizeof(bcast_task_t),xbt_free_ref); xbt_dynar_t done = NULL; - xbt_os_timer_start(timer); + xbt_os_cputimer_start(timer); send_one(0,SD_workstation_get_number()); do { if (done != NULL && !xbt_dynar_is_empty(done)) { @@ -97,7 +97,7 @@ int main(int argc, char **argv) { } done=SD_simulate(-1); } while(!xbt_dynar_is_empty(done)); - xbt_os_timer_stop(timer); + xbt_os_cputimer_stop(timer); printf("exec_time:%lf\n", xbt_os_timer_elapsed(timer) ); xbt_dynar_free(&done); diff --git a/src/include/xbt/xbt_os_time.h b/src/include/xbt/xbt_os_time.h index a86bcdd96c..a6d848d5ae 100644 --- a/src/include/xbt/xbt_os_time.h +++ b/src/include/xbt/xbt_os_time.h @@ -22,9 +22,18 @@ XBT_PUBLIC(void) xbt_os_sleep(double sec); typedef struct s_xbt_os_timer *xbt_os_timer_t; XBT_PUBLIC(xbt_os_timer_t) xbt_os_timer_new(void); XBT_PUBLIC(void) xbt_os_timer_free(xbt_os_timer_t timer); -XBT_PUBLIC(void) xbt_os_timer_start(xbt_os_timer_t timer); -XBT_PUBLIC(void) xbt_os_timer_resume(xbt_os_timer_t timer); -XBT_PUBLIC(void) xbt_os_timer_stop(xbt_os_timer_t timer); XBT_PUBLIC(double) xbt_os_timer_elapsed(xbt_os_timer_t timer); + +XBT_PUBLIC(void) xbt_os_walltimer_start(xbt_os_timer_t timer); +XBT_PUBLIC(void) xbt_os_walltimer_resume(xbt_os_timer_t timer); +XBT_PUBLIC(void) xbt_os_walltimer_stop(xbt_os_timer_t timer); + +XBT_PUBLIC(void) xbt_os_cputimer_start(xbt_os_timer_t timer); +XBT_PUBLIC(void) xbt_os_cputimer_resume(xbt_os_timer_t timer); +XBT_PUBLIC(void) xbt_os_cputimer_stop(xbt_os_timer_t timer); + +XBT_PUBLIC(void) xbt_os_threadtimer_start(xbt_os_timer_t timer); +XBT_PUBLIC(void) xbt_os_threadtimer_resume(xbt_os_timer_t timer); +XBT_PUBLIC(void) xbt_os_threadtimer_stop(xbt_os_timer_t timer); #endif diff --git a/src/mc/mc_compare.c b/src/mc/mc_compare.c index da1efaaba8..b51f045685 100644 --- a/src/mc/mc_compare.c +++ b/src/mc/mc_compare.c @@ -173,16 +173,16 @@ int snapshot_compare(mc_snapshot_t s1, mc_snapshot_t s2){ xbt_os_timer_t global_timer = xbt_os_timer_new(); xbt_os_timer_t timer = xbt_os_timer_new(); - xbt_os_timer_start(global_timer); + xbt_os_walltimer_start(global_timer); #ifdef MC_DEBUG - xbt_os_timer_start(timer); + xbt_os_walltimer_start(timer); #endif /* Compare number of processes */ if(s1->nb_processes != s2->nb_processes){ #ifdef MC_DEBUG - xbt_os_timer_stop(timer); + xbt_os_walltimer_stop(timer); mc_comp_times->nb_processes_comparison_time = xbt_os_timer_elapsed(timer); XBT_DEBUG("Different number of processes : %d - %d", s1->nb_processes, s2->nb_processes); errors++; @@ -192,7 +192,7 @@ int snapshot_compare(mc_snapshot_t s1, mc_snapshot_t s2){ #endif xbt_os_timer_free(timer); - xbt_os_timer_stop(global_timer); + xbt_os_walltimer_stop(global_timer); mc_snapshot_comparison_time = xbt_os_timer_elapsed(global_timer); xbt_os_timer_free(global_timer); @@ -204,13 +204,13 @@ int snapshot_compare(mc_snapshot_t s1, mc_snapshot_t s2){ } #ifdef MC_DEBUG - xbt_os_timer_start(timer); + xbt_os_walltimer_start(timer); #endif /* Compare number of bytes used in each heap */ if(s1->heap_bytes_used != s2->heap_bytes_used){ #ifdef MC_DEBUG - xbt_os_timer_stop(timer); + xbt_os_walltimer_stop(timer); mc_comp_times->bytes_used_comparison_time = xbt_os_timer_elapsed(timer); XBT_DEBUG("Different number of bytes used in each heap : %zu - %zu", s1->heap_bytes_used, s2->heap_bytes_used); errors++; @@ -220,7 +220,7 @@ int snapshot_compare(mc_snapshot_t s1, mc_snapshot_t s2){ #endif xbt_os_timer_free(timer); - xbt_os_timer_stop(global_timer); + xbt_os_walltimer_stop(global_timer); mc_snapshot_comparison_time = xbt_os_timer_elapsed(global_timer); xbt_os_timer_free(global_timer); @@ -231,12 +231,12 @@ int snapshot_compare(mc_snapshot_t s1, mc_snapshot_t s2){ #endif }else{ #ifdef MC_DEBUG - xbt_os_timer_stop(timer); + xbt_os_walltimer_stop(timer); #endif } #ifdef MC_DEBUG - xbt_os_timer_start(timer); + xbt_os_walltimer_start(timer); #endif /* Compare size of stacks */ @@ -249,7 +249,7 @@ int snapshot_compare(mc_snapshot_t s1, mc_snapshot_t s2){ if(size_used1 != size_used2){ #ifdef MC_DEBUG if(is_diff == 0){ - xbt_os_timer_stop(timer); + xbt_os_walltimer_stop(timer); mc_comp_times->stacks_sizes_comparison_time = xbt_os_timer_elapsed(timer); } XBT_DEBUG("Different size used in stacks : %zu - %zu", size_used1, size_used2); @@ -261,7 +261,7 @@ int snapshot_compare(mc_snapshot_t s1, mc_snapshot_t s2){ #endif xbt_os_timer_free(timer); - xbt_os_timer_stop(global_timer); + xbt_os_walltimer_stop(global_timer); mc_snapshot_comparison_time = xbt_os_timer_elapsed(global_timer); xbt_os_timer_free(global_timer); @@ -276,15 +276,15 @@ int snapshot_compare(mc_snapshot_t s1, mc_snapshot_t s2){ #ifdef MC_DEBUG if(is_diff == 0) - xbt_os_timer_stop(timer); - xbt_os_timer_start(timer); + xbt_os_walltimer_stop(timer); + xbt_os_walltimer_start(timer); #endif /* Compare hash of global variables */ if(s1->hash_global != NULL && s2->hash_global != NULL){ if(strcmp(s1->hash_global, s2->hash_global) != 0){ #ifdef MC_DEBUG - xbt_os_timer_stop(timer); + xbt_os_walltimer_stop(timer); mc_comp_times->hash_global_variables_comparison_time = xbt_os_timer_elapsed(timer); XBT_DEBUG("Different hash of global variables : %s - %s", s1->hash_global, s2->hash_global); errors++; @@ -294,7 +294,7 @@ int snapshot_compare(mc_snapshot_t s1, mc_snapshot_t s2){ #endif xbt_os_timer_free(timer); - xbt_os_timer_stop(global_timer); + xbt_os_walltimer_stop(global_timer); mc_snapshot_comparison_time = xbt_os_timer_elapsed(global_timer); xbt_os_timer_free(global_timer); @@ -307,14 +307,14 @@ int snapshot_compare(mc_snapshot_t s1, mc_snapshot_t s2){ } #ifdef MC_DEBUG - xbt_os_timer_start(timer); + xbt_os_walltimer_start(timer); #endif /* Compare hash of local variables */ if(s1->hash_local != NULL && s2->hash_local != NULL){ if(strcmp(s1->hash_local, s2->hash_local) != 0){ #ifdef MC_DEBUG - xbt_os_timer_stop(timer); + xbt_os_walltimer_stop(timer); mc_comp_times->hash_local_variables_comparison_time = xbt_os_timer_elapsed(timer); XBT_DEBUG("Different hash of local variables : %s - %s", s1->hash_local, s2->hash_local); errors++; @@ -324,7 +324,7 @@ int snapshot_compare(mc_snapshot_t s1, mc_snapshot_t s2){ #endif xbt_os_timer_free(timer); - xbt_os_timer_stop(global_timer); + xbt_os_walltimer_stop(global_timer); mc_snapshot_comparison_time = xbt_os_timer_elapsed(global_timer); xbt_os_timer_free(global_timer); @@ -337,7 +337,7 @@ int snapshot_compare(mc_snapshot_t s1, mc_snapshot_t s2){ } #ifdef MC_DEBUG - xbt_os_timer_start(timer); + xbt_os_walltimer_start(timer); #endif /* Init heap information used in heap comparison algorithm */ @@ -347,7 +347,7 @@ int snapshot_compare(mc_snapshot_t s1, mc_snapshot_t s2){ is_diff = compare_global_variables(2, s1->regions[2]->data, s2->regions[2]->data); if(is_diff != 0){ #ifdef MC_DEBUG - xbt_os_timer_stop(timer); + xbt_os_walltimer_stop(timer); mc_comp_times->binary_global_variables_comparison_time = xbt_os_timer_elapsed(timer); XBT_DEBUG("Different global variables in binary"); errors++; @@ -358,7 +358,7 @@ int snapshot_compare(mc_snapshot_t s1, mc_snapshot_t s2){ reset_heap_information(); xbt_os_timer_free(timer); - xbt_os_timer_stop(global_timer); + xbt_os_walltimer_stop(global_timer); mc_snapshot_comparison_time = xbt_os_timer_elapsed(global_timer); xbt_os_timer_free(global_timer); @@ -371,15 +371,15 @@ int snapshot_compare(mc_snapshot_t s1, mc_snapshot_t s2){ #ifdef MC_DEBUG if(is_diff == 0) - xbt_os_timer_stop(timer); - xbt_os_timer_start(timer); + xbt_os_walltimer_stop(timer); + xbt_os_walltimer_start(timer); #endif /* Compare libsimgrid global variables */ is_diff = compare_global_variables(1, s1->regions[1]->data, s2->regions[1]->data); if(is_diff != 0){ #ifdef MC_DEBUG - xbt_os_timer_stop(timer); + xbt_os_walltimer_stop(timer); mc_comp_times->libsimgrid_global_variables_comparison_time = xbt_os_timer_elapsed(timer); XBT_DEBUG("Different global variables in libsimgrid"); errors++; @@ -390,7 +390,7 @@ int snapshot_compare(mc_snapshot_t s1, mc_snapshot_t s2){ reset_heap_information(); xbt_os_timer_free(timer); - xbt_os_timer_stop(global_timer); + xbt_os_walltimer_stop(global_timer); mc_snapshot_comparison_time = xbt_os_timer_elapsed(global_timer); xbt_os_timer_free(global_timer); @@ -403,8 +403,8 @@ int snapshot_compare(mc_snapshot_t s1, mc_snapshot_t s2){ #ifdef MC_DEBUG if(is_diff == 0) - xbt_os_timer_stop(timer); - xbt_os_timer_start(timer); + xbt_os_walltimer_stop(timer); + xbt_os_walltimer_start(timer); #endif /* Stacks comparison */ @@ -417,7 +417,7 @@ int snapshot_compare(mc_snapshot_t s1, mc_snapshot_t s2){ if(diff_local > 0){ #ifdef MC_DEBUG if(is_diff == 0){ - xbt_os_timer_stop(timer); + xbt_os_walltimer_stop(timer); mc_comp_times->stacks_comparison_time = xbt_os_timer_elapsed(timer); } XBT_DEBUG("Different local variables between stacks %d", cursor + 1); @@ -431,7 +431,7 @@ int snapshot_compare(mc_snapshot_t s1, mc_snapshot_t s2){ reset_heap_information(); xbt_os_timer_free(timer); - xbt_os_timer_stop(global_timer); + xbt_os_walltimer_stop(global_timer); mc_snapshot_comparison_time = xbt_os_timer_elapsed(global_timer); xbt_os_timer_free(global_timer); @@ -445,14 +445,14 @@ int snapshot_compare(mc_snapshot_t s1, mc_snapshot_t s2){ } #ifdef MC_DEBUG - xbt_os_timer_start(timer); + xbt_os_walltimer_start(timer); #endif /* Compare heap */ if(mmalloc_compare_heap((xbt_mheap_t)s1->regions[0]->data, (xbt_mheap_t)s2->regions[0]->data)){ #ifdef MC_DEBUG - xbt_os_timer_stop(timer); + xbt_os_walltimer_stop(timer); mc_comp_times->heap_comparison_time = xbt_os_timer_elapsed(timer); XBT_DEBUG("Different heap (mmalloc_compare)"); errors++; @@ -465,7 +465,7 @@ int snapshot_compare(mc_snapshot_t s1, mc_snapshot_t s2){ #endif reset_heap_information(); - xbt_os_timer_stop(global_timer); + xbt_os_walltimer_stop(global_timer); mc_snapshot_comparison_time = xbt_os_timer_elapsed(global_timer); xbt_os_timer_free(global_timer); @@ -476,7 +476,7 @@ int snapshot_compare(mc_snapshot_t s1, mc_snapshot_t s2){ #endif }else{ #ifdef MC_DEBUG - xbt_os_timer_stop(timer); + xbt_os_walltimer_stop(timer); #endif } @@ -485,7 +485,7 @@ int snapshot_compare(mc_snapshot_t s1, mc_snapshot_t s2){ xbt_os_timer_free(timer); #ifdef MC_VERBOSE - xbt_os_timer_stop(global_timer); + xbt_os_walltimer_stop(global_timer); mc_snapshot_comparison_time = xbt_os_timer_elapsed(global_timer); #endif diff --git a/src/simix/smx_context_raw.c b/src/simix/smx_context_raw.c index f2f05446a2..59533e9240 100644 --- a/src/simix/smx_context_raw.c +++ b/src/simix/smx_context_raw.c @@ -447,9 +447,9 @@ static void smx_ctx_raw_runall_serial(xbt_dynar_t processes) time_thread_sr[t] = 0; } - xbt_os_timer_start(timer); + xbt_os_cputimer_start(timer); smx_ctx_raw_resume(process); - xbt_os_timer_stop(timer); + xbt_os_cputimer_stop(timer); elapsed = xbt_os_timer_elapsed(timer); time_thread_ssr[t] += elapsed; time_thread_sr[((smx_ctx_raw_t)process->context)->thread] += elapsed; @@ -524,8 +524,10 @@ static void smx_ctx_raw_suspend_parallel(smx_context_t context) else { /* all processes were run, go to the barrier */ XBT_DEBUG("No more processes to run"); + unsigned long worker_id = (unsigned long) xbt_os_thread_get_specific(raw_worker_id_key); + next_context = (smx_context_t)raw_workers_context[worker_id]; XBT_DEBUG("Restoring worker stack %lu (working threads = %lu)", worker_id, raw_threads_working); diff --git a/src/simix/smx_global.c b/src/simix/smx_global.c index 3799230caf..c578d5178e 100644 --- a/src/simix/smx_global.c +++ b/src/simix/smx_global.c @@ -64,7 +64,7 @@ void SIMIX_global_init(int *argc, char **argv) #ifdef TIME_BENCH_AMDAHL simix_global->timer_seq = xbt_os_timer_new(); simix_global->timer_par = xbt_os_timer_new(); - xbt_os_timer_start(simix_global->timer_seq); + xbt_os_cputimer_start(simix_global->timer_seq); #endif simix_global->process_to_run = xbt_dynar_new(sizeof(smx_process_t), NULL); simix_global->process_that_ran = xbt_dynar_new(sizeof(smx_process_t), NULL); @@ -156,7 +156,7 @@ static void SIMIX_clean(void) surf_exit(); #ifdef TIME_BENCH_AMDAHL - xbt_os_timer_stop(simix_global->timer_seq); + xbt_os_cputimer_stop(simix_global->timer_seq); XBT_INFO("Amdhal timing informations. Sequential time: %lf; Parallel time: %lf", xbt_os_timer_elapsed(simix_global->timer_seq), xbt_os_timer_elapsed(simix_global->timer_par)); @@ -226,13 +226,13 @@ void SIMIX_run(void) /* Run all processes that are ready to run, possibly in parallel */ #ifdef TIME_BENCH_AMDAHL - xbt_os_timer_stop(simix_global->timer_seq); - xbt_os_timer_resume(simix_global->timer_par); + xbt_os_cputimer_stop(simix_global->timer_seq); + xbt_os_cputimer_resume(simix_global->timer_par); #endif SIMIX_process_runall(); #ifdef TIME_BENCH_AMDAHL - xbt_os_timer_stop(simix_global->timer_par); - xbt_os_timer_resume(simix_global->timer_seq); + xbt_os_cputimer_stop(simix_global->timer_par); + xbt_os_cputimer_resume(simix_global->timer_seq); #endif /* Move all killing processes to the end of the list, because killing a process that have an ongoing simcall is a bad idea */ diff --git a/src/smpi/smpi_bench.c b/src/smpi/smpi_bench.c index 18e4205c05..357e6f806b 100644 --- a/src/smpi/smpi_bench.c +++ b/src/smpi/smpi_bench.c @@ -149,7 +149,7 @@ static void smpi_execute(double duration) void smpi_bench_begin(void) { - xbt_os_timer_start(smpi_process_timer()); + xbt_os_threadtimer_start(smpi_process_timer()); smpi_current_rank = smpi_process_index(); } @@ -157,7 +157,7 @@ void smpi_bench_end(void) { xbt_os_timer_t timer = smpi_process_timer(); - xbt_os_timer_stop(timer); + xbt_os_threadtimer_stop(timer); smpi_execute(xbt_os_timer_elapsed(timer)); } @@ -320,7 +320,7 @@ void smpi_sample_3(int global, const char *file, int line) } // ok, benchmarking this loop is over - xbt_os_timer_stop(smpi_process_timer()); + xbt_os_threadtimer_stop(smpi_process_timer()); // update the stats double sample, n; diff --git a/src/xbt/xbt_os_time.c b/src/xbt/xbt_os_time.c index 9788f9f343..4e0f331857 100644 --- a/src/xbt/xbt_os_time.c +++ b/src/xbt/xbt_os_time.c @@ -109,65 +109,294 @@ void xbt_os_timer_free(xbt_os_timer_t timer) free(timer); } -void xbt_os_timer_resume(xbt_os_timer_t timer) +double xbt_os_timer_elapsed(xbt_os_timer_t timer) { #ifdef 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) - 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); + 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(_XBT_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 - timer->elapse = timer->stop - timer->start; - timer->start = (unsigned long int) (time(NULL)); + return (double) timer->stop - (double) timer->start + (double) + timer->elapse; #endif } -void xbt_os_timer_start(xbt_os_timer_t timer) +void xbt_os_walltimer_start(xbt_os_timer_t timer) { #ifdef HAVE_POSIX_GETTIME timer->elapse.tv_sec = 0; timer->elapse.tv_nsec = 0; - clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &(timer->start)); + clock_gettime(CLOCK_REALTIME, &(timer->start)); #elif defined(HAVE_GETTIMEOFDAY) timer->elapse.tv_sec = 0; timer->elapse.tv_usec = 0; gettimeofday(&(timer->start), NULL); +#elif defined(_XBT_WIN32) + timer->elapse.tv_sec = 0; + timer->elapse.tv_usec = 0; +# if defined(WIN32_WCE) || (_WIN32_WINNT < 0x0400) + struct _timeb tm; + + _ftime(&tm); + + timer->start.tv_sec = tm.time; + timer->start.tv_usec = tm.millitm * 1000; + +# else + FILETIME ft; + unsigned __int64 tm; + + GetSystemTimeAsFileTime(&ft); + tm = (unsigned __int64) ft.dwHighDateTime << 32; + tm |= ft.dwLowDateTime; + tm /= 10; + tm -= 11644473600000000ULL; + + timer->start.tv_sec = (long) (tm / 1000000L); + timer->start.tv_usec = (long) (tm % 1000000L); +# endif /* windows version checker */ #else timer->elapse = 0; timer->start = (unsigned long int) (time(NULL)); #endif } -void xbt_os_timer_stop(xbt_os_timer_t timer) +void xbt_os_walltimer_resume(xbt_os_timer_t timer) { #ifdef HAVE_POSIX_GETTIME - clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &(timer->stop)); + 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) - gettimeofday(&(timer->stop), NULL); + 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); +#elif defined(_XBT_WIN32) + timer->elapse.tv_sec += timer->stop.tv_sec - timer->start.tv_sec; + timer->elapse.tv_usec += timer->stop.tv_usec - timer->start.tv_usec; +# if defined(WIN32_WCE) || (_WIN32_WINNT < 0x0400) + struct _timeb tm; + + _ftime(&tm); + + timer->start.tv_sec = tm.time; + timer->start.tv_usec = tm.millitm * 1000; + +# else + FILETIME ft; + unsigned __int64 tm; + + GetSystemTimeAsFileTime(&ft); + tm = (unsigned __int64) ft.dwHighDateTime << 32; + tm |= ft.dwLowDateTime; + tm /= 10; + tm -= 11644473600000000ULL; + + timer->start.tv_sec = (long) (tm / 1000000L); + timer->start.tv_usec = (long) (tm % 1000000L); +# endif #else - timer->stop = (unsigned long int) (time(NULL)); + timer->elapse = timer->stop - timer->start; + timer->start = (unsigned long int) (time(NULL)); #endif } -double xbt_os_timer_elapsed(xbt_os_timer_t timer) +void xbt_os_walltimer_stop(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); + clock_gettime(CLOCK_REALTIME, &(timer->stop)); #elif defined(HAVE_GETTIMEOFDAY) - 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); + gettimeofday(&(timer->stop), NULL); +#elif defined(_XBT_WIN32) +# if defined(WIN32_WCE) || (_WIN32_WINNT < 0x0400) + struct _timeb tm; + + _ftime(&tm); + + timer->stop.tv_sec = tm.time; + timer->stop.tv_usec = tm.millitm * 1000; + +# else + FILETIME ft; + unsigned __int64 tm; + + GetSystemTimeAsFileTime(&ft); + tm = (unsigned __int64) ft.dwHighDateTime << 32; + tm |= ft.dwLowDateTime; + tm /= 10; + tm -= 11644473600000000ULL; + + timer->stop.tv_sec = (long) (tm / 1000000L); + timer->stop.tv_usec = (long) (tm % 1000000L); +# endif #else - return (double) timer->stop - (double) timer->start + (double) - timer->elapse; + timer->stop = (unsigned long int) (time(NULL)); +#endif +} + +void xbt_os_cputimer_start(xbt_os_timer_t timer) +{ +#ifdef HAVE_POSIX_GETTIME + timer->elapse.tv_sec = 0; + timer->elapse.tv_nsec = 0; + clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &(timer->start)); +#elif defined(_XBT_WIN32) + timer->elapse.tv_sec = 0; + timer->elapse.tv_nsec = 0; +# if defined(WIN32_WCE) || (_WIN32_WINNT < 0x0400) + THROW_UNIMPLEMENTED; +# else + HANDLE h = GetCurrentProcess(); + FILETIME creationTime, exitTime, kernelTime, userTime; + GetProcessTimes(h, &creationTime, &exitTime, &kernelTime, &userTime); + unsigned __int64 ktm, utm; + ktm = (unsigned __int64) kernelTime.dwHighDateTime << 32; + ktm |= kernelTime.dwLowDateTime; + ktm /= 10; + utm = (unsigned __int64) userTime.dwHighDateTime << 32; + utm |= userTime.dwLowDateTime; + utm /= 10; + timer->start.tv_sec = (long) (ktm / 1000000L) + (long) (utm / 1000000L); + timer->start.tv_usec = (long) (ktm % 1000000L) + (long) (utm % 1000000L); +# endif /* windows version checker */ +#endif +} + +void xbt_os_cputimer_resume(xbt_os_timer_t timer) +{ +#ifdef 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(_XBT_WIN32) + timer->elapse.tv_sec += timer->stop.tv_sec - timer->start.tv_sec; + timer->elapse.tv_nsec += timer->stop.tv_nsec - timer->start.tv_nsec; +# if defined(WIN32_WCE) || (_WIN32_WINNT < 0x0400) + THROW_UNIMPLEMENTED; +# else + HANDLE h = GetCurrentProcess(); + FILETIME creationTime, exitTime, kernelTime, userTime; + GetProcessTimes(h, &creationTime, &exitTime, &kernelTime, &userTime); + unsigned __int64 ktm, utm; + ktm = (unsigned __int64) kernelTime.dwHighDateTime << 32; + ktm |= kernelTime.dwLowDateTime; + ktm /= 10; + utm = (unsigned __int64) userTime.dwHighDateTime << 32; + utm |= userTime.dwLowDateTime; + utm /= 10; + timer->start.tv_sec = (long) (ktm / 1000000L) + (long) (utm / 1000000L); + timer->start.tv_usec = (long) (ktm % 1000000L) + (long) (utm % 1000000L); +# endif /* windows version checker */ + +#endif +} + +void xbt_os_cputimer_stop(xbt_os_timer_t timer) +{ +#ifdef HAVE_POSIX_GETTIME + clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &(timer->stop)); +#elif defined(_XBT_WIN32) +# if defined(WIN32_WCE) || (_WIN32_WINNT < 0x0400) + THROW_UNIMPLEMENTED; +# else + HANDLE h = GetCurrentProcess(); + FILETIME creationTime, exitTime, kernelTime, userTime; + GetProcessTimes(h, &creationTime, &exitTime, &kernelTime, &userTime); + unsigned __int64 ktm, utm; + ktm = (unsigned __int64) kernelTime.dwHighDateTime << 32; + ktm |= kernelTime.dwLowDateTime; + ktm /= 10; + utm = (unsigned __int64) userTime.dwHighDateTime << 32; + utm |= userTime.dwLowDateTime; + utm /= 10; + timer->stop.tv_sec = (long) (ktm / 1000000L) + (long) (utm / 1000000L); + timer->stop.tv_usec = (long) (ktm % 1000000L) + (long) (utm % 1000000L); +# endif /* windows version checker */ +#endif +} + +void xbt_os_threadtimer_start(xbt_os_timer_t timer) +{ +#ifdef HAVE_POSIX_GETTIME + timer->elapse.tv_sec = 0; + timer->elapse.tv_nsec = 0; + clock_gettime(CLOCK_THREAD_CPUTIME_ID, &(timer->start)); +#elif defined(_XBT_WIN32) + struct timeval tv; +# if defined(WIN32_WCE) || (_WIN32_WINNT < 0x0400) + THROW_UNIMPLEMENTED; +# else + HANDLE h = GetCurrentThread(); + FILETIME creationTime, exitTime, kernelTime, userTime; + GetThreadTimes(h, &creationTime, &exitTime, &kernelTime, &userTime); + unsigned __int64 ktm, utm; + ktm = (unsigned __int64) kernelTime.dwHighDateTime << 32; + ktm |= kernelTime.dwLowDateTime; + ktm /= 10; + utm = (unsigned __int64) userTime.dwHighDateTime << 32; + utm |= userTime.dwLowDateTime; + utm /= 10; + timer->start.tv_sec = (long) (ktm / 1000000L) + (long) (utm / 1000000L); + timer->start.tv_usec = (long) (ktm % 1000000L) + (long) (utm % 1000000L); +# endif /* windows version checker */ +#endif +} + +void xbt_os_threadtimer_resume(xbt_os_timer_t timer) +{ +#ifdef 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(_XBT_WIN32) + timer->elapse.tv_sec += timer->stop.tv_sec - timer->start.tv_sec; + timer->elapse.tv_nsec += timer->stop.tv_nsec - timer->start.tv_nsec; +# if defined(WIN32_WCE) || (_WIN32_WINNT < 0x0400) + THROW_UNIMPLEMENTED; +# else + HANDLE h = GetCurrentThread(); + FILETIME creationTime, exitTime, kernelTime, userTime; + GetThreadTimes(h, &creationTime, &exitTime, &kernelTime, &userTime); + unsigned __int64 ktm, utm; + ktm = (unsigned __int64) kernelTime.dwHighDateTime << 32; + ktm |= kernelTime.dwLowDateTime; + ktm /= 10; + utm = (unsigned __int64) userTime.dwHighDateTime << 32; + utm |= userTime.dwLowDateTime; + utm /= 10; + timer->start.tv_sec = (long) (ktm / 1000000L) + (long) (utm / 1000000L); + timer->start.tv_usec = (long) (ktm % 1000000L) + (long) (utm % 1000000L); +# endif /* windows version checker */ +#endif +} + +void xbt_os_threadtimer_stop(xbt_os_timer_t timer) +{ +#ifdef HAVE_POSIX_GETTIME + clock_gettime(CLOCK_THREAD_CPUTIME_ID, &(timer->stop)); +#elif defined(_XBT_WIN32) +# if defined(WIN32_WCE) || (_WIN32_WINNT < 0x0400) + THROW_UNIMPLEMENTED; +# else + HANDLE h = GetCurrentThread(); + FILETIME creationTime, exitTime, kernelTime, userTime; + GetThreadTimes(h, &creationTime, &exitTime, &kernelTime, &userTime); + unsigned __int64 ktm, utm; + ktm = (unsigned __int64) kernelTime.dwHighDateTime << 32; + ktm |= kernelTime.dwLowDateTime; + ktm /= 10; + utm = (unsigned __int64) userTime.dwHighDateTime << 32; + utm |= userTime.dwLowDateTime; + utm /= 10; + timer->stop.tv_sec = (long) (ktm / 1000000L) + (long) (utm / 1000000L); + timer->stop.tv_usec = (long) (ktm % 1000000L) + (long) (utm % 1000000L); +# endif /* windows version checker */ #endif } diff --git a/teshsuite/simdag/platforms/Evaluate_get_route_time.c b/teshsuite/simdag/platforms/Evaluate_get_route_time.c index 7fa2e1cd09..db7782c7f2 100644 --- a/teshsuite/simdag/platforms/Evaluate_get_route_time.c +++ b/teshsuite/simdag/platforms/Evaluate_get_route_time.c @@ -45,9 +45,9 @@ int main(int argc, char **argv) w2 = workstations[j]; printf("%d\tand\t%d\t\t",i,j); - xbt_os_timer_start(timer); + xbt_os_cputimer_start(timer); SD_route_get_list(w1, w2); - xbt_os_timer_stop(timer); + xbt_os_cputimer_stop(timer); printf("%lf\n", xbt_os_timer_elapsed(timer) ); diff --git a/teshsuite/simdag/platforms/Evaluate_parse_time.c b/teshsuite/simdag/platforms/Evaluate_parse_time.c index a710788aa3..09726fb6e7 100644 --- a/teshsuite/simdag/platforms/Evaluate_parse_time.c +++ b/teshsuite/simdag/platforms/Evaluate_parse_time.c @@ -22,9 +22,9 @@ int main(int argc, char **argv) SD_init(&argc, argv); /* creation of the environment, timed */ - xbt_os_timer_start(timer); + xbt_os_cputimer_start(timer); SD_create_environment(argv[1]); - xbt_os_timer_stop(timer); + xbt_os_cputimer_stop(timer); /* Display the result and exit after cleanup */ printf( "%lf\n", xbt_os_timer_elapsed(timer) ); diff --git a/teshsuite/simdag/platforms/flatifier.c b/teshsuite/simdag/platforms/flatifier.c index 5f5d48d4eb..0fcec51730 100644 --- a/teshsuite/simdag/platforms/flatifier.c +++ b/teshsuite/simdag/platforms/flatifier.c @@ -74,9 +74,9 @@ static void create_environment(xbt_os_timer_t parse_time, const char *platformFi { xbt_ex_t e; TRY { - xbt_os_timer_start(parse_time); + xbt_os_cputimer_start(parse_time); SD_create_environment(platformFile); - xbt_os_timer_stop(parse_time); + xbt_os_cputimer_stop(parse_time); } CATCH(e) { xbt_die("Error while loading %s: %s", platformFile, e.msg); -- 2.20.1