XBT_PUBLIC(void) sg_host_msg_set(sg_host_t host, msg_host_priv_t priv);
XBT_PUBLIC(void) sg_host_msg_destroy(sg_host_t host);
+// ========== SD Layer ==============
+typedef struct SD_workstation *SD_workstation_priv_t;
+SD_workstation_priv_t sg_host_sd(sg_host_t host);
+XBT_PUBLIC(void) sg_host_sd_set(sg_host_t host, SD_workstation_priv_t priv);
+XBT_PUBLIC(void) sg_host_sd_destroy(sg_host_t host);
+
// ========== Simix layer =============
typedef struct s_smx_host_priv *smx_host_priv_t;
XBT_PUBLIC(smx_host_priv_t) sg_host_simix(sg_host_t host);
SG_BEGIN_DECL()
XBT_PUBLIC_DATA(xbt_lib_t) host_lib;
-XBT_PUBLIC_DATA(int) SURF_HOST_LEVEL; //Surf workstation level
-XBT_PUBLIC_DATA(int) SIMIX_STORAGE_LEVEL; //Simix storage level
-XBT_PUBLIC_DATA(int) SD_HOST_LEVEL; //Simdag host level
-XBT_PUBLIC_DATA(int) SD_STORAGE_LEVEL; //Simdag storage level
-XBT_PUBLIC_DATA(int) COORD_HOST_LEVEL; //Coordinates level
-XBT_PUBLIC_DATA(int) NS3_HOST_LEVEL; //host node for ns3
+XBT_PUBLIC_DATA(int) SURF_HOST_LEVEL; //Surf workstation level
+XBT_PUBLIC_DATA(int) SIMIX_STORAGE_LEVEL; //Simix storage level
+XBT_PUBLIC_DATA(int) SD_STORAGE_LEVEL; //Simdag storage level
+XBT_PUBLIC_DATA(int) COORD_HOST_LEVEL; //Coordinates level
+XBT_PUBLIC_DATA(int) NS3_HOST_LEVEL; //host node for ns3
XBT_PUBLIC_DATA(xbt_lib_t) link_lib;
XBT_PUBLIC_DATA(int) SD_LINK_LEVEL; //Simdag level
/* Initialize MSG hosts */
xbt_lib_foreach(host_lib, cursor, name, data) {
- if(sg_host_simix((sg_host_t)data))
- __MSG_host_create(xbt_dict_cursor_get_elm(cursor));
+ __MSG_host_create(xbt_dict_cursor_get_elm(cursor));
}
/* Initialize MSG storages */
*/
void __MSG_host_priv_free(msg_host_priv_t priv)
{
+
+ if (priv == NULL)
+ return;
unsigned int size = xbt_dict_size(priv->dp_objs);
if (size > 0)
XBT_WARN("dp_objs: %u pending task?", size);
/*
* \brief Destroys a host (internal call only)
*/
-void __MSG_host_destroy(msg_host_t host)
+void __MSG_host_destroy(msg_host_t host) //FIXME: killme?
{
/* TODO:
* What happens if VMs still remain on this host?
#include "xbt/mallocator.h"
#include <stdbool.h>
+SG_BEGIN_DECL()
+
/* Global variables */
typedef struct SD_global {
SD_task_t current_task; /* only used in sequential mode */
} 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);
-}
-
/* Storage */
typedef s_xbt_dictelm_t s_SD_storage_t;
typedef struct SD_storage {
} s_SD_storage_priv_t, *SD_storage_priv_t;
static inline SD_storage_priv_t SD_storage_priv(SD_storage_t storage){
- return xbt_lib_get_level(storage, SD_STORAGE_LEVEL);
+ return (SD_storage_priv_t)xbt_lib_get_level(storage, SD_STORAGE_LEVEL);
}
/* Task */
void TRACE_sd_task_execute_end(SD_task_t task);
void TRACE_sd_task_destroy(SD_task_t task);
+SG_END_DECL()
#endif
#endif
XBT_DEBUG("ADD SD LEVELS");
- SD_HOST_LEVEL = xbt_lib_add_level(host_lib,__SD_workstation_destroy);
SD_LINK_LEVEL = xbt_lib_add_level(link_lib,__SD_link_destroy);
SD_STORAGE_LEVEL = xbt_lib_add_level(storage_lib,__SD_storage_destroy);
for (i = 0; i < host_nb; i++) {
if (SD_workstation_get_access_mode(task->workstation_list[i]) ==
SD_WORKSTATION_SEQUENTIAL_ACCESS) {
- SD_workstation_priv(task->workstation_list[i])->current_task = task;
+ sg_host_sd(task->workstation_list[i])->current_task = task;
xbt_assert(__SD_workstation_is_busy(task->workstation_list[i]),
"The workstation should be busy now");
}
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 (SD_workstation_priv(workstation)->access_mode == SD_WORKSTATION_SEQUENTIAL_ACCESS) {
+ if (sg_host_sd(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(SD_workstation_priv(workstation)->task_fifo, task);
+ xbt_fifo_push(sg_host_sd(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)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,
+ SD_workstation_get_name(workstation), (int)sg_host_sd(workstation)->access_mode);
+ if (sg_host_sd(workstation)->access_mode == SD_WORKSTATION_SEQUENTIAL_ACCESS) {
+ xbt_assert(sg_host_sd(workstation)->task_fifo != NULL,
"Workstation '%s' has sequential access but no FIFO!",
SD_workstation_get_name(workstation));
- xbt_assert(SD_workstation_priv(workstation)->current_task =
+ xbt_assert(sg_host_sd(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 */
- SD_workstation_priv(workstation)->current_task = NULL;
+ sg_host_sd(workstation)->current_task = NULL;
XBT_DEBUG("Getting candidate in FIFO");
candidate =
xbt_fifo_get_item_content(xbt_fifo_get_first_item
- (SD_workstation_priv(workstation)->task_fifo));
+ (sg_host_sd(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 = SD_workstation_priv(workstation)->access_mode == SD_WORKSTATION_SHARED_ACCESS
+ can_start = sg_host_sd(workstation)->access_mode == SD_WORKSTATION_SHARED_ACCESS
|| candidate ==
xbt_fifo_get_item_content(xbt_fifo_get_first_item
- (SD_workstation_priv(workstation)->task_fifo));
+ (sg_host_sd(workstation)->task_fifo));
}
XBT_DEBUG("Candidate '%s' can start: %d", SD_task_get_name(candidate),
workstation = candidate->workstation_list[j];
/* update the FIFO */
- 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 */
+ if (sg_host_sd(workstation)->access_mode == SD_WORKSTATION_SEQUENTIAL_ACCESS) {
+ candidate = xbt_fifo_shift(sg_host_sd(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");
workstation->current_task = NULL;
name = surf_resource_name(surf_workstation);
- xbt_lib_set(host_lib,name,SD_HOST_LEVEL,workstation);
- return xbt_lib_get_elm_or_null(host_lib,name);
+ sg_host_t sg_host = sg_host_by_name(name);
+ sg_host_sd_set(sg_host,workstation);
+ return sg_host;
}
/* Creates a storage and registers it in SD.
*/
void *SD_workstation_get_data(SD_workstation_t workstation)
{
- return SD_workstation_priv(workstation)->data;
+ return sg_host_sd(workstation)->data;
}
/**
*/
void SD_workstation_set_data(SD_workstation_t workstation, void *data)
{
- SD_workstation_priv(workstation)->data = data;
+ sg_host_sd(workstation)->data = data;
}
/**
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 (SD_workstation_priv(ws)->access_mode){
+ switch (sg_host_sd(ws)->access_mode){
case SD_WORKSTATION_SHARED_ACCESS:
XBT_INFO(" - access mode: Space shared");
break;
e_SD_workstation_access_mode_t
SD_workstation_get_access_mode(SD_workstation_t workstation)
{
- return SD_workstation_priv(workstation)->access_mode;
+ return sg_host_sd(workstation)->access_mode;
}
/**
access_mode != SD_WORKSTATION_SHARED_ACCESS,
"Trying to set an invalid access mode");
- if (access_mode == SD_workstation_priv(workstation)->access_mode) {
+ if (access_mode == sg_host_sd(workstation)->access_mode) {
return; // nothing is changed
}
- SD_workstation_priv(workstation)->access_mode = access_mode;
+ sg_host_sd(workstation)->access_mode = access_mode;
if (access_mode == SD_WORKSTATION_SHARED_ACCESS) {
- xbt_fifo_free(SD_workstation_priv(workstation)->task_fifo);
- SD_workstation_priv(workstation)->task_fifo = NULL;
+ xbt_fifo_free(sg_host_sd(workstation)->task_fifo);
+ sg_host_sd(workstation)->task_fifo = NULL;
} else {
- SD_workstation_priv(workstation)->task_fifo = xbt_fifo_new();
+ sg_host_sd(workstation)->task_fifo = xbt_fifo_new();
}
}
XBT_DEBUG
("Workstation '%s' access mode: '%s', current task: %s, fifo size: %d",
SD_workstation_get_name(workstation),
- (SD_workstation_priv(workstation)->access_mode ==
+ (sg_host_sd(workstation)->access_mode ==
SD_WORKSTATION_SHARED_ACCESS) ? "SHARED" : "FIFO",
- (SD_workstation_priv(workstation)->current_task ?
- SD_task_get_name(SD_workstation_priv(workstation)->current_task)
+ (sg_host_sd(workstation)->current_task ?
+ SD_task_get_name(sg_host_sd(workstation)->current_task)
: "none"),
- (SD_workstation_priv(workstation)->task_fifo ? xbt_fifo_size(SD_workstation_priv(workstation)->task_fifo) :
+ (sg_host_sd(workstation)->task_fifo ? xbt_fifo_size(sg_host_sd(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);
+ return sg_host_sd(workstation)->access_mode == SD_WORKSTATION_SEQUENTIAL_ACCESS &&
+ (sg_host_sd(workstation)->current_task != NULL
+ || xbt_fifo_size(sg_host_sd(workstation)->task_fifo) > 0);
}
/* Destroys a workstation.
void __SD_workstation_destroy(void *workstation)
{
+ if (workstation==NULL)
+ return;
SD_workstation_priv_t w;
/* workstation->surf_workstation is freed by surf_exit and workstation->data is freed by the user */
* \param workstation a workstation */
SD_task_t SD_workstation_get_current_task(SD_workstation_t workstation)
{
- xbt_assert(SD_workstation_priv(workstation)->access_mode == SD_WORKSTATION_SEQUENTIAL_ACCESS,
+ xbt_assert(sg_host_sd(workstation)->access_mode == SD_WORKSTATION_SEQUENTIAL_ACCESS,
"Access mode must be set to SD_WORKSTATION_SEQUENTIAL_ACCESS"
" to use this function");
- return (SD_workstation_priv(workstation)->current_task);
+ return (sg_host_sd(workstation)->current_task);
}
/**
// ========= Layering madness ==============
int MSG_HOST_LEVEL;
+int SD_HOST_LEVEL;
int SIMIX_HOST_LEVEL;
int ROUTING_HOST_LEVEL;
int SURF_CPU_LEVEL;
-#include "simix/smx_host_private.h" // SIMIX_host_destroy. FIXME: killme
#include "msg/msg_private.h" // MSG_host_priv_free. FIXME: killme
+#include "simdag/private.h" // __SD_workstation_destroy. FIXME: killme
+#include "simix/smx_host_private.h" // SIMIX_host_destroy. FIXME: killme
#include "surf/cpu_interface.hpp"
#include "surf/surf_routing.hpp"
}
-void sg_host_init() {
- SIMIX_HOST_LEVEL = xbt_lib_add_level(host_lib,SIMIX_host_destroy);
+void sg_host_init() { // FIXME: only add the needed levels
MSG_HOST_LEVEL = xbt_lib_add_level(host_lib, (void_f_pvoid_t) __MSG_host_priv_free);
+ SD_HOST_LEVEL = xbt_lib_add_level(host_lib,__SD_workstation_destroy);
+
+ SIMIX_HOST_LEVEL = xbt_lib_add_level(host_lib,SIMIX_host_destroy);
SURF_CPU_LEVEL = xbt_lib_add_level(host_lib,surf_cpu_free);
ROUTING_HOST_LEVEL = xbt_lib_add_level(host_lib,routing_asr_host_free);
}
void sg_host_msg_destroy(sg_host_t host) {
xbt_lib_unset(host_lib,host->key,MSG_HOST_LEVEL,1);
}
+// ========== SimDag Layer ==============
+SD_workstation_priv_t sg_host_sd(sg_host_t host) {
+ return (SD_workstation_priv_t) xbt_lib_get_level(host, SD_HOST_LEVEL);
+}
+void sg_host_sd_set(sg_host_t host, SD_workstation_priv_t smx_host) {
+ xbt_lib_set(host_lib,host->key,SD_HOST_LEVEL,smx_host);
+}
+void sg_host_sd_destroy(sg_host_t host) {
+ xbt_lib_unset(host_lib,host->key,SD_HOST_LEVEL,1);
+}
// ========== Simix layer =============
-
smx_host_priv_t sg_host_simix(sg_host_t host){
return (smx_host_priv_t) xbt_lib_get_level(host, SIMIX_HOST_LEVEL);
}
int SIMIX_STORAGE_LEVEL; //Simix storage level
int MSG_STORAGE_LEVEL; //Msg storage level
int MSG_FILE_LEVEL; //Msg file level
-int SD_HOST_LEVEL; //Simdag host level
int SD_STORAGE_LEVEL; //Simdag storage level
int COORD_HOST_LEVEL=0; //Coordinates level
int NS3_HOST_LEVEL; //host node for ns3