Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
cleanup the resource::Action::State::IGNORED thing
[simgrid.git] / src / surf / cpu_ti.hpp
index 6bcbcdc..a4f9184 100644 (file)
@@ -1,14 +1,14 @@
-/* Copyright (c) 2013-2015. The SimGrid Team.
- * All rights reserved.                                                     */
+/* Copyright (c) 2013-2018. 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 <boost/intrusive/list.hpp>
+
 #include <xbt/base.h>
 
-#include "cpu_interface.hpp"
-#include "trace_mgr_private.h"
-#include "surf/surf_routing.h"
+#include "src/surf/cpu_interface.hpp"
+#include "src/surf/trace_mgr.hpp"
 
 /* Epsilon */
 #define EPSILON 0.000000001
@@ -19,30 +19,27 @@ namespace surf {
 /***********
  * Classes *
  ***********/
-class XBT_PRIVATE CpuTiTrace;
-class XBT_PRIVATE CpuTiTgmr;
 class XBT_PRIVATE CpuTiModel;
 class XBT_PRIVATE CpuTi;
-class XBT_PRIVATE CpuTiAction;
-
-struct tiTag;
 
 /*********
  * Trace *
  *********/
 class CpuTiTrace {
 public:
-  CpuTiTrace(tmgr_trace_t speedTrace);
+  explicit CpuTiTrace(tmgr_trace_t speedTrace);
+  CpuTiTrace(const CpuTiTrace&) = delete;
+  CpuTiTrace& operator=(const CpuTiTrace&) = delete;
   ~CpuTiTrace();
 
-  double integrateSimple(double a, double b);
-  double integrateSimplePoint(double a);
-  double solveSimple(double a, double amount);
+  double integrate_simple(double a, double b);
+  double integrate_simple_point(double a);
+  double solve_simple(double a, double amount);
 
-  double *p_timePoints;
-  double *p_integral;
-  int m_nbPoints;
-  int binarySearch(double *array, double a, int low, int high);
+  double* time_points_;
+  double *integral_;
+  int nb_points_;
+  int binary_search(double* array, double a, int low, int high);
 };
 
 enum trace_type {
@@ -51,98 +48,90 @@ enum trace_type {
   TRACE_DYNAMIC               /*< Dynamic, have an availability file */
 };
 
-class CpuTiTgmr {
+class CpuTiTmgr {
 public:
-  CpuTiTgmr(trace_type type, double value)
-    : m_type(type), m_value(value)
-       {};
-  CpuTiTgmr(tmgr_trace_t speedTrace, double value);
-  ~CpuTiTgmr();
+  CpuTiTmgr(trace_type type, double value) : type_(type), value_(value){};
+  CpuTiTmgr(tmgr_trace_t speedTrace, double value);
+  CpuTiTmgr(const CpuTiTmgr&) = delete;
+  CpuTiTmgr& operator=(const CpuTiTmgr&) = delete;
+  ~CpuTiTmgr();
 
   double integrate(double a, double b);
   double solve(double a, double amount);
-  double solveSomewhatSimple(double a, double amount);
-  double getPowerScale(double a);
+  double get_power_scale(double a);
 
-  trace_type m_type;
-  double m_value;                 /*< Percentage of cpu speed available. Value fixed between 0 and 1 */
+  trace_type type_;
+  double value_;                 /*< Percentage of cpu speed available. Value fixed between 0 and 1 */
 
   /* Dynamic */
-  double m_lastTime = 0.0;             /*< Integral interval last point (discrete time) */
-  double m_total = 0.0;                 /*< Integral total between 0 and last_pointn */
+  double last_time_ = 0.0;             /*< Integral interval last point (discrete time) */
+  double total_    = 0.0;             /*< Integral total between 0 and last_pointn */
 
-  CpuTiTrace *p_trace = nullptr;
-  tmgr_trace_t p_speedTrace = nullptr;
+  CpuTiTrace *trace_ = nullptr;
+  tmgr_trace_t speed_trace_ = nullptr;
 };
 
 /**********
  * Action *
  **********/
 
-class CpuTiAction: public CpuAction {
+class XBT_PRIVATE CpuTiAction : public CpuAction {
   friend class CpuTi;
 public:
-  CpuTiAction(CpuTiModel *model, double cost, bool failed,
-                   CpuTi *cpu);
+  CpuTiAction(CpuTi* cpu, double cost);
+  ~CpuTiAction();
 
-  void setState(e_surf_action_state_t state) override;
-  int unref() override;
+  void set_state(kernel::resource::Action::State state) override;
   void cancel() override;
-  void updateIndexHeap(int i);
   void suspend() override;
   void resume() override;
-  void setMaxDuration(double duration) override;
-  void setPriority(double priority) override;
-  double getRemains() override;
-  void setAffinity(Cpu * /*cpu*/, unsigned long /*mask*/) override {};
-
-  CpuTi *p_cpu;
-  int m_indexHeap;
-  int m_suspended = 0;
-public:
+  void set_max_duration(double duration) override;
+  void set_priority(double priority) override;
+  double get_remains() override;
+
+  CpuTi *cpu_;
+
   boost::intrusive::list_member_hook<> action_ti_hook;
 };
 
-typedef boost::intrusive::member_hook<
-  CpuTiAction, boost::intrusive::list_member_hook<>, &CpuTiAction::action_ti_hook> ActionTiListOptions;
-typedef boost::intrusive::list<
-  CpuTiAction, ActionTiListOptions > ActionTiList;
+typedef boost::intrusive::member_hook<CpuTiAction, boost::intrusive::list_member_hook<>, &CpuTiAction::action_ti_hook> ActionTiListOptions;
+typedef boost::intrusive::list<CpuTiAction, ActionTiListOptions > ActionTiList;
 
 /************
  * Resource *
  ************/
 class CpuTi : public Cpu {
 public:
-  CpuTi(CpuTiModel *model, simgrid::s4u::Host *host, xbt_dynar_t speedPeak,
-        int pstate, double speedScale, tmgr_trace_t speedTrace, int core,
-        int initiallyOn, tmgr_trace_t stateTrace) ;
-  ~CpuTi();
-
-  void updateState(tmgr_trace_iterator_t event_type, double value, double date) override;
-  void updateActionsFinishTime(double now);
-  bool isUsed() override;
-  CpuAction *execute(double size) override;
+  CpuTi(CpuTiModel* model, simgrid::s4u::Host* host, std::vector<double>* speed_per_pstate, int core);
+  ~CpuTi() override;
+
+  void set_speed_trace(tmgr_trace_t trace) override;
+
+  void apply_event(tmgr_trace_event_t event, double value) override;
+  void update_actions_finish_time(double now);
+  void update_remaining_amount(double now);
+
+  bool is_used() override;
+  CpuAction *execution_start(double size) override;
+  simgrid::kernel::resource::Action* execution_start(double size, int requestedCores) override
+  {
+    THROW_UNIMPLEMENTED;
+    return nullptr;
+  }
   CpuAction *sleep(double duration) override;
-  double getAvailableSpeed() override;
-
-  void modified(bool modified);
+  double get_available_speed() override;
 
-  CpuTiTgmr *p_availTrace;       /*< Structure with data needed to integrate trace file */
-  tmgr_trace_iterator_t p_stateEvent = NULL; /*< trace file with states events (ON or OFF) */
-  tmgr_trace_iterator_t p_speedEvent = NULL; /*< trace file with availability events */
-  ActionTiList *p_actionSet;        /*< set with all actions running on cpu */
-  double m_sumPriority;          /*< the sum of actions' priority that are running on cpu */
-  double m_lastUpdate = 0;       /*< last update of actions' remaining amount done */
+  void set_modified(bool modified);
 
-  double current_frequency;
+  CpuTiTmgr* speed_integrated_trace_ = nullptr; /*< Structure with data needed to integrate trace file */
+  ActionTiList action_set_;                     /*< set with all actions running on cpu */
+  double sum_priority_ = 0;                  /*< the sum of actions' priority that are running on cpu */
+  double last_update_  = 0;                  /*< last update of actions' remaining amount done */
 
-  void updateRemainingAmount(double now);
-public:
   boost::intrusive::list_member_hook<> cpu_ti_hook;
 };
 
-typedef boost::intrusive::member_hook<
-  CpuTi, boost::intrusive::list_member_hook<>, &CpuTi::cpu_ti_hook> CpuTiListOptions;
+typedef boost::intrusive::member_hook<CpuTi, boost::intrusive::list_member_hook<>, &CpuTi::cpu_ti_hook> CpuTiListOptions;
 typedef boost::intrusive::list<CpuTi, CpuTiListOptions> CpuTiList;
 
 /*********
@@ -150,28 +139,13 @@ typedef boost::intrusive::list<CpuTi, CpuTiListOptions> CpuTiList;
  *********/
 class CpuTiModel : public CpuModel {
 public:
-  CpuTiModel();
-  ~CpuTiModel();
-  Cpu *createCpu(simgrid::s4u::Host *host,  xbt_dynar_t speedPeak,
-                          int pstate, double speedScale,
-                          tmgr_trace_t speedTrace, int core,
-                          int initiallyOn,
-                          tmgr_trace_t state_trace) override;
-  double shareResources(double now) override;
-  void updateActionsState(double now, double delta) override;
-  void addTraces() override;
-
-  ActionList *p_runningActionSetThatDoesNotNeedBeingChecked;
-  CpuTiList *p_modifiedCpu;
-  xbt_heap_t p_tiActionHeap;
-
-protected:
-  void NotifyResourceTurnedOn(simgrid::surf::Resource*){};
-  void NotifyResourceTurnedOff(simgrid::surf::Resource*){};
-
-  void NotifyActionCancel(Action*){};
-  void NotifyActionResume(Action*){};
-  void NotifyActionSuspend(Action*){};
+  CpuTiModel() : CpuModel(Model::UpdateAlgo::Full){};
+  ~CpuTiModel() override;
+  Cpu* createCpu(simgrid::s4u::Host* host, std::vector<double>* speed_per_pstate, int core) override;
+  double next_occuring_event(double now) override;
+  void update_actions_state(double now, double delta) override;
+
+  CpuTiList modified_cpus_;
 };
 
 }