From c8e414e235d6dec3d30c349a61de69eb88060ff4 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Sat, 18 Jul 2015 12:42:26 +0200 Subject: [PATCH] [SGpp] make ROUTING_HOST_LEVEL private. That was painful --- include/simgrid/host.h | 7 +++++++ include/surf/surf_routing.h | 1 - src/bindings/java/surf_swig.cpp | 4 ++-- src/include/surf/surf.h | 3 --- src/instr/instr_paje_containers.c | 3 ++- src/simgrid/host.cpp | 29 ++++++++++++++++++++++++-- src/surf/host_clm03.cpp | 2 +- src/surf/host_ptask_L07.cpp | 2 +- src/surf/surf_c_bindings.cpp | 8 +------ src/surf/surf_interface.cpp | 11 ++-------- src/surf/surf_routing.cpp | 12 +++++------ src/surf/surf_routing.hpp | 5 +---- src/surf/surf_routing_generic.cpp | 5 +---- src/surf/vm_hl13.cpp | 13 ++++++------ src/xbt/lib.c | 1 - teshsuite/simdag/platforms/flatifier.c | 6 +++--- 16 files changed, 60 insertions(+), 52 deletions(-) diff --git a/include/simgrid/host.h b/include/simgrid/host.h index 15c66f5916..72d6d99448 100644 --- a/include/simgrid/host.h +++ b/include/simgrid/host.h @@ -12,6 +12,7 @@ SG_BEGIN_DECL() typedef xbt_dictelm_t sg_host_t; XBT_PUBLIC(sg_host_t) sg_host_by_name(const char *name); +XBT_PUBLIC(sg_host_t) sg_host_by_name_or_create(const char *name); static XBT_INLINE char *sg_host_get_name(sg_host_t host){ return host->key; } @@ -43,6 +44,12 @@ XBT_PUBLIC(surf_cpu_t) sg_host_surfcpu(sg_host_t host); XBT_PUBLIC(void) sg_host_surfcpu_set(sg_host_t host, surf_cpu_t cpu); XBT_PUBLIC(void) sg_host_surfcpu_destroy(sg_host_t host); +// ========== RoutingEdge ============ +typedef struct RoutingEdge *RoutingEdgePtr; +XBT_PUBLIC(RoutingEdgePtr) sg_host_edge(sg_host_t host); +XBT_PUBLIC(void) sg_host_edge_set(sg_host_t host, RoutingEdgePtr edge); +XBT_PUBLIC(void) sg_host_edge_destroy(sg_host_t host, int do_callback); + // Module initializer. Won't survive the conversion to C++. Hopefully. XBT_PUBLIC(void) sg_host_init(void); diff --git a/include/surf/surf_routing.h b/include/surf/surf_routing.h index 836a5d3fa9..3c635ee09e 100644 --- a/include/surf/surf_routing.h +++ b/include/surf/surf_routing.h @@ -13,7 +13,6 @@ SG_BEGIN_DECL() XBT_PUBLIC_DATA(xbt_lib_t) host_lib; -XBT_PUBLIC_DATA(int) ROUTING_HOST_LEVEL; //Routing level 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 diff --git a/src/bindings/java/surf_swig.cpp b/src/bindings/java/surf_swig.cpp index c1cc3afc14..c1e2986ec8 100644 --- a/src/bindings/java/surf_swig.cpp +++ b/src/bindings/java/surf_swig.cpp @@ -39,8 +39,8 @@ void setCpu(char *name, Cpu *cpu) { } NetworkLinkDynar getRoute(char *srcName, char *dstName) { - RoutingEdge *src = (RoutingEdge*)xbt_lib_get_or_null(host_lib, srcName, ROUTING_HOST_LEVEL); - RoutingEdge *dst = (RoutingEdge*)xbt_lib_get_or_null(host_lib, dstName, ROUTING_HOST_LEVEL); + RoutingEdge *src = sg_host_edge(sg_host_by_name(srcName)); + RoutingEdge *dst = sg_host_edge(sg_host_by_name(dstName)); xbt_assert(src,"Cannot get the route from a NULL source"); xbt_assert(dst,"Cannot get the route to a NULL destination"); xbt_dynar_t route = xbt_dynar_new(sizeof(RoutingEdgePtr), NULL); diff --git a/src/include/surf/surf.h b/src/include/surf/surf.h index ed552ac83a..aa9dbddaeb 100644 --- a/src/include/surf/surf.h +++ b/src/include/surf/surf.h @@ -188,9 +188,6 @@ XBT_PUBLIC_DATA(routing_platf_t) routing_platf; static inline surf_host_t surf_host_resource_priv(const void *host){ return (surf_host_t) xbt_lib_get_level((xbt_dictelm_t)host, SURF_HOST_LEVEL); } -static inline void *surf_routing_resource_priv(const void *host){ - return (void*)xbt_lib_get_level((xbt_dictelm_t)host, ROUTING_HOST_LEVEL); -} static inline void *surf_storage_resource_priv(const void *storage){ return (void*)xbt_lib_get_level((xbt_dictelm_t)storage, SURF_STORAGE_LEVEL); } diff --git a/src/instr/instr_paje_containers.c b/src/instr/instr_paje_containers.c index 752649eeb3..76f92be33e 100644 --- a/src/instr/instr_paje_containers.c +++ b/src/instr/instr_paje_containers.c @@ -55,11 +55,12 @@ container_t PJ_container_new (const char *name, e_container_types kind, containe new->name = xbt_strdup (name); // name of the container new->id = xbt_strdup (id_str); // id (or alias) of the container new->father = father; + sg_host_t sg_host = sg_host_by_name(name); //Search for network_element_t switch (kind){ case INSTR_HOST: - new->net_elm = xbt_lib_get_or_null(host_lib,name,ROUTING_HOST_LEVEL); + new->net_elm = sg_host_edge(sg_host); if(!new->net_elm) xbt_die("Element '%s' not found",name); break; case INSTR_ROUTER: diff --git a/src/simgrid/host.cpp b/src/simgrid/host.cpp index 564aea92f6..61d2dac72a 100644 --- a/src/simgrid/host.cpp +++ b/src/simgrid/host.cpp @@ -12,28 +12,43 @@ sg_host_t sg_host_by_name(const char *name){ return xbt_lib_get_elm_or_null(host_lib, name); } +sg_host_t sg_host_by_name_or_create(const char *name) { + sg_host_t res = xbt_lib_get_elm_or_null(host_lib, name); + if (!res) { + xbt_lib_set(host_lib,name,0,NULL); // Should only create the bucklet with no data added + res = xbt_lib_get_elm_or_null(host_lib, name); + } + return res; +} + // ========= Layering madness ============== -int SIMIX_HOST_LEVEL; int MSG_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 "surf/cpu_interface.hpp" +#include "surf/surf_routing.hpp" static XBT_INLINE void surf_cpu_free(void *r) { delete static_cast(r); } +static XBT_INLINE void routing_asr_host_free(void *p) { + delete static_cast(p); +} void sg_host_init() { SIMIX_HOST_LEVEL = xbt_lib_add_level(host_lib,SIMIX_host_destroy); MSG_HOST_LEVEL = xbt_lib_add_level(host_lib, (void_f_pvoid_t) __MSG_host_priv_free); 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); } - // ========== MSG Layer ============== msg_host_priv_t sg_host_msg(sg_host_t host) { return (msg_host_priv_t) xbt_lib_get_level(host, MSG_HOST_LEVEL); @@ -67,6 +82,16 @@ void sg_host_surfcpu_set(sg_host_t host, surf_cpu_t cpu) { void sg_host_surfcpu_destroy(sg_host_t host) { xbt_lib_unset(host_lib,host->key,SURF_CPU_LEVEL,1); } +// ========== RoutingEdge ============ +RoutingEdgePtr sg_host_edge(sg_host_t host) { + return (RoutingEdgePtr) xbt_lib_get_level(host, ROUTING_HOST_LEVEL); +} +void sg_host_edge_set(sg_host_t host, RoutingEdgePtr edge) { + xbt_lib_set(host_lib, host->key, ROUTING_HOST_LEVEL, edge); +} +void sg_host_edge_destroy(sg_host_t host, int do_callback) { + xbt_lib_unset(host_lib,host->key,ROUTING_HOST_LEVEL,do_callback); +} diff --git a/src/surf/host_clm03.cpp b/src/surf/host_clm03.cpp index 9cac53fccc..0a34da940d 100644 --- a/src/surf/host_clm03.cpp +++ b/src/surf/host_clm03.cpp @@ -59,7 +59,7 @@ HostPtr HostCLM03Model::createHost(const char *name){ sg_host_t sg_host = sg_host_by_name(name); HostPtr host = new HostCLM03(surf_host_model, name, NULL, (xbt_dynar_t)xbt_lib_get_or_null(storage_lib, name, ROUTING_STORAGE_HOST_LEVEL), - (RoutingEdgePtr)xbt_lib_get_or_null(host_lib, name, ROUTING_HOST_LEVEL), + sg_host_edge(sg_host), sg_host_surfcpu(sg_host)); XBT_DEBUG("Create host %s with %ld mounted disks", name, xbt_dynar_length(host->p_storage)); xbt_lib_set(host_lib, name, SURF_HOST_LEVEL, host); diff --git a/src/surf/host_ptask_L07.cpp b/src/surf/host_ptask_L07.cpp index 053611a34a..e7ce1752d6 100644 --- a/src/surf/host_ptask_L07.cpp +++ b/src/surf/host_ptask_L07.cpp @@ -282,7 +282,7 @@ HostPtr HostL07Model::createHost(const char *name) name); wk = new HostL07(this, name, NULL, - static_cast(xbt_lib_get_or_null(host_lib, name, ROUTING_HOST_LEVEL)), + sg_host_edge(sg_host), sg_host_surfcpu(sg_host)); xbt_lib_set(host_lib, name, SURF_HOST_LEVEL, wk); diff --git a/src/surf/surf_c_bindings.cpp b/src/surf/surf_c_bindings.cpp index 5a44b9b6c0..e32a3e0223 100644 --- a/src/surf/surf_c_bindings.cpp +++ b/src/surf/surf_c_bindings.cpp @@ -22,10 +22,6 @@ static HostPtr get_casted_host(surf_resource_t resource){ return static_cast(surf_host_resource_priv(resource)); } -static RoutingEdgePtr get_casted_routing(surf_resource_t resource){ - return static_cast(surf_routing_resource_priv(resource)); -} - static VMPtr get_casted_vm(surf_resource_t resource){ return static_cast(surf_host_resource_priv(resource)); } @@ -444,7 +440,6 @@ void surf_host_set_params(surf_resource_t host, ws_params_t params){ void surf_vm_destroy(surf_resource_t resource){ /* Before clearing the entries in host_lib, we have to pick up resources. */ VMPtr vm = get_casted_vm(resource); - RoutingEdgePtr routing = get_casted_routing(resource); char* name = xbt_dict_get_elm_key(resource); /* We deregister objects from host_lib, without invoking the freeing callback * of each level. @@ -453,14 +448,13 @@ void surf_vm_destroy(surf_resource_t resource){ * including MSG_HOST_LEVEL and others. We should unregister only what we know. */ sg_host_surfcpu_destroy((sg_host_t)resource); - xbt_lib_unset(host_lib, name, ROUTING_HOST_LEVEL, 0); + sg_host_edge_destroy((sg_host_t)resource,1); xbt_lib_unset(host_lib, name, SURF_HOST_LEVEL, 0); /* TODO: comment out when VM storage is implemented. */ // xbt_lib_unset(host_lib, name, SURF_STORAGE_LEVEL, 0); delete vm; - delete routing; } void surf_vm_suspend(surf_resource_t vm){ diff --git a/src/surf/surf_interface.cpp b/src/surf/surf_interface.cpp index cbb2f02a6a..136414e95e 100644 --- a/src/surf/surf_interface.cpp +++ b/src/surf/surf_interface.cpp @@ -354,15 +354,10 @@ int find_model_description(s_surf_model_description_t * table, return -1; } -static XBT_INLINE void routing_asr_host_free(void *p) -{ - delete ((RoutingEdgePtr) p); -} - static XBT_INLINE void routing_asr_prop_free(void *p) { - xbt_dict_t elm = (xbt_dict_t) p; - xbt_dict_free(&elm); + //xbt_dict_t elm = (xbt_dict_t) p; + //xbt_dict_free(&elm); FIXME: leaking in some case? That's a sometimes double-free with AsCluster::~AsCluster } static XBT_INLINE void surf_link_free(void *r) @@ -401,8 +396,6 @@ void surf_init(int *argc, char **argv) sg_host_init(); XBT_DEBUG("Add routing levels"); - ROUTING_HOST_LEVEL = xbt_lib_add_level(host_lib,routing_asr_host_free); - ROUTING_ASR_LEVEL = xbt_lib_add_level(as_router_lib,routing_asr_host_free); ROUTING_PROP_ASR_LEVEL = xbt_lib_add_level(as_router_lib,routing_asr_prop_free); XBT_DEBUG("Add SURF levels"); diff --git a/src/surf/surf_routing.cpp b/src/surf/surf_routing.cpp index 6c723ec1ee..1508045c65 100644 --- a/src/surf/surf_routing.cpp +++ b/src/surf/surf_routing.cpp @@ -23,7 +23,6 @@ */ xbt_lib_t host_lib; -int ROUTING_HOST_LEVEL; //Routing level int SURF_HOST_LEVEL; //Surf host level int SIMIX_STORAGE_LEVEL; //Simix storage level int MSG_STORAGE_LEVEL; //Msg storage level @@ -55,7 +54,8 @@ static xbt_dict_t random_value = NULL; * Routing edges are either host and routers, whatever */ RoutingEdgePtr sg_routing_edge_by_name_or_null(const char *name) { - RoutingEdgePtr net_elm = (RoutingEdgePtr) xbt_lib_get_or_null(host_lib, name, ROUTING_HOST_LEVEL); + sg_host_t h = sg_host_by_name(name); + RoutingEdgePtr net_elm = h==NULL?NULL: sg_host_edge(h); if (!net_elm) net_elm = (RoutingEdgePtr) xbt_lib_get_or_null(as_router_lib, name, ROUTING_ASR_LEVEL); return net_elm; @@ -119,7 +119,7 @@ struct s_model_type routing_models[] = { */ static void parse_S_host_link(sg_platf_host_link_cbarg_t host) { - RoutingEdgePtr info = static_cast(xbt_lib_get_or_null(host_lib, host->id, ROUTING_HOST_LEVEL)); + RoutingEdgePtr info = sg_host_edge(sg_host_by_name(host->id)); xbt_assert(info, "Host '%s' not found!", host->id); xbt_assert(current_routing->p_modelDesc == &routing_models[SURF_MODEL_CLUSTER] || current_routing->p_modelDesc == &routing_models[SURF_MODEL_VIVALDI], @@ -151,15 +151,15 @@ static void parse_S_host(sg_platf_host_cbarg_t host) { if (current_routing->p_hierarchy == SURF_ROUTING_NULL) current_routing->p_hierarchy = SURF_ROUTING_BASE; - xbt_assert(!xbt_lib_get_or_null(host_lib, host->id, ROUTING_HOST_LEVEL), - "Reading a host, processing unit \"%s\" already exists", host->id); + xbt_assert(!sg_host_by_name(host->id), + "Reading a host, processing unit \"%s\" already exists", host->id); RoutingEdgePtr info = new RoutingEdgeImpl(xbt_strdup(host->id), -1, SURF_NETWORK_ELEMENT_HOST, current_routing); info->setId(current_routing->parsePU(info)); - xbt_lib_set(host_lib, host->id, ROUTING_HOST_LEVEL, (void *) info); + sg_host_edge_set(sg_host_by_name_or_create(host->id), info); XBT_DEBUG("Having set name '%s' id '%d'", host->id, info->getId()); if(mount_list){ diff --git a/src/surf/surf_routing.hpp b/src/surf/surf_routing.hpp index a45a29cc6b..0980e57849 100644 --- a/src/surf/surf_routing.hpp +++ b/src/surf/surf_routing.hpp @@ -21,7 +21,7 @@ xbt_edge_t new_xbt_graph_edge (xbt_graph_t graph, xbt_node_t s, xbt_node_t d, xb * Classes * ***********/ -/* Note: As and RoutingEdge are declard as struct instead of class, to keep +/* Note: As and RoutingEdge are declared as struct instead of class, to keep compatibility with C files where they are mentioned. */ struct As; typedef As *AsPtr; @@ -29,9 +29,6 @@ typedef As *AsPtr; class RoutingModelDescription; typedef RoutingModelDescription *RoutingModelDescriptionPtr; -struct RoutingEdge; -typedef RoutingEdge *RoutingEdgePtr; - class Onelink; typedef Onelink *OnelinkPtr; diff --git a/src/surf/surf_routing_generic.cpp b/src/surf/surf_routing_generic.cpp index c67abb4407..407f50caed 100644 --- a/src/surf/surf_routing_generic.cpp +++ b/src/surf/surf_routing_generic.cpp @@ -429,10 +429,7 @@ AsPtr AsGeneric::autonomousSystemExist(char *element) AsPtr AsGeneric::processingUnitsExist(char *element) { - AsPtr element_as; - element_as = ((RoutingEdgePtr) - xbt_lib_get_or_null(host_lib, - element, ROUTING_HOST_LEVEL))->getRcComponent(); + AsPtr element_as = sg_host_edge(sg_host_by_name(element)) ->getRcComponent(); if (element_as == this) return element_as; return asExist(element_as); diff --git a/src/surf/vm_hl13.cpp b/src/surf/vm_hl13.cpp index b7e7b9b31f..e72a6283ba 100644 --- a/src/surf/vm_hl13.cpp +++ b/src/surf/vm_hl13.cpp @@ -233,8 +233,9 @@ VMHL13::VMHL13(VMModelPtr model, const char* name, xbt_dict_t props, * from the VM name, we have to make sure that the system does not call the * free callback for the network resource object. The network resource object * is still used by the physical machine. */ - p_netElm = new RoutingEdgeWrapper(static_cast(xbt_lib_get_or_null(host_lib, sub_ws->getName(), ROUTING_HOST_LEVEL))); - xbt_lib_set(host_lib, name, ROUTING_HOST_LEVEL, p_netElm); + sg_host_t sg_sub_ws = sg_host_by_name_or_create(sub_ws->getName()); + p_netElm = new RoutingEdgeWrapper(sg_host_edge(sg_sub_ws)); + sg_host_edge_set(sg_host_by_name_or_create(name), p_netElm); p_subWs = sub_ws; p_currentState = SURF_VM_STATE_CREATED; @@ -334,19 +335,17 @@ void VMHL13::migrate(surf_resource_t ind_dst_pm) xbt_assert(ws_dst); - /* do something */ - /* update net_elm with that of the destination physical host */ RoutingEdgePtr old_net_elm = p_netElm; - RoutingEdgePtr new_net_elm = new RoutingEdgeWrapper(static_cast(xbt_lib_get_or_null(host_lib, pm_name_dst, ROUTING_HOST_LEVEL))); + RoutingEdgePtr new_net_elm = new RoutingEdgeWrapper(sg_host_edge(sg_host_by_name(pm_name_dst))); xbt_assert(new_net_elm); /* Unregister the current net_elm from host_lib. Do not call the free callback. */ - xbt_lib_unset(host_lib, vm_name, ROUTING_HOST_LEVEL, 0); + sg_host_edge_destroy(sg_host_by_name(vm_name), 0); /* Then, resister the new one. */ p_netElm = new_net_elm; - xbt_lib_set(host_lib, vm_name, ROUTING_HOST_LEVEL, p_netElm); + sg_host_edge_set(sg_host_by_name(vm_name), p_netElm); p_subWs = ws_dst; diff --git a/src/xbt/lib.c b/src/xbt/lib.c index 953666cddb..4f9313eced 100644 --- a/src/xbt/lib.c +++ b/src/xbt/lib.c @@ -70,7 +70,6 @@ void xbt_lib_set(xbt_lib_t lib, const char *key, int level, void *obj) elts[level] = obj; } -/* for vm */ void xbt_lib_unset(xbt_lib_t lib, const char *key, int level, int invoke_callback) { void **elts = xbt_dict_get_or_null(lib->dict, key); diff --git a/teshsuite/simdag/platforms/flatifier.c b/teshsuite/simdag/platforms/flatifier.c index a9c1c256e2..2e32367aff 100644 --- a/teshsuite/simdag/platforms/flatifier.c +++ b/teshsuite/simdag/platforms/flatifier.c @@ -193,14 +193,14 @@ int main(int argc, char **argv) xbt_lib_foreach(host_lib, cursor_src, src, value1) // Routes from host { - value1 = xbt_lib_get_or_null(host_lib,src,ROUTING_HOST_LEVEL); + value1 = sg_host_edge(sg_host_by_name(src)); xbt_lib_foreach(host_lib, cursor_dst, dst, value2) //to host { printf(" \n " ,src ,dst); xbt_dynar_t route=NULL; - value2 = xbt_lib_get_or_null(host_lib,dst,ROUTING_HOST_LEVEL); + value2 = sg_host_edge(sg_host_by_name(dst)); routing_get_route_and_latency(value1,value2,&route,NULL); for(i=0;i\n " ,src, dst); xbt_dynar_t route=NULL; - value2 = xbt_lib_get_or_null(host_lib,dst,ROUTING_HOST_LEVEL); + value2 = sg_host_edge(sg_host_by_name(dst)); routing_get_route_and_latency((sg_routing_edge_t)value1,(sg_routing_edge_t)value2,&route, NULL); for(i=0;i