From b197602d9f391f0020949e793fd191bb722af74a Mon Sep 17 00:00:00 2001 From: Gabriel Corona Date: Thu, 17 Dec 2015 14:13:38 +0100 Subject: [PATCH] [surf] Add backlinks from Cpu to surf::Host By the way, we change sg_host_surfcpu_register(host, cpu) into cpu->plug(host). --- include/simgrid/host.h | 1 - src/simgrid/host.cpp | 6 ------ src/surf/cpu_interface.cpp | 11 +++++++++++ src/surf/cpu_interface.hpp | 3 +++ src/surf/sg_platf.cpp | 3 ++- src/surf/vm_hl13.cpp | 2 +- 6 files changed, 17 insertions(+), 9 deletions(-) diff --git a/include/simgrid/host.h b/include/simgrid/host.h index e440ef9036..83bba0b707 100644 --- a/include/simgrid/host.h +++ b/include/simgrid/host.h @@ -54,7 +54,6 @@ XBT_PUBLIC(void) sg_host_simix_destroy(sg_host_t host); // ========== SURF CPU ============ 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_register(sg_host_t host, surf_cpu_t cpu); XBT_PUBLIC(void) sg_host_surfcpu_destroy(sg_host_t host); // ========== RoutingEdge ============ diff --git a/src/simgrid/host.cpp b/src/simgrid/host.cpp index f2d53f3b65..c4c9f2042b 100644 --- a/src/simgrid/host.cpp +++ b/src/simgrid/host.cpp @@ -135,12 +135,6 @@ surf_cpu_t sg_host_surfcpu(sg_host_t host) { void sg_host_surfcpu_set(sg_host_t host, surf_cpu_t cpu) { host->set_facet(simgrid::surf::Cpu::LEVEL, cpu); } -void sg_host_surfcpu_register(sg_host_t host, surf_cpu_t cpu) -{ - surf_callback_emit(simgrid::surf::cpuCreatedCallbacks, cpu); - surf_callback_emit(simgrid::surf::cpuStateChangedCallbacks, cpu, SURF_RESOURCE_ON, cpu->getState()); - sg_host_surfcpu_set(host, cpu); -} void sg_host_surfcpu_destroy(sg_host_t host) { host->set_facet(nullptr); } diff --git a/src/surf/cpu_interface.cpp b/src/surf/cpu_interface.cpp index 17029dbf13..d99dad7aa3 100644 --- a/src/surf/cpu_interface.cpp +++ b/src/surf/cpu_interface.cpp @@ -231,6 +231,17 @@ void Cpu::setState(e_surf_resource_state_t state) surf_callback_emit(cpuStateChangedCallbacks, this, old, state); } +void Cpu::plug(simgrid::Host* host) +{ + if (this->m_host != nullptr) + xbt_die("Aleady plugged into host %s", host->id().c_str()); + host->set_facet(this); + this->m_host = host; + simgrid::surf::cpuCreatedCallbacks(this); + simgrid::surf::cpuStateChangedCallbacks(this, + SURF_RESOURCE_ON, this->getState()); +} + /********** * Action * **********/ diff --git a/src/surf/cpu_interface.hpp b/src/surf/cpu_interface.hpp index 79bc81dc71..3ba667a1d0 100644 --- a/src/surf/cpu_interface.hpp +++ b/src/surf/cpu_interface.hpp @@ -177,15 +177,18 @@ public: virtual int getPstate()=0; void setState(e_surf_resource_state_t state); + void plug(simgrid::Host* host); void addTraces(void); int m_core = 1; /* Amount of cores */ double m_speedPeak; /*< CPU speed peak, ie max value */ double m_speedScale; /*< Percentage of CPU available according to the trace, in [O,1] */ + simgrid::Host* m_host = nullptr; /* Note (hypervisor): */ lmm_constraint_t *p_constraintCore=NULL; void **p_constraintCoreId=NULL; + }; /********** diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index 8efd18df47..8797417b5d 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -60,6 +60,7 @@ void sg_platf_new_host(sg_platf_host_cbarg_t host) if (current_routing) net = routing_add_host(current_routing, host); + sg_host_t h = simgrid::Host::by_name_or_create(host->id); simgrid::surf::Cpu *cpu = surf_cpu_model_pm->createCpu( host->id, host->speed_peak, @@ -70,7 +71,7 @@ void sg_platf_new_host(sg_platf_host_cbarg_t host) host->initial_state, host->state_trace, host->properties); - sg_host_surfcpu_register(sg_host_by_name(host->id), cpu); + cpu->plug(h); surf_host_model->createHost(host->id, net, cpu); if (TRACE_is_enabled() && TRACE_needs_platform()) diff --git a/src/surf/vm_hl13.cpp b/src/surf/vm_hl13.cpp index 85f83f6456..208e24ee53 100644 --- a/src/surf/vm_hl13.cpp +++ b/src/surf/vm_hl13.cpp @@ -200,7 +200,7 @@ VMHL13::VMHL13(VMModel *model, const char* name, xbt_dict_t props, SURF_RESOURCE_ON, // host->initial_state, NULL, // host->state_trace, NULL); // host->properties, - sg_host_surfcpu_register(host, p_cpu); + p_cpu->plug(host); /* We create cpu_action corresponding to a VM process on the host operating system. */ /* FIXME: TODO: we have to periodically input GUESTOS_NOISE to the system? how ? */ -- 2.20.1