Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[surf] new (abstract) class: PropertyHolder, with only one purpose
[simgrid.git] / src / surf / cpu_interface.cpp
index 2b7c2e3..0142878 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,27 +140,26 @@ void CpuModel::updateActionsStateFull(double now, double delta)
 /************
  * Resource *
  ************/
-Cpu::Cpu(){
+Cpu::Cpu()
+{
 }
 
 
-Cpu::Cpu(Model *model, const char *name, xbt_dict_t props,
+Cpu::Cpu(Model *model, const char *name,
          int core, double speedPeak, double speedScale,
          e_surf_resource_state_t stateInitial)
- : Resource(model, name, props, stateInitial)
+ : Resource(model, name, stateInitial)
  , m_core(core)
  , m_speedPeak(speedPeak)
  , m_speedScale(speedScale)
- , p_constraintCore(NULL)
- , p_constraintCoreId(NULL)
 {
 
 }
 
-Cpu::Cpu(Model *model, const char *name, xbt_dict_t props,
+Cpu::Cpu(Model *model, const char *name,
         lmm_constraint_t constraint, int core, double speedPeak,
         double speedScale, e_surf_resource_state_t stateInitial)
- : Resource(model, name, props, constraint, stateInitial)
+ : Resource(model, name, constraint, stateInitial)
  , m_core(core)
  , m_speedPeak(speedPeak)
  , m_speedScale(speedScale)
@@ -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);
@@ -176,14 +181,14 @@ Cpu::Cpu(Model *model, const char *name, xbt_dict_t props,
   }
 }
 
-Cpu::Cpu(Model *model, const char *name, xbt_dict_t props,
+Cpu::Cpu(Model *model, const char *name,
   lmm_constraint_t constraint, int core, double speedPeak, double speedScale)
-: Cpu(model, name, props, constraint, core, speedPeak, speedScale, SURF_RESOURCE_ON)
+: Cpu(model, name, constraint, core, speedPeak, speedScale, SURF_RESOURCE_ON)
 {}
 
-Cpu::Cpu(Model *model, const char *name, xbt_dict_t props,
+Cpu::Cpu(Model *model, const char *name,
   int core, double speedPeak, double speedScale)
-: Cpu(model, name, props, core, speedPeak, speedScale, SURF_RESOURCE_ON)
+: Cpu(model, name, core, speedPeak, speedScale, SURF_RESOURCE_ON)
 {}
 
 Cpu::~Cpu(){
@@ -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 *
  **********/