From: Martin Quinson Date: Fri, 24 Feb 2017 15:54:26 +0000 (+0100) Subject: finish the transition from C structures to C++ objects X-Git-Tag: v3_15~289 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/f903911759edb23ddddbd427beb6a78f7ff50048?ds=sidebyside finish the transition from C structures to C++ objects Actually, we should stop using sg_platf_new_link and use NetZone::createLink() but this later function is not ready yet. And I don't want to revert the work of Fred so I'd better fix it. --- diff --git a/src/bindings/lua/lua_platf.cpp b/src/bindings/lua/lua_platf.cpp index 41f408c8f8..f9f80a90c1 100644 --- a/src/bindings/lua/lua_platf.cpp +++ b/src/bindings/lua/lua_platf.cpp @@ -61,16 +61,14 @@ int console_close(lua_State *L) { } int console_add_backbone(lua_State *L) { - s_sg_platf_link_cbarg_t link; - memset(&link,0,sizeof(link)); - int type; + LinkCreationArgs link; link.properties = nullptr; lua_ensure(lua_istable(L, -1),"Bad Arguments to create backbone in Lua. Should be a table with named arguments."); lua_pushstring(L, "id"); - type = lua_gettable(L, -2); + int type = lua_gettable(L, -2); lua_ensure(type == LUA_TSTRING, "Attribute 'id' must be specified for backbone and must be a string."); link.id = lua_tostring(L, -1); lua_pop(L, 1); @@ -79,14 +77,14 @@ int console_add_backbone(lua_State *L) { type = lua_gettable(L, -2); lua_ensure(type == LUA_TSTRING || type == LUA_TNUMBER, "Attribute 'bandwidth' must be specified for backbone and must either be a string (in the right format; see docs) or a number."); - link.bandwidth = surf_parse_get_bandwidth(lua_tostring(L, -1),"bandwidth of backbone",link.id); + link.bandwidth = surf_parse_get_bandwidth(lua_tostring(L, -1), "bandwidth of backbone", link.id.c_str()); lua_pop(L, 1); lua_pushstring(L, "lat"); type = lua_gettable(L, -2); lua_ensure(type == LUA_TSTRING || type == LUA_TNUMBER, "Attribute 'lat' must be specified for backbone and must either be a string (in the right format; see docs) or a number."); - link.latency = surf_parse_get_time(lua_tostring(L, -1),"latency of backbone",link.id); + link.latency = surf_parse_get_time(lua_tostring(L, -1), "latency of backbone", link.id.c_str()); lua_pop(L, 1); lua_pushstring(L, "sharing_policy"); @@ -101,7 +99,7 @@ int console_add_backbone(lua_State *L) { } sg_platf_new_link(&link); - routing_cluster_add_backbone(simgrid::surf::LinkImpl::byName(link.id)); + routing_cluster_add_backbone(simgrid::surf::LinkImpl::byName(link.id.c_str())); return 0; } @@ -201,17 +199,15 @@ int console_add_host(lua_State *L) { } int console_add_link(lua_State *L) { - s_sg_platf_link_cbarg_t link; - memset(&link,0,sizeof(link)); + LinkCreationArgs link; - int type; const char* policy; lua_ensure(lua_istable(L, -1), "Bad Arguments to create link, Should be a table with named arguments"); // get Id Value lua_pushstring(L, "id"); - type = lua_gettable(L, -2); + int type = lua_gettable(L, -2); lua_ensure(type == LUA_TSTRING || type == LUA_TNUMBER, "Attribute 'id' must be specified for any link and must be a string."); link.id = lua_tostring(L, -1); @@ -225,7 +221,7 @@ int console_add_link(lua_State *L) { if (type == LUA_TNUMBER) link.bandwidth = lua_tonumber(L, -1); else // LUA_TSTRING - link.bandwidth = surf_parse_get_bandwidth(lua_tostring(L, -1),"bandwidth of link", link.id); + link.bandwidth = surf_parse_get_bandwidth(lua_tostring(L, -1), "bandwidth of link", link.id.c_str()); lua_pop(L, 1); //get latency value @@ -236,7 +232,7 @@ int console_add_link(lua_State *L) { if (type == LUA_TNUMBER) link.latency = lua_tonumber(L, -1); else // LUA_TSTRING - link.latency = surf_parse_get_time(lua_tostring(L, -1),"latency of link", link.id); + link.latency = surf_parse_get_time(lua_tostring(L, -1), "latency of link", link.id.c_str()); lua_pop(L, 1); /*Optional Arguments */ diff --git a/src/kernel/routing/ClusterZone.cpp b/src/kernel/routing/ClusterZone.cpp index 19cd4e9bfd..b3363f9a25 100644 --- a/src/kernel/routing/ClusterZone.cpp +++ b/src/kernel/routing/ClusterZone.cpp @@ -123,8 +123,7 @@ void ClusterZone::create_links_for_node(sg_platf_cluster_cbarg_t cluster, int id { char* link_id = bprintf("%s_link_%d", cluster->id, id); - s_sg_platf_link_cbarg_t link; - memset(&link, 0, sizeof(link)); + LinkCreationArgs link; link.id = link_id; link.bandwidth = cluster->bw; link.latency = cluster->lat; @@ -145,7 +144,6 @@ void ClusterZone::create_links_for_node(sg_platf_cluster_cbarg_t cluster, int id linkDown = linkUp; } privateLinks_.insert({position, {linkUp, linkDown}}); - xbt_free(link_id); } } } diff --git a/src/kernel/routing/DragonflyZone.cpp b/src/kernel/routing/DragonflyZone.cpp index 3e68e8e1d8..12dd63c43a 100644 --- a/src/kernel/routing/DragonflyZone.cpp +++ b/src/kernel/routing/DragonflyZone.cpp @@ -138,8 +138,7 @@ void DragonflyZone::createLink(char* id, int numlinks, surf::LinkImpl** linkup, { *linkup = nullptr; *linkdown = nullptr; - s_sg_platf_link_cbarg_t linkTemplate; - memset(&linkTemplate, 0, sizeof(linkTemplate)); + LinkCreationArgs linkTemplate; linkTemplate.bandwidth = this->cluster_->bw * numlinks; linkTemplate.latency = this->cluster_->lat; linkTemplate.policy = this->cluster_->sharing_policy; // sthg to do with that ? diff --git a/src/kernel/routing/FatTreeZone.cpp b/src/kernel/routing/FatTreeZone.cpp index b74a6cbc7a..702655ba75 100644 --- a/src/kernel/routing/FatTreeZone.cpp +++ b/src/kernel/routing/FatTreeZone.cpp @@ -430,9 +430,8 @@ void FatTreeZone::generateDotFile(const std::string& filename) const FatTreeNode::FatTreeNode(sg_platf_cluster_cbarg_t cluster, int id, int level, int position) : id(id), level(level), position(position) { - s_sg_platf_link_cbarg_t linkTemplate; + LinkCreationArgs linkTemplate; if (cluster->limiter_link) { - memset(&linkTemplate, 0, sizeof(linkTemplate)); linkTemplate.bandwidth = cluster->limiter_link; linkTemplate.latency = 0; linkTemplate.policy = SURF_LINK_SHARED; @@ -441,7 +440,6 @@ FatTreeNode::FatTreeNode(sg_platf_cluster_cbarg_t cluster, int id, int level, in this->limiterLink = surf::LinkImpl::byName(linkTemplate.id.c_str()); } if (cluster->loopback_bw || cluster->loopback_lat) { - memset(&linkTemplate, 0, sizeof(linkTemplate)); linkTemplate.bandwidth = cluster->loopback_bw; linkTemplate.latency = cluster->loopback_lat; linkTemplate.policy = SURF_LINK_FATPIPE; @@ -455,13 +453,12 @@ FatTreeLink::FatTreeLink(sg_platf_cluster_cbarg_t cluster, FatTreeNode* downNode : upNode(upNode), downNode(downNode) { static int uniqueId = 0; - s_sg_platf_link_cbarg_t linkTemplate; - memset(&linkTemplate, 0, sizeof(linkTemplate)); + LinkCreationArgs linkTemplate; linkTemplate.bandwidth = cluster->bw; linkTemplate.latency = cluster->lat; linkTemplate.policy = cluster->sharing_policy; // sthg to do with that ? - linkTemplate.id = - "link_from_" + std::to_string( downNode->id) + "_" + std::to_string(upNode->id) + "_" + std::to_string(uniqueId); + linkTemplate.id = + "link_from_" + std::to_string(downNode->id) + "_" + std::to_string(upNode->id) + "_" + std::to_string(uniqueId); sg_platf_new_link(&linkTemplate); if (cluster->sharing_policy == SURF_LINK_FULLDUPLEX) { diff --git a/src/kernel/routing/TorusZone.cpp b/src/kernel/routing/TorusZone.cpp index f632e6eb55..f7c80c9a64 100644 --- a/src/kernel/routing/TorusZone.cpp +++ b/src/kernel/routing/TorusZone.cpp @@ -48,8 +48,7 @@ void TorusZone::create_links_for_node(sg_platf_cluster_cbarg_t cluster, int id, int dim_product = 1; // Needed to calculate the next neighbor_id for (unsigned int j = 0; j < xbt_dynar_length(dimensions_); j++) { - s_sg_platf_link_cbarg_t link; - memset(&link, 0, sizeof(link)); + LinkCreationArgs link; current_dimension = xbt_dynar_get_as(dimensions_, j, int); neighbor_rank_id = ((static_cast(rank) / dim_product) % current_dimension == current_dimension - 1) ? rank - (current_dimension - 1) * dim_product diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index 33d727a123..bb4d2e8483 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -115,7 +115,8 @@ simgrid::kernel::routing::NetPoint* sg_platf_new_router(const char* name, const return netpoint; } -void sg_platf_new_link(sg_platf_link_cbarg_t link){ +void sg_platf_new_link(LinkCreationArgs* link) +{ std::vector names; if (link->policy == SURF_LINK_FULLDUPLEX) { @@ -154,7 +155,6 @@ void sg_platf_new_cluster(sg_platf_cluster_cbarg_t cluster) int rankId=0; - s_sg_platf_link_cbarg_t link; // What an inventive way of initializing the AS that I have as ancestor :-( s_sg_platf_AS_cbarg_t AS; @@ -228,7 +228,7 @@ void sg_platf_new_cluster(sg_platf_cluster_cbarg_t cluster) char *tmp_link = bprintf("%s_loopback", link_id); XBT_DEBUG("", tmp_link, cluster->loopback_bw); - memset(&link, 0, sizeof(link)); + LinkCreationArgs link; link.id = tmp_link; link.bandwidth = cluster->loopback_bw; link.latency = cluster->loopback_lat; @@ -249,7 +249,7 @@ void sg_platf_new_cluster(sg_platf_cluster_cbarg_t cluster) char *tmp_link = bprintf("%s_limiter", link_id); XBT_DEBUG("", tmp_link, cluster->limiter_link); - memset(&link, 0, sizeof(link)); + LinkCreationArgs link; link.id = tmp_link; link.bandwidth = cluster->limiter_link; link.latency = 0; @@ -288,7 +288,7 @@ void sg_platf_new_cluster(sg_platf_cluster_cbarg_t cluster) //Make the backbone if ((cluster->bb_bw != 0) || (cluster->bb_lat != 0)) { - memset(&link, 0, sizeof(link)); + LinkCreationArgs link; link.id = std::string(cluster->id)+ "_backbone"; link.bandwidth = cluster->bb_bw; link.latency = cluster->bb_lat; @@ -331,8 +331,7 @@ void sg_platf_new_cabinet(sg_platf_cabinet_cbarg_t cabinet) host.speed_per_pstate.push_back(cabinet->speed); sg_platf_new_host(&host); - s_sg_platf_link_cbarg_t link; - memset(&link, 0, sizeof(link)); + LinkCreationArgs link; link.policy = SURF_LINK_FULLDUPLEX; link.latency = cabinet->lat; link.bandwidth = cabinet->bw; diff --git a/src/surf/xml/platf_private.hpp b/src/surf/xml/platf_private.hpp index bd8a1b610d..092e81c5f3 100644 --- a/src/surf/xml/platf_private.hpp +++ b/src/surf/xml/platf_private.hpp @@ -57,16 +57,17 @@ typedef struct { const char* link_down; } s_sg_platf_host_link_cbarg_t, *sg_platf_host_link_cbarg_t; -typedef struct { +class LinkCreationArgs { +public: std::string id; - double bandwidth; - tmgr_trace_t bandwidth_trace; - double latency; - tmgr_trace_t latency_trace; - tmgr_trace_t state_trace; - e_surf_link_sharing_policy_t policy; - xbt_dict_t properties; -} s_sg_platf_link_cbarg_t, *sg_platf_link_cbarg_t; + double bandwidth = 0; + tmgr_trace_t bandwidth_trace = nullptr; + double latency = 0; + tmgr_trace_t latency_trace = nullptr; + tmgr_trace_t state_trace = nullptr; + e_surf_link_sharing_policy_t policy = SURF_LINK_FATPIPE; + xbt_dict_t properties = nullptr; +}; typedef struct s_sg_platf_peer_cbarg *sg_platf_peer_cbarg_t; typedef struct s_sg_platf_peer_cbarg { @@ -202,7 +203,7 @@ XBT_PUBLIC(void) sg_platf_new_host (sg_platf_host_cbarg_t host); // Add an XBT_PUBLIC(void) sg_platf_new_hostlink(sg_platf_host_link_cbarg_t h); // Add an host_link to the currently described AS XBT_PUBLIC(simgrid::kernel::routing::NetPoint*) sg_platf_new_router(const char* name, const char* coords); // Add a router to the currently described AS -XBT_PUBLIC(void) sg_platf_new_link (sg_platf_link_cbarg_t link); // Add a link to the currently described AS +XBT_PUBLIC(void) sg_platf_new_link(LinkCreationArgs* link); // Add a link to the currently described AS XBT_PUBLIC(void) sg_platf_new_peer (sg_platf_peer_cbarg_t peer); // Add a peer to the currently described AS XBT_PUBLIC(void) sg_platf_new_cluster(sg_platf_cluster_cbarg_t clust); // Add a cluster to the currently described AS XBT_PUBLIC(void) sg_platf_new_cabinet(sg_platf_cabinet_cbarg_t cabinet); // Add a cabinet to the currently described AS diff --git a/src/surf/xml/surfxml_sax_cb.cpp b/src/surf/xml/surfxml_sax_cb.cpp index 274a939e27..f855907c29 100644 --- a/src/surf/xml/surfxml_sax_cb.cpp +++ b/src/surf/xml/surfxml_sax_cb.cpp @@ -652,8 +652,7 @@ void STag_surfxml_link(){ } void ETag_surfxml_link(){ - s_sg_platf_link_cbarg_t link; - memset(&link,0,sizeof(link)); + LinkCreationArgs link; link.properties = current_property_set; current_property_set = nullptr; @@ -711,8 +710,7 @@ void STag_surfxml_link___ctn(){ } void ETag_surfxml_backbone(){ - s_sg_platf_link_cbarg_t link; - memset(&link,0,sizeof(link)); + LinkCreationArgs link; link.properties = nullptr; link.id = std::string(A_surfxml_backbone_id);