Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix SIMIX_post_io. For now SIMIX_req_file_read makes a Surf sleep action.
[simgrid.git] / src / simix / smx_smurf.c
index cc612ae..6f243b5 100644 (file)
@@ -5,88 +5,33 @@
 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)
+XBT_INLINE smx_req_t SIMIX_req_mine()
 {
-  return req_lists[thread_pid];
-}
-
-/* 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()
+/**
+ * \brief Makes the current process do a request to the kernel and yields
+ * until completion.
+ * \param self the current process
+ */
+void SIMIX_request_push(smx_process_t self)
 {
-  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();
+  if (self != simix_global->maestro_process) {
+    XBT_DEBUG("Yield process '%s' on request of type %s (%d)", self->name,
+        SIMIX_request_name(self->request.call), self->request.call);
+    SIMIX_process_yield(self);
   } else {
-    SIMIX_request_pre(&issuer->request, 0);
+    SIMIX_request_pre(&self->request, 0);
   }
 }
 
-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){
-    XBT_DEBUG("Answer request %s (%d)", SIMIX_request_name(req->call), req->call);
+    XBT_DEBUG("Answer request %s (%d) issued by %s (%p)", SIMIX_request_name(req->call), req->call,
+        req->issuer->name, req->issuer);
     req->issuer->request.call = REQ_NO_REQ;
     xbt_dynar_push_as(simix_global->process_to_run, smx_process_t, req->issuer);
   }
@@ -94,6 +39,7 @@ void SIMIX_request_answer(smx_req_t req)
 
 void SIMIX_request_pre(smx_req_t req, int value)
 {
+  XBT_DEBUG("Handling request %p: %s", req, SIMIX_request_name(req->call));
 
   switch (req->call) {
     case REQ_COMM_TEST:
@@ -125,6 +71,7 @@ void SIMIX_request_pre(smx_req_t req, int value)
           req->comm_send.src_buff,
           req->comm_send.src_buff_size,
           req->comm_send.match_fun,
+          NULL, /* no clean function since it's not detached */
           req->comm_send.data,
           0);
       SIMIX_pre_comm_wait(req, comm, req->comm_send.timeout, 0);
@@ -140,6 +87,7 @@ void SIMIX_request_pre(smx_req_t req, int value)
           req->comm_isend.src_buff,
           req->comm_isend.src_buff_size,
           req->comm_isend.match_fun,
+          req->comm_isend.clean_fun,
           req->comm_isend.data,
           req->comm_isend.detached);
       SIMIX_request_answer(req);
@@ -377,9 +325,8 @@ void SIMIX_request_pre(smx_req_t req, int value)
       break;
 
     case REQ_PROCESS_CHANGE_HOST:
-      SIMIX_process_change_host(
+      SIMIX_pre_process_change_host(
          req->process_change_host.process,
-         req->process_change_host.source,
          req->process_change_host.dest);
       SIMIX_request_answer(req);
       break;
@@ -534,12 +481,17 @@ void SIMIX_request_pre(smx_req_t req, int value)
       SIMIX_request_answer(req);
       break;
 
+    case REQ_FILE_READ:
+      SIMIX_pre_file_read(req);
+      break;
+
     case REQ_NO_REQ:
       THROWF(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;
+
   }
 }
 
@@ -565,6 +517,7 @@ void SIMIX_request_post(smx_action_t action)
       break;
 
     case SIMIX_ACTION_IO:
+      SIMIX_post_io(action);
       break;
   }
 }