From 5410c0dedd6e07e55c0a74a0664d1f8a73d69c1e Mon Sep 17 00:00:00 2001 From: Gabriel Corona Date: Thu, 17 Dec 2015 14:56:57 +0100 Subject: [PATCH] [surf] Use the pointers to simgrid::Host instead of looking by name --- src/surf/cpu_interface.hpp | 2 ++ src/surf/host_interface.hpp | 1 + src/surf/host_ptask_L07.cpp | 2 +- src/surf/network_ns3.cpp | 2 +- src/surf/surf_c_bindings.cpp | 5 +---- src/surf/surf_routing.cpp | 5 +++-- src/surf/virtual_machine.cpp | 2 +- src/surf/vm_hl13.cpp | 3 +-- 8 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/surf/cpu_interface.hpp b/src/surf/cpu_interface.hpp index 3ba667a1d0..e28d4d3913 100644 --- a/src/surf/cpu_interface.hpp +++ b/src/surf/cpu_interface.hpp @@ -185,6 +185,8 @@ public: double m_speedScale; /*< Percentage of CPU available according to the trace, in [O,1] */ simgrid::Host* m_host = nullptr; + simgrid::Host* getHost() { return m_host; } + /* Note (hypervisor): */ lmm_constraint_t *p_constraintCore=NULL; void **p_constraintCoreId=NULL; diff --git a/src/surf/host_interface.hpp b/src/surf/host_interface.hpp index ed143b8836..5c081d2b9a 100644 --- a/src/surf/host_interface.hpp +++ b/src/surf/host_interface.hpp @@ -279,6 +279,7 @@ public: void getParams(vm_params_t params); /** @brief Sets the params of that VM/PM */ void setParams(vm_params_t params); + simgrid::Host* getHost() { return p_host; } private: s_vm_params_t p_params; }; diff --git a/src/surf/host_ptask_L07.cpp b/src/surf/host_ptask_L07.cpp index 2f573c0929..fea3be0a0e 100644 --- a/src/surf/host_ptask_L07.cpp +++ b/src/surf/host_ptask_L07.cpp @@ -454,7 +454,7 @@ Action *CpuL07::execute(double size) double *flops_amount = xbt_new0(double, 1); double *bytes_amount = xbt_new0(double, 1); - host_list[0] = sg_host_by_name(getName()); + host_list[0] = getHost(); flops_amount[0] = size; return static_cast(getModel()) diff --git a/src/surf/network_ns3.cpp b/src/surf/network_ns3.cpp index 84996b1571..d4cb31c09d 100644 --- a/src/surf/network_ns3.cpp +++ b/src/surf/network_ns3.cpp @@ -41,7 +41,7 @@ static void simgrid_ns3_add_host(simgrid::surf::Host* host) { const char* id = host->getName(); XBT_DEBUG("NS3_ADD_HOST '%s'", id); - simgrid::Host::by_name_or_create(id)->set_facet(NS3_HOST_LEVEL, ns3_add_host(id)); + host->getHost()->set_facet(NS3_HOST_LEVEL, ns3_add_host(id)); } static void parse_ns3_add_link(sg_platf_link_cbarg_t link) diff --git a/src/surf/surf_c_bindings.cpp b/src/surf/surf_c_bindings.cpp index 740ed9d6f2..4b6ca5a63a 100644 --- a/src/surf/surf_c_bindings.cpp +++ b/src/surf/surf_c_bindings.cpp @@ -385,8 +385,6 @@ void surf_host_set_params(sg_host_t host, vm_params_t params){ } void surf_vm_destroy(sg_host_t resource){ - /* Before clearing the entries in host_lib, we have to pick up resources. */ - const char* name = resource->id().c_str(); /* We deregister objects from host_lib, without invoking the freeing callback * of each level. * @@ -395,8 +393,7 @@ void surf_vm_destroy(sg_host_t resource){ */ sg_host_surfcpu_destroy(resource); sg_host_edge_destroy(resource,1); - // TODO, use backlink from simgrid::surf::Host to simgrid::Host - simgrid::Host::by_name_or_null(name)->set_facet((simgrid::surf::Host*)nullptr); + resource->set_facet(nullptr); /* TODO: comment out when VM storage is implemented. */ // host->set_facet(SURF_STORAGE_LEVEL, nullptr); diff --git a/src/surf/surf_routing.cpp b/src/surf/surf_routing.cpp index b267423760..4ad2e76499 100644 --- a/src/surf/surf_routing.cpp +++ b/src/surf/surf_routing.cpp @@ -172,7 +172,8 @@ simgrid::surf::RoutingEdge *routing_add_host( SURF_NETWORK_ELEMENT_HOST, current_routing); routingEdge->setId(current_routing->parsePU(routingEdge)); - sg_host_edge_set(sg_host_by_name_or_create(host->id), routingEdge); + sg_host_t h = sg_host_by_name_or_create(host->id); + sg_host_edge_set(h, routingEdge); XBT_DEBUG("Having set name '%s' id '%d'", host->id, routingEdge->getId()); simgrid::surf::routingEdgeCreatedCallbacks(routingEdge); @@ -196,7 +197,7 @@ simgrid::surf::RoutingEdge *routing_add_host( } xbt_dynar_shrink(ctn, 0); xbt_dynar_free(&ctn_str); - simgrid::Host::by_name_or_create(host->id)->set_facet(COORD_HOST_LEVEL, (void *) ctn); + h->set_facet(COORD_HOST_LEVEL, (void *) ctn); XBT_DEBUG("Having set host coordinates for '%s'",host->id); } diff --git a/src/surf/virtual_machine.cpp b/src/surf/virtual_machine.cpp index 9fc07fc868..943d23e5c9 100644 --- a/src/surf/virtual_machine.cpp +++ b/src/surf/virtual_machine.cpp @@ -62,7 +62,7 @@ void VirtualMachine::setState(e_surf_resource_state_t state){ **/ sg_host_t VirtualMachine::getPm() { - return simgrid::Host::by_name_or_null(p_subWs->getName()); + return p_subWs->getHost(); } /********** diff --git a/src/surf/vm_hl13.cpp b/src/surf/vm_hl13.cpp index 037749c0fc..f0c0ce8baa 100644 --- a/src/surf/vm_hl13.cpp +++ b/src/surf/vm_hl13.cpp @@ -340,8 +340,7 @@ void VMHL13::setAffinity(Cpu *cpu, unsigned long mask){ **/ sg_host_t VMHL13::getPm() { - // TODO, store pointer to the PM? - return simgrid::Host::by_name_or_null(p_subWs->getName()); + return p_subWs->getHost(); } /* Adding a task to a VM updates the VCPU task on its physical machine. */ -- 2.20.1