Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Implement functions file_read and file_open into simix like fread and fwrite in posix
authornavarro <navarro@caraja.(none)>
Tue, 31 Jan 2012 13:04:30 +0000 (14:04 +0100)
committernavarro <navarro@caraja.(none)>
Tue, 31 Jan 2012 13:08:37 +0000 (14:08 +0100)
include/msg/datatypes.h
include/simix/datatypes.h
include/simix/simix.h
src/simix/smx_io.c
src/simix/smx_io_private.h
src/simix/smx_smurf.c
src/simix/smx_smurf_private.h
src/simix/smx_user.c

index 1d02d0a..6a008c9 100644 (file)
@@ -135,6 +135,16 @@ typedef enum {
 } MSG_error_t;
 /** @} */
 
 } MSG_error_t;
 /** @} */
 
+/* ******************************** File ************************************ */
+
+/** @brief File datatype
+    @ingroup m_datatypes_management_details */
+typedef struct m_file {
+  char *name;                   /**< @brief host name if any */
+  void *data;                   /**< @brief user data */
+} s_m_file_t;
+/** @} */
+
 
 SG_END_DECL()
 #endif
 
 SG_END_DECL()
 #endif
index 12fb148..b05bdf3 100644 (file)
 
 SG_BEGIN_DECL()
 
 
 SG_BEGIN_DECL()
 
+/* ****************************** File *********************************** */
+typedef struct s_smx_file *smx_file_t;
+
+
+
 /* ******************************** Host ************************************ */
 /** @defgroup m_datatypes_management_details Details on SIMIX datatypes */
 /** @brief Host datatype  
 /* ******************************** Host ************************************ */
 /** @defgroup m_datatypes_management_details Details on SIMIX datatypes */
 /** @brief Host datatype  
index 7dadf97..beab8b6 100644 (file)
@@ -244,7 +244,8 @@ XBT_PUBLIC(void) simcall_sem_acquire_timeout(smx_sem_t sem,
 XBT_PUBLIC(unsigned int) simcall_sem_acquire_any(xbt_dynar_t sems);
 XBT_PUBLIC(int) simcall_sem_get_capacity(smx_sem_t sem);
 
 XBT_PUBLIC(unsigned int) simcall_sem_acquire_any(xbt_dynar_t sems);
 XBT_PUBLIC(int) simcall_sem_get_capacity(smx_sem_t sem);
 
-XBT_PUBLIC(void) simcall_file_read(char* name);
+XBT_PUBLIC(size_t) simcall_file_read(void* ptr, size_t size, size_t nmemb, smx_file_t* stream);
+XBT_PUBLIC(size_t) simcall_file_write(const void* ptr, size_t size, size_t nmemb, smx_file_t* stream);
 
 SG_END_DECL()
 #endif                          /* _SIMIX_SIMIX_H */
 
 SG_END_DECL()
 #endif                          /* _SIMIX_SIMIX_H */
index 50ed47e..e4072e6 100644 (file)
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_io, simix,
                                 "Logging specific to SIMIX (io)");
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_io, simix,
                                 "Logging specific to SIMIX (io)");
 
+
+//SIMIX FILE READ
 void SIMIX_pre_file_read(smx_simcall_t simcall)
 {
 void SIMIX_pre_file_read(smx_simcall_t simcall)
 {
-  smx_action_t action = SIMIX_file_read(simcall->issuer, simcall->file_read.name);
+  smx_action_t action = SIMIX_file_read(simcall->issuer,
+      simcall->file_read.ptr,
+      simcall->file_read.size,
+      simcall->file_read.nmemb,
+      simcall->file_read.stream);
   xbt_fifo_push(action->simcalls, simcall);
   simcall->issuer->waiting_action = action;
 }
 
   xbt_fifo_push(action->simcalls, simcall);
   simcall->issuer->waiting_action = action;
 }
 
-smx_action_t SIMIX_file_read(smx_process_t process, char* name)
+smx_action_t SIMIX_file_read(smx_process_t process, void* ptr, size_t size, size_t nmemb, smx_file_t* stream)
 {
   smx_action_t action;
   smx_host_t host = process->smx_host;
 {
   smx_action_t action;
   smx_host_t host = process->smx_host;
@@ -50,6 +56,48 @@ smx_action_t SIMIX_file_read(smx_process_t process, char* name)
   return action;
 }
 
   return action;
 }
 
+//SIMIX FILE WRITE
+void SIMIX_pre_file_write(smx_simcall_t simcall)
+{
+  smx_action_t action = SIMIX_file_write(simcall->issuer,
+      simcall->file_write.ptr,
+      simcall->file_write.size,
+      simcall->file_write.nmemb,
+      simcall->file_write.stream);
+  xbt_fifo_push(action->simcalls, simcall);
+  simcall->issuer->waiting_action = action;
+}
+
+smx_action_t SIMIX_file_write(smx_process_t process, const void* ptr, size_t size, size_t nmemb, smx_file_t* stream)
+{
+  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.write(host->host, name),
+  action->io.surf_io = surf_workstation_model->extension.workstation.sleep(host->host, 2.0);
+
+  surf_workstation_model->action_data_set(action->io.surf_io, action);
+  XBT_DEBUG("Create io action %p", action);
+
+  return action;
+}
+
 void SIMIX_post_io(smx_action_t action)
 {
   switch (surf_workstation_model->action_state_get(action->io.surf_io)) {
 void SIMIX_post_io(smx_action_t action)
 {
   switch (surf_workstation_model->action_state_get(action->io.surf_io)) {
index ec2fa34..cca116a 100644 (file)
 #include "simix/datatypes.h"
 #include "smx_smurf_private.h"
 
 #include "simix/datatypes.h"
 #include "smx_smurf_private.h"
 
+/** @brief File datatype
+    @ingroup m_datatypes_management_details */
+typedef struct s_smx_file {
+  char *name;                   /**< @brief host name if any */
+  void *data;                   /**< @brief user data */
+} s_smx_file_t;
+typedef struct s_smx_file *smx_file_t;
+/** @} */
+
 void SIMIX_pre_file_read(smx_simcall_t simcall);
 void SIMIX_pre_file_read(smx_simcall_t simcall);
-smx_action_t SIMIX_file_read(smx_process_t process, char* name);
+void SIMIX_pre_file_write(smx_simcall_t simcall);
+smx_action_t SIMIX_file_read(smx_process_t process, void* ptr, size_t size, size_t nmemb, smx_file_t* stream);
+smx_action_t SIMIX_file_write(smx_process_t process, const void* ptr, size_t size, size_t nmemb, smx_file_t* stream);
+
 void SIMIX_post_io(smx_action_t action);
 void SIMIX_io_destroy(smx_action_t action);
 void SIMIX_io_finish(smx_action_t action);
 void SIMIX_post_io(smx_action_t action);
 void SIMIX_io_destroy(smx_action_t action);
 void SIMIX_io_finish(smx_action_t action);
index d16d6df..8629749 100644 (file)
@@ -485,6 +485,10 @@ void SIMIX_simcall_pre(smx_simcall_t simcall, int value)
       SIMIX_pre_file_read(simcall);
       break;
 
       SIMIX_pre_file_read(simcall);
       break;
 
+    case SIMCALL_FILE_WRITE:
+      SIMIX_pre_file_write(simcall);
+      break;
+
     case SIMCALL_NONE:
       THROWF(arg_error,0,"Asked to do the noop syscall on %s@%s",
           SIMIX_process_get_name(simcall->issuer),
     case SIMCALL_NONE:
       THROWF(arg_error,0,"Asked to do the noop syscall on %s@%s",
           SIMIX_process_get_name(simcall->issuer),
index b8ab301..da45db6 100644 (file)
@@ -84,7 +84,12 @@ SIMCALL_ENUM_ELEMENT(SIMCALL_SEM_WOULD_BLOCK),\
 SIMCALL_ENUM_ELEMENT(SIMCALL_SEM_ACQUIRE),\
 SIMCALL_ENUM_ELEMENT(SIMCALL_SEM_ACQUIRE_TIMEOUT),\
 SIMCALL_ENUM_ELEMENT(SIMCALL_SEM_GET_CAPACITY),\
 SIMCALL_ENUM_ELEMENT(SIMCALL_SEM_ACQUIRE),\
 SIMCALL_ENUM_ELEMENT(SIMCALL_SEM_ACQUIRE_TIMEOUT),\
 SIMCALL_ENUM_ELEMENT(SIMCALL_SEM_GET_CAPACITY),\
-SIMCALL_ENUM_ELEMENT(SIMCALL_FILE_READ)
+SIMCALL_ENUM_ELEMENT(SIMCALL_FILE_READ),\
+SIMCALL_ENUM_ELEMENT(SIMCALL_FILE_WRITE),\
+SIMCALL_ENUM_ELEMENT(SIMCALL_FILE_OPEN),\
+SIMCALL_ENUM_ELEMENT(SIMCALL_FILE_CLOSE),\
+SIMCALL_ENUM_ELEMENT(SIMCALL_FILE_STAT)
+
 
 /* SIMCALL_COMM_IS_LATENCY_BOUNDED and SIMCALL_SET_CATEGORY make things complicated
  * because they are not always present */
 
 /* SIMCALL_COMM_IS_LATENCY_BOUNDED and SIMCALL_SET_CATEGORY make things complicated
  * because they are not always present */
@@ -503,8 +508,20 @@ typedef struct s_smx_simcall {
     } sem_get_capacity;
 
     struct {
     } sem_get_capacity;
 
     struct {
-      char* name;;
+      void *ptr;
+      size_t size;
+      size_t nmemb;
+      smx_file_t* stream;
+      size_t result;
     } file_read;
     } file_read;
+
+    struct {
+      const void *ptr;
+      size_t size;
+      size_t nmemb;
+      smx_file_t* stream;
+      size_t result;
+    } file_write;
   };
 } s_smx_simcall_t, *smx_simcall_t;
 
   };
 } s_smx_simcall_t, *smx_simcall_t;
 
index 6c8825e..667fb0b 100644 (file)
@@ -1177,13 +1177,32 @@ int simcall_sem_get_capacity(smx_sem_t sem)
   return simcall->sem_get_capacity.result;
 }
 
   return simcall->sem_get_capacity.result;
 }
 
-void simcall_file_read(char* name)
+size_t simcall_file_read(void* ptr, size_t size, size_t nmemb, smx_file_t* stream)
 {
   smx_simcall_t simcall = SIMIX_simcall_mine();
 
   simcall->call = SIMCALL_FILE_READ;
 {
   smx_simcall_t simcall = SIMIX_simcall_mine();
 
   simcall->call = SIMCALL_FILE_READ;
-  simcall->file_read.name = name;
+  simcall->file_read.ptr = ptr;
+  simcall->file_read.size = size;
+  simcall->file_read.nmemb = nmemb;
+  simcall->file_read.stream = stream;
   SIMIX_simcall_push(simcall->issuer);
   SIMIX_simcall_push(simcall->issuer);
+
+  return simcall->file_read.result;
+}
+
+size_t simcall_file_write(const void* ptr, size_t size, size_t nmemb, smx_file_t* stream)
+{
+  smx_simcall_t simcall = SIMIX_simcall_mine();
+
+  simcall->call = SIMCALL_FILE_READ;
+  simcall->file_write.ptr = ptr;
+  simcall->file_write.size = size;
+  simcall->file_write.nmemb = nmemb;
+  simcall->file_write.stream = stream;
+  SIMIX_simcall_push(simcall->issuer);
+
+  return simcall->file_write.result;
 }
 
 /* ************************************************************************** */
 }
 
 /* ************************************************************************** */