Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Simplify process cleanup calls between SIMIX and MSG
[simgrid.git] / src / simix / smx_context_raw.c
index c03fb50..c4848f8 100644 (file)
@@ -161,14 +161,14 @@ static smx_context_factory_t raw_factory;
 
 #include "xbt/xbt_os_time.h"
 static xbt_os_timer_t timer;
-static double totaltime;
+static double totaltime = 0;
 
 
 static void smx_ctx_raw_wrapper(smx_ctx_raw_t context);
 
 static int smx_ctx_raw_factory_finalize(smx_context_factory_t *factory)
 { 
-  VERB1("Total User Time: %lf", totaltime);
+  XBT_VERB("Total User Time: %lf", totaltime);
   if(parmap)
       xbt_parmap_destroy(parmap);
   return smx_ctx_base_factory_finalize(factory);
@@ -229,11 +229,9 @@ static void smx_ctx_raw_free(smx_context_t context)
 static void smx_ctx_raw_suspend(smx_context_t context)
 {
   smx_current_context = (smx_context_t)maestro_raw_context;
-  xbt_os_timer_stop(timer);
   raw_swapcontext(
       &((smx_ctx_raw_t) context)->stack_top,
       ((smx_ctx_raw_t) context)->old_stack_top);
-  xbt_os_timer_start(timer);
 }
 
 static void smx_ctx_raw_stop(smx_context_t context)
@@ -244,7 +242,6 @@ static void smx_ctx_raw_stop(smx_context_t context)
 
 static void smx_ctx_raw_wrapper(smx_ctx_raw_t context)
 { 
-  xbt_os_timer_start(timer);
   (context->super.code) (context->super.argc, context->super.argv);
 
   smx_ctx_raw_stop((smx_context_t) context);
@@ -257,18 +254,19 @@ static void smx_ctx_raw_resume(smx_process_t process)
   raw_swapcontext(
       &((smx_ctx_raw_t) context)->old_stack_top,
       ((smx_ctx_raw_t) context)->stack_top);
-  totaltime += xbt_os_timer_elapsed(timer);
 }
 
-
 static void smx_ctx_raw_runall_serial(xbt_dynar_t processes)
 {
   smx_process_t process;
   unsigned int cursor;
 
   xbt_dynar_foreach(processes, cursor, process) {
-    DEBUG2("Schedule item %u of %lu",cursor,xbt_dynar_length(processes));
+    XBT_DEBUG("Schedule item %u of %lu",cursor,xbt_dynar_length(processes));
+    xbt_os_timer_start(timer);
     smx_ctx_raw_resume(process);
+    xbt_os_timer_stop(timer);
+    totaltime += xbt_os_timer_elapsed(timer);
   }
   xbt_dynar_reset(processes);
 }
@@ -291,12 +289,12 @@ static int smx_ctx_raw_get_thread_id(){
 static void smx_ctx_raw_runall(xbt_dynar_t processes)
 {
   if (xbt_dynar_length(processes) >= SIMIX_context_get_parallel_threshold()) {
-    DEBUG1("Runall // %lu", xbt_dynar_length(processes));
+    XBT_DEBUG("Runall // %lu", xbt_dynar_length(processes));
     raw_factory->self = smx_ctx_raw_self_parallel;
     raw_factory->get_thread_id = smx_ctx_raw_get_thread_id;
     smx_ctx_raw_runall_parallel(processes);
   } else {
-    DEBUG1("Runall serial %lu", xbt_dynar_length(processes));
+    XBT_DEBUG("Runall serial %lu", xbt_dynar_length(processes));
     raw_factory->self = smx_ctx_base_self;
     raw_factory->get_thread_id = smx_ctx_base_get_thread_id;
     smx_ctx_raw_runall_serial(processes);
@@ -305,7 +303,7 @@ static void smx_ctx_raw_runall(xbt_dynar_t processes)
 
 void SIMIX_ctx_raw_factory_init(smx_context_factory_t *factory)
 {
-  VERB0("Using raw contexts. Because the glibc is just not good enough for us.");
+  XBT_VERB("Using raw contexts. Because the glibc is just not good enough for us.");
   smx_ctx_base_factory_init(factory);
 
   (*factory)->finalize  = smx_ctx_raw_factory_finalize;