Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
more verbose on problem
[simgrid.git] / src / simix / smx_smurf.c
index 0b61bea..60e64b1 100644 (file)
@@ -5,58 +5,60 @@
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_smurf, simix,
                                 "Logging specific to SIMIX (SMURF)");
 
-static xbt_dynar_t req_vector;
-static xbt_os_mutex_t sync_req_vector;
+/* Requests to handle at the end of this round of scheduling user processes */
+static xbt_heap_t req_todo;
+/* to protect the write actions in the heap */
+static xbt_os_mutex_t sync_req_positions;
 
 void SIMIX_request_init(void)
 {
-  sync_req_vector = xbt_os_mutex_init();
-  req_vector = xbt_dynar_new(sizeof(void *), NULL);
+  req_todo = xbt_heap_new(5,NULL);
+  sync_req_positions = xbt_os_mutex_init();
 }
 
 void SIMIX_request_destroy(void)
 {
-  xbt_os_mutex_destroy(sync_req_vector);
-  xbt_dynar_free(&req_vector);
+  xbt_heap_free(req_todo);
+  xbt_os_mutex_destroy(sync_req_positions);
 }
 
-void SIMIX_request_push(smx_req_t req)
+/* FIXME: we may want to save the initialization of issuer... */
+XBT_INLINE smx_req_t SIMIX_req_mine() {
+  smx_process_t issuer = SIMIX_process_self();
+  return &issuer->request;
+}
+
+void SIMIX_request_push()
 {
-  req->issuer = SIMIX_process_self();
-  if (req->issuer != simix_global->maestro_process){
+  smx_process_t issuer = SIMIX_process_self();
+  if (issuer != simix_global->maestro_process){
+    issuer->request.issuer = issuer;
+
     if (_surf_parallel_contexts)
-      xbt_os_mutex_acquire(sync_req_vector);
-    xbt_dynar_set_as(req_vector, req->issuer->pid, smx_req_t, req);
+      xbt_os_mutex_acquire(sync_req_positions);
+    xbt_heap_push(req_todo,&issuer->request,issuer->pid);
+    DEBUG3("Pushed request %d of %s; now %d requests waiting",
+        issuer->request.call,issuer->name,xbt_heap_size(req_todo));
     if (_surf_parallel_contexts)
-      xbt_os_mutex_release(sync_req_vector);
-    req->issuer->request = req;
-    DEBUG2("Yield process '%s' on request of type %d", req->issuer->name, req->call);
+      xbt_os_mutex_release(sync_req_positions);
+
+    DEBUG2("Yield process '%s' on request of type %d", issuer->name, issuer->request.call);
     SIMIX_process_yield();
   } else {
-    SIMIX_request_pre(req);
+    SIMIX_request_pre(&issuer->request);
   }
 }
 
 smx_req_t SIMIX_request_pop(void)
 {
-  smx_req_t request = NULL;
-  if (_surf_parallel_contexts)
-    xbt_os_mutex_acquire(sync_req_vector);
-  while (xbt_dynar_length(req_vector)){
-    request = xbt_dynar_pop_as(req_vector, smx_req_t);
-    if (request)
-      break;
-  }
-  if (_surf_parallel_contexts)
-    xbt_os_mutex_release(sync_req_vector);
-  return request;
+  return xbt_heap_pop(req_todo);
 }
 
 void SIMIX_request_answer(smx_req_t req)
 {
   if (req->issuer != simix_global->maestro_process){
-    req->issuer->request = NULL;    
-    xbt_swag_insert(req->issuer, simix_global->process_to_run);
+    req->issuer->request.call = REQ_NO_REQ;
+    xbt_dynar_push_as(simix_global->process_to_run, smx_process_t, req->issuer);
   }
 }
 
@@ -102,6 +104,12 @@ int SIMIX_request_is_enabled(smx_req_t req)
 void SIMIX_request_pre(smx_req_t req)
 {
   switch (req->call) {
+  case REQ_NO_REQ:
+    THROW2(arg_error,0,"Asked to do the noop syscall on %s@%s",
+        SIMIX_process_get_name(req->issuer),
+        SIMIX_host_get_name(SIMIX_process_get_host(req->issuer))
+        );
+    break;
 
     case REQ_HOST_GET_BY_NAME:
       req->host_get_by_name.result =
@@ -369,8 +377,13 @@ void SIMIX_request_pre(smx_req_t req)
       SIMIX_request_answer(req);
       break;
 
-    case REQ_COMM_GET_DATA:
-      req->comm_get_data.result = SIMIX_comm_get_data(req->comm_get_data.comm);
+    case REQ_COMM_GET_SRC_DATA:
+      req->comm_get_src_data.result = SIMIX_comm_get_src_data(req->comm_get_src_data.comm);
+      SIMIX_request_answer(req);
+      break;
+
+    case REQ_COMM_GET_DST_DATA:
+      req->comm_get_dst_data.result = SIMIX_comm_get_dst_data(req->comm_get_dst_data.comm);
       SIMIX_request_answer(req);
       break;