Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[surf] Add backlinks from Cpu to surf::Host
authorGabriel Corona <gabriel.corona@loria.fr>
Thu, 17 Dec 2015 13:13:38 +0000 (14:13 +0100)
committerGabriel Corona <gabriel.corona@loria.fr>
Thu, 17 Dec 2015 13:31:55 +0000 (14:31 +0100)
By the way, we change sg_host_surfcpu_register(host, cpu) into
cpu->plug(host).

include/simgrid/host.h
src/simgrid/host.cpp
src/surf/cpu_interface.cpp
src/surf/cpu_interface.hpp
src/surf/sg_platf.cpp
src/surf/vm_hl13.cpp

index e440ef9..83bba0b 100644 (file)
@@ -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 ============
index f2d53f3..c4c9f20 100644 (file)
@@ -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<simgrid::surf::Cpu>(nullptr);
 }
index 17029db..d99dad7 100644 (file)
@@ -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 *
  **********/
index 79bc81d..3ba667a 100644 (file)
@@ -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;
+
 };
 
 /**********
index 8efd18d..8797417 100644 (file)
@@ -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())
index 85f83f6..208e24e 100644 (file)
@@ -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 ? */