> [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.
+
#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
/* ******************************** 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
some <em>private data</em> 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 ************************************ */
/* 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);
#ifndef SIMDAG_DATATYPES_H
#define SIMDAG_DATATYPES_H
+#include "xbt/dict.h"
/** @brief Workstation datatype
@ingroup SD_datatypes_management
resource with computing capabilities</em> and has a <em>name</em>.
@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
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
\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,
*/
/** \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);
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);
* @{ */
/** @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,
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)
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;
}
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 {
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);
}
}
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));
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);
}
}
/* 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));
}
}
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);
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
#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.
*
*/
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
*/
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;
}
*/
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
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
/*
* \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);
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;
}
{
xbt_assert((h != NULL), "Invalid parameters");
- return (simcall_host_get_speed(h->smx_host));
+ return (simcall_host_get_speed(h));
}
/** \ingroup m_host_management
{
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
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));
}
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)
#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);
#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) {
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;
}
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;
}
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);
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);
} 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 {
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");
}
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);
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);
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));
/* 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),
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");
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);
}
/**
*/
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);
}
/**
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;
*/
void *SD_workstation_get_data(SD_workstation_t workstation)
{
- return workstation->data;
+ return SD_workstation_priv(workstation)->data;
}
/**
*/
void SD_workstation_set_data(SD_workstation_t workstation, void *data)
{
- workstation->data = data;
+ SD_workstation_priv(workstation)->data = data;
}
/**
*/
const char *SD_workstation_get_name(SD_workstation_t workstation)
{
- return surf_resource_name(workstation->surf_workstation);
+ return sg_host_name(workstation);
}
/**
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));
}
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;
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);
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));
}
/**
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);
}
/**
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);
}
/**
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;
}
/**
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();
}
}
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.
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);
* \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);
}
/**
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;
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) */
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);
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));
}
}
}
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);
}
/**
*/
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;
xbt_swag_free(host->process_list);
/* Clean host structure */
- free(host->name);
- free(host);
-
+ free(host);
return;
}
&& (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)
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){
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){
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){
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){
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){
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)
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);
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
{
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;
}
}
- 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)
}
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,
/* 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);
/* 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()) {
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;
}
/* 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;
}
{
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;
#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);
/* 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);
#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);
/* 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);
#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);
/* 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);
#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);
/* 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);
#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);
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);
#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);
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);
#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);
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);
#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);
}
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;
}
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)
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);
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");
}
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;
}
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 */
/* 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);
}
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;
}
/*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;
}
*/
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);
}
(*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);
}
}
*/
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;
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);
}
/* 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);
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);
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);
* 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;
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();
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);
}
}
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;
{
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),
xbt_lib_set(host_lib, name, SURF_CPU_LEVEL, cpu);
- return cpu;
+ return xbt_lib_get_elm_or_null(host_lib, name);;
}
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 =
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;
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)
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");
}
xbt_lib_set(host_lib, name, SURF_CPU_LEVEL, cpu);
- return cpu;
+ return xbt_lib_get_elm_or_null(host_lib, name);
}
/* 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);
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);
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;
}
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;
}
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;
}
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
}
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 =
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;
((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();
}
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();
}
{
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();
}
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;
}
/**
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 */
{
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),
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){
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;
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));
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)
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);
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,
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);
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)
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);
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;
}
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,
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,
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);
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++) {
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) {
{
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;
}
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);
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)
/* 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);
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);
*/
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;
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;
}
/* 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*/
#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;
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;
+}