Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add some support to bench the sequential and parallel parts of a simulation
authorMartin Quinson <martin.quinson@loria.fr>
Sun, 22 Jul 2012 10:17:20 +0000 (12:17 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Sun, 22 Jul 2012 10:17:20 +0000 (12:17 +0200)
This is activated by defining the TIME_BENCH_AMDAHL macro at compile
time (for example by decomenting its definition in smx_private.h).

This is useful to evaluate the maximal possible speedup of a given
simulation by applying the Amdahl Law.

This could be changed into a command line flag at some point, but we
first have to assess the performance impact of playing that much with
the timers (should be limited, but who knows?).

The initial patch was from Jean-Noel Quintin, thanks for that!

src/simix/smx_context_raw.c
src/simix/smx_global.c
src/simix/smx_private.h

index fa653a7..6c6b435 100644 (file)
@@ -23,7 +23,7 @@ typedef struct s_smx_ctx_raw {
 #ifdef HAVE_VALGRIND_VALGRIND_H
   unsigned int valgrind_stack_id; /* the valgrind stack id */
 #endif
 #ifdef HAVE_VALGRIND_VALGRIND_H
   unsigned int valgrind_stack_id; /* the valgrind stack id */
 #endif
-#ifdef TIME_BENCH
+#ifdef TIME_BENCH_PER_SR
   unsigned int thread;            /* Just for measuring purposes */
 #endif
 } s_smx_ctx_raw_t, *smx_ctx_raw_t;
   unsigned int thread;            /* Just for measuring purposes */
 #endif
 } s_smx_ctx_raw_t, *smx_ctx_raw_t;
@@ -192,7 +192,7 @@ void raw_swapcontext(raw_stack_t* old, raw_stack_t new) {
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_context);
 
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_context);
 
-#ifdef TIME_BENCH
+#ifdef TIME_BENCH_PER_SR
 #include "xbt/xbt_os_time.h"
 #define NUM_THREADS 4
 static xbt_os_timer_t timer;
 #include "xbt/xbt_os_time.h"
 #define NUM_THREADS 4
 static xbt_os_timer_t timer;
@@ -259,7 +259,7 @@ void SIMIX_ctx_raw_factory_init(smx_context_factory_t *factory)
     (*factory)->runall = smx_ctx_raw_runall_serial;
     (*factory)->suspend = smx_ctx_raw_suspend_serial;
   }
     (*factory)->runall = smx_ctx_raw_runall_serial;
     (*factory)->suspend = smx_ctx_raw_suspend_serial;
   }
-#ifdef TIME_BENCH
+#ifdef TIME_BENCH_PER_SR
   timer = xbt_os_timer_new();
 #endif
 }
   timer = xbt_os_timer_new();
 #endif
 }
@@ -270,7 +270,7 @@ void SIMIX_ctx_raw_factory_init(smx_context_factory_t *factory)
  */
 static int smx_ctx_raw_factory_finalize(smx_context_factory_t *factory)
 {
  */
 static int smx_ctx_raw_factory_finalize(smx_context_factory_t *factory)
 {
-#ifdef TIME_BENCH
+#ifdef TIME_BENCH_PER_SR
   XBT_CRITICAL("Total wasted time in %u SR: %lf", sr_count, time_wasted_sr);
   XBT_CRITICAL("Total wasted time in %u SSR: %lf", ssr_count, time_wasted_ssr);
 #endif
   XBT_CRITICAL("Total wasted time in %u SR: %lf", sr_count, time_wasted_sr);
   XBT_CRITICAL("Total wasted time in %u SSR: %lf", ssr_count, time_wasted_ssr);
 #endif
@@ -410,7 +410,7 @@ static void smx_ctx_raw_resume_serial(smx_process_t first_process)
       ((smx_ctx_raw_t) context)->stack_top);
 }
 
       ((smx_ctx_raw_t) context)->stack_top);
 }
 
-#ifdef TIME_BENCH
+#ifdef TIME_BENCH_PER_SR
 static void smx_ctx_raw_runall_serial(xbt_dynar_t processes)
 {
   smx_process_t process;
 static void smx_ctx_raw_runall_serial(xbt_dynar_t processes)
 {
   smx_process_t process;
index da1f2cc..db0f051 100644 (file)
@@ -59,6 +59,11 @@ void SIMIX_global_init(int *argc, char **argv)
   if (!simix_global) {
     simix_global = xbt_new0(s_smx_global_t, 1);
 
   if (!simix_global) {
     simix_global = xbt_new0(s_smx_global_t, 1);
 
+#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);
+#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);
     simix_global->process_list =
     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);
     simix_global->process_list =
@@ -107,7 +112,7 @@ void SIMIX_global_init(int *argc, char **argv)
  */
 void SIMIX_clean(void)
 {
  */
 void SIMIX_clean(void)
 {
-#ifdef TIME_BENCH
+#ifdef TIME_BENCH_PER_SR
   smx_ctx_raw_new_sr();
 #endif
 
   smx_ctx_raw_new_sr();
 #endif
 
@@ -143,6 +148,15 @@ void SIMIX_clean(void)
 
   surf_exit();
 
 
   surf_exit();
 
+#ifdef TIME_BENCH_AMDAHL
+  xbt_os_timer_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));
+  xbt_os_timer_free(simix_global->timer_seq);
+  xbt_os_timer_free(simix_global->timer_par);
+#endif
+
   xbt_mallocator_free(simix_global->action_mallocator);
   xbt_free(simix_global);
   simix_global = NULL;
   xbt_mallocator_free(simix_global->action_mallocator);
   xbt_free(simix_global);
   simix_global = NULL;
@@ -196,7 +210,7 @@ void SIMIX_run(void)
   do {
     XBT_DEBUG("New Schedule Round; size(queue)=%lu",
         xbt_dynar_length(simix_global->process_to_run));
   do {
     XBT_DEBUG("New Schedule Round; size(queue)=%lu",
         xbt_dynar_length(simix_global->process_to_run));
-#ifdef TIME_BENCH
+#ifdef TIME_BENCH_PER_SR
     smx_ctx_raw_new_sr();
 #endif
     while (!xbt_dynar_is_empty(simix_global->process_to_run)) {
     smx_ctx_raw_new_sr();
 #endif
     while (!xbt_dynar_is_empty(simix_global->process_to_run)) {
@@ -204,7 +218,15 @@ void SIMIX_run(void)
               xbt_dynar_length(simix_global->process_to_run));
 
       /* Run all processes that are ready to run, possibly in parallel */
               xbt_dynar_length(simix_global->process_to_run));
 
       /* 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);
+#endif
       SIMIX_process_runall();
       SIMIX_process_runall();
+#ifdef TIME_BENCH_AMDAHL
+      xbt_os_timer_stop(simix_global->timer_par);
+      xbt_os_timer_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 */
       xbt_dynar_three_way_partition(simix_global->process_that_ran, process_syscall_color);
 
       /* Move all killing processes to the end of the list, because killing a process that have an ongoing simcall is a bad idea */
       xbt_dynar_three_way_partition(simix_global->process_that_ran, process_syscall_color);
index 472d523..8dcf056 100644 (file)
@@ -14,6 +14,7 @@
 #include "xbt/dict.h"
 #include "xbt/mallocator.h"
 #include "xbt/config.h"
 #include "xbt/dict.h"
 #include "xbt/mallocator.h"
 #include "xbt/config.h"
+#include "xbt/xbt_os_time.h"
 #include "xbt/function_types.h"
 #include "xbt/ex_interface.h"
 #include "instr/instr_private.h"
 #include "xbt/function_types.h"
 #include "xbt/ex_interface.h"
 #include "instr/instr_private.h"
@@ -25,7 +26,8 @@
 #include "smx_synchro_private.h"
 
 /* Define only for SimGrid benchmarking purposes */
 #include "smx_synchro_private.h"
 
 /* Define only for SimGrid benchmarking purposes */
-#undef TIME_BENCH
+//#define TIME_BENCH_PER_SR /* this aims at measuring the time spent in each scheduling round per each thread. The code is thus run in sequential to bench separately each SSR */
+//#define TIME_BENCH_AMDAHL /* this aims at measuring the porting of time that could be parallelized at maximum (to get the optimal speedup by applying the amdahl law). */
 
 /********************************** Simix Global ******************************/
 typedef struct s_smx_global {
 
 /********************************** Simix Global ******************************/
 typedef struct s_smx_global {
@@ -41,6 +43,11 @@ typedef struct s_smx_global {
   void_pfn_smxprocess_t cleanup_process_function;
   xbt_mallocator_t action_mallocator;
   void_pfn_smxhost_t autorestart;
   void_pfn_smxprocess_t cleanup_process_function;
   xbt_mallocator_t action_mallocator;
   void_pfn_smxhost_t autorestart;
+
+#ifdef TIME_BENCH_AMDAHL
+  xbt_os_timer_t timer_seq; /* used to bench the sequential and parallel parts of the simulation, if requested to */
+  xbt_os_timer_t timer_par;
+#endif
 } s_smx_global_t, *smx_global_t;
 
 extern smx_global_t simix_global;
 } s_smx_global_t, *smx_global_t;
 
 extern smx_global_t simix_global;