Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Simplify the handling of SIMIX requests.
authorArnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
Thu, 5 May 2011 17:02:18 +0000 (19:02 +0200)
committerArnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
Thu, 5 May 2011 17:02:18 +0000 (19:02 +0200)
Re-use the list of process_to_run instead of swags of requests, and
ensures the requests are correctly ordered, even on parallel run with
the thread factory.

src/simix/private.h
src/simix/smurf_private.h
src/simix/smx_context_raw.c
src/simix/smx_context_sysv.c
src/simix/smx_context_thread.c
src/simix/smx_global.c
src/simix/smx_smurf.c

index cce6355..874f4b4 100644 (file)
@@ -31,6 +31,7 @@
 typedef struct s_smx_global {
   smx_context_factory_t context_factory;
   xbt_dynar_t process_to_run;
+  xbt_dynar_t process_that_ran;
   xbt_swag_t process_list;
   xbt_swag_t process_to_destroy;
   smx_process_t maestro_process;
index 1c15a37..251b40f 100644 (file)
@@ -119,7 +119,6 @@ SIMIX_REQ_LIST
  * \brief Represents a SIMIX request.
  */
 typedef struct s_smx_req {
-  s_xbt_swag_hookup_t reqtable_hookup;
   e_smx_req_t call;
   smx_process_t issuer;
 
@@ -505,11 +504,7 @@ typedef struct s_smx_req {
 
 /******************************** General *************************************/
 
-void SIMIX_request_init(void);
-void SIMIX_request_destroy(void);
-xbt_swag_t SIMIX_request_get_reqlist(int thread_pid);
 void SIMIX_request_push(void);
-smx_req_t SIMIX_request_pop(void);
 void SIMIX_request_answer(smx_req_t);
 void SIMIX_request_pre(smx_req_t, int);
 void SIMIX_request_post(smx_action_t);
index 8a9a6f5..28f7831 100644 (file)
@@ -316,8 +316,6 @@ static void smx_ctx_raw_runall_serial(xbt_dynar_t processes)
     XBT_VERB("Time SSR thread %u = %lf (max %lf)", cursor, time_thread_ssr[cursor], tmax);
     time_wasted_ssr += tmax - time_thread_ssr[cursor];
   }
-
-  xbt_dynar_reset(processes);
 }
 
 void smx_ctx_raw_new_sr(void);
@@ -349,7 +347,6 @@ static void smx_ctx_raw_runall_serial(xbt_dynar_t processes)
     XBT_DEBUG("Schedule item %u of %lu",cursor,xbt_dynar_length(processes));
     smx_ctx_raw_resume(process);
   }
-  xbt_dynar_reset(processes);
 }
 #endif
 
@@ -358,7 +355,6 @@ static void smx_ctx_raw_runall_parallel(xbt_dynar_t processes)
 #ifdef CONTEXT_THREADS
   xbt_parmap_apply(parmap, (void_f_pvoid_t)smx_ctx_raw_resume, processes);
 #endif
-  xbt_dynar_reset(processes);
 }
 
 static smx_context_t smx_ctx_raw_self_parallel(void)
index 24189f8..caa6d45 100644 (file)
@@ -215,7 +215,6 @@ void smx_ctx_sysv_runall(xbt_dynar_t processes)
     XBT_DEBUG("Schedule item %u of %lu",cursor,xbt_dynar_length(processes));
     smx_ctx_sysv_resume(process->context);
   }
-  xbt_dynar_reset(processes);
 }
 
 void smx_ctx_sysv_resume_parallel(smx_process_t process)
@@ -234,7 +233,6 @@ void smx_ctx_sysv_runall_parallel(xbt_dynar_t processes)
 #ifdef CONTEXT_THREADS
   xbt_parmap_apply(parmap, (void_f_pvoid_t)smx_ctx_sysv_resume_parallel, processes);
 #endif
-  xbt_dynar_reset(processes);
 }
 
 smx_context_t smx_ctx_sysv_self_parallel(void)
index eddfe9f..a602a22 100644 (file)
@@ -180,7 +180,6 @@ static void smx_ctx_thread_runall_serial(xbt_dynar_t processes)
     xbt_os_sem_release(((smx_ctx_thread_t) process->context)->begin);
     xbt_os_sem_acquire(((smx_ctx_thread_t) process->context)->end);
   }
-  xbt_dynar_reset(processes);
 }
 
 static void smx_ctx_thread_runall_parallel(xbt_dynar_t processes)
@@ -194,7 +193,6 @@ static void smx_ctx_thread_runall_parallel(xbt_dynar_t processes)
   xbt_dynar_foreach(processes, index, process) {
      xbt_os_sem_acquire(((smx_ctx_thread_t) process->context)->end);
   }
-  xbt_dynar_reset(processes);
 }
 
 static smx_context_t smx_ctx_thread_self(void)
index cd48273..89fec34 100644 (file)
@@ -78,7 +78,8 @@ void SIMIX_global_init(int *argc, char **argv)
 
     simix_global = xbt_new0(s_smx_global_t, 1);
 
-    simix_global->process_to_run = xbt_dynar_new(sizeof(void *), NULL);
+    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 =
         xbt_swag_new(xbt_swag_offset(proc, process_hookup));
     simix_global->process_to_destroy =
@@ -102,9 +103,6 @@ void SIMIX_global_init(int *argc, char **argv)
     __xbt_running_ctx_fetch = SIMIX_process_get_running_context;
     __xbt_ex_terminate = SIMIX_process_exception_terminate;
 
-    /* Initialize request mechanism */
-    SIMIX_request_init();
-
     /* Initialize the SIMIX network module */
     SIMIX_network_init();
 
@@ -136,12 +134,10 @@ void SIMIX_clean(void)
   /* Exit the SIMIX network module */
   SIMIX_network_exit();
 
-  /* Exit request mechanism */
-  SIMIX_request_destroy();
-
   xbt_heap_free(simix_timers);
   /* Free the remaining data structures */
   xbt_dynar_free(&simix_global->process_to_run);
+  xbt_dynar_free(&simix_global->process_that_ran);
   xbt_swag_free(simix_global->process_to_destroy);
   xbt_swag_free(simix_global->process_list);
   simix_global->process_list = NULL;
@@ -188,7 +184,7 @@ XBT_INLINE double SIMIX_get_clock(void)
 void SIMIX_run(void)
 {
   double time = 0;
-  smx_req_t req;
+  smx_process_t process;
   xbt_swag_t set;
   surf_action_t action;
   smx_timer_t timer;
@@ -205,9 +201,15 @@ void SIMIX_run(void)
       XBT_DEBUG("New Sub-Schedule Round; size(queue)=%lu",
               xbt_dynar_length(simix_global->process_to_run));
       SIMIX_context_runall(simix_global->process_to_run);
-      while ((req = SIMIX_request_pop())) {
-        XBT_DEBUG("Handling request %p", req);
-        SIMIX_request_pre(req, 0);
+      xbt_dynar_t tmp = simix_global->process_that_ran;
+      simix_global->process_that_ran = simix_global->process_to_run;
+      simix_global->process_to_run = tmp;
+      xbt_dynar_reset(simix_global->process_to_run);
+      xbt_dynar_foreach(simix_global->process_that_ran, iter, process) {
+        if (process->request.call != REQ_NO_REQ) {
+          XBT_DEBUG("Handling request %p", &process->request);
+          SIMIX_request_pre(&process->request, 0);
+        }
       }
     }
 
index 840166a..6a65331 100644 (file)
@@ -5,57 +5,19 @@
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_smurf, simix,
                                 "Logging specific to SIMIX (SMURF)");
 
-/* Tables with the requests to handle at the end of this round of scheduling
- * user processes. There is one for each thread of execution. */
-static xbt_swag_t *req_lists;
-
-void SIMIX_request_init(void)
-{
-  s_smx_req_t req;
-  int i, nthreads = SIMIX_context_get_nthreads();
-
-  req_lists = xbt_new0(xbt_swag_t, nthreads);
-  for(i=0; i < nthreads; i++)
-    req_lists[i] = xbt_swag_new(xbt_swag_offset(req, reqtable_hookup));
-
-}
-
-void SIMIX_request_destroy(void)
-{
-  int i, nthreads = SIMIX_context_get_nthreads();
-
-  for(i=0; i < nthreads; i++)
-    xbt_swag_free(req_lists[i]);
-
-  xbt_free(req_lists);
-}
-
-xbt_swag_t SIMIX_request_get_reqlist(int thread_pid)
-{
-  return req_lists[thread_pid];
-}
-
 /* FIXME: we may want to save the initialization of issuer... */
-XBT_INLINE smx_req_t SIMIX_req_mine() {
+XBT_INLINE smx_req_t SIMIX_req_mine()
+{
   smx_process_t issuer = SIMIX_process_self();
   return &issuer->request;
 }
 
 void SIMIX_request_push()
 {
-  xbt_swag_t req_table;
   smx_process_t issuer = SIMIX_process_self();
 
   if (issuer != simix_global->maestro_process){
     issuer->request.issuer = issuer;
-    req_table = SIMIX_request_get_reqlist(SIMIX_context_get_thread_id());
-
-    xbt_swag_insert_at_tail(&issuer->request, req_table);
-
-    XBT_DEBUG("Pushed request %s (%d) of %s",
-        SIMIX_request_name(issuer->request.call), issuer->request.call,
-        issuer->name);
-
     XBT_DEBUG("Yield process '%s' on request of type %s (%d)", issuer->name,
         SIMIX_request_name(issuer->request.call), issuer->request.call);
     SIMIX_process_yield();
@@ -64,25 +26,6 @@ void SIMIX_request_push()
   }
 }
 
-smx_req_t SIMIX_request_pop(void)
-{
-  int i;
-  smx_req_t req = NULL;
-  int nthreads = SIMIX_context_get_nthreads();
-
-  for(i=0; i < nthreads; i++){
-    if((req = xbt_swag_extract(req_lists[i]))){
-      XBT_DEBUG("Popped request %s (%d) of %s",
-          SIMIX_request_name(req->issuer->request.call),
-          req->issuer->request.call,
-          req->issuer->name);
-      return req;
-    }
-  }
-
-  return NULL;
-}
-
 void SIMIX_request_answer(smx_req_t req)
 {
   if (req->issuer != simix_global->maestro_process){