Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[SGpp] make ROUTING_HOST_LEVEL private. That was painful
authorMartin Quinson <martin.quinson@loria.fr>
Sat, 18 Jul 2015 10:42:26 +0000 (12:42 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Sat, 18 Jul 2015 18:07:03 +0000 (20:07 +0200)
16 files changed:
include/simgrid/host.h
include/surf/surf_routing.h
src/bindings/java/surf_swig.cpp
src/include/surf/surf.h
src/instr/instr_paje_containers.c
src/simgrid/host.cpp
src/surf/host_clm03.cpp
src/surf/host_ptask_L07.cpp
src/surf/surf_c_bindings.cpp
src/surf/surf_interface.cpp
src/surf/surf_routing.cpp
src/surf/surf_routing.hpp
src/surf/surf_routing_generic.cpp
src/surf/vm_hl13.cpp
src/xbt/lib.c
teshsuite/simdag/platforms/flatifier.c

index 15c66f5..72d6d99 100644 (file)
@@ -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);
index 836a5d3..3c635ee 100644 (file)
@@ -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
index c1cc3af..c1e2986 100644 (file)
@@ -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);
index ed552ac..aa9dbdd 100644 (file)
@@ -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);
 }
index 752649e..76f92be 100644 (file)
@@ -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:
index 564aea9..61d2dac 100644 (file)
@@ -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<CpuPtr>(r);
 }
+static XBT_INLINE void routing_asr_host_free(void *p) {
+  delete static_cast<RoutingEdgePtr>(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);
+}
 
 
 
index 9cac53f..0a34da9 100644 (file)
@@ -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);
index 053611a..e7ce175 100644 (file)
@@ -282,7 +282,7 @@ HostPtr HostL07Model::createHost(const char *name)
               name);
 
   wk = new HostL07(this, name, NULL,
-                                 static_cast<RoutingEdgePtr>(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);
index 5a44b9b..e32a3e0 100644 (file)
@@ -22,10 +22,6 @@ static HostPtr get_casted_host(surf_resource_t resource){
   return static_cast<HostPtr>(surf_host_resource_priv(resource));
 }
 
-static RoutingEdgePtr get_casted_routing(surf_resource_t resource){
-  return static_cast<RoutingEdgePtr>(surf_routing_resource_priv(resource));
-}
-
 static VMPtr get_casted_vm(surf_resource_t resource){
   return static_cast<VMPtr>(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){
index cbb2f02..136414e 100644 (file)
@@ -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");
index 6c723ec..1508045 100644 (file)
@@ -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<RoutingEdgePtr>(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){
index a45a29c..0980e57 100644 (file)
@@ -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;
 
index c67abb4..407f50c 100644 (file)
@@ -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);
index b7e7b9b..e72a628 100644 (file)
@@ -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<RoutingEdgePtr>(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<RoutingEdgePtr>(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;
 
index 953666c..4f9313e 100644 (file)
@@ -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);
index a9c1c25..2e32367 100644 (file)
@@ -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("  <route src=\"%s\" dst=\"%s\">\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<xbt_dynar_length(route) ;i++)
         {
@@ -263,7 +263,7 @@ int main(int argc, char **argv)
           printf("  <route src=\"%s\" dst=\"%s\">\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<xbt_dynar_length(route) ;i++)
           {