Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[surf] Add backlinks from Cpu to surf::Host
[simgrid.git] / src / surf / cpu_interface.cpp
index 2b7c2e321e11b827b589d7cdb0da268ede391965..d99dad7aa3213ba02e92a8f51fca2e9c86da580c 100644 (file)
@@ -20,6 +20,14 @@ simgrid::surf::CpuModel *surf_cpu_model_vm;
 namespace simgrid {
 namespace surf {
 
+simgrid::xbt::FacetLevel<simgrid::Host, Cpu> Cpu::LEVEL;
+
+void Cpu::init()
+{
+  if (!LEVEL.valid())
+    LEVEL = simgrid::Host::add_level<simgrid::surf::Cpu>();
+}
+
 /*************
  * Callbacks *
  *************/
@@ -132,7 +140,8 @@ void CpuModel::updateActionsStateFull(double now, double delta)
 /************
  * Resource *
  ************/
-Cpu::Cpu(){
+Cpu::Cpu()
+{
 }
 
 
@@ -143,8 +152,6 @@ Cpu::Cpu(Model *model, const char *name, xbt_dict_t props,
  , m_core(core)
  , m_speedPeak(speedPeak)
  , m_speedScale(speedScale)
- , p_constraintCore(NULL)
- , p_constraintCoreId(NULL)
 {
 
 }
@@ -161,8 +168,6 @@ Cpu::Cpu(Model *model, const char *name, xbt_dict_t props,
   if (core > 1)
     xbt_assert(model == surf_cpu_model_pm);
 
-  p_constraintCore = NULL;
-  p_constraintCoreId = NULL;
   if (model->getUpdateMechanism() != UM_UNDEFINED) {
        p_constraintCore = xbt_new(lmm_constraint_t, core);
        p_constraintCoreId = xbt_new(void*, core);
@@ -226,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 *
  **********/