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 0f34218..6f243b5 100644 (file)
@@ -5,67 +5,33 @@
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_smurf, simix,
                                 "Logging specific to SIMIX (SMURF)");
 
-/* 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)
+XBT_INLINE smx_req_t SIMIX_req_mine()
 {
-  req_todo = xbt_heap_new(5,NULL);
-  sync_req_positions = xbt_os_mutex_init();
-}
-
-void SIMIX_request_destroy(void)
-{
-  xbt_heap_free(req_todo);
-  xbt_os_mutex_destroy(sync_req_positions);
-}
-
-/* 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)
 {
-  smx_process_t issuer = SIMIX_process_self();
-  if (issuer != simix_global->maestro_process){
-    issuer->request.issuer = issuer;
-
-    if (smx_parallel_contexts)
-      xbt_os_mutex_acquire(sync_req_positions);
-    xbt_heap_push(req_todo,&issuer->request,issuer->pid);
-    DEBUG4("Pushed request %s (%d) of %s; now %d requests waiting",
-        SIMIX_request_name(issuer->request.call), issuer->request.call,
-        issuer->name,xbt_heap_size(req_todo));
-    if (smx_parallel_contexts)
-      xbt_os_mutex_release(sync_req_positions);
-
-    DEBUG3("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)
-{
-  smx_req_t req = xbt_heap_pop(req_todo);
-  if(req)
-    DEBUG4("Popped request %s (%d) of %s; now %d requests waiting",
-        SIMIX_request_name(req->issuer->request.call),
-        req->issuer->request.call,
-        req->issuer->name,xbt_heap_size(req_todo));
-  return req;
-}
-
 void SIMIX_request_answer(smx_req_t req)
 {
   if (req->issuer != simix_global->maestro_process){
-    DEBUG2("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);
   }
@@ -73,8 +39,9 @@ void SIMIX_request_answer(smx_req_t req)
 
 void SIMIX_request_pre(smx_req_t req, int value)
 {
-  switch (req->call) {
+  XBT_DEBUG("Handling request %p: %s", req, SIMIX_request_name(req->call));
 
+  switch (req->call) {
     case REQ_COMM_TEST:
       SIMIX_pre_comm_test(req);
       break;
@@ -84,13 +51,33 @@ void SIMIX_request_pre(smx_req_t req, int value)
       break;
 
     case REQ_COMM_WAIT:
-      SIMIX_pre_comm_wait(req, value);
+      SIMIX_pre_comm_wait(req,
+          req->comm_wait.comm,
+          req->comm_wait.timeout,
+          value);
       break;
 
     case REQ_COMM_WAITANY:
       SIMIX_pre_comm_waitany(req, value);
       break;
 
+    case REQ_COMM_SEND:
+    {
+      smx_action_t comm = SIMIX_comm_isend(
+          req->issuer,
+          req->comm_send.rdv,
+          req->comm_send.task_size,
+          req->comm_send.rate,
+          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);
+      break;
+    }
+
     case REQ_COMM_ISEND:
       req->comm_isend.result = SIMIX_comm_isend(
           req->issuer,
@@ -100,10 +87,25 @@ 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.data);
+          req->comm_isend.clean_fun,
+          req->comm_isend.data,
+          req->comm_isend.detached);
       SIMIX_request_answer(req);
       break;
 
+    case REQ_COMM_RECV:
+    {
+      smx_action_t comm = SIMIX_comm_irecv(
+          req->issuer,
+          req->comm_recv.rdv,
+          req->comm_recv.dst_buff,
+          req->comm_recv.dst_buff_size,
+          req->comm_recv.match_fun,
+          req->comm_recv.data);
+      SIMIX_pre_comm_wait(req, comm, req->comm_recv.timeout, 0);
+      break;
+    }
+
     case REQ_COMM_IRECV:
       req->comm_irecv.result = SIMIX_comm_irecv(
           req->issuer,
@@ -147,30 +149,6 @@ void SIMIX_request_pre(smx_req_t req, int value)
       SIMIX_request_answer(req);
       break;
 
-    case REQ_COMM_GET_SRC_BUFF:
-      req->comm_get_src_buff.result =
-          SIMIX_comm_get_src_buff(req->comm_get_src_buff.comm);
-      SIMIX_request_answer(req);
-      break;
-
-    case REQ_COMM_GET_DST_BUFF:
-      req->comm_get_dst_buff.result =
-          SIMIX_comm_get_dst_buff(req->comm_get_dst_buff.comm);
-      SIMIX_request_answer(req);
-      break;
-
-    case REQ_COMM_GET_SRC_BUFF_SIZE:
-      req->comm_get_src_buff_size.result =
-          SIMIX_comm_get_src_buff_size(req->comm_get_src_buff_size.comm);
-      SIMIX_request_answer(req);
-      break;
-
-    case REQ_COMM_GET_DST_BUFF_SIZE:
-      req->comm_get_dst_buff_size.result =
-          SIMIX_comm_get_dst_buff_size(req->comm_get_dst_buff_size.comm);
-      SIMIX_request_answer(req);
-      break;
-
     case REQ_COMM_GET_SRC_PROC:
       req->comm_get_src_proc.result =
           SIMIX_comm_get_src_proc(req->comm_get_src_proc.comm);
@@ -215,7 +193,7 @@ void SIMIX_request_pre(smx_req_t req, int value)
       break;
 
     case REQ_RDV_GET_HEAD:
-      req->rdv_get_head.result =        SIMIX_rdv_get_head(req->rdv_get_head.rdv);
+      req->rdv_get_head.result = SIMIX_rdv_get_head(req->rdv_get_head.rdv);
       SIMIX_request_answer(req);
       break;
 
@@ -268,7 +246,8 @@ void SIMIX_request_pre(smx_req_t req, int value)
       req->host_execute.result = SIMIX_host_execute(
          req->host_execute.name,
          req->host_execute.host,
-         req->host_execute.computation_amount);
+         req->host_execute.computation_amount,
+         req->host_execute.priority);
       SIMIX_request_answer(req);
       break;
 
@@ -318,7 +297,8 @@ void SIMIX_request_pre(smx_req_t req, int value)
       break;
 
     case REQ_PROCESS_CREATE:
-      req->process_create.result = SIMIX_process_create(
+      SIMIX_process_create(
+          req->process_create.process,
          req->process_create.name,
          req->process_create.code,
          req->process_create.data,
@@ -330,14 +310,23 @@ void SIMIX_request_pre(smx_req_t req, int value)
       break;
 
     case REQ_PROCESS_KILL:
-      SIMIX_process_kill(req->process_kill.process, req->issuer);
+      SIMIX_process_kill(req->process_kill.process);
+      SIMIX_request_answer(req);
+      break;
+
+    case REQ_PROCESS_KILLALL:
+      SIMIX_process_killall(req->issuer);
+      SIMIX_request_answer(req);
+      break;
+
+    case REQ_PROCESS_CLEANUP:
+      SIMIX_process_cleanup(req->process_cleanup.process);
       SIMIX_request_answer(req);
       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;
@@ -492,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:
-      THROW2(arg_error,0,"Asked to do the noop syscall on %s@%s",
+      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;
+
   }
 }
 
@@ -523,6 +517,7 @@ void SIMIX_request_post(smx_action_t action)
       break;
 
     case SIMIX_ACTION_IO:
+      SIMIX_post_io(action);
       break;
   }
 }