From 84736de8fcf2bd8af274a77c2b31d63191a6a822 Mon Sep 17 00:00:00 2001 From: navarro Date: Tue, 31 Jan 2012 14:04:30 +0100 Subject: [PATCH] Implement functions file_read and file_open into simix like fread and fwrite in posix --- include/msg/datatypes.h | 10 +++++++ include/simix/datatypes.h | 5 ++++ include/simix/simix.h | 3 +- src/simix/smx_io.c | 52 +++++++++++++++++++++++++++++++++-- src/simix/smx_io_private.h | 14 +++++++++- src/simix/smx_smurf.c | 4 +++ src/simix/smx_smurf_private.h | 21 ++++++++++++-- src/simix/smx_user.c | 23 ++++++++++++++-- 8 files changed, 124 insertions(+), 8 deletions(-) diff --git a/include/msg/datatypes.h b/include/msg/datatypes.h index 1d02d0ad8a..6a008c9be9 100644 --- a/include/msg/datatypes.h +++ b/include/msg/datatypes.h @@ -135,6 +135,16 @@ typedef enum { } 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 diff --git a/include/simix/datatypes.h b/include/simix/datatypes.h index 12fb1483dd..b05bdf311c 100644 --- a/include/simix/datatypes.h +++ b/include/simix/datatypes.h @@ -13,6 +13,11 @@ 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 diff --git a/include/simix/simix.h b/include/simix/simix.h index 7dadf97079..beab8b6446 100644 --- a/include/simix/simix.h +++ b/include/simix/simix.h @@ -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(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 */ diff --git a/src/simix/smx_io.c b/src/simix/smx_io.c index 50ed47e771..e4072e62d8 100644 --- a/src/simix/smx_io.c +++ b/src/simix/smx_io.c @@ -13,14 +13,20 @@ 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) { - 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; } -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; @@ -50,6 +56,48 @@ smx_action_t SIMIX_file_read(smx_process_t process, char* name) 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)) { diff --git a/src/simix/smx_io_private.h b/src/simix/smx_io_private.h index ec2fa34fe5..cca116a088 100644 --- a/src/simix/smx_io_private.h +++ b/src/simix/smx_io_private.h @@ -10,8 +10,20 @@ #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); -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); diff --git a/src/simix/smx_smurf.c b/src/simix/smx_smurf.c index d16d6dfd8a..86297496bf 100644 --- a/src/simix/smx_smurf.c +++ b/src/simix/smx_smurf.c @@ -485,6 +485,10 @@ void SIMIX_simcall_pre(smx_simcall_t simcall, int value) 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), diff --git a/src/simix/smx_smurf_private.h b/src/simix/smx_smurf_private.h index b8ab301c2d..da45db68e9 100644 --- a/src/simix/smx_smurf_private.h +++ b/src/simix/smx_smurf_private.h @@ -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_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 */ @@ -503,8 +508,20 @@ typedef struct s_smx_simcall { } sem_get_capacity; struct { - char* name;; + void *ptr; + size_t size; + size_t nmemb; + smx_file_t* stream; + size_t result; } 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; diff --git a/src/simix/smx_user.c b/src/simix/smx_user.c index 6c8825e0a1..667fb0b962 100644 --- a/src/simix/smx_user.c +++ b/src/simix/smx_user.c @@ -1177,13 +1177,32 @@ int simcall_sem_get_capacity(smx_sem_t sem) 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; - 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); + + 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; } /* ************************************************************************** */ -- 2.20.1