From c638214a29abfed2c93678be136ad7d2dcd1940e Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Sat, 18 Jul 2015 15:25:34 +0200 Subject: [PATCH] make SD_HOST_LEVEL private --- include/simgrid/host.h | 6 ++++++ include/surf/surf_routing.h | 11 +++++----- src/msg/msg_environment.c | 3 +-- src/msg/msg_host.c | 5 ++++- src/simdag/private.h | 9 ++++---- src/simdag/sd_global.c | 1 - src/simdag/sd_task.c | 26 +++++++++++----------- src/simdag/sd_workstation.c | 43 ++++++++++++++++++++----------------- src/simgrid/host.cpp | 21 ++++++++++++++---- src/surf/surf_routing.cpp | 1 - 10 files changed, 73 insertions(+), 53 deletions(-) diff --git a/include/simgrid/host.h b/include/simgrid/host.h index a005912916..2a7af9a36b 100644 --- a/include/simgrid/host.h +++ b/include/simgrid/host.h @@ -32,6 +32,12 @@ msg_host_priv_t sg_host_msg(sg_host_t host); 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); diff --git a/include/surf/surf_routing.h b/include/surf/surf_routing.h index 3c635ee09e..da83650af5 100644 --- a/include/surf/surf_routing.h +++ b/include/surf/surf_routing.h @@ -13,12 +13,11 @@ 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 diff --git a/src/msg/msg_environment.c b/src/msg/msg_environment.c index 00cbe8e028..8a042aa571 100644 --- a/src/msg/msg_environment.c +++ b/src/msg/msg_environment.c @@ -44,8 +44,7 @@ void MSG_post_create_environment(void) { /* 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 */ diff --git a/src/msg/msg_host.c b/src/msg/msg_host.c index 27aa5e950a..1105123d40 100644 --- a/src/msg/msg_host.c +++ b/src/msg/msg_host.c @@ -145,6 +145,9 @@ void MSG_host_off(msg_host_t host) */ 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); @@ -161,7 +164,7 @@ void __MSG_host_priv_free(msg_host_priv_t priv) /* * \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? diff --git a/src/simdag/private.h b/src/simdag/private.h index 67e9e7beab..0f1575d92d 100644 --- a/src/simdag/private.h +++ b/src/simdag/private.h @@ -16,6 +16,8 @@ #include "xbt/mallocator.h" #include +SG_BEGIN_DECL() + /* Global variables */ typedef struct SD_global { @@ -64,10 +66,6 @@ typedef struct SD_workstation { 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 { @@ -76,7 +74,7 @@ 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 */ @@ -219,5 +217,6 @@ void TRACE_sd_task_execute_start(SD_task_t task); void TRACE_sd_task_execute_end(SD_task_t task); void TRACE_sd_task_destroy(SD_task_t task); +SG_END_DECL() #endif diff --git a/src/simdag/sd_global.c b/src/simdag/sd_global.c index b8c3c8151a..b1dcbabbff 100644 --- a/src/simdag/sd_global.c +++ b/src/simdag/sd_global.c @@ -87,7 +87,6 @@ void SD_init(int *argc, char **argv) #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); diff --git a/src/simdag/sd_task.c b/src/simdag/sd_task.c index aa310877e7..0907c4f9e4 100644 --- a/src/simdag/sd_task.c +++ b/src/simdag/sd_task.c @@ -1106,7 +1106,7 @@ void __SD_task_really_run(SD_task_t task) 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"); } @@ -1185,11 +1185,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 (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); @@ -1239,23 +1239,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)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)); @@ -1309,10 +1309,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 = 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), @@ -1324,8 +1324,8 @@ void __SD_task_just_done(SD_task_t task) 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"); diff --git a/src/simdag/sd_workstation.c b/src/simdag/sd_workstation.c index 697d5ee2c6..5f8ebcc2e0 100644 --- a/src/simdag/sd_workstation.c +++ b/src/simdag/sd_workstation.c @@ -31,8 +31,9 @@ SD_workstation_t __SD_workstation_create(void *surf_workstation, 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. @@ -112,7 +113,7 @@ int SD_workstation_get_number(void) */ void *SD_workstation_get_data(SD_workstation_t workstation) { - return SD_workstation_priv(workstation)->data; + return sg_host_sd(workstation)->data; } /** @@ -127,7 +128,7 @@ void *SD_workstation_get_data(SD_workstation_t workstation) */ void SD_workstation_set_data(SD_workstation_t workstation, void *data) { - SD_workstation_priv(workstation)->data = data; + sg_host_sd(workstation)->data = data; } /** @@ -178,7 +179,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 (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; @@ -424,7 +425,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 SD_workstation_priv(workstation)->access_mode; + return sg_host_sd(workstation)->access_mode; } /** @@ -450,17 +451,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 == 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(); } } @@ -514,17 +515,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), - (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. @@ -532,6 +533,8 @@ int __SD_workstation_is_busy(SD_workstation_t 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 */ @@ -550,11 +553,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(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); } /** diff --git a/src/simgrid/host.cpp b/src/simgrid/host.cpp index 7eb97bfe8b..af11f632bf 100644 --- a/src/simgrid/host.cpp +++ b/src/simgrid/host.cpp @@ -39,13 +39,15 @@ xbt_dynar_t sg_hosts_as_dynar(void) { // ========= 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" @@ -57,9 +59,11 @@ static XBT_INLINE void routing_asr_host_free(void *p) { } -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); } @@ -74,9 +78,18 @@ void sg_host_msg_set(sg_host_t host, msg_host_priv_t smx_host) { 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); } diff --git a/src/surf/surf_routing.cpp b/src/surf/surf_routing.cpp index 1508045c65..d445c46741 100644 --- a/src/surf/surf_routing.cpp +++ b/src/surf/surf_routing.cpp @@ -27,7 +27,6 @@ int SURF_HOST_LEVEL; //Surf 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 -- 2.20.1