Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Starting simix mecanism for io.
authornavarro <navarro@caraja.(none)>
Thu, 19 Jan 2012 15:31:41 +0000 (16:31 +0100)
committernavarro <navarro@caraja.(none)>
Thu, 19 Jan 2012 15:32:02 +0000 (16:32 +0100)
buildtools/Cmake/DefinePackages.cmake
include/simix/simix.h
include/xbt/ex.h
src/simix/io_private.h [new file with mode: 0644]
src/simix/private.h
src/simix/smurf_private.h
src/simix/smx_io.c [new file with mode: 0644]
src/simix/smx_process.c
src/simix/smx_smurf.c
src/simix/smx_user.c

index c30f7ef..b15345e 100644 (file)
@@ -84,6 +84,7 @@ set(EXTRA_DIST
        src/simix/network_private.h
        src/simix/smurf_private.h
        src/simix/synchro_private.h
+       src/simix/io_private.h
        
        src/smpi/private.h
        src/smpi/smpi_mpi_dt_private.h
@@ -249,6 +250,7 @@ set(SIMIX_SRC
        src/simix/smx_user.c
        src/simix/smx_smurf.c
        src/simix/smx_context_raw.c
+       src/simix/smx_io.c
 )
 
 set(MSG_SRC
index df128f6..5878388 100644 (file)
@@ -242,6 +242,8 @@ XBT_PUBLIC(void) SIMIX_req_sem_acquire_timeout(smx_sem_t sem,
 XBT_PUBLIC(unsigned int) SIMIX_req_sem_acquire_any(xbt_dynar_t sems);
 XBT_PUBLIC(int) SIMIX_req_sem_get_capacity(smx_sem_t sem);
 
+XBT_PUBLIC(void) SIMIX_req_file_read(char* name);
+
 const char *SIMIX_request_name(int kind);
 
 SG_END_DECL()
index f1f3cc9..f23bd37 100644 (file)
@@ -262,7 +262,8 @@ typedef enum {
   cancel_error,   /**< an action was canceled */
   thread_error,    /**< error while [un]locking */
   host_error,                            /**< host failed */
-  tracing_error   /**< error during the simulation tracing */
+  tracing_error,   /**< error during the simulation tracing */
+  io_error          /**< disk or file error */
 } xbt_errcat_t;
 
 XBT_PUBLIC(const char *) xbt_ex_catname(xbt_errcat_t cat);
diff --git a/src/simix/io_private.h b/src/simix/io_private.h
new file mode 100644 (file)
index 0000000..bccaf05
--- /dev/null
@@ -0,0 +1,19 @@
+/* Copyright (c) 2007, 2008, 2009, 2010. The SimGrid Team.
+ * All rights reserved.                                                     */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
+#ifndef _SIMIX_IO_PRIVATE_H
+#define _SIMIX_IO_PRIVATE_H
+
+#include "simix/datatypes.h"
+#include "smurf_private.h"
+
+void SIMIX_pre_file_read(smx_req_t req);
+smx_action_t SIMIX_file_read(smx_process_t process, char* name);
+void SIMIX_post_file_read(smx_action_t action);
+void SIMIX_io_destroy(smx_action_t action);
+void SIMIX_io_finish(smx_action_t action);
+
+#endif
index 4032673..6a9bb77 100644 (file)
@@ -19,6 +19,7 @@
 #include "instr/instr_private.h"
 #include "process_private.h"
 #include "host_private.h"
+#include "io_private.h"
 #include "network_private.h"
 #include "smurf_private.h"
 #include "synchro_private.h"
@@ -125,6 +126,10 @@ typedef struct s_smx_action {
       surf_action_t sleep;
     } synchro;
 
+    struct {
+    smx_host_t host;                /* The host that is sleeping */
+    surf_action_t surf_io;
+    } io;
   };
 
 #ifdef HAVE_LATENCY_BOUND_TRACKING
index 6284d5b..b8431a4 100644 (file)
@@ -83,7 +83,8 @@ SIMIX_REQ_ENUM_ELEMENT(REQ_SEM_RELEASE),\
 SIMIX_REQ_ENUM_ELEMENT(REQ_SEM_WOULD_BLOCK),\
 SIMIX_REQ_ENUM_ELEMENT(REQ_SEM_ACQUIRE),\
 SIMIX_REQ_ENUM_ELEMENT(REQ_SEM_ACQUIRE_TIMEOUT),\
-SIMIX_REQ_ENUM_ELEMENT(REQ_SEM_GET_CAPACITY)
+SIMIX_REQ_ENUM_ELEMENT(REQ_SEM_GET_CAPACITY),\
+SIMIX_REQ_ENUM_ELEMENT(REQ_FILE_READ)
 
 /* REQ_COMM_IS_LATENCY_BOUNDED and REQ_SET_CATEGORY make things complicated
  * because they are not always present */
@@ -500,6 +501,10 @@ typedef struct s_smx_req {
       smx_sem_t sem;
       int result;
     } sem_get_capacity;
+
+    struct {
+      char* name;;
+    } file_read;
   };
 } s_smx_req_t, *smx_req_t;
 
diff --git a/src/simix/smx_io.c b/src/simix/smx_io.c
new file mode 100644 (file)
index 0000000..f535e9c
--- /dev/null
@@ -0,0 +1,127 @@
+/* Copyright (c) 2007, 2008, 2009, 2010. The SimGrid Team.
+ * All rights reserved.                                                     */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
+#include "private.h"
+#include "xbt/sysdep.h"
+#include "xbt/log.h"
+#include "xbt/dict.h"
+#include "mc/mc.h"
+
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_io, simix,
+                                "Logging specific to SIMIX (io)");
+
+void SIMIX_pre_file_read(smx_req_t req)
+{
+  smx_action_t action = SIMIX_file_read(req->issuer, req->file_read.name);
+  xbt_fifo_push(action->request_list, req);
+  req->issuer->waiting_action = action;
+}
+
+smx_action_t SIMIX_file_read(smx_process_t process, char* name)
+{
+  smx_action_t action;
+  smx_host_t host = process->smx_host;
+
+  /* check if the host is active */
+  if (surf_workstation_model->extension.
+      workstation.get_state(host->host) != SURF_RESOURCE_ON) {
+    THROWF(host_error, 0, "Host %s failed, you cannot call this function",
+           host->name);
+  }
+
+  action = xbt_mallocator_get(simix_global->action_mallocator);
+  action->type = SIMIX_ACTION_IO;
+  action->name = NULL;
+#ifdef HAVE_TRACING
+  action->category = NULL;
+#endif
+
+  action->io.host = host;
+  //  TODO in surf model disk???
+  //  action->io.surf_io = surf_workstation_model->extension.disk.read(host->host, name),
+    action->io.surf_io = surf_workstation_model->extension.workstation.sleep(host->host, 1.0);
+
+  surf_workstation_model->action_data_set(action->io.surf_io, action);
+  XBT_DEBUG("Create io action %p", action);
+
+  return action;
+}
+
+void SIMIX_post_file_read(smx_action_t action)
+{
+  smx_req_t req;
+
+  while ((req = xbt_fifo_shift(action->request_list))) {
+
+    switch(surf_workstation_model->action_state_get(action->io.surf_io)){
+    case SURF_ACTION_FAILED:
+      action->state = SIMIX_FAILED;
+      break;
+
+    case SURF_ACTION_DONE:
+      action->state = SIMIX_DONE;
+      break;
+
+    default:
+      THROW_IMPOSSIBLE;
+      break;
+    }
+  }
+  /* If there are requests associated with the action, then answer them */
+  if (xbt_fifo_size(action->request_list))
+         SIMIX_io_finish(action);
+}
+
+void SIMIX_io_destroy(smx_action_t action)
+{
+  XBT_DEBUG("Destroy action %p", action);
+  if (action->io.surf_io)
+    action->io.surf_io->model_type->action_unref(action->io.surf_io);
+  xbt_mallocator_release(simix_global->action_mallocator, action);
+}
+
+void SIMIX_io_finish(smx_action_t action)
+{
+  volatile xbt_fifo_item_t item;
+  smx_req_t req;
+
+  xbt_fifo_foreach(action->request_list, item, req, smx_req_t) {
+
+    switch (action->state) {
+
+      case SIMIX_DONE:
+        /* do nothing, action done */
+        break;
+
+      case SIMIX_FAILED:
+        TRY {
+          THROWF(io_error, 0, "IO failed");
+        }
+       CATCH(req->issuer->running_ctx->exception) {
+         req->issuer->doexception = 1;
+       }
+      break;
+
+      case SIMIX_CANCELED:
+        TRY {
+          THROWF(cancel_error, 0, "Canceled");
+        }
+       CATCH(req->issuer->running_ctx->exception) {
+         req->issuer->doexception = 1;
+        }
+       break;
+
+      default:
+        xbt_die("Internal error in SIMIX_io_finish: unexpected action state %d",
+            action->state);
+    }
+    req->issuer->waiting_action = NULL;
+    SIMIX_request_answer(req);
+  }
+
+  /* We no longer need it */
+  SIMIX_io_destroy(action);
+}
index 5af0e0b..bf04014 100644 (file)
@@ -284,8 +284,8 @@ void SIMIX_process_kill(smx_process_t process) {
        break;
 
       case SIMIX_ACTION_IO:
-       THROW_UNIMPLEMENTED;
-       break;
+    SIMIX_io_destroy(process->waiting_action);
+    break;
     }
   }
 
index 1fb1585..2b77bb1 100644 (file)
@@ -481,6 +481,10 @@ 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),
index 09e26ea..abc1d02 100644 (file)
@@ -1176,6 +1176,17 @@ int SIMIX_req_sem_get_capacity(smx_sem_t sem)
   SIMIX_request_push(req->issuer);
   return req->sem_get_capacity.result;
 }
+
+void SIMIX_req_file_read(char* name)
+{
+         smx_req_t req = SIMIX_req_mine();
+
+         req->call = REQ_FILE_READ;
+         req->file_read.name = name;
+         SIMIX_request_push(req->issuer);
+
+}
+
 /* ************************************************************************** */
 
 /** @brief returns a printable string representing the request kind */