Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[CR] Minor improvement.
[simgrid.git] / src / surf / cpu_cas01.hpp
index 316df92..b5279e4 100644 (file)
@@ -1,16 +1,22 @@
-/* Copyright (c) 2013-2015. The SimGrid Team.
- * All rights reserved.                                                     */
+/* Copyright (c) 2013-2021. The SimGrid Team. All rights reserved.          */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
-#include <xbt/base.h>
+#ifndef SIMGRID_SURF_CPUCAS01_HPP
+#define SIMGRID_SURF_CPUCAS01_HPP
 
-#include "cpu_interface.hpp"
+#include "src/kernel/resource/CpuImpl.hpp"
+#include "xbt/base.h"
+
+namespace simgrid {
+namespace kernel {
+namespace resource {
 
 /***********
  * Classes *
  ***********/
+
 class XBT_PRIVATE CpuCas01Model;
 class XBT_PRIVATE CpuCas01;
 class XBT_PRIVATE CpuCas01Action;
@@ -18,68 +24,52 @@ class XBT_PRIVATE CpuCas01Action;
 /*********
  * Model *
  *********/
+
 class CpuCas01Model : public CpuModel {
 public:
-  CpuCas01Model();
-  ~CpuCas01Model();
-
-  double (CpuCas01Model::*shareResources)(double now);
-  void (CpuCas01Model::*updateActionsState)(double now, double delta);
-
-  Cpu *createCpu(const char *name, xbt_dynar_t power_peak, int pstate,
-                   double power_scale,
-                          tmgr_trace_t power_trace, int core,
-                          e_surf_resource_state_t state_initial,
-                          tmgr_trace_t state_trace,
-                          xbt_dict_t cpu_properties);
-  double shareResourcesFull(double now);
-  void addTraces();
-  ActionList *p_cpuRunningActionSetThatDoesNotNeedBeingChecked;
+  explicit CpuCas01Model(const std::string& name);
+  CpuCas01Model(const CpuCas01Model&) = delete;
+  CpuCas01Model& operator=(const CpuCas01Model&) = delete;
+
+  CpuImpl* create_cpu(s4u::Host* host, const std::vector<double>& speed_per_pstate) override;
 };
 
 /************
  * Resource *
  ************/
 
-class CpuCas01 : public Cpu {
+class CpuCas01 : public CpuImpl {
+  std::function<s4u::Host::CpuFactorCb> factor_cb_ = {};
+
 public:
-  CpuCas01(CpuCas01Model *model, const char *name, xbt_dynar_t power_peak,
-        int pstate, double powerScale, tmgr_trace_t powerTrace, int core,
-        e_surf_resource_state_t stateInitial, tmgr_trace_t stateTrace,
-       xbt_dict_t properties) ;
-  ~CpuCas01();
-  void updateState(tmgr_trace_event_t event_type, double value, double date);
-  CpuAction *execute(double size);
-  CpuAction *sleep(double duration);
-
-  double getCurrentPowerPeak();
-  double getPowerPeakAt(int pstate_index);
-  int getNbPstates();
-  void setPstate(int pstate_index);
-  int  getPstate();
-  bool isUsed();
-  void setStateEvent(tmgr_trace_event_t stateEvent);
-  void setPowerEvent(tmgr_trace_event_t stateEvent);
-  xbt_dynar_t getPowerPeakList();
-
-  int getPState();
-
-private:
-  tmgr_trace_event_t p_stateEvent;
-  tmgr_trace_event_t p_powerEvent;
-  xbt_dynar_t p_powerPeakList;       /*< List of supported CPU capacities */
-  int m_pstate;                      /*< Current pstate (index in the power_peak_list)*/
+  using CpuImpl::CpuImpl;
+  CpuCas01(const CpuCas01&) = delete;
+  CpuCas01& operator=(const CpuCas01&) = delete;
+  void apply_event(profile::Event* event, double value) override;
+  CpuAction* execution_start(double size, double user_bound) override;
+  CpuAction* execution_start(double size, int requested_cores, double user_bound) override;
+  CpuAction* sleep(double duration) override;
+  void set_factor_cb(const std::function<s4u::Host::CpuFactorCb>& cb) override;
+
+protected:
+  void on_speed_change() override;
 };
 
 /**********
  * Action *
  **********/
-class CpuCas01Action: public CpuAction {
-  friend CpuAction *CpuCas01::execute(double size);
-  friend CpuAction *CpuCas01::sleep(double duration);
-public:
-  CpuCas01Action(Model *model, double cost, bool failed, double power,
-                 lmm_constraint_t constraint);
+class CpuCas01Action : public CpuAction {
+  int requested_core_ = 1;
 
-  ~CpuCas01Action() {};
+public:
+  CpuCas01Action(Model* model, double cost, bool failed, double speed, lmm::Constraint* constraint, int requested_core);
+  CpuCas01Action(const CpuCas01Action&) = delete;
+  CpuCas01Action& operator=(const CpuCas01Action&) = delete;
+  int requested_core() const { return requested_core_; }
 };
+
+} // namespace resource
+} // namespace kernel
+} // namespace simgrid
+
+#endif