Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
simplify how cpus are plugged into hosts at creation
authorMartin Quinson <martin.quinson@loria.fr>
Wed, 23 Dec 2015 01:34:44 +0000 (02:34 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Wed, 23 Dec 2015 01:34:44 +0000 (02:34 +0100)
src/surf/cpu_cas01.cpp
src/surf/cpu_cas01.hpp
src/surf/cpu_interface.cpp
src/surf/cpu_interface.hpp
src/surf/cpu_ti.cpp
src/surf/cpu_ti.hpp
src/surf/host_ptask_L07.cpp
src/surf/host_ptask_L07.hpp
src/surf/sg_platf.cpp
src/surf/vm_hl13.cpp

index 1535c15..c767a73 100644 (file)
@@ -99,7 +99,7 @@ CpuCas01Model::~CpuCas01Model()
   delete p_cpuRunningActionSetThatDoesNotNeedBeingChecked;
 }
 
-Cpu *CpuCas01Model::createCpu(const char *name, xbt_dynar_t speedPeak,
+Cpu *CpuCas01Model::createCpu(simgrid::Host *host, xbt_dynar_t speedPeak,
                                  int pstate, double speedScale,
                           tmgr_trace_t speedTrace, int core,
                           e_surf_resource_state_t state_initial,
@@ -108,7 +108,7 @@ Cpu *CpuCas01Model::createCpu(const char *name, xbt_dynar_t speedPeak,
   xbt_assert(xbt_dynar_getfirst_as(speedPeak, double) > 0.0,
       "Speed has to be >0.0. Did you forget to specify the mandatory power attribute?");
   xbt_assert(core > 0, "Invalid number of cores %d. Must be larger than 0", core);
-  Cpu *cpu = new CpuCas01(this, name, speedPeak, pstate, speedScale, speedTrace, core, state_initial, state_trace);
+  Cpu *cpu = new CpuCas01(this, host, speedPeak, pstate, speedScale, speedTrace, core, state_initial, state_trace);
   return cpu;
 }
 
@@ -152,10 +152,10 @@ void CpuCas01Model::addTraces()
 /************
  * Resource *
  ************/
-CpuCas01::CpuCas01(CpuCas01Model *model, const char *name, xbt_dynar_t speedPeak,
+CpuCas01::CpuCas01(CpuCas01Model *model, simgrid::Host *host, xbt_dynar_t speedPeak,
                          int pstate, double speedScale, tmgr_trace_t speedTrace, int core,
                          e_surf_resource_state_t stateInitial, tmgr_trace_t stateTrace)
-: Cpu(model, name,
+: Cpu(model, host,
          lmm_constraint_new(model->getMaxminSystem(), this, core * speedScale * xbt_dynar_get_as(speedPeak, pstate, double)),
          core, xbt_dynar_get_as(speedPeak, pstate, double), speedScale,
     stateInitial) {
index 8d53c81..66dd3f7 100644 (file)
@@ -31,7 +31,7 @@ public:
   double (CpuCas01Model::*shareResources)(double now);
   void (CpuCas01Model::*updateActionsState)(double now, double delta);
 
-  Cpu *createCpu(const char *name, xbt_dynar_t speedPeak, int pstate,
+  Cpu *createCpu(simgrid::Host *host, xbt_dynar_t speedPeak, int pstate,
                    double speedScale,
                           tmgr_trace_t speedTrace, int core,
                           e_surf_resource_state_t state_initial,
@@ -47,7 +47,7 @@ public:
 
 class CpuCas01 : public Cpu {
 public:
-  CpuCas01(CpuCas01Model *model, const char *name, xbt_dynar_t speedPeak,
+  CpuCas01(CpuCas01Model *model, simgrid::Host *host, xbt_dynar_t speedPeak,
         int pstate, double speedScale, tmgr_trace_t speedTrace, int core,
         e_surf_resource_state_t stateInitial, tmgr_trace_t stateTrace) ;
   ~CpuCas01();
index 10334fa..78785a9 100644 (file)
@@ -143,26 +143,28 @@ Cpu::Cpu()
 }
 
 
-Cpu::Cpu(Model *model, const char *name,
+Cpu::Cpu(Model *model, simgrid::Host *host,
          int core, double speedPeak, double speedScale,
          e_surf_resource_state_t stateInitial)
- : Resource(model, name, stateInitial)
+ : Resource(model, host->getName().c_str(), stateInitial)
  , m_core(core)
  , m_speedPeak(speedPeak)
  , m_speedScale(speedScale)
+ , m_host(host)
 {
 
 }
 
-Cpu::Cpu(Model *model, const char *name,
+Cpu::Cpu(Model *model, simgrid::Host *host,
         lmm_constraint_t constraint, int core, double speedPeak,
         double speedScale, e_surf_resource_state_t stateInitial)
- : Resource(model, name, constraint, stateInitial)
+ : Resource(model, host->getName().c_str(), constraint, stateInitial)
  , m_core(core)
  , m_speedPeak(speedPeak)
  , m_speedScale(speedScale)
+ , m_host(host)
 {
-  /* At now, we assume that a VM does not have a multicore CPU. */
+  /* Currently, we assume that a VM does not have a multicore CPU. */
   if (core > 1)
     xbt_assert(model == surf_cpu_model_pm);
 
@@ -173,20 +175,20 @@ Cpu::Cpu(Model *model, const char *name,
     int i;
     for (i = 0; i < core; i++) {
       /* just for a unique id, never used as a string. */
-      p_constraintCoreId[i] = bprintf("%s:%i", name, i);
+      p_constraintCoreId[i] = bprintf("%s:%i", host->getName().c_str(), i);
       p_constraintCore[i] = lmm_constraint_new(model->getMaxminSystem(), p_constraintCoreId[i], m_speedScale * m_speedPeak);
     }
   }
 }
 
-Cpu::Cpu(Model *model, const char *name,
+Cpu::Cpu(Model *model, simgrid::Host *host,
   lmm_constraint_t constraint, int core, double speedPeak, double speedScale)
-: Cpu(model, name, constraint, core, speedPeak, speedScale, SURF_RESOURCE_ON)
+: Cpu(model, host, constraint, core, speedPeak, speedScale, SURF_RESOURCE_ON)
 {}
 
-Cpu::Cpu(Model *model, const char *name,
+Cpu::Cpu(Model *model, simgrid::Host *host,
   int core, double speedPeak, double speedScale)
-: Cpu(model, name, core, speedPeak, speedScale, SURF_RESOURCE_ON)
+: Cpu(model, host, core, speedPeak, speedScale, SURF_RESOURCE_ON)
 {}
 
 Cpu::~Cpu()
@@ -222,14 +224,6 @@ int Cpu::getCore()
   return m_core;
 }
 
-void Cpu::plug(simgrid::Host* host)
-{
-  if (this->m_host != nullptr)
-    xbt_die("Already plugged into host %s", host->getName().c_str());
-  host->extension_set(this);
-  this->m_host = host;
-}
-
 /**********
  * Action *
  **********/
index 12a8e00..4f1b156 100644 (file)
@@ -53,7 +53,7 @@ public:
    * @param state_initial [TODO]
    * @param state_trace [TODO]
    */
-  virtual Cpu *createCpu(const char *name, xbt_dynar_t speedPeak,
+  virtual Cpu *createCpu(simgrid::Host *host, xbt_dynar_t speedPeak,
                       int pstate, double speedScale,
                           tmgr_trace_t speedTrace, int core,
                           e_surf_resource_state_t state_initial,
@@ -82,14 +82,14 @@ public:
    * @brief Cpu constructor
    *
    * @param model The CpuModel associated to this Cpu
-   * @param name The name of the Cpu
+   * @param host The host in which this Cpu should be plugged
    * @param constraint The lmm constraint associated to this Cpu if it is part of a LMM component
    * @param core The number of core of this Cpu
    * @param speedPeak The speed peak of this Cpu in flops (max speed)
    * @param speedScale The speed scale of this Cpu in [0;1] (available amount)
    * @param stateInitial whether it is created running or crashed
    */
-  Cpu(simgrid::surf::Model *model, const char *name,
+  Cpu(simgrid::surf::Model *model, simgrid::Host *host,
          lmm_constraint_t constraint, int core, double speedPeak, double speedScale,
          e_surf_resource_state_t stateInitial);
 
@@ -97,19 +97,19 @@ public:
    * @brief Cpu constructor
    *
    * @param model The CpuModel associated to this Cpu
-   * @param name The name of the Cpu
+   * @param host The host in which this Cpu should be plugged
    * @param core The number of core of this Cpu
    * @param speedPeak The speed peak of this Cpu in flops (max speed)
    * @param speedScale The speed scale of this Cpu in [0;1] (available amount)
    * @param stateInitial whether it is created running or crashed
    */
-  Cpu(simgrid::surf::Model *model, const char *name,
+  Cpu(simgrid::surf::Model *model, simgrid::Host *host,
          int core, double speedPeak, double speedScale,
          e_surf_resource_state_t stateInitial);
 
-  Cpu(simgrid::surf::Model *model, const char *name,
+  Cpu(simgrid::surf::Model *model, simgrid::Host *host,
          lmm_constraint_t constraint, int core, double speedPeak, double speedScale);
-  Cpu(simgrid::surf::Model *model, const char *name,
+  Cpu(simgrid::surf::Model *model, simgrid::Host *host,
          int core, double speedPeak, double speedScale);
 
   ~Cpu();
@@ -148,8 +148,6 @@ public:
   virtual void setPstate(int pstate_index)=0;
   virtual int  getPstate()=0;
 
-  void plug(simgrid::Host* host);
-
   void addTraces(void);
   simgrid::Host* getHost() { return m_host; }
 
@@ -157,7 +155,7 @@ public:
   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;
+  simgrid::Host* m_host;
 
   /* Note (hypervisor): */
   lmm_constraint_t *p_constraintCore=NULL;
index 90447fb..a72268a 100644 (file)
@@ -435,7 +435,7 @@ CpuTiModel::~CpuTiModel()
   xbt_heap_free(p_tiActionHeap);
 }
 
-Cpu *CpuTiModel::createCpu(const char *name,
+Cpu *CpuTiModel::createCpu(simgrid::Host *host,
                               xbt_dynar_t speedPeak,
                               int pstate,
                            double speedScale,
@@ -447,7 +447,7 @@ Cpu *CpuTiModel::createCpu(const char *name,
   xbt_assert(core==1,"Multi-core not handled with this model yet");
   xbt_assert(xbt_dynar_getfirst_as(speedPeak, double) > 0.0,
       "Speed has to be >0.0. Did you forget to specify the mandatory speed attribute?");
-  CpuTi *cpu = new CpuTi(this, name, speedPeak, pstate, speedScale, speedTrace,
+  CpuTi *cpu = new CpuTi(this, host, speedPeak, pstate, speedScale, speedTrace,
                           core, stateInitial, stateTrace);
   return cpu;
 }
@@ -548,10 +548,10 @@ void CpuTiModel::addTraces()
 /************
  * Resource *
  ************/
-CpuTi::CpuTi(CpuTiModel *model, const char *name, xbt_dynar_t speedPeak,
+CpuTi::CpuTi(CpuTiModel *model, simgrid::Host *host, xbt_dynar_t speedPeak,
         int pstate, double speedScale, tmgr_trace_t speedTrace, int core,
         e_surf_resource_state_t stateInitial, tmgr_trace_t stateTrace)
-  : Cpu(model, name, core, 0, speedScale, stateInitial)
+  : Cpu(model, host, core, 0, speedScale, stateInitial)
 {
   p_speedEvent = NULL;
   m_speedScale = speedScale;
index f95c819..06b10df 100644 (file)
@@ -115,7 +115,7 @@ typedef boost::intrusive::list<
 class CpuTi : public Cpu {
 public:
   CpuTi() {};
-  CpuTi(CpuTiModel *model, const char *name, xbt_dynar_t speedPeak,
+  CpuTi(CpuTiModel *model, simgrid::Host *host, xbt_dynar_t speedPeak,
         int pstate, double speedScale, tmgr_trace_t speedTrace, int core,
         e_surf_resource_state_t stateInitial, tmgr_trace_t stateTrace) ;
   ~CpuTi();
@@ -160,7 +160,7 @@ class CpuTiModel : public CpuModel {
 public:
   CpuTiModel();
   ~CpuTiModel();
-  Cpu *createCpu(const char *name,  xbt_dynar_t speedPeak,
+  Cpu *createCpu(simgrid::Host *host,  xbt_dynar_t speedPeak,
                           int pstate, double speedScale,
                           tmgr_trace_t speedTrace, int core,
                           e_surf_resource_state_t state_initial,
index 9ac974c..700aa0c 100644 (file)
@@ -289,14 +289,14 @@ Action *NetworkL07Model::communicate(RoutingEdge *src, RoutingEdge *dst,
   return res;
 }
 
-Cpu *CpuL07Model::createCpu(const char *name,  xbt_dynar_t powerPeak,
+Cpu *CpuL07Model::createCpu(simgrid::Host *host,  xbt_dynar_t powerPeak,
                           int pstate, double power_scale,
                           tmgr_trace_t power_trace, int core,
                           e_surf_resource_state_t state_initial,
                           tmgr_trace_t state_trace)
 {
   double power_initial = xbt_dynar_get_as(powerPeak, pstate, double);
-  CpuL07 *cpu = new CpuL07(this, name, power_initial, power_scale, power_trace,
+  CpuL07 *cpu = new CpuL07(this, host, power_initial, power_scale, power_trace,
                          core, state_initial, state_trace);
   return cpu;
 }
@@ -387,10 +387,10 @@ void HostL07Model::addTraces()
 /************
  * Resource *
  ************/
-CpuL07::CpuL07(CpuL07Model *model, const char* name,
+CpuL07::CpuL07(CpuL07Model *model, simgrid::Host *host,
                     double speedInitial, double speedScale, tmgr_trace_t speedTrace,
                           int core, e_surf_resource_state_t state_initial, tmgr_trace_t state_trace)
- : Cpu(model, name, lmm_constraint_new(ptask_maxmin_system, this, speedInitial * speedScale),
+ : Cpu(model, host, lmm_constraint_new(ptask_maxmin_system, this, speedInitial * speedScale),
           core, speedInitial, speedScale, state_initial)
 {
   xbt_assert(m_speedScale > 0, "Power has to be >0");
index b69b496..5b8c107 100644 (file)
@@ -58,7 +58,7 @@ public:
   CpuL07Model(HostL07Model *hmodel) : CpuModel() {p_hostModel = hmodel;};
   ~CpuL07Model() {surf_cpu_model_pm = NULL;};
 
-  Cpu *createCpu(const char *name,  xbt_dynar_t speedPeak,
+  Cpu *createCpu(simgrid::Host *host,  xbt_dynar_t speedPeak,
                           int pstate, double speedScale,
                           tmgr_trace_t speedTrace, int core,
                           e_surf_resource_state_t state_initial,
@@ -98,7 +98,7 @@ class CpuL07 : public Cpu {
   tmgr_trace_event_t p_stateEvent;
   tmgr_trace_event_t p_speedEvent;
 public:
-  CpuL07(CpuL07Model *model, const char* name,
+  CpuL07(CpuL07Model *model, simgrid::Host *host,
                 double power_scale, double power_initial, tmgr_trace_t power_trace,
      int core, e_surf_resource_state_t state_initial, tmgr_trace_t state_trace);
   ~CpuL07();
index b189642..208484b 100644 (file)
@@ -62,7 +62,7 @@ void sg_platf_new_host(sg_platf_host_cbarg_t host)
 
   sg_host_t h = simgrid::Host::by_name_or_create(host->id);
   simgrid::surf::Cpu *cpu = surf_cpu_model_pm->createCpu(
-        host->id,
+               h,
         host->speed_peak,
         host->pstate,
         host->speed_scale,
@@ -70,7 +70,6 @@ void sg_platf_new_host(sg_platf_host_cbarg_t host)
         host->core_amount,
         host->initial_state,
         host->state_trace);
-  cpu->plug(h);
   surf_host_model->createHost(host->id, net, cpu, host->properties)->attach(h);
   if (TRACE_is_enabled() && TRACE_needs_platform())
     sg_instr_new_host(host);
index 19d008d..89cbef1 100644 (file)
@@ -186,7 +186,7 @@ VMHL13::VMHL13(VMModel *model, const char* name, xbt_dict_t props, sg_host_t hos
   // Roughly, create a vcpu resource by using the values of the sub_cpu one.
   CpuCas01 *sub_cpu = static_cast<CpuCas01*>(sg_host_surfcpu(host_PM));
 
-  p_cpu = surf_cpu_model_vm->createCpu(name, // name
+  p_cpu = surf_cpu_model_vm->createCpu(host, // the machine hosting the VM
       sub_cpu->getSpeedPeakList(),        // host->power_peak,
       sub_cpu->getPState(),
       1,                          // host->power_scale,
@@ -194,7 +194,6 @@ VMHL13::VMHL13(VMModel *model, const char* name, xbt_dict_t props, sg_host_t hos
       1,                          // host->core_amount,
       SURF_RESOURCE_ON,           // host->initial_state,
       NULL);                      // host->state_trace,
-  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 ? */