From: Paul Bédaride Date: Mon, 21 Jan 2013 13:08:04 +0000 (+0100) Subject: All hosts types fusion to xbt_dictelm_t X-Git-Tag: v3_9_rc1~75 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/48404c66fc4d8248308db1d1398cb79a6763077e All hosts types fusion to xbt_dictelm_t --- diff --git a/examples/lua/console/master_slave_bypass.tesh b/examples/lua/console/master_slave_bypass.tesh index 7b5044df93..9dc96274ee 100644 --- a/examples/lua/console/master_slave_bypass.tesh +++ b/examples/lua/console/master_slave_bypass.tesh @@ -106,3 +106,4 @@ $ lua master_slave_bypass.lua --log=surf_parse.thres:critical > [Ginette:Slave:(4) 480.903871] [lua/INFO] Slave 'slave 3': I'm Done . See You !! > [Tremblay:Master:(1) 480.903871] [lua/INFO] Master: Everything's done. > [480.903871] [lua/INFO] Simulation's over.See you. + diff --git a/include/msg/datatypes.h b/include/msg/datatypes.h index cedd660b20..0536dbb264 100644 --- a/include/msg/datatypes.h +++ b/include/msg/datatypes.h @@ -7,6 +7,7 @@ #define MSG_DATATYPE_H #include "xbt/misc.h" #include "xbt/file_stat.h" +#include "xbt/lib.h" #include "simgrid/simix.h" #include "simgrid_config.h" // for HAVE_TRACING @@ -29,13 +30,7 @@ typedef struct s_smx_rvpoint *msg_mailbox_t; /* ******************************** Host ************************************ */ -typedef struct msg_host { - xbt_swag_t vms; - smx_host_t smx_host; /**< SIMIX representation of this host */ -#ifdef MSG_USE_DEPRECATED - msg_mailbox_t *mailboxes; /**< the channels */ -#endif -} s_msg_host_t; +extern int MSG_HOST_LEVEL; /** @brief Host datatype. @ingroup m_host_management @@ -47,7 +42,21 @@ typedef struct msg_host { some private data that can be only accessed by local process. */ -typedef struct msg_host *msg_host_t; +typedef xbt_dictelm_t msg_host_t; +typedef s_xbt_dictelm_t s_msg_host_t; + +typedef struct msg_host_priv { + xbt_swag_t vms; +#ifdef MSG_USE_DEPRECATED + msg_mailbox_t *mailboxes; /**< the channels */ +#endif +} s_msg_host_priv_t, *msg_host_priv_t; + +static inline msg_host_priv_t MSG_host_priv(msg_host_t host){ + return xbt_lib_get_level(host, MSG_HOST_LEVEL); +} + + /* ******************************** Task ************************************ */ diff --git a/include/msg/msg.h b/include/msg/msg.h index afac0e94f5..d3999e6345 100644 --- a/include/msg/msg.h +++ b/include/msg/msg.h @@ -95,7 +95,7 @@ XBT_PUBLIC(int) MSG_get_host_msgload(msg_host_t host); /* int MSG_get_msgload(void); This function lacks specification; discard it */ XBT_PUBLIC(double) MSG_get_host_speed(msg_host_t h); XBT_PUBLIC(int) MSG_host_is_avail(msg_host_t h); -XBT_PUBLIC(void) __MSG_host_destroy(msg_host_t host); +XBT_PUBLIC(void) __MSG_host_destroy(msg_host_priv_t host); /*property handlers*/ XBT_PUBLIC(xbt_dict_t) MSG_host_get_properties(msg_host_t host); diff --git a/include/simdag/datatypes.h b/include/simdag/datatypes.h index 53a9f1aaed..40fa48b682 100644 --- a/include/simdag/datatypes.h +++ b/include/simdag/datatypes.h @@ -6,6 +6,7 @@ #ifndef SIMDAG_DATATYPES_H #define SIMDAG_DATATYPES_H +#include "xbt/dict.h" /** @brief Workstation datatype @ingroup SD_datatypes_management @@ -15,7 +16,7 @@ resource with computing capabilities and has a name. @see SD_workstation_management */ -typedef struct SD_workstation *SD_workstation_t; +typedef xbt_dictelm_t SD_workstation_t; /** @brief Workstation access mode @ingroup SD_datatypes_management diff --git a/include/simgrid/platf.h b/include/simgrid/platf.h index 677ea14d1d..49ad142b00 100644 --- a/include/simgrid/platf.h +++ b/include/simgrid/platf.h @@ -70,6 +70,11 @@ XBT_PUBLIC(probabilist_event_generator_t) tmgr_event_generator_new_exponential(c XBT_PUBLIC(probabilist_event_generator_t) tmgr_event_generator_new_weibull(const char* id, double scale, double shape); +typedef xbt_dictelm_t sg_host_t; +static inline char* sg_host_name(sg_host_t host) { + return host->key; +} + /* * Platform creation functions. Instead of passing 123 arguments to the creation functions diff --git a/include/simgrid/simix.h b/include/simgrid/simix.h index cdb0a2acfd..46763d42b4 100644 --- a/include/simgrid/simix.h +++ b/include/simgrid/simix.h @@ -34,7 +34,8 @@ typedef union u_smx_scalar u_smx_scalar_t; \see m_host_management @{ */ -typedef struct s_smx_host *smx_host_t; +typedef xbt_dictelm_t smx_host_t; +typedef struct s_smx_host_priv *smx_host_priv_t; typedef enum { SIMIX_WAITING, SIMIX_READY, diff --git a/include/xbt/dict.h b/include/xbt/dict.h index 80c6f803e4..cf00544e1b 100644 --- a/include/xbt/dict.h +++ b/include/xbt/dict.h @@ -45,7 +45,20 @@ SG_BEGIN_DECL() */ /** \brief Dictionary data type (opaque structure) */ + typedef struct s_xbt_dict *xbt_dict_t; +typedef struct s_xbt_dictelm *xbt_dictelm_t; +typedef struct s_xbt_dictelm s_xbt_dictelm_t; +typedef struct s_xbt_dictelm { + char *key; + int key_len; + unsigned int hash_code; + + void *content; + + xbt_dictelm_t next; +} s_xbt_dictelm_t; + XBT_PUBLIC(xbt_dict_t) xbt_dict_new(void); XBT_PUBLIC(xbt_dict_t) xbt_dict_new_homogeneous(void_f_pvoid_t free_ctn); XBT_PUBLIC(void) xbt_dict_free(xbt_dict_t * dict); @@ -65,6 +78,8 @@ XBT_PUBLIC(void) xbt_dict_set(xbt_dict_t dict, const char *key, void *data, XBT_PUBLIC(void *) xbt_dict_get(xbt_dict_t dict, const char *key); XBT_PUBLIC(void *) xbt_dict_get_or_null(xbt_dict_t dict, const char *key); XBT_PUBLIC(char *) xbt_dict_get_key(xbt_dict_t dict, const void *data); +XBT_PUBLIC(xbt_dictelm_t) xbt_dict_get_elm(xbt_dict_t dict, const char *key); +XBT_PUBLIC(xbt_dictelm_t) xbt_dict_get_elm_or_null(xbt_dict_t dict, const char *key); XBT_PUBLIC(void) xbt_dict_remove(xbt_dict_t dict, const char *key); XBT_PUBLIC(void) xbt_dict_reset(xbt_dict_t dict); @@ -123,13 +138,23 @@ XBT_PUBLIC(void) xbt_dicti_remove(xbt_dict_t dict, uintptr_t key); * @{ */ /** @brief Cursor on dictionaries (opaque type) */ +struct s_xbt_dict_cursor { + xbt_dictelm_t current; + int line; + xbt_dict_t dict; +}; typedef struct s_xbt_dict_cursor *xbt_dict_cursor_t; + +static inline xbt_dictelm_t xbt_dict_cursor_get_elm(xbt_dict_cursor_t cursor) { + return cursor->current; +} + XBT_PUBLIC(xbt_dict_cursor_t) xbt_dict_cursor_new(const xbt_dict_t dict); XBT_PUBLIC(void) xbt_dict_cursor_free(xbt_dict_cursor_t * cursor); XBT_PUBLIC(void) xbt_dict_cursor_rewind(xbt_dict_cursor_t cursor); - +xbt_dictelm_t xbt_dict_cursor_get_elm(xbt_dict_cursor_t cursor); XBT_PUBLIC(char *) xbt_dict_cursor_get_key(xbt_dict_cursor_t cursor); XBT_PUBLIC(void *) xbt_dict_cursor_get_data(xbt_dict_cursor_t cursor); XBT_PUBLIC(void) xbt_dict_cursor_set_data(xbt_dict_cursor_t cursor, diff --git a/include/xbt/lib.h b/include/xbt/lib.h index ec5db54cee..cdc9fc7942 100644 --- a/include/xbt/lib.h +++ b/include/xbt/lib.h @@ -28,6 +28,8 @@ XBT_PUBLIC(void) xbt_lib_set(xbt_lib_t lib, const char *name, int level, void *obj); XBT_PUBLIC(void *) xbt_lib_get_or_null(xbt_lib_t lib, const char *name, int level); +XBT_PUBLIC(xbt_dictelm_t) xbt_lib_get_elm_or_null(xbt_lib_t lib, const char *key); +XBT_PUBLIC(void *) xbt_lib_get_level(xbt_dictelm_t elm, int level); #define xbt_lib_length(lib) xbt_dict_length((lib)->dict) diff --git a/src/bindings/lua/lua_host.c b/src/bindings/lua/lua_host.c index 3090b4b141..a862a2ae86 100644 --- a/src/bindings/lua/lua_host.c +++ b/src/bindings/lua/lua_host.c @@ -184,7 +184,7 @@ static int l_host_sleep(lua_State *L) static int l_host_destroy(lua_State *L) { msg_host_t ht = sglua_check_host(L, 1); - __MSG_host_destroy(ht); + __MSG_host_destroy(MSG_host_priv(ht)); return 0; } diff --git a/src/include/surf/surf.h b/src/include/surf/surf.h index 5bb8d1924b..5a612accf1 100644 --- a/src/include/surf/surf.h +++ b/src/include/surf/surf.h @@ -333,14 +333,24 @@ typedef struct surf_model { surf_model_t surf_model_init(void); void surf_model_exit(surf_model_t model); +static inline void *surf_cpu_resource_priv(const void *host) { + return xbt_lib_get_level((void *)host, SURF_CPU_LEVEL); +} +static inline void *surf_workstation_resource_priv(const void *host){ + return xbt_lib_get_level((void *)host, SURF_WKS_LEVEL); +} +static inline void *surf_storage_resource_priv(const void *host){ + return xbt_lib_get_level((void *)host, SURF_STORAGE_LEVEL); +} + static inline void *surf_cpu_resource_by_name(const char *name) { - return xbt_lib_get_or_null(host_lib, name, SURF_CPU_LEVEL); + return xbt_lib_get_elm_or_null(host_lib, name); } static inline void *surf_workstation_resource_by_name(const char *name){ - return xbt_lib_get_or_null(host_lib, name, SURF_WKS_LEVEL); + return xbt_lib_get_elm_or_null(host_lib, name); } static inline void *surf_storage_resource_by_name(const char *name){ - return xbt_lib_get_or_null(storage_lib, name, SURF_STORAGE_LEVEL); + return xbt_lib_get_elm_or_null(storage_lib, name); } typedef struct surf_resource { diff --git a/src/msg/instr_msg_process.c b/src/msg/instr_msg_process.c index dba5b6b829..7c6239a41e 100644 --- a/src/msg/instr_msg_process.c +++ b/src/msg/instr_msg_process.c @@ -66,7 +66,7 @@ void TRACE_msg_process_create (const char *process_name, int process_pid, msg_ho int len = INSTR_DEFAULT_STR_SIZE; char str[INSTR_DEFAULT_STR_SIZE]; - container_t host_container = PJ_container_get (SIMIX_host_get_name(host->smx_host)); + container_t host_container = PJ_container_get (SIMIX_host_get_name(host)); PJ_container_new(instr_process_id_2(process_name, process_pid, str, len), INSTR_MSG_PROCESS, host_container); } } diff --git a/src/msg/instr_msg_vm.c b/src/msg/instr_msg_vm.c index 73581c5e83..7b7e3e4d6f 100644 --- a/src/msg/instr_msg_vm.c +++ b/src/msg/instr_msg_vm.c @@ -46,7 +46,7 @@ void TRACE_msg_vm_change_host(msg_vm_t vm, msg_host_t old_host, msg_host_t new_h PJ_container_free(existing_container); //create new container on the new_host location - msg = PJ_container_new(instr_vm_id(vm, str, len), INSTR_MSG_VM, PJ_container_get(SIMIX_host_get_name(new_host->smx_host))); + msg = PJ_container_new(instr_vm_id(vm, str, len), INSTR_MSG_VM, PJ_container_get(SIMIX_host_get_name(new_host))); //end link msg = PJ_container_get(instr_vm_id(vm, str, len)); @@ -61,7 +61,7 @@ void TRACE_msg_vm_create (const char *vm_name, msg_host_t host) int len = INSTR_DEFAULT_STR_SIZE; char str[INSTR_DEFAULT_STR_SIZE]; - container_t host_container = PJ_container_get (SIMIX_host_get_name(host->smx_host)); + container_t host_container = PJ_container_get (SIMIX_host_get_name(host)); PJ_container_new(instr_vm_id_2(vm_name, str, len), INSTR_MSG_VM, host_container); } } diff --git a/src/msg/msg_environment.c b/src/msg/msg_environment.c index 0eb3952a13..44ef32caf1 100644 --- a/src/msg/msg_environment.c +++ b/src/msg/msg_environment.c @@ -45,7 +45,7 @@ void MSG_post_create_environment(void) { /* Initialize MSG hosts */ xbt_lib_foreach(host_lib, cursor, name, data) { if(data[SIMIX_HOST_LEVEL]) - __MSG_host_create((smx_host_t)data[SIMIX_HOST_LEVEL]); + __MSG_host_create(xbt_dict_cursor_get_elm(cursor)); } } diff --git a/src/msg/msg_gos.c b/src/msg/msg_gos.c index 38b579d283..bcc59e135c 100644 --- a/src/msg/msg_gos.c +++ b/src/msg/msg_gos.c @@ -75,7 +75,7 @@ msg_error_t MSG_parallel_task_execute(msg_task_t task) XBT_DEBUG("Parallel execution action created: %p", simdata->compute); } else { simdata->compute = simcall_host_execute(task->name, - p_simdata->m_host->smx_host, + p_simdata->m_host, simdata->computation_amount, simdata->priority); diff --git a/src/msg/msg_host.c b/src/msg/msg_host.c index a503903cb5..a767553db3 100644 --- a/src/msg/msg_host.c +++ b/src/msg/msg_host.c @@ -29,10 +29,9 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(msg); msg_host_t __MSG_host_create(smx_host_t workstation) { const char *name = SIMIX_host_get_name(workstation); - msg_host_t host = xbt_new0(s_msg_host_t, 1); + msg_host_priv_t host = xbt_new0(s_msg_host_priv_t, 1); s_msg_vm_t vm; // simply to compute the offset - host->smx_host = workstation; host->vms = xbt_swag_new(xbt_swag_offset(vm,host_vms_hookup)); #ifdef MSG_USE_DEPRECATED @@ -52,10 +51,11 @@ msg_host_t __MSG_host_create(smx_host_t workstation) #endif xbt_lib_set(host_lib,name,MSG_HOST_LEVEL,host); - - return host; + + return xbt_lib_get_elm_or_null(host_lib, name); } + /** \ingroup msg_host_management * \brief Finds a msg_host_t using its name. * @@ -65,7 +65,7 @@ msg_host_t __MSG_host_create(smx_host_t workstation) */ msg_host_t MSG_get_host_by_name(const char *name) { - return (msg_host_t) xbt_lib_get_or_null(host_lib,name,MSG_HOST_LEVEL); + return (msg_host_t) xbt_lib_get_elm_or_null(host_lib,name); } /** \ingroup m_host_management @@ -77,7 +77,7 @@ msg_host_t MSG_get_host_by_name(const char *name) */ msg_error_t MSG_host_set_data(msg_host_t host, void *data) { - SIMIX_host_set_data(host->smx_host,data); + SIMIX_host_set_data(host,data); return MSG_OK; } @@ -91,7 +91,7 @@ msg_error_t MSG_host_set_data(msg_host_t host, void *data) */ void *MSG_host_get_data(msg_host_t host) { - return SIMIX_host_get_data(host->smx_host); + return SIMIX_host_get_data(host); } /** \ingroup m_host_management @@ -102,7 +102,7 @@ void *MSG_host_get_data(msg_host_t host) its name. */ const char *MSG_host_get_name(msg_host_t host) { - return SIMIX_host_get_name(host->smx_host); + return SIMIX_host_get_name(host); } /** \ingroup m_host_management @@ -117,15 +117,14 @@ msg_host_t MSG_host_self(void) /* * \brief Destroys a host (internal call only) */ -void __MSG_host_destroy(msg_host_t host) { +void __MSG_host_destroy(msg_host_priv_t host) { #ifdef MSG_USE_DEPRECATED if (msg_global->max_channel > 0) free(host->mailboxes); #endif if (xbt_swag_size(host->vms) > 0 ) { - XBT_VERB("Host %s shut down, but it still hosts %d VMs. They will be leaked.", - MSG_host_get_name(host),xbt_swag_size(host->vms)); + XBT_VERB("Host shut down, but it still hosts %d VMs. They will be leaked.",xbt_swag_size(host->vms)); } xbt_swag_free(host->vms); free(host); @@ -172,8 +171,10 @@ xbt_dynar_t MSG_hosts_as_dynar(void) { xbt_dynar_t res = xbt_dynar_new(sizeof(msg_host_t),NULL); xbt_lib_foreach(host_lib, cursor, key, data) { - if(routing_get_network_element_type(key) == SURF_NETWORK_ELEMENT_HOST) - xbt_dynar_push(res, data + MSG_HOST_LEVEL); + if(routing_get_network_element_type(key) == SURF_NETWORK_ELEMENT_HOST) { + xbt_dictelm_t elm = xbt_dict_cursor_get_elm(cursor); + xbt_dynar_push(res, &elm); + } } return res; } @@ -198,7 +199,7 @@ double MSG_get_host_speed(msg_host_t h) { xbt_assert((h != NULL), "Invalid parameters"); - return (simcall_host_get_speed(h->smx_host)); + return (simcall_host_get_speed(h)); } /** \ingroup m_host_management @@ -223,7 +224,7 @@ xbt_dict_t MSG_host_get_properties(msg_host_t host) { xbt_assert((host != NULL), "Invalid parameters (host is NULL)"); - return (simcall_host_get_properties(host->smx_host)); + return (simcall_host_get_properties(host)); } /** \ingroup m_host_management @@ -249,5 +250,5 @@ void MSG_host_set_property_value(msg_host_t host, const char *name, char *value, int MSG_host_is_avail(msg_host_t host) { xbt_assert((host != NULL), "Invalid parameters (host is NULL)"); - return (simcall_host_get_state(host->smx_host)); + return (simcall_host_get_state(host)); } diff --git a/src/msg/msg_mailbox.c b/src/msg/msg_mailbox.c index 17504f2f35..942f332433 100644 --- a/src/msg/msg_mailbox.c +++ b/src/msg/msg_mailbox.c @@ -41,8 +41,7 @@ int MSG_mailbox_get_count_host_waiting_tasks(msg_mailbox_t mailbox, msg_host_t host) { - return simcall_rdv_comm_count_by_host(mailbox, - host->smx_host); + return simcall_rdv_comm_count_by_host(mailbox, host); } msg_mailbox_t MSG_mailbox_get_by_alias(const char *alias) diff --git a/src/msg/msg_private.h b/src/msg/msg_private.h index 7edcb02124..b7801c9f70 100644 --- a/src/msg/msg_private.h +++ b/src/msg/msg_private.h @@ -139,7 +139,7 @@ XBT_PUBLIC_DATA(MSG_Global_t) msg_global; #endif msg_host_t __MSG_host_create(smx_host_t workstation); -void __MSG_host_destroy(msg_host_t host); +void __MSG_host_destroy(msg_host_priv_t host); void __MSG_display_process_status(void); diff --git a/src/msg/msg_process.c b/src/msg/msg_process.c index ddce625a76..cf7ce52b6a 100644 --- a/src/msg/msg_process.c +++ b/src/msg/msg_process.c @@ -182,7 +182,7 @@ msg_process_t MSG_process_create_with_environment(const char *name, #endif /* Let's create the process: SIMIX may decide to start it right now, * even before returning the flow control to us */ - simcall_process_create(&process, name, code, simdata, SIMIX_host_get_name(host->smx_host), -1, + simcall_process_create(&process, name, code, simdata, sg_host_name(host), -1, argc, argv, properties,0); if (!process) { @@ -231,7 +231,7 @@ msg_error_t MSG_process_migrate(msg_process_t process, msg_host_t host) msg_host_t now = simdata->m_host; TRACE_msg_process_change_host(process, now, host); #endif - simcall_process_change_host(process, host->smx_host); + simcall_process_change_host(process, host); return MSG_OK; } diff --git a/src/msg/msg_task.c b/src/msg/msg_task.c index 013c4f12e3..101689c4d4 100644 --- a/src/msg/msg_task.c +++ b/src/msg/msg_task.c @@ -112,7 +112,7 @@ MSG_parallel_task_create(const char *name, int host_nb, simdata->comm_amount = communication_amount; for (i = 0; i < host_nb; i++) - simdata->host_list[i] = host_list[i]->smx_host; + simdata->host_list[i] = host_list[i]; return task; } diff --git a/src/msg/msg_vm.c b/src/msg/msg_vm.c index 426bbb753f..c025372f06 100644 --- a/src/msg/msg_vm.c +++ b/src/msg/msg_vm.c @@ -28,7 +28,7 @@ msg_vm_t MSG_vm_start(msg_host_t location, const char *name, int coreAmount) { res->processes = xbt_dynar_new(sizeof(msg_process_t),NULL); xbt_swag_insert(res,msg_global->vms); - xbt_swag_insert(res,location->vms); + xbt_swag_insert(res, MSG_host_priv(location)->vms); #ifdef HAVE_TRACING TRACE_msg_vm_create(name, location); @@ -111,8 +111,8 @@ void MSG_vm_migrate(msg_vm_t vm, msg_host_t destination) { xbt_dynar_foreach(vm->processes,cpt,process) { MSG_process_migrate(process,destination); } - xbt_swag_remove(vm,vm->location->vms); - xbt_swag_insert_at_tail(vm,destination->vms); + xbt_swag_remove(vm, MSG_host_priv(vm->location)->vms); + xbt_swag_insert_at_tail(vm, MSG_host_priv(destination)->vms); #ifdef HAVE_TRACING TRACE_msg_vm_change_host(vm,vm->location,destination); diff --git a/src/simdag/private.h b/src/simdag/private.h index 1010a54f93..e4025a39d3 100644 --- a/src/simdag/private.h +++ b/src/simdag/private.h @@ -56,14 +56,18 @@ typedef struct SD_link { } s_SD_link_t; /* Workstation */ +typedef s_xbt_dictelm_t s_SD_workstation_t; typedef struct SD_workstation { - void *surf_workstation; /* surf object */ void *data; /* user data */ e_SD_workstation_access_mode_t access_mode; xbt_fifo_t task_fifo; /* only used in sequential mode */ SD_task_t current_task; /* only used in sequential mode */ -} s_SD_workstation_t; +} s_SD_workstation_priv_t, *SD_workstation_priv_t; + +static inline SD_workstation_priv_t SD_workstation_priv(SD_workstation_t host){ + return xbt_lib_get_level(host, SD_HOST_LEVEL); +} /* Task */ typedef struct SD_task { diff --git a/src/simdag/sd_task.c b/src/simdag/sd_task.c index ba6486413f..472e3327d3 100644 --- a/src/simdag/sd_task.c +++ b/src/simdag/sd_task.c @@ -1050,7 +1050,7 @@ void __SD_task_really_run(SD_task_t task) for (i = 0; i < workstation_nb; i++) { if (SD_workstation_get_access_mode(task->workstation_list[i]) == SD_WORKSTATION_SEQUENTIAL_ACCESS) { - task->workstation_list[i]->current_task = task; + SD_workstation_priv(task->workstation_list[i])->current_task = task; xbt_assert(__SD_workstation_is_busy(task->workstation_list[i]), "The workstation should be busy now"); } @@ -1066,7 +1066,7 @@ void __SD_task_really_run(SD_task_t task) surf_workstations = xbt_new(void *, workstation_nb); for (i = 0; i < workstation_nb; i++) - surf_workstations[i] = task->workstation_list[i]->surf_workstation; + surf_workstations[i] = task->workstation_list[i]; double *computation_amount = xbt_new0(double, workstation_nb); double *communication_amount = xbt_new0(double, workstation_nb * workstation_nb); @@ -1132,11 +1132,11 @@ int __SD_task_try_to_run(SD_task_t task) if (!can_start) { /* if the task cannot start and is not in the FIFOs yet */ for (i = 0; i < task->workstation_nb; i++) { workstation = task->workstation_list[i]; - if (workstation->access_mode == SD_WORKSTATION_SEQUENTIAL_ACCESS) { + if (SD_workstation_priv(workstation)->access_mode == SD_WORKSTATION_SEQUENTIAL_ACCESS) { XBT_DEBUG("Pushing task '%s' in the FIFO of workstation '%s'", SD_task_get_name(task), SD_workstation_get_name(workstation)); - xbt_fifo_push(workstation->task_fifo, task); + xbt_fifo_push(SD_workstation_priv(workstation)->task_fifo, task); } } __SD_task_set_state(task, SD_IN_FIFO); @@ -1186,23 +1186,23 @@ void __SD_task_just_done(SD_task_t task) for (i = 0; i < task->workstation_nb; i++) { workstation = task->workstation_list[i]; XBT_DEBUG("Workstation '%s': access_mode = %d", - SD_workstation_get_name(workstation), (int)workstation->access_mode); - if (workstation->access_mode == SD_WORKSTATION_SEQUENTIAL_ACCESS) { - xbt_assert(workstation->task_fifo != NULL, + SD_workstation_get_name(workstation), (int)SD_workstation_priv(workstation)->access_mode); + if (SD_workstation_priv(workstation)->access_mode == SD_WORKSTATION_SEQUENTIAL_ACCESS) { + xbt_assert(SD_workstation_priv(workstation)->task_fifo != NULL, "Workstation '%s' has sequential access but no FIFO!", SD_workstation_get_name(workstation)); - xbt_assert(workstation->current_task = + xbt_assert(SD_workstation_priv(workstation)->current_task = task, "Workstation '%s': current task should be '%s'", SD_workstation_get_name(workstation), SD_task_get_name(task)); /* the task is over so we can release the workstation */ - workstation->current_task = NULL; + SD_workstation_priv(workstation)->current_task = NULL; XBT_DEBUG("Getting candidate in FIFO"); candidate = xbt_fifo_get_item_content(xbt_fifo_get_first_item - (workstation->task_fifo)); + (SD_workstation_priv(workstation)->task_fifo)); if (candidate != NULL) { XBT_DEBUG("Candidate: '%s'", SD_task_get_name(candidate)); @@ -1256,10 +1256,10 @@ void __SD_task_just_done(SD_task_t task) /* I can start on this workstation if the workstation is shared or if I am the first task in the FIFO */ - can_start = workstation->access_mode == SD_WORKSTATION_SHARED_ACCESS + can_start = SD_workstation_priv(workstation)->access_mode == SD_WORKSTATION_SHARED_ACCESS || candidate == xbt_fifo_get_item_content(xbt_fifo_get_first_item - (workstation->task_fifo)); + (SD_workstation_priv(workstation)->task_fifo)); } XBT_DEBUG("Candidate '%s' can start: %d", SD_task_get_name(candidate), @@ -1271,8 +1271,8 @@ void __SD_task_just_done(SD_task_t task) workstation = candidate->workstation_list[j]; /* update the FIFO */ - if (workstation->access_mode == SD_WORKSTATION_SEQUENTIAL_ACCESS) { - candidate = xbt_fifo_shift(workstation->task_fifo); /* the return value is stored just for debugging */ + if (SD_workstation_priv(workstation)->access_mode == SD_WORKSTATION_SEQUENTIAL_ACCESS) { + candidate = xbt_fifo_shift(SD_workstation_priv(workstation)->task_fifo); /* the return value is stored just for debugging */ XBT_DEBUG("Head of the FIFO: '%s'", (candidate != NULL) ? SD_task_get_name(candidate) : "NULL"); diff --git a/src/simdag/sd_workstation.c b/src/simdag/sd_workstation.c index 1be8d28622..f961c7f12b 100644 --- a/src/simdag/sd_workstation.c +++ b/src/simdag/sd_workstation.c @@ -23,19 +23,18 @@ SD_workstation_t __SD_workstation_create(void *surf_workstation, void *data) { - SD_workstation_t workstation; + SD_workstation_priv_t workstation; const char *name; - workstation = xbt_new(s_SD_workstation_t, 1); - workstation->surf_workstation = surf_workstation; + workstation = xbt_new(s_SD_workstation_priv_t, 1); workstation->data = data; /* user data */ workstation->access_mode = SD_WORKSTATION_SHARED_ACCESS; /* default mode is shared */ workstation->task_fifo = NULL; workstation->current_task = NULL; - name = SD_workstation_get_name(workstation); + name = surf_resource_name(surf_workstation); xbt_lib_set(host_lib,name,SD_HOST_LEVEL,workstation); - return workstation; + return xbt_lib_get_elm_or_null(host_lib,name); } /** @@ -48,7 +47,7 @@ SD_workstation_t __SD_workstation_create(void *surf_workstation, */ SD_workstation_t SD_workstation_get_by_name(const char *name) { - return xbt_lib_get_or_null(host_lib, name, SD_HOST_LEVEL); + return xbt_lib_get_elm_or_null(host_lib, name); } /** @@ -76,7 +75,7 @@ const SD_workstation_t *SD_workstation_get_list(void) i = 0; xbt_lib_foreach(host_lib, cursor, key, data) { if(data[SD_HOST_LEVEL]) - sd_global->workstation_list[i++] = (SD_workstation_t) data[SD_HOST_LEVEL]; + sd_global->workstation_list[i++] = xbt_dict_cursor_get_elm(cursor); } } return sd_global->workstation_list; @@ -102,7 +101,7 @@ int SD_workstation_get_number(void) */ void *SD_workstation_get_data(SD_workstation_t workstation) { - return workstation->data; + return SD_workstation_priv(workstation)->data; } /** @@ -117,7 +116,7 @@ void *SD_workstation_get_data(SD_workstation_t workstation) */ void SD_workstation_set_data(SD_workstation_t workstation, void *data) { - workstation->data = data; + SD_workstation_priv(workstation)->data = data; } /** @@ -128,7 +127,7 @@ void SD_workstation_set_data(SD_workstation_t workstation, void *data) */ const char *SD_workstation_get_name(SD_workstation_t workstation) { - return surf_resource_name(workstation->surf_workstation); + return sg_host_name(workstation); } /** @@ -154,8 +153,7 @@ const char *SD_workstation_get_property_value(SD_workstation_t ws, xbt_dict_t SD_workstation_get_properties(SD_workstation_t workstation) { return surf_workstation_model->extension. - workstation.get_properties(workstation->surf_workstation); - + workstation.get_properties(surf_workstation_resource_priv(workstation)); } @@ -170,7 +168,7 @@ void SD_workstation_dump(SD_workstation_t ws) XBT_INFO("Displaying workstation %s", SD_workstation_get_name(ws)); XBT_INFO(" - power: %.0f", SD_workstation_get_power(ws)); XBT_INFO(" - available power: %.2f", SD_workstation_get_available_power(ws)); - switch (ws->access_mode){ + switch (SD_workstation_priv(ws)->access_mode){ case SD_WORKSTATION_SHARED_ACCESS: XBT_INFO(" - access mode: Space shared"); break; @@ -221,8 +219,8 @@ const SD_link_t *SD_route_get_list(SD_workstation_t src, sd_global->recyclable_route = xbt_new(SD_link_t, SD_link_get_number()); } - surf_src = src->surf_workstation; - surf_dst = dst->surf_workstation; + surf_src = src; + surf_dst = dst; surf_route = surf_workstation_model->extension.workstation.get_route(surf_src, surf_dst); @@ -246,8 +244,7 @@ const SD_link_t *SD_route_get_list(SD_workstation_t src, int SD_route_get_size(SD_workstation_t src, SD_workstation_t dst) { return xbt_dynar_length(surf_workstation_model->extension. - workstation.get_route(src->surf_workstation, - dst->surf_workstation)); + workstation.get_route(src, dst)); } /** @@ -260,7 +257,7 @@ int SD_route_get_size(SD_workstation_t src, SD_workstation_t dst) double SD_workstation_get_power(SD_workstation_t workstation) { return surf_workstation_model->extension.workstation. - get_speed(workstation->surf_workstation, 1.0); + get_speed(workstation, 1.0); } /** @@ -273,7 +270,7 @@ double SD_workstation_get_power(SD_workstation_t workstation) double SD_workstation_get_available_power(SD_workstation_t workstation) { return surf_workstation_model->extension. - workstation.get_available_speed(workstation->surf_workstation); + workstation.get_available_speed(workstation); } /** @@ -413,7 +410,7 @@ double SD_route_get_communication_time(SD_workstation_t src, e_SD_workstation_access_mode_t SD_workstation_get_access_mode(SD_workstation_t workstation) { - return workstation->access_mode; + return SD_workstation_priv(workstation)->access_mode; } /** @@ -439,17 +436,17 @@ void SD_workstation_set_access_mode(SD_workstation_t workstation, access_mode != SD_WORKSTATION_SHARED_ACCESS, "Trying to set an invalid access mode"); - if (access_mode == workstation->access_mode) { + if (access_mode == SD_workstation_priv(workstation)->access_mode) { return; // nothing is changed } - workstation->access_mode = access_mode; + SD_workstation_priv(workstation)->access_mode = access_mode; if (access_mode == SD_WORKSTATION_SHARED_ACCESS) { - xbt_fifo_free(workstation->task_fifo); - workstation->task_fifo = NULL; + xbt_fifo_free(SD_workstation_priv(workstation)->task_fifo); + SD_workstation_priv(workstation)->task_fifo = NULL; } else { - workstation->task_fifo = xbt_fifo_new(); + SD_workstation_priv(workstation)->task_fifo = xbt_fifo_new(); } } @@ -472,17 +469,17 @@ int __SD_workstation_is_busy(SD_workstation_t workstation) XBT_DEBUG ("Workstation '%s' access mode: '%s', current task: %s, fifo size: %d", SD_workstation_get_name(workstation), - (workstation->access_mode == + (SD_workstation_priv(workstation)->access_mode == SD_WORKSTATION_SHARED_ACCESS) ? "SHARED" : "FIFO", - (workstation->current_task ? - SD_task_get_name(workstation->current_task) + (SD_workstation_priv(workstation)->current_task ? + SD_task_get_name(SD_workstation_priv(workstation)->current_task) : "none"), - (workstation->task_fifo ? xbt_fifo_size(workstation->task_fifo) : + (SD_workstation_priv(workstation)->task_fifo ? xbt_fifo_size(SD_workstation_priv(workstation)->task_fifo) : 0)); - return workstation->access_mode == SD_WORKSTATION_SEQUENTIAL_ACCESS && - (workstation->current_task != NULL - || xbt_fifo_size(workstation->task_fifo) > 0); + return SD_workstation_priv(workstation)->access_mode == SD_WORKSTATION_SEQUENTIAL_ACCESS && + (SD_workstation_priv(workstation)->current_task != NULL + || xbt_fifo_size(SD_workstation_priv(workstation)->task_fifo) > 0); } /* Destroys a workstation. @@ -490,11 +487,11 @@ int __SD_workstation_is_busy(SD_workstation_t workstation) void __SD_workstation_destroy(void *workstation) { - SD_workstation_t w; + SD_workstation_priv_t w; /* workstation->surf_workstation is freed by surf_exit and workstation->data is freed by the user */ - w = (SD_workstation_t) workstation; + w = (SD_workstation_priv_t) workstation; if (w->access_mode == SD_WORKSTATION_SEQUENTIAL_ACCESS) { xbt_fifo_free(w->task_fifo); @@ -508,11 +505,11 @@ void __SD_workstation_destroy(void *workstation) * \param workstation a workstation */ SD_task_t SD_workstation_get_current_task(SD_workstation_t workstation) { - xbt_assert(workstation->access_mode == SD_WORKSTATION_SEQUENTIAL_ACCESS, + xbt_assert(SD_workstation_priv(workstation)->access_mode == SD_WORKSTATION_SEQUENTIAL_ACCESS, "Access mode must be set to SD_WORKSTATION_SEQUENTIAL_ACCESS" " to use this function"); - return (workstation->current_task); + return (SD_workstation_priv(workstation)->current_task); } /** diff --git a/src/simix/smx_deployment.c b/src/simix/smx_deployment.c index 766658e230..07f130d8b6 100644 --- a/src/simix/smx_deployment.c +++ b/src/simix/smx_deployment.c @@ -41,7 +41,7 @@ static void parse_process(sg_platf_process_cbarg_t process) arg->name = (char*)(process->argv)[0]; arg->code = parse_code; arg->data = NULL; - arg->hostname = host->name; + arg->hostname = sg_host_name(host); arg->argc = process->argc; arg->argv = (char**)(process->argv); arg->kill_time = kill_time; @@ -51,21 +51,21 @@ static void parse_process(sg_platf_process_cbarg_t process) arg->hostname, start_time); SIMIX_timer_set(start_time, &SIMIX_process_create_from_wrapper, arg); } else { // start_time <= SIMIX_get_clock() - XBT_DEBUG("Starting Process %s(%s) right now", process->argv[0], host->name); + XBT_DEBUG("Starting Process %s(%s) right now", process->argv[0], sg_host_name(host)); if (simix_global->create_process_function) simix_global->create_process_function(&process_created, (char*)(process->argv)[0], parse_code, NULL, - host->name, + sg_host_name(host), kill_time, process->argc, (char**)(process->argv), current_property_set, auto_restart); else - simcall_process_create(&process_created, (char*)(process->argv)[0], parse_code, NULL, host->name, kill_time, process->argc, + simcall_process_create(&process_created, (char*)(process->argv)[0], parse_code, NULL, sg_host_name(host), kill_time, process->argc, (char**)process->argv, current_property_set,auto_restart); /* verify if process has been created (won't be the case if the host is currently dead, but that's fine) */ @@ -184,7 +184,7 @@ void SIMIX_process_set_function(const char *process_host, smx_host_t host = SIMIX_host_get_by_name(process_host); if (!host) THROWF(arg_error, 0, "Host '%s' unknown", process_host); - process.host = host->name; + process.host = sg_host_name(host); process.argc = 1 + xbt_dynar_length(arguments); process.argv = (const char**)xbt_new(char *, process.argc + 1); diff --git a/src/simix/smx_global.c b/src/simix/smx_global.c index 3d72dd400b..6c0623cb71 100644 --- a/src/simix/smx_global.c +++ b/src/simix/smx_global.c @@ -457,12 +457,12 @@ void SIMIX_display_process_status(void) break; } XBT_INFO("Process %lu (%s@%s): waiting for %s action %p (%s) in state %d to finish", - process->pid, process->name, process->smx_host->name, + process->pid, process->name, sg_host_name(process->smx_host), action_description, process->waiting_action, process->waiting_action->name, (int)process->waiting_action->state); } else { - XBT_INFO("Process %lu (%s@%s)", process->pid, process->name, process->smx_host->name); + XBT_INFO("Process %lu (%s@%s)", process->pid, process->name, sg_host_name(process->smx_host)); } } } diff --git a/src/simix/smx_host.c b/src/simix/smx_host.c index f0b1e0d6b0..114e14b6c2 100644 --- a/src/simix/smx_host.c +++ b/src/simix/smx_host.c @@ -24,20 +24,18 @@ static void SIMIX_execution_finish(smx_action_t action); smx_host_t SIMIX_host_create(const char *name, void *workstation, void *data) { - smx_host_t smx_host = xbt_new0(s_smx_host_t, 1); + smx_host_priv_t smx_host = xbt_new0(s_smx_host_priv_t, 1); s_smx_process_t proc; /* Host structure */ - smx_host->name = xbt_strdup(name); smx_host->data = data; - smx_host->host = workstation; smx_host->process_list = xbt_swag_new(xbt_swag_offset(proc, host_proc_hookup)); /* Update global variables */ - xbt_lib_set(host_lib,smx_host->name,SIMIX_HOST_LEVEL,smx_host); - - return smx_host; + xbt_lib_set(host_lib,name,SIMIX_HOST_LEVEL,smx_host); + + return xbt_lib_get_elm_or_null(host_lib, name); } /** @@ -47,14 +45,14 @@ smx_host_t SIMIX_host_create(const char *name, */ void SIMIX_host_destroy(void *h) { - smx_host_t host = (smx_host_t) h; + smx_host_priv_t host = (smx_host_priv_t) h; xbt_assert((host != NULL), "Invalid parameters"); /* Clean Simulator data */ if (xbt_swag_size(host->process_list) != 0) { char *msg = - bprintf("Shutting down host %s, but it's not empty:", host->name); + bprintf("Shutting down host, but it's not empty:"); char *tmp; smx_process_t process = NULL; @@ -70,9 +68,7 @@ void SIMIX_host_destroy(void *h) xbt_swag_free(host->process_list); /* Clean host structure */ - free(host->name); - free(host); - + free(host); return; } @@ -102,7 +98,7 @@ smx_host_t SIMIX_host_get_by_name(const char *name){ && (host_lib != NULL)), "Environment not set yet"); - return xbt_lib_get_or_null(host_lib, name, SIMIX_HOST_LEVEL); + return xbt_lib_get_elm_or_null(host_lib, name); } smx_host_t SIMIX_host_self(void) @@ -131,7 +127,7 @@ const char* SIMIX_pre_host_get_name(smx_simcall_t simcall, smx_host_t host){ const char* SIMIX_host_get_name(smx_host_t host){ xbt_assert((host != NULL), "Invalid parameters"); - return host->name; + return sg_host_name(host); } xbt_dict_t SIMIX_pre_host_get_properties(smx_simcall_t simcall, smx_host_t host){ @@ -140,7 +136,7 @@ xbt_dict_t SIMIX_pre_host_get_properties(smx_simcall_t simcall, smx_host_t host) xbt_dict_t SIMIX_host_get_properties(smx_host_t host){ xbt_assert((host != NULL), "Invalid parameters (simix host is NULL)"); - return surf_workstation_model->extension.workstation.get_properties(host->host); + return surf_workstation_model->extension.workstation.get_properties(host); } double SIMIX_pre_host_get_speed(smx_simcall_t simcall, smx_host_t host){ @@ -150,7 +146,7 @@ double SIMIX_host_get_speed(smx_host_t host){ xbt_assert((host != NULL), "Invalid parameters (simix host is NULL)"); return surf_workstation_model->extension.workstation. - get_speed(host->host, 1.0); + get_speed(host, 1.0); } double SIMIX_pre_host_get_available_speed(smx_simcall_t simcall, smx_host_t host){ @@ -160,7 +156,7 @@ double SIMIX_host_get_available_speed(smx_host_t host){ xbt_assert((host != NULL), "Invalid parameters (simix host is NULL)"); return surf_workstation_model->extension.workstation. - get_available_speed(host->host); + get_available_speed(host); } int SIMIX_pre_host_get_state(smx_simcall_t simcall, smx_host_t host){ @@ -170,7 +166,7 @@ int SIMIX_host_get_state(smx_host_t host){ xbt_assert((host != NULL), "Invalid parameters (simix host is NULL)"); return surf_workstation_model->extension.workstation. - get_state(host->host); + get_state(host); } void* SIMIX_pre_host_self_get_data(smx_simcall_t simcall){ @@ -194,7 +190,7 @@ void* SIMIX_pre_host_get_data(smx_simcall_t simcall,smx_host_t host){ void* SIMIX_host_get_data(smx_host_t host){ xbt_assert((host != NULL), "Invalid parameters (simix host is NULL)"); - return host->data; + return SIMIX_host_priv(host)->data; } void _SIMIX_host_free_process_arg(void *); void _SIMIX_host_free_process_arg(void *data) @@ -220,8 +216,8 @@ void SIMIX_host_add_auto_restart_process(smx_host_t host, xbt_dict_t properties, int auto_restart) { - if (!host->auto_restart_processes) { - host->auto_restart_processes = xbt_dynar_new(sizeof(smx_process_arg_t),_SIMIX_host_free_process_arg); + if (!SIMIX_host_priv(host)->auto_restart_processes) { + SIMIX_host_priv(host)->auto_restart_processes = xbt_dynar_new(sizeof(smx_process_arg_t),_SIMIX_host_free_process_arg); } smx_process_arg_t arg = xbt_new(s_smx_process_arg_t,1); arg->name = xbt_strdup(name); @@ -243,11 +239,11 @@ void SIMIX_host_add_auto_restart_process(smx_host_t host, arg->auto_restart = auto_restart; if( SIMIX_host_get_state(host) == SURF_RESOURCE_OFF - && !xbt_dict_get_or_null(watched_hosts_lib,host->name)){ - xbt_dict_set(watched_hosts_lib,host->name,host,NULL); - XBT_DEBUG("Have push host %s to watched_hosts_lib because state == SURF_RESOURCE_OFF",host->name); + && !xbt_dict_get_or_null(watched_hosts_lib,sg_host_name(host))){ + xbt_dict_set(watched_hosts_lib,sg_host_name(host),host,NULL); + XBT_DEBUG("Have push host %s to watched_hosts_lib because state == SURF_RESOURCE_OFF",sg_host_name(host)); } - xbt_dynar_push_as(host->auto_restart_processes,smx_process_arg_t,arg); + xbt_dynar_push_as(SIMIX_host_priv(host)->auto_restart_processes,smx_process_arg_t,arg); } /** * \brief Restart the list of processes that have been registered to the host @@ -256,7 +252,7 @@ void SIMIX_host_restart_processes(smx_host_t host) { unsigned int cpt; smx_process_arg_t arg; - xbt_dynar_foreach(host->auto_restart_processes,cpt,arg) { + xbt_dynar_foreach(SIMIX_host_priv(host)->auto_restart_processes,cpt,arg) { smx_process_t process; @@ -287,7 +283,7 @@ void SIMIX_host_restart_processes(smx_host_t host) } } - xbt_dynar_reset(host->auto_restart_processes); + xbt_dynar_reset(SIMIX_host_priv(host)->auto_restart_processes); } void SIMIX_host_autorestart(smx_host_t host) @@ -303,9 +299,9 @@ void SIMIX_pre_host_set_data(smx_simcall_t simcall, smx_host_t host, void *data) } void SIMIX_host_set_data(smx_host_t host, void *data){ xbt_assert((host != NULL), "Invalid parameters"); - xbt_assert((host->data == NULL), "Data already set"); + xbt_assert((SIMIX_host_priv(host)->data == NULL), "Data already set"); - host->data = data; + SIMIX_host_priv(host)->data = data; } smx_action_t SIMIX_pre_host_execute(smx_simcall_t simcall,const char *name, @@ -329,7 +325,7 @@ smx_action_t SIMIX_host_execute(const char *name, /* set surf's action */ if (!MC_is_active()) { action->execution.surf_exec = - surf_workstation_model->extension.workstation.execute(host->host, + surf_workstation_model->extension.workstation.execute(host, computation_amount); surf_workstation_model->action_data_set(action->execution.surf_exec, action); surf_workstation_model->set_priority(action->execution.surf_exec, priority); @@ -369,7 +365,7 @@ smx_action_t SIMIX_host_parallel_execute(const char *name, /* set surf's action */ workstation_list = xbt_new0(void *, host_nb); for (i = 0; i < host_nb; i++) - workstation_list[i] = host_list[i]->host; + workstation_list[i] = host_list[i]; /* set surf's action */ if (!MC_is_active()) { @@ -484,7 +480,7 @@ void SIMIX_execution_finish(smx_action_t action) break; case SIMIX_FAILED: - XBT_DEBUG("SIMIX_execution_finished: host '%s' failed", simcall->issuer->smx_host->name); + XBT_DEBUG("SIMIX_execution_finished: host '%s' failed", sg_host_name(simcall->issuer->smx_host)); simcall->issuer->context->iwannadie = 1; //SMX_EXCEPTION(simcall->issuer, host_error, 0, "Host failed"); break; @@ -500,7 +496,7 @@ void SIMIX_execution_finish(smx_action_t action) } /* check if the host is down */ if (surf_workstation_model->extension. - workstation.get_state(simcall->issuer->smx_host->host) != SURF_RESOURCE_ON) { + workstation.get_state(simcall->issuer->smx_host) != SURF_RESOURCE_ON) { simcall->issuer->context->iwannadie = 1; } @@ -517,7 +513,7 @@ void SIMIX_post_host_execute(smx_action_t action) { if (action->type == SIMIX_ACTION_EXECUTE && /* FIMXE: handle resource failure * for parallel tasks too */ - surf_workstation_model->extension.workstation.get_state(action->execution.host->host) == SURF_RESOURCE_OFF) { + surf_workstation_model->extension.workstation.get_state(action->execution.host) == SURF_RESOURCE_OFF) { /* If the host running the action failed, notice it so that the asking * process can be killed if it runs on that host itself */ action->state = SIMIX_FAILED; diff --git a/src/simix/smx_host_private.h b/src/simix/smx_host_private.h index 6819f61005..6b03c1708e 100644 --- a/src/simix/smx_host_private.h +++ b/src/simix/smx_host_private.h @@ -11,13 +11,16 @@ #include "smx_smurf_private.h" /** @brief Host datatype */ -typedef struct s_smx_host { - char *name; /**< @brief host name if any */ - void *host; /* SURF modeling */ +typedef struct s_smx_host_priv { xbt_swag_t process_list; xbt_dynar_t auto_restart_processes; void *data; /**< @brief user data */ -} s_smx_host_t; +} s_smx_host_priv_t; + +static inline smx_host_priv_t SIMIX_host_priv(smx_host_t host){ + return xbt_lib_get_level(host, SIMIX_HOST_LEVEL); +} + smx_host_t SIMIX_host_create(const char *name, void *workstation, void *data); void SIMIX_host_destroy(void *host); diff --git a/src/simix/smx_io.c b/src/simix/smx_io.c index 383510b531..f261620d80 100644 --- a/src/simix/smx_io.c +++ b/src/simix/smx_io.c @@ -30,9 +30,9 @@ smx_action_t SIMIX_file_read(smx_process_t process, void* ptr, size_t size, size /* check if the host is active */ if (surf_workstation_model->extension. - workstation.get_state(host->host) != SURF_RESOURCE_ON) { + workstation.get_state(host) != SURF_RESOURCE_ON) { THROWF(host_error, 0, "Host %s failed, you cannot call this function", - host->name); + sg_host_name(host)); } action = xbt_mallocator_get(simix_global->action_mallocator); @@ -43,7 +43,7 @@ smx_action_t SIMIX_file_read(smx_process_t process, void* ptr, size_t size, size #endif action->io.host = host; - action->io.surf_io = surf_workstation_model->extension.workstation.read(host->host, ptr, size, nmemb, stream->surf_file); + action->io.surf_io = surf_workstation_model->extension.workstation.read(host, ptr, size, nmemb, stream->surf_file); surf_workstation_model->action_data_set(action->io.surf_io, action); XBT_DEBUG("Create io action %p", action); @@ -67,9 +67,9 @@ smx_action_t SIMIX_file_write(smx_process_t process, const void* ptr, size_t siz /* check if the host is active */ if (surf_workstation_model->extension. - workstation.get_state(host->host) != SURF_RESOURCE_ON) { + workstation.get_state(host) != SURF_RESOURCE_ON) { THROWF(host_error, 0, "Host %s failed, you cannot call this function", - host->name); + sg_host_name(host)); } action = xbt_mallocator_get(simix_global->action_mallocator); @@ -80,7 +80,7 @@ smx_action_t SIMIX_file_write(smx_process_t process, const void* ptr, size_t siz #endif action->io.host = host; - action->io.surf_io = surf_workstation_model->extension.workstation.write(host->host, ptr, size, nmemb, stream->surf_file); + action->io.surf_io = surf_workstation_model->extension.workstation.write(host, ptr, size, nmemb, stream->surf_file); surf_workstation_model->action_data_set(action->io.surf_io, action); XBT_DEBUG("Create io action %p", action); @@ -104,9 +104,9 @@ smx_action_t SIMIX_file_open(smx_process_t process ,const char* mount, const cha /* check if the host is active */ if (surf_workstation_model->extension. - workstation.get_state(host->host) != SURF_RESOURCE_ON) { + workstation.get_state(host) != SURF_RESOURCE_ON) { THROWF(host_error, 0, "Host %s failed, you cannot call this function", - host->name); + sg_host_name(host)); } action = xbt_mallocator_get(simix_global->action_mallocator); @@ -117,7 +117,7 @@ smx_action_t SIMIX_file_open(smx_process_t process ,const char* mount, const cha #endif action->io.host = host; - action->io.surf_io = surf_workstation_model->extension.workstation.open(host->host, mount, path, mode); + action->io.surf_io = surf_workstation_model->extension.workstation.open(host, mount, path, mode); surf_workstation_model->action_data_set(action->io.surf_io, action); XBT_DEBUG("Create io action %p", action); @@ -140,9 +140,9 @@ smx_action_t SIMIX_file_close(smx_process_t process, smx_file_t fp) /* check if the host is active */ if (surf_workstation_model->extension. - workstation.get_state(host->host) != SURF_RESOURCE_ON) { + workstation.get_state(host) != SURF_RESOURCE_ON) { THROWF(host_error, 0, "Host %s failed, you cannot call this function", - host->name); + sg_host_name(host)); } action = xbt_mallocator_get(simix_global->action_mallocator); @@ -153,7 +153,7 @@ smx_action_t SIMIX_file_close(smx_process_t process, smx_file_t fp) #endif action->io.host = host; - action->io.surf_io = surf_workstation_model->extension.workstation.close(host->host, fp->surf_file); + action->io.surf_io = surf_workstation_model->extension.workstation.close(host, fp->surf_file); surf_workstation_model->action_data_set(action->io.surf_io, action); XBT_DEBUG("Create io action %p", action); @@ -175,9 +175,9 @@ smx_action_t SIMIX_file_stat(smx_process_t process, smx_file_t fd, s_file_stat_t 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) { + workstation.get_state(host) != SURF_RESOURCE_ON) { THROWF(host_error, 0, "Host %s failed, you cannot call this function", - host->name); + sg_host_name(host)); } action = xbt_mallocator_get(simix_global->action_mallocator); @@ -188,7 +188,7 @@ smx_action_t SIMIX_file_stat(smx_process_t process, smx_file_t fd, s_file_stat_t #endif action->io.host = host; - action->io.surf_io = surf_workstation_model->extension.workstation.stat(host->host, fd->surf_file); + action->io.surf_io = surf_workstation_model->extension.workstation.stat(host, fd->surf_file); surf_workstation_model->action_data_set(action->io.surf_io, action); XBT_DEBUG("Create io action %p", action); @@ -210,9 +210,9 @@ smx_action_t SIMIX_file_unlink(smx_process_t process, smx_file_t fd) 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) { + workstation.get_state(host) != SURF_RESOURCE_ON) { THROWF(host_error, 0, "Host %s failed, you cannot call this function", - host->name); + sg_host_name(host)); } action = xbt_mallocator_get(simix_global->action_mallocator); @@ -223,7 +223,7 @@ smx_action_t SIMIX_file_unlink(smx_process_t process, smx_file_t fd) #endif action->io.host = host; - action->io.surf_io = surf_workstation_model->extension.workstation.unlink(host->host, fd->surf_file); + action->io.surf_io = surf_workstation_model->extension.workstation.unlink(host, fd->surf_file); surf_workstation_model->action_data_set(action->io.surf_io, action); XBT_DEBUG("Create io action %p", action); @@ -244,9 +244,9 @@ smx_action_t SIMIX_file_ls(smx_process_t process, const char* mount, const char 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) { + if (surf_workstation_model->extension.workstation.get_state(host) != SURF_RESOURCE_ON) { THROWF(host_error, 0, "Host %s failed, you cannot call this function", - host->name); + sg_host_name(host)); } action = xbt_mallocator_get(simix_global->action_mallocator); @@ -257,7 +257,7 @@ smx_action_t SIMIX_file_ls(smx_process_t process, const char* mount, const char #endif action->io.host = host; - action->io.surf_io = surf_workstation_model->extension.workstation.ls(host->host,mount,path); + action->io.surf_io = surf_workstation_model->extension.workstation.ls(host,mount,path); surf_workstation_model->action_data_set(action->io.surf_io, action); XBT_DEBUG("Create io action %p", action); @@ -387,7 +387,7 @@ void SIMIX_io_finish(smx_action_t action) } if (surf_workstation_model->extension. - workstation.get_state(simcall->issuer->smx_host->host) != SURF_RESOURCE_ON) { + workstation.get_state(simcall->issuer->smx_host) != SURF_RESOURCE_ON) { simcall->issuer->context->iwannadie = 1; } diff --git a/src/simix/smx_network.c b/src/simix/smx_network.c index 23600af323..48c05f3029 100644 --- a/src/simix/smx_network.c +++ b/src/simix/smx_network.c @@ -619,7 +619,7 @@ void SIMIX_pre_comm_wait(smx_simcall_t simcall, smx_action_t action, double time if (action->state != SIMIX_WAITING && action->state != SIMIX_RUNNING) { SIMIX_comm_finish(action); } else { /* if (timeout >= 0) { we need a surf sleep action even when there is no timeout, otherwise surf won't tell us when the host fails */ - sleep = surf_workstation_model->extension.workstation.sleep(simcall->issuer->smx_host->host, timeout); + sleep = surf_workstation_model->extension.workstation.sleep(simcall->issuer->smx_host, timeout); surf_workstation_model->action_data_set(sleep, action); if (simcall->issuer == action->comm.src_proc) @@ -737,7 +737,7 @@ XBT_INLINE void SIMIX_comm_start(smx_action_t action) SIMIX_host_get_name(sender), SIMIX_host_get_name(receiver)); action->comm.surf_comm = surf_workstation_model->extension.workstation. - communicate(sender->host, receiver->host, action->comm.task_size, action->comm.rate); + communicate(sender, receiver, action->comm.task_size, action->comm.rate); surf_workstation_model->action_data_set(action->comm.surf_comm, action); @@ -834,8 +834,8 @@ void SIMIX_comm_finish(smx_action_t action) case SIMIX_LINK_FAILURE: XBT_DEBUG("Link failure in action %p between '%s' and '%s': posting an exception to the issuer: %s (%p) detached:%d", action, - action->comm.src_proc ? action->comm.src_proc->smx_host->name : NULL, - action->comm.dst_proc ? action->comm.dst_proc->smx_host->name : NULL, + action->comm.src_proc ? sg_host_name(action->comm.src_proc->smx_host) : NULL, + action->comm.dst_proc ? sg_host_name(action->comm.dst_proc->smx_host) : NULL, simcall->issuer->name, simcall->issuer, action->comm.detached); if (action->comm.src_proc == simcall->issuer) { XBT_DEBUG("I'm source"); @@ -871,7 +871,7 @@ void SIMIX_comm_finish(smx_action_t action) } if (surf_workstation_model->extension. - workstation.get_state(simcall->issuer->smx_host->host) != SURF_RESOURCE_ON) { + workstation.get_state(simcall->issuer->smx_host) != SURF_RESOURCE_ON) { simcall->issuer->context->iwannadie = 1; } @@ -1124,9 +1124,9 @@ void SIMIX_comm_copy_data(smx_action_t comm) XBT_DEBUG("Copying comm %p data from %s (%p) -> %s (%p) (%zu bytes)", comm, - comm->comm.src_proc ? comm->comm.src_proc->smx_host->name : "a finished process", + comm->comm.src_proc ? sg_host_name(comm->comm.src_proc->smx_host) : "a finished process", comm->comm.src_buff, - comm->comm.dst_proc ? comm->comm.dst_proc->smx_host->name : "a finished process", + comm->comm.dst_proc ? sg_host_name(comm->comm.dst_proc->smx_host) : "a finished process", comm->comm.dst_buff, buff_size); /* Copy at most dst_buff_size bytes of the message to receiver's buffer */ diff --git a/src/simix/smx_new_api.c b/src/simix/smx_new_api.c index 7c5498d49b..acafb0e3a9 100644 --- a/src/simix/smx_new_api.c +++ b/src/simix/smx_new_api.c @@ -68,9 +68,9 @@ smx_action_t SIMIX_new_api_fct(smx_process_t process, const char* param1, double /* check if the host is active */ if (surf_workstation_model->extension. - workstation.get_state(host->host) != SURF_RESOURCE_ON) { + workstation.get_state(host) != SURF_RESOURCE_ON) { THROWF(host_error, 0, "Host %s failed, you cannot call this function", - host->name); + sg_host_name(host)); } action = xbt_mallocator_get(simix_global->action_mallocator); @@ -124,7 +124,7 @@ void SIMIX_new_api_finish(smx_action_t action) } if (surf_workstation_model->extension. - workstation.get_state(simcall->issuer->smx_host->host) != SURF_RESOURCE_ON) { + workstation.get_state(simcall->issuer->smx_host) != SURF_RESOURCE_ON) { simcall->issuer->context->iwannadie = 1; } diff --git a/src/simix/smx_process.c b/src/simix/smx_process.c index 434f87a531..6172807a78 100644 --- a/src/simix/smx_process.c +++ b/src/simix/smx_process.c @@ -97,7 +97,7 @@ void SIMIX_process_cleanup(smx_process_t process) /*xbt_swag_remove(process, simix_global->process_to_run);*/ xbt_swag_remove(process, simix_global->process_list); - xbt_swag_remove(process, process->smx_host->process_list); + xbt_swag_remove(process, SIMIX_host_priv(process->smx_host)->process_list); xbt_swag_insert(process, simix_global->process_to_destroy); process->context->iwannadie = 0; } @@ -162,12 +162,12 @@ void SIMIX_process_stop(smx_process_t arg) { */ if (arg->auto_restart && !SIMIX_host_get_state(arg->smx_host)) { SIMIX_host_add_auto_restart_process(arg->smx_host,arg->name,arg->code, arg->data, - arg->smx_host->name, + sg_host_name(arg->smx_host), arg->kill_time, arg->argc,arg->argv,arg->properties, arg->auto_restart); } - XBT_DEBUG("Process %s (%s) is dead",arg->name,arg->smx_host->name); + XBT_DEBUG("Process %s (%s) is dead",arg->name,sg_host_name(arg->smx_host)); /* stop the context */ SIMIX_context_stop(arg->context); } @@ -268,20 +268,20 @@ void SIMIX_process_create(smx_process_t *process, (*process)->properties = properties; /* Add the process to it's host process list */ - xbt_swag_insert(*process, host->process_list); + xbt_swag_insert(*process, SIMIX_host_priv(host)->process_list); XBT_DEBUG("Start context '%s'", (*process)->name); /* Now insert it in the global process list and in the process to run list */ xbt_swag_insert(*process, simix_global->process_list); - XBT_DEBUG("Inserting %s(%s) in the to_run list", (*process)->name, host->name); + XBT_DEBUG("Inserting %s(%s) in the to_run list", (*process)->name, sg_host_name(host)); xbt_dynar_push_as(simix_global->process_to_run, smx_process_t, *process); } if (kill_time > SIMIX_get_clock()) { if (simix_global->kill_process_function) { XBT_DEBUG("Process %s(%s) will be kill at time %f", (*process)->name, - (*process)->smx_host->name, kill_time); + sg_host_name((*process)->smx_host), kill_time); SIMIX_timer_set(kill_time, simix_global->kill_process_function, *process); } } @@ -320,7 +320,7 @@ void SIMIX_pre_process_kill(smx_simcall_t simcall, smx_process_t process) { */ void SIMIX_process_kill(smx_process_t process, smx_process_t issuer) { - XBT_DEBUG("Killing process %s on %s", process->name, process->smx_host->name); + XBT_DEBUG("Killing process %s on %s", process->name, sg_host_name(process->smx_host)); process->context->iwannadie = 1; process->blocked = 0; @@ -401,9 +401,9 @@ void SIMIX_process_change_host(smx_process_t process, smx_host_t dest) { xbt_assert((process != NULL), "Invalid parameters"); - xbt_swag_remove(process, process->smx_host->process_list); + xbt_swag_remove(process, SIMIX_host_priv(process->smx_host)->process_list); process->smx_host = dest; - xbt_swag_insert(process, dest->process_list); + xbt_swag_insert(process, SIMIX_host_priv(dest)->process_list); } @@ -651,9 +651,9 @@ smx_action_t SIMIX_process_sleep(smx_process_t process, double duration) /* check if the host is active */ if (surf_workstation_model->extension. - workstation.get_state(host->host) != SURF_RESOURCE_ON) { + workstation.get_state(host) != SURF_RESOURCE_ON) { THROWF(host_error, 0, "Host %s failed, you cannot call this function", - host->name); + sg_host_name(host)); } action = xbt_mallocator_get(simix_global->action_mallocator); @@ -665,7 +665,7 @@ smx_action_t SIMIX_process_sleep(smx_process_t process, double duration) action->sleep.host = host; action->sleep.surf_sleep = - surf_workstation_model->extension.workstation.sleep(host->host, duration); + surf_workstation_model->extension.workstation.sleep(host, duration); surf_workstation_model->action_data_set(action->sleep.surf_sleep, action); XBT_DEBUG("Create sleep action %p", action); @@ -695,7 +695,7 @@ void SIMIX_post_process_sleep(smx_action_t action) break; } if (surf_workstation_model->extension. - workstation.get_state(simcall->issuer->smx_host->host) != SURF_RESOURCE_ON) { + workstation.get_state(simcall->issuer->smx_host) != SURF_RESOURCE_ON) { simcall->issuer->context->iwannadie = 1; } simcall_process_sleep__set__result(simcall, state); @@ -867,12 +867,12 @@ smx_process_t SIMIX_pre_process_restart(smx_simcall_t simcall, smx_process_t pro * Restart a process, starting it again from the beginning. */ smx_process_t SIMIX_process_restart(smx_process_t process, smx_process_t issuer) { - XBT_DEBUG("Restarting process %s on %s", process->name, process->smx_host->name); + XBT_DEBUG("Restarting process %s on %s", process->name, sg_host_name(process->smx_host)); //retrieve the arguments of the old process //FIXME: Factorise this with SIMIX_host_add_auto_restart_process ? s_smx_process_arg_t arg; arg.code = process->code; - arg.hostname = process->smx_host->name; + arg.hostname = sg_host_name(process->smx_host); arg.kill_time = process->kill_time; arg.argc = process->argc; arg.data = process->data; diff --git a/src/simix/smx_synchro.c b/src/simix/smx_synchro.c index 1237446d61..414b927cfa 100644 --- a/src/simix/smx_synchro.c +++ b/src/simix/smx_synchro.c @@ -28,7 +28,7 @@ static smx_action_t SIMIX_synchro_wait(smx_host_t smx_host, double timeout) action->type = SIMIX_ACTION_SYNCHRO; action->name = xbt_strdup("synchro"); action->synchro.sleep = - surf_workstation_model->extension.workstation.sleep(smx_host->host, timeout); + surf_workstation_model->extension.workstation.sleep(smx_host, timeout); surf_workstation_model->action_data_set(action->synchro.sleep, action); XBT_OUT(); diff --git a/src/simix/smx_user.c b/src/simix/smx_user.c index cf5caa2179..15fca99e57 100644 --- a/src/simix/smx_user.c +++ b/src/simix/smx_user.c @@ -440,7 +440,7 @@ void simcall_process_set_kill_time(smx_process_t process, double kill_time) if (kill_time > SIMIX_get_clock()) { if (simix_global->kill_process_function) { XBT_DEBUG("Set kill time %f for process %s(%s)",kill_time, process->name, - process->smx_host->name); + sg_host_name(process->smx_host)); SIMIX_timer_set(kill_time, simix_global->kill_process_function, process); } } diff --git a/src/surf/cpu_cas01.c b/src/surf/cpu_cas01.c index 79bbc86b73..b492ee1106 100644 --- a/src/surf/cpu_cas01.c +++ b/src/surf/cpu_cas01.c @@ -37,8 +37,6 @@ typedef struct cpu_Cas01 { XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_cpu, surf, "Logging specific to the SURF CPU IMPROVED module"); - - static xbt_swag_t cpu_running_action_set_that_does_not_need_being_checked = NULL; @@ -54,7 +52,7 @@ static void *cpu_create_resource(const char *name, double power_peak, { cpu_Cas01_t cpu = NULL; - xbt_assert(!surf_cpu_resource_by_name(name), + xbt_assert(!surf_cpu_resource_priv(surf_cpu_resource_by_name(name)), "Host '%s' declared several times in the platform file", name); cpu = (cpu_Cas01_t) surf_resource_new(sizeof(s_cpu_Cas01_t), @@ -81,7 +79,7 @@ static void *cpu_create_resource(const char *name, double power_peak, xbt_lib_set(host_lib, name, SURF_CPU_LEVEL, cpu); - return cpu; + return xbt_lib_get_elm_or_null(host_lib, name);; } @@ -229,7 +227,7 @@ static void cpu_update_resource_state(void *id, static surf_action_t cpu_execute(void *cpu, double size) { surf_action_cpu_Cas01_t action = NULL; - cpu_Cas01_t CPU = cpu; + cpu_Cas01_t CPU = surf_cpu_resource_priv(cpu); XBT_IN("(%s,%g)", surf_resource_name(CPU), size); action = @@ -262,7 +260,7 @@ static surf_action_t cpu_action_sleep(void *cpu, double duration) if (duration > 0) duration = MAX(duration, MAXMIN_PRECISION); - XBT_IN("(%s,%g)", surf_resource_name(cpu), duration); + XBT_IN("(%s,%g)", surf_resource_name(surf_cpu_resource_priv(cpu)), duration); action = (surf_action_cpu_Cas01_t) cpu_execute(cpu, 1.0); // FIXME: sleep variables should not consume 1.0 in lmm_expand GENERIC_ACTION(action).max_duration = duration; @@ -292,18 +290,18 @@ static surf_action_t cpu_action_sleep(void *cpu, double duration) static e_surf_resource_state_t cpu_get_state(void *cpu) { - return ((cpu_Cas01_t) cpu)->state_current; + return ((cpu_Cas01_t)surf_cpu_resource_priv(cpu))->state_current; } static double cpu_get_speed(void *cpu, double load) { - return load * (((cpu_Cas01_t) cpu)->power_peak); + return load * ((cpu_Cas01_t)surf_cpu_resource_priv(cpu))->power_peak; } static double cpu_get_available_speed(void *cpu) { /* number between 0 and 1 */ - return ((cpu_Cas01_t) cpu)->power_scale; + return ((cpu_Cas01_t)surf_cpu_resource_priv(cpu))->power_scale; } static void cpu_finalize(void) diff --git a/src/surf/cpu_ti.c b/src/surf/cpu_ti.c index 30d23f88c1..b44fd4d035 100644 --- a/src/surf/cpu_ti.c +++ b/src/surf/cpu_ti.c @@ -155,7 +155,7 @@ static void* cpu_ti_create_resource(const char *name, double power_peak, cpu_ti_t cpu = NULL; s_surf_action_cpu_ti_t ti_action; xbt_assert(core==1,"Multi-core not handled with this model yet"); - xbt_assert(!surf_cpu_resource_by_name(name), + xbt_assert(!surf_cpu_resource_priv(surf_cpu_resource_by_name(name)), "Host '%s' declared several times in the platform file", name); xbt_assert(core==1,"Multi-core not handled with this model yet"); @@ -185,7 +185,7 @@ static void* cpu_ti_create_resource(const char *name, double power_peak, } xbt_lib_set(host_lib, name, SURF_CPU_LEVEL, cpu); - return cpu; + return xbt_lib_get_elm_or_null(host_lib, name); } @@ -216,7 +216,7 @@ static void add_traces_cpu_ti(void) /* connect all traces relative to hosts */ xbt_dict_foreach(trace_connect_list_host_avail, cursor, trace_name, elm) { tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name); - cpu_ti_t cpu = surf_cpu_resource_by_name(elm); + cpu_ti_t cpu = surf_cpu_resource_priv(surf_cpu_resource_by_name(elm)); xbt_assert(cpu, "Host %s undefined", elm); xbt_assert(trace, "Trace %s undefined", trace_name); @@ -232,7 +232,7 @@ static void add_traces_cpu_ti(void) xbt_dict_foreach(trace_connect_list_power, cursor, trace_name, elm) { tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name); - cpu_ti_t cpu = surf_cpu_resource_by_name(elm); + cpu_ti_t cpu = surf_cpu_resource_priv(surf_cpu_resource_by_name(elm)); xbt_assert(cpu, "Host %s undefined", elm); xbt_assert(trace, "Trace %s undefined", trace_name); @@ -277,11 +277,11 @@ static int cpu_ti_action_unref(surf_action_t action) if (!action->refcount) { xbt_swag_remove(action, action->state_set); /* remove from action_set */ - xbt_swag_remove(action, ACTION_GET_CPU(action)->action_set); + xbt_swag_remove(action, ((cpu_ti_t)surf_cpu_resource_priv(ACTION_GET_CPU(action)))->action_set); /* remove from heap */ xbt_heap_remove(cpu_ti_action_heap, ((surf_action_cpu_ti_t) action)->index_heap); - xbt_swag_insert(ACTION_GET_CPU(action), cpu_ti_modified_cpu); + xbt_swag_insert(((cpu_ti_t)surf_cpu_resource_priv(ACTION_GET_CPU(action))), cpu_ti_modified_cpu); surf_action_free(&action); return 1; } @@ -293,7 +293,7 @@ static void cpu_ti_action_cancel(surf_action_t action) surf_action_state_set(action, SURF_ACTION_FAILED); xbt_heap_remove(cpu_ti_action_heap, ((surf_action_cpu_ti_t) action)->index_heap); - xbt_swag_insert(ACTION_GET_CPU(action), cpu_ti_modified_cpu); + xbt_swag_insert(surf_cpu_resource_priv(ACTION_GET_CPU(action)), cpu_ti_modified_cpu); return; } @@ -301,7 +301,7 @@ static void cpu_ti_action_state_set(surf_action_t action, e_surf_action_state_t state) { surf_action_state_set(action, state); - xbt_swag_insert(ACTION_GET_CPU(action), cpu_ti_modified_cpu); + xbt_swag_insert(surf_cpu_resource_priv(ACTION_GET_CPU(action)), cpu_ti_modified_cpu); return; } @@ -482,7 +482,7 @@ static void cpu_ti_update_actions_state(double now, double delta) GENERIC_ACTION(action).remains = 0; cpu_ti_action_state_set((surf_action_t) action, SURF_ACTION_DONE); /* update remaining amout of all actions */ - cpu_ti_update_remaining_amount(action->cpu, surf_get_clock()); + cpu_ti_update_remaining_amount(surf_cpu_resource_priv(action->cpu), surf_get_clock()); } #undef GENERIC_ACTION } @@ -563,7 +563,7 @@ static void cpu_ti_update_resource_state(void *id, static surf_action_t cpu_ti_execute(void *cpu, double size) { surf_action_cpu_ti_t action = NULL; - cpu_ti_t CPU = cpu; + cpu_ti_t CPU = surf_cpu_resource_priv(cpu); XBT_IN("(%s,%g)", surf_resource_name(CPU), size); action = @@ -595,7 +595,7 @@ static surf_action_t cpu_ti_action_sleep(void *cpu, double duration) if (duration > 0) duration = MAX(duration, MAXMIN_PRECISION); - XBT_IN("(%s,%g)", surf_resource_name(cpu), duration); + XBT_IN("(%s,%g)", surf_resource_name(surf_cpu_resource_priv(cpu)), duration); action = (surf_action_cpu_ti_t) cpu_ti_execute(cpu, 1.0); action->generic_action.max_duration = duration; action->suspended = 2; @@ -618,7 +618,7 @@ static void cpu_ti_action_suspend(surf_action_t action) ((surf_action_cpu_ti_t) action)->suspended = 1; xbt_heap_remove(cpu_ti_action_heap, ((surf_action_cpu_ti_t) action)->index_heap); - xbt_swag_insert(ACTION_GET_CPU(action), cpu_ti_modified_cpu); + xbt_swag_insert(surf_cpu_resource_priv(ACTION_GET_CPU(action)), cpu_ti_modified_cpu); } XBT_OUT(); } @@ -628,7 +628,7 @@ static void cpu_ti_action_resume(surf_action_t action) XBT_IN("(%p)", action); if (((surf_action_cpu_ti_t) action)->suspended != 2) { ((surf_action_cpu_ti_t) action)->suspended = 0; - xbt_swag_insert(ACTION_GET_CPU(action), cpu_ti_modified_cpu); + xbt_swag_insert(surf_cpu_resource_priv(ACTION_GET_CPU(action)), cpu_ti_modified_cpu); } XBT_OUT(); } @@ -673,7 +673,7 @@ static void cpu_ti_action_set_priority(surf_action_t action, { XBT_IN("(%p,%g)", action, priority); action->priority = priority; - xbt_swag_insert(ACTION_GET_CPU(action), cpu_ti_modified_cpu); + xbt_swag_insert(surf_cpu_resource_priv(ACTION_GET_CPU(action)), cpu_ti_modified_cpu); XBT_OUT(); } @@ -689,12 +689,12 @@ static double cpu_ti_action_get_remains(surf_action_t action) static e_surf_resource_state_t cpu_ti_get_state(void *cpu) { - return ((cpu_ti_t) cpu)->state_current; + return ((cpu_ti_t)surf_cpu_resource_priv(cpu))->state_current; } static double cpu_ti_get_speed(void *cpu, double load) { - return load * (((cpu_ti_t) cpu)->power_peak); + return load * ((cpu_ti_t)surf_cpu_resource_priv(cpu))->power_peak; } /** @@ -722,7 +722,7 @@ static double surf_cpu_ti_get_power_scale(surf_cpu_ti_tgmr_t trace, static double cpu_ti_get_available_speed(void *cpu) { - cpu_ti_t CPU = cpu; + cpu_ti_t CPU = surf_cpu_resource_priv(cpu); CPU->power_scale = surf_cpu_ti_get_power_scale(CPU->avail_trace, surf_get_clock()); /* number between 0 and 1 */ diff --git a/src/surf/storage.c b/src/surf/storage.c index 4d82cd3189..ff827791b4 100644 --- a/src/surf/storage.c +++ b/src/surf/storage.c @@ -232,7 +232,7 @@ static void* storage_create_resource(const char* id, const char* model,const cha { storage_t storage = NULL; - xbt_assert(!surf_storage_resource_by_name(id), + xbt_assert(!surf_storage_resource_priv(surf_storage_resource_by_name(id)), "Storage '%s' declared several times in the platform file", id); storage = (storage_t) surf_resource_new(sizeof(s_storage_t), @@ -673,7 +673,7 @@ static void storage_parse_mount(sg_platf_mount_cbarg_t mount) XBT_DEBUG("ROUTING Mount '%s' on '%s'",mount->id, mount->name); s_mount_t mnt; - mnt.id = surf_storage_resource_by_name(mount->id); + mnt.id = surf_storage_resource_priv(surf_storage_resource_by_name(mount->id)); mnt.name = xbt_strdup(mount->name); if(!mount_list){ diff --git a/src/surf/workstation.c b/src/surf/workstation.c index fec50a4d3d..13798ec37c 100644 --- a/src/surf/workstation.c +++ b/src/surf/workstation.c @@ -14,7 +14,6 @@ typedef struct workstation_CLM03 { s_surf_resource_t generic_resource; /* Must remain first to add this to a trace */ - void *cpu; void *net_elm; xbt_dynar_t storage; } s_workstation_CLM03_t, *workstation_CLM03_t; @@ -30,7 +29,6 @@ static void workstation_new(sg_platf_host_cbarg_t host) workstation->generic_resource.model = surf_workstation_model; workstation->generic_resource.name = xbt_strdup(host->id); - workstation->cpu = xbt_lib_get_or_null(host_lib, host->id, SURF_CPU_LEVEL); workstation->storage = xbt_lib_get_or_null(storage_lib,host->id,ROUTING_STORAGE_HOST_LEVEL); workstation->net_elm = xbt_lib_get_or_null(host_lib,host->id,ROUTING_HOST_LEVEL); XBT_DEBUG("Create workstation %s with %ld mounted disks",host->id,xbt_dynar_length(workstation->storage)); @@ -113,14 +111,14 @@ static void ws_update_resource_state(void *id, static surf_action_t ws_execute(void *workstation, double size) { - void *cpu = ((workstation_CLM03_t) workstation)->cpu; - return ((surf_resource_t) cpu)->model->extension.cpu.execute(cpu, size); + surf_resource_t cpu = ((surf_resource_t) surf_cpu_resource_priv(workstation)); + return cpu->model->extension.cpu.execute(workstation, size); } static surf_action_t ws_action_sleep(void *workstation, double duration) { return surf_cpu_model->extension.cpu. - sleep(((workstation_CLM03_t) workstation)->cpu, duration); + sleep(workstation, duration); } static void ws_action_suspend(surf_action_t action) @@ -210,8 +208,8 @@ static surf_action_t ws_communicate(void *workstation_src, void *workstation_dst, double size, double rate) { - workstation_CLM03_t src = (workstation_CLM03_t) workstation_src; - workstation_CLM03_t dst = (workstation_CLM03_t) workstation_dst; + workstation_CLM03_t src = surf_workstation_resource_priv(workstation_src); + workstation_CLM03_t dst = surf_workstation_resource_priv(workstation_dst); return surf_network_model->extension.network. communicate(src->net_elm, dst->net_elm, size, rate); @@ -220,20 +218,19 @@ static surf_action_t ws_communicate(void *workstation_src, static e_surf_resource_state_t ws_get_state(void *workstation) { return surf_cpu_model->extension.cpu. - get_state(((workstation_CLM03_t) workstation)->cpu); + get_state(workstation); } static double ws_get_speed(void *workstation, double load) { return surf_cpu_model->extension.cpu. - get_speed(((workstation_CLM03_t) workstation)->cpu, load); + get_speed(workstation, load); } static double ws_get_available_speed(void *workstation) { return surf_cpu_model->extension.cpu. - get_available_speed(((workstation_CLM03_t) - workstation)->cpu); + get_available_speed(workstation); } static surf_action_t ws_execute_parallel_task(int workstation_nb, @@ -275,8 +272,8 @@ static surf_action_t ws_execute_parallel_task(int workstation_nb, static xbt_dynar_t ws_get_route(void *workstation_src, void *workstation_dst) { XBT_DEBUG("ws_get_route"); - workstation_CLM03_t src = (workstation_CLM03_t) workstation_src; - workstation_CLM03_t dst = (workstation_CLM03_t) workstation_dst; + workstation_CLM03_t src = surf_workstation_resource_priv(workstation_src); + workstation_CLM03_t dst = surf_workstation_resource_priv(workstation_dst); return surf_network_model->extension. network.get_route(src->net_elm, dst->net_elm); @@ -305,7 +302,7 @@ static void ws_finalize(void) static xbt_dict_t ws_get_properties(const void *ws) { - return surf_resource_properties(((workstation_CLM03_t) ws)->cpu); + return surf_resource_properties(surf_cpu_resource_priv(ws)); } static storage_t find_storage_on_mount_list(void *workstation,const char* storage) @@ -313,9 +310,10 @@ static storage_t find_storage_on_mount_list(void *workstation,const char* storag storage_t st = NULL; s_mount_t mnt; unsigned int cursor; - xbt_dynar_t storage_list = ((workstation_CLM03_t) workstation)->storage; + workstation_CLM03_t ws = (workstation_CLM03_t) surf_workstation_resource_priv(workstation); + xbt_dynar_t storage_list = ws->storage; - XBT_DEBUG("Search for storage name '%s' on '%s'",storage,((workstation_CLM03_t) workstation)->generic_resource.name); + XBT_DEBUG("Search for storage name '%s' on '%s'",storage,ws->generic_resource.name); xbt_dynar_foreach(storage_list,cursor,mnt) { XBT_DEBUG("See '%s'",mnt.name); @@ -324,7 +322,7 @@ static storage_t find_storage_on_mount_list(void *workstation,const char* storag break; } } - if(!st) xbt_die("Can't find mount '%s' for '%s'",storage,((workstation_CLM03_t) workstation)->generic_resource.name); + if(!st) xbt_die("Can't find mount '%s' for '%s'",storage,ws->generic_resource.name); return st; } diff --git a/src/surf/workstation_ptask_L07.c b/src/surf/workstation_ptask_L07.c index 662b3844b0..183c3053f1 100644 --- a/src/surf/workstation_ptask_L07.c +++ b/src/surf/workstation_ptask_L07.c @@ -96,8 +96,8 @@ static void ptask_update_action_bound(surf_action_workstation_L07_t action) if (action->communication_amount[i * workstation_nb + j] > 0) { double lat = 0.0; - routing_get_route_and_latency(action->workstation_list[i]->info, - action->workstation_list[j]->info, + routing_get_route_and_latency(((cpu_L07_t)surf_workstation_resource_priv(action->workstation_list[i]))->info, + ((cpu_L07_t)surf_workstation_resource_priv(action->workstation_list[j]))->info, &route, &lat); lat_current = MAX(lat_current, @@ -430,17 +430,17 @@ static void ptask_finalize(void) static e_surf_resource_state_t ptask_resource_get_state(void *cpu) { - return ((cpu_L07_t) cpu)->state_current; + return ((cpu_L07_t)surf_workstation_resource_priv(cpu))->state_current; } static double ptask_get_speed(void *cpu, double load) { - return load * (((cpu_L07_t) cpu)->power_scale); + return load * ((cpu_L07_t)surf_workstation_resource_priv(cpu))->power_scale; } static double ptask_get_available_speed(void *cpu) { - return ((cpu_L07_t) cpu)->power_current; + return ((cpu_L07_t)surf_workstation_resource_priv(cpu))->power_current; } static surf_action_t ptask_execute_parallel_task(int workstation_nb, @@ -473,8 +473,8 @@ static surf_action_t ptask_execute_parallel_task(int workstation_nb, link_L07_t link; routing_get_route_and_latency( - ((cpu_L07_t)workstation_list[i])->info, - ((cpu_L07_t)workstation_list[j])->info, + ((cpu_L07_t)surf_workstation_resource_priv(workstation_list[i]))->info, + ((cpu_L07_t)surf_workstation_resource_priv(workstation_list[j]))->info, &route,&lat); latency = MAX(latency, lat); @@ -516,7 +516,7 @@ static surf_action_t ptask_execute_parallel_task(int workstation_nb, for (i = 0; i < workstation_nb; i++) lmm_expand(ptask_maxmin_system, - ((cpu_L07_t) workstation_list[i])->constraint, + ((cpu_L07_t)surf_workstation_resource_priv(workstation_list[i]))->constraint, action->variable, computation_amount[i]); for (i = 0; i < workstation_nb; i++) { @@ -527,8 +527,8 @@ static surf_action_t ptask_execute_parallel_task(int workstation_nb, continue; routing_get_route_and_latency( - ((cpu_L07_t)workstation_list[i])->info, - ((cpu_L07_t)workstation_list[j])->info, + ((cpu_L07_t)surf_workstation_resource_priv(workstation_list[i]))->info, + ((cpu_L07_t)surf_workstation_resource_priv(workstation_list[j]))->info, &route,NULL); xbt_dynar_foreach(route, cpt, link) { @@ -600,7 +600,7 @@ static xbt_dynar_t ptask_get_route(void *src, void *dst) // FIXME: kill that cal { xbt_dynar_t route=NULL; routing_get_route_and_latency( - ((cpu_L07_t)src)->info, ((cpu_L07_t)dst)->info, + ((cpu_L07_t)surf_workstation_resource_priv(src))->info, ((cpu_L07_t)surf_workstation_resource_priv(dst))->info, &route,NULL); return route; } @@ -632,7 +632,7 @@ static void* ptask_cpu_create_resource(const char *name, double power_scale, xbt_dict_t cpu_properties) { cpu_L07_t cpu = NULL; - xbt_assert(!surf_workstation_resource_by_name(name), + xbt_assert(!surf_workstation_resource_priv(surf_workstation_resource_by_name(name)), "Host '%s' declared several times in the platform file.", name); @@ -662,7 +662,7 @@ static void* ptask_cpu_create_resource(const char *name, double power_scale, xbt_lib_set(host_lib, name, SURF_WKS_LEVEL, cpu); - return cpu; + return xbt_lib_get_elm_or_null(host_lib, name); } static void ptask_parse_cpu_init(sg_platf_host_cbarg_t host) @@ -775,7 +775,7 @@ static void ptask_add_traces(void) /* Connect traces relative to cpu */ xbt_dict_foreach(trace_connect_list_host_avail, cursor, trace_name, elm) { tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name); - cpu_L07_t host = surf_workstation_resource_by_name(elm); + cpu_L07_t host = surf_workstation_resource_priv(surf_workstation_resource_by_name(elm)); xbt_assert(host, "Host %s undefined", elm); xbt_assert(trace, "Trace %s undefined", trace_name); @@ -786,7 +786,7 @@ static void ptask_add_traces(void) xbt_dict_foreach(trace_connect_list_power, cursor, trace_name, elm) { tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name); - cpu_L07_t host = surf_workstation_resource_by_name(elm); + cpu_L07_t host = surf_workstation_resource_priv(surf_workstation_resource_by_name(elm)); xbt_assert(host, "Host %s undefined", elm); xbt_assert(trace, "Trace %s undefined", trace_name); diff --git a/src/xbt/dict.c b/src/xbt/dict.c index f52f98bf08..80c8a6cf26 100644 --- a/src/xbt/dict.c +++ b/src/xbt/dict.c @@ -316,27 +316,45 @@ char *xbt_dict_get_key(xbt_dict_t dict, const void *data) */ XBT_INLINE void *xbt_dict_get(xbt_dict_t dict, const char *key) { - - unsigned int hash_code = xbt_str_hash(key); - xbt_dictelm_t current; - - xbt_assert(dict); - - current = dict->table[hash_code & dict->table_size]; - while (current != NULL - && (hash_code != current->hash_code || strcmp(key, current->key))) - current = current->next; + return xbt_dict_get_elm(dict, key)->content; +} +/** + * \brief Retrieve element from the dict (null-terminated key) + * + * \param dict the dealer of data + * \param key the key to find data + * \return the s_xbt_dictelm_t that we are looking for + * + * Search the given \a key. Throws not_found_error when not found. + * Check xbt_dict_get_or_null() for a version returning NULL without exception when + * not found. + */ +XBT_INLINE xbt_dictelm_t xbt_dict_get_elm(xbt_dict_t dict, const char *key) +{ + xbt_dictelm_t current = xbt_dict_get_elm_or_null(dict, key); if (current == NULL) THROWF(not_found_error, 0, "key %s not found", key); - return current->content; + return current; } /** * \brief like xbt_dict_get(), but returning NULL when not found */ XBT_INLINE void *xbt_dict_get_or_null(xbt_dict_t dict, const char *key) +{ + xbt_dictelm_t current = xbt_dict_get_elm_or_null(dict, key); + + if (current == NULL) + return NULL; + + return current->content; +} +/** + * \brief like xbt_dict_get_elm(), but returning NULL when not found + */ +XBT_INLINE xbt_dictelm_t xbt_dict_get_elm_or_null(xbt_dict_t dict, const char *key) { unsigned int hash_code = xbt_str_hash(key); xbt_dictelm_t current; @@ -347,11 +365,7 @@ XBT_INLINE void *xbt_dict_get_or_null(xbt_dict_t dict, const char *key) while (current != NULL && (hash_code != current->hash_code || strcmp(key, current->key))) current = current->next; - - if (current == NULL) - return NULL; - - return current->content; + return current; } diff --git a/src/xbt/dict_cursor.c b/src/xbt/dict_cursor.c index 7141a17837..cd7e1892d2 100644 --- a/src/xbt/dict_cursor.c +++ b/src/xbt/dict_cursor.c @@ -20,11 +20,6 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_dict_cursor, xbt_dict, /* To traverse (simple) dicts */ /* Don't add or remove entries to the dict while traversing !!! */ /*###########################################################################*/ -struct s_xbt_dict_cursor { - xbt_dictelm_t current; - int line; - xbt_dict_t dict; -}; #undef xbt_dict_CURSOR_DEBUG /*#define xbt_dict_CURSOR_DEBUG 1*/ diff --git a/src/xbt/dict_private.h b/src/xbt/dict_private.h index 490fe38cbb..77292d1b4a 100644 --- a/src/xbt/dict_private.h +++ b/src/xbt/dict_private.h @@ -17,19 +17,8 @@ #include "xbt/dict.h" #include "xbt/mallocator.h" -typedef struct s_xbt_dictelm *xbt_dictelm_t; - #define MAX_FILL_PERCENT 80 -typedef struct s_xbt_dictelm { - char *key; - int key_len; - unsigned int hash_code; - - void *content; - - xbt_dictelm_t next; -} s_xbt_dictelm_t; typedef struct s_xbt_het_dictelm { s_xbt_dictelm_t element; diff --git a/src/xbt/lib.c b/src/xbt/lib.c index 163c0deb9e..ccb1e0ef42 100644 --- a/src/xbt/lib.c +++ b/src/xbt/lib.c @@ -75,3 +75,13 @@ void *xbt_lib_get_or_null(xbt_lib_t lib, const char *key, int level) void **elts = xbt_dict_get_or_null(lib->dict, key); return elts ? elts[level] : NULL; } + +xbt_dictelm_t xbt_lib_get_elm_or_null(xbt_lib_t lib, const char *key) +{ + return xbt_dict_get_elm_or_null(lib->dict, key); +} + +void *xbt_lib_get_level(xbt_dictelm_t elm, int level){ + void **elts = elm->content; + return elts ? elts[level] : NULL; +}