Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
make test pass. The finalization barrier is needed in this case, which is suboptimal.
[simgrid.git] / src / surf / cpu_interface.hpp
index 22f07b5..8f63dd4 100644 (file)
@@ -38,7 +38,7 @@ public:
    *                         This ignores any potential external load coming from a trace.
    * @param core The number of core of this Cpu
    */
-  virtual Cpu* create_cpu(s4u::Host* host, const std::vector<double>& speed_per_pstate, int core) = 0;
+  virtual CpuImpl* create_cpu(s4u::Host* host, const std::vector<double>& speed_per_pstate) = 0;
 
   void update_actions_state_lazy(double now, double delta) override;
   void update_actions_state_full(double now, double delta) override;
@@ -48,14 +48,18 @@ public:
  * Resource *
  ************/
 
-class XBT_PUBLIC Cpu : public Resource_T<Cpu> {
+class XBT_PUBLIC CpuImpl : public Resource_T<CpuImpl> {
   friend vm::VirtualMachineImpl; // Resets the VCPU
 
   s4u::Host* piface_;
   int core_count_ = 1;
-  int pstate_ = 0;                       /*< Current pstate (index in the speed_per_pstate_)*/
+  unsigned long pstate_ = 0;             /*< Current pstate (index in the speed_per_pstate_)*/
   std::vector<double> speed_per_pstate_; /*< List of supported CPU capacities (pstate related). Not 'const' because VCPU
                                             get modified on migration */
+  s4u::Host::SharingPolicy sharing_policy_ = s4u::Host::SharingPolicy::LINEAR;
+  s4u::NonLinearResourceCb sharing_policy_cb_;
+
+  void apply_sharing_policy_cfg() const;
 
 public:
   /**
@@ -64,17 +68,19 @@ public:
    * @param host The host in which this Cpu should be plugged
    * @param speed_per_pstate Processor speed (in flop per second) for each pstate
    */
-  Cpu(s4u::Host* host, const std::vector<double>& speed_per_pstate);
+  CpuImpl(s4u::Host* host, const std::vector<double>& speed_per_pstate);
 
-  Cpu(const Cpu&) = delete;
-  Cpu& operator=(const Cpu&) = delete;
+  CpuImpl(const CpuImpl&) = delete;
+  CpuImpl& operator=(const CpuImpl&) = delete;
 
   /** @brief Public interface */
   s4u::Host* get_iface() { return piface_; }
 
-  Cpu* set_core_count(int core_count);
+  CpuImpl* set_core_count(int core_count);
   virtual int get_core_count();
 
+  void seal() override;
+
   /** @brief Get a forecast of the speed (in flops/s) if the load were as provided.
    *
    * The provided load should encompasses both the application's activities and the external load that come from a
@@ -91,34 +97,52 @@ public:
   virtual double get_speed_ratio() { return speed_.scale; }
 
   /** @brief Get the peak processor speed (in flops/s), at the specified pstate */
-  virtual double get_pstate_peak_speed(int pstate_index) const;
+  virtual double get_pstate_peak_speed(unsigned long pstate_index) const;
+
+  virtual unsigned long get_pstate_count() const { return speed_per_pstate_.size(); }
+
+  virtual unsigned long get_pstate() const { return pstate_; }
+  virtual CpuImpl* set_pstate(unsigned long pstate_index);
+
+  /*< @brief Setup the profile file with availability events (peak speed changes due to external load).
+   * Profile must contain relative values (ratio between 0 and 1)
+   */
+  virtual CpuImpl* set_speed_profile(profile::Profile* profile);
 
-  virtual int get_pstate_count() const { return speed_per_pstate_.size(); }
+  /**
+   * @brief Set the CPU's speed
+   *
+   * @param speed_per_state list of powers for this processor (default power is at index 0)
+   */
+  CpuImpl* set_pstate_speed(const std::vector<double>& speed_per_state);
 
-  virtual void set_pstate(int pstate_index);
-  virtual int get_pstate() const { return pstate_; }
+  void set_sharing_policy(s4u::Host::SharingPolicy policy, const s4u::NonLinearResourceCb& cb);
+  s4u::Host::SharingPolicy get_sharing_policy() const;
 
-  /*< @brief Setup the trace file with availability events (peak speed changes due to external load).
-   * Trace must contain relative values (ratio between 0 and 1)
+  /**
+   * @brief Sets factor callback
+   * Implemented only for cas01
    */
-  virtual void set_speed_profile(profile::Profile* profile);
+  virtual void set_factor_cb(const std::function<s4u::Host::CpuFactorCb>& cb) { THROW_UNIMPLEMENTED; }
 
   /**
    * @brief Execute some quantity of computation
    *
    * @param size The value of the processing amount (in flop) needed to process
+   * @param user_bound User's bound for execution speed
    * @return The CpuAction corresponding to the processing
    */
-  virtual CpuAction* execution_start(double size) = 0;
+  virtual CpuAction* execution_start(double size, double user_bound) = 0;
 
   /**
    * @brief Execute some quantity of computation on more than one core
    *
    * @param size The value of the processing amount (in flop) needed to process
    * @param requested_cores The desired amount of cores. Must be >= 1
+   * @param user_bound User's bound for execution speed
    * @return The CpuAction corresponding to the processing
    */
-  virtual CpuAction* execution_start(double size, int requested_cores) = 0;
+  virtual CpuAction* execution_start(double size, int requested_cores, double user_bound) = 0;
 
   /**
    * @brief Make a process sleep for duration (in seconds)
@@ -137,7 +161,7 @@ protected:
    * Used to reset a VCPU when its VM migrates to another host, so it only resets the fields that should be in this
    *case.
    **/
-  virtual void reset_vcpu(Cpu* that);
+  virtual void reset_vcpu(CpuImpl* that);
 
   Metric speed_                  = {1.0, 0, nullptr};
 };
@@ -161,7 +185,7 @@ public:
   void set_state(Action::State state) override;
 
   void update_remains_lazy(double now) override;
-  std::list<Cpu*> cpus() const;
+  std::list<CpuImpl*> cpus() const;
 
   void suspend() override;
   void resume() override;