Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add squeletons for models
authorPaul Bédaride <paul.bedaride@gmail.com>
Fri, 9 Aug 2013 15:32:26 +0000 (17:32 +0200)
committerPaul Bédaride <paul.bedaride@gmail.com>
Fri, 9 Aug 2013 15:32:26 +0000 (17:32 +0200)
buildtools/Cmake/DefinePackages.cmake
src/surf/cpu.hpp [new file with mode: 0644]
src/surf/cpu_ti.cpp [new file with mode: 0644]
src/surf/cpu_ti.hpp [new file with mode: 0644]
src/surf/surf.cpp [new file with mode: 0644]
src/surf/surf.hpp [new file with mode: 0644]
src/surf/surf_c.h [new file with mode: 0644]

index faa5eb4..9538a0d 100644 (file)
@@ -40,6 +40,8 @@ set(EXTRA_DIST
   src/smpi/colls/coll_tuned_topo.h
   src/smpi/private.h
   src/smpi/smpi_mpi_dt_private.h
+  src/surf/cpu.hpp
+  src/surf/cpu_ti.hpp
   src/surf/cpu_ti_private.h
   src/surf/gtnets/gtnets_interface.h
   src/surf/gtnets/gtnets_simulator.h
@@ -59,6 +61,8 @@ set(EXTRA_DIST
   src/surf/simgrid.dtd
   src/surf/simgrid_dtd.c
   src/surf/storage_private.h
+  src/surf/surf_c.h
+  src/surf/surf.hpp
   src/surf/surf_private.h
   src/surf/surf_routing_private.h
   src/surf/surfxml_parse.c
@@ -284,6 +288,7 @@ set(NS3_SRC
   )
 
 set(SURF_SRC
+  src/surf/cpu_ti.cpp
   src/surf/cpu_cas01.c
   src/surf/cpu_ti.c
   src/surf/fair_bottleneck.cpp
@@ -299,6 +304,7 @@ set(SURF_SRC
   src/surf/sg_platf.c
   src/surf/storage.c
   src/surf/surf.c
+  src/surf/surf.cpp
   src/surf/surf_action.c
   src/surf/surf_model.c
   src/surf/surf_routing.c
diff --git a/src/surf/cpu.hpp b/src/surf/cpu.hpp
new file mode 100644 (file)
index 0000000..530d324
--- /dev/null
@@ -0,0 +1,57 @@
+#include "surf.hpp"
+
+#ifndef SURF_MODEL_CPU_H_
+#define SURF_MODEL_CPU_H_
+
+/***********
+ * Classes *
+ ***********/
+class CpuModel;
+typedef CpuModel *CpuModelPtr;
+
+class Cpu;
+typedef Cpu *CpuPtr;
+
+class CpuAction;
+typedef CpuAction *CpuActionPtr;
+
+/*********
+ * Model *
+ *********/
+class CpuModel : public Model {
+public:
+  CpuModel(string name) : Model(name) {};
+  CpuPtr createResource(string name);
+
+  virtual void addTraces() =0;
+};
+
+/************
+ * Resource *
+ ************/
+class Cpu : public Resource {
+public:
+  Cpu(CpuModelPtr model, string name, xbt_dict_t properties) : Resource(model, name, properties) {};
+  CpuActionPtr execute(double size);
+  CpuActionPtr sleep(double duration);
+  e_surf_resource_state_t getState();
+  int getCore();
+  double getSpeed(double load);
+  double getAvailableSpeed();
+  void addTraces(void);
+
+protected:
+  double m_powerPeak;
+  //virtual boost::shared_ptr<Action> execute(double size) = 0;
+  //virtual boost::shared_ptr<Action> sleep(double duration) = 0;
+};
+
+/**********
+ * Action *
+ **********/
+class CpuAction : public Action {
+public:
+  CpuAction(ModelPtr model, double cost, bool failed): Action(model, cost, failed) {};
+};
+
+#endif /* SURF_MODEL_CPU_H_ */
diff --git a/src/surf/cpu_ti.cpp b/src/surf/cpu_ti.cpp
new file mode 100644 (file)
index 0000000..c9abf60
--- /dev/null
@@ -0,0 +1,512 @@
+#include "cpu_ti.hpp"
+#include "solver.hpp"
+
+#ifndef SURF_MODEL_CPUTI_H_
+#define SURF_MODEL_CPUTI_H_
+
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_cpu_tii, surf,
+                                "Logging specific to the SURF CPU TRACE INTEGRATION module");
+
+static std::vector<CpuTiActionPtr>
+    cpu_ti_running_action_set_that_does_not_need_being_checked;
+static std::vector<CpuTiPtr> cpu_ti_modified_cpu;
+static std::vector<CpuTiActionPtr> cpu_ti_action_heap;
+
+/*********
+ * Trace *
+ *********/
+static double surf_cpu_ti_integrate_trace(surf_cpu_ti_tgmr_t trace,
+                                          double a, double b);
+
+
+static double surf_cpu_ti_solve_trace(surf_cpu_ti_tgmr_t trace, double a,
+                                      double amount);
+static double surf_cpu_ti_solve_trace_somewhat_simple(surf_cpu_ti_tgmr_t
+                                                      trace, double a,
+                                                      double amount);
+
+static void surf_cpu_ti_free_tmgr(surf_cpu_ti_tgmr_t trace);
+
+static double surf_cpu_ti_integrate_trace_simple(surf_cpu_ti_trace_t trace,
+                                                 double a, double b);
+static double surf_cpu_ti_integrate_trace_simple_point(surf_cpu_ti_trace_t
+                                                       trace, double a);
+static double surf_cpu_ti_solve_trace_simple(surf_cpu_ti_trace_t trace,
+                                             double a, double amount);
+static int surf_cpu_ti_binary_search(double *array, double a, int low,
+                                     int high);
+
+static void surf_cpu_ti_free_trace(surf_cpu_ti_trace_t trace)
+{
+  xbt_free(trace->time_points);
+  xbt_free(trace->integral);
+  xbt_free(trace);
+}
+
+static void surf_cpu_ti_free_tmgr(surf_cpu_ti_tgmr_t trace)
+{
+  if (trace->trace)
+    surf_cpu_ti_free_trace(trace->trace);
+  xbt_free(trace);
+}
+
+static surf_cpu_ti_trace_t surf_cpu_ti_trace_new(tmgr_trace_t power_trace)
+{
+  surf_cpu_ti_trace_t trace;
+  s_tmgr_event_t val;
+  unsigned int cpt;
+  double integral = 0;
+  double time = 0;
+  int i = 0;
+  trace = xbt_new0(s_surf_cpu_ti_trace_t, 1);
+  trace->time_points = (double*) xbt_malloc0(sizeof(double) *
+                  (xbt_dynar_length(power_trace->s_list.event_list) + 1));
+  trace->integral = (double*) xbt_malloc0(sizeof(double) *
+                  (xbt_dynar_length(power_trace->s_list.event_list) + 1));
+  trace->nb_points = xbt_dynar_length(power_trace->s_list.event_list);
+  xbt_dynar_foreach(power_trace->s_list.event_list, cpt, val) {
+    trace->time_points[i] = time;
+    trace->integral[i] = integral;
+    integral += val.delta * val.value;
+    time += val.delta;
+    i++;
+  }
+  trace->time_points[i] = time;
+  trace->integral[i] = integral;
+  return trace;
+}
+
+/**
+* \brief Integrate trace
+*
+* Wrapper around surf_cpu_integrate_trace_simple() to get
+* the cyclic effect.
+*
+* \param trace Trace structure.
+* \param a      Begin of interval
+* \param b      End of interval
+* \return the integrate value. -1 if an error occurs.
+*/
+static double surf_cpu_ti_integrate_trace(surf_cpu_ti_tgmr_t trace,
+                                          double a, double b)
+{
+  double first_chunk;
+  double middle_chunk;
+  double last_chunk;
+  int a_index, b_index;
+
+  if ((a < 0.0) || (a > b)) {
+    XBT_CRITICAL
+        ("Error, invalid integration interval [%.2f,%.2f]. You probably have a task executing with negative computation amount. Check your code.",
+         a, b);
+    xbt_abort();
+  }
+  if (a == b)
+    return 0.0;
+
+  if (trace->type == TRACE_FIXED) {
+    return ((b - a) * trace->value);
+  }
+
+  if (ceil(a / trace->last_time) == a / trace->last_time)
+    a_index = 1 + (int) (ceil(a / trace->last_time));
+  else
+    a_index = (int) (ceil(a / trace->last_time));
+
+  b_index = (int) (floor(b / trace->last_time));
+
+  if (a_index > b_index) {      /* Same chunk */
+    return surf_cpu_ti_integrate_trace_simple(trace->trace,
+                                              a - (a_index -
+                                                   1) * trace->last_time,
+                                              b -
+                                              (b_index) *
+                                              trace->last_time);
+  }
+
+  first_chunk = surf_cpu_ti_integrate_trace_simple(trace->trace,
+                                                   a - (a_index -
+                                                        1) *
+                                                   trace->last_time,
+                                                   trace->last_time);
+  middle_chunk = (b_index - a_index) * trace->total;
+  last_chunk = surf_cpu_ti_integrate_trace_simple(trace->trace,
+                                                  0.0,
+                                                  b -
+                                                  (b_index) *
+                                                  trace->last_time);
+
+  XBT_DEBUG("first_chunk=%.2f  middle_chunk=%.2f  last_chunk=%.2f\n",
+         first_chunk, middle_chunk, last_chunk);
+
+  return (first_chunk + middle_chunk + last_chunk);
+}
+
+/**
+ * \brief Auxiliary function to calculate the integral between a and b.
+ *     It simply calculates the integral at point a and b and returns the difference 
+ *   between them.
+ * \param trace    Trace structure
+ * \param a        Initial point
+ * \param b  Final point
+ * \return  Integral
+*/
+static double surf_cpu_ti_integrate_trace_simple(surf_cpu_ti_trace_t trace,
+                                                 double a, double b)
+{
+  return surf_cpu_ti_integrate_trace_simple_point(trace,
+                                                  b) -
+      surf_cpu_ti_integrate_trace_simple_point(trace, a);
+}
+
+/**
+ * \brief Auxiliary function to calculate the integral at point a.
+ * \param trace    Trace structure
+ * \param a        point
+ * \return  Integral
+*/
+static double surf_cpu_ti_integrate_trace_simple_point(surf_cpu_ti_trace_t
+                                                       trace, double a)
+{
+  double integral = 0;
+  int ind;
+  double a_aux = a;
+  ind =
+      surf_cpu_ti_binary_search(trace->time_points, a, 0,
+                                trace->nb_points - 1);
+  integral += trace->integral[ind];
+  XBT_DEBUG
+      ("a %lf ind %d integral %lf ind + 1 %lf ind %lf time +1 %lf time %lf",
+       a, ind, integral, trace->integral[ind + 1], trace->integral[ind],
+       trace->time_points[ind + 1], trace->time_points[ind]);
+  double_update(&a_aux, trace->time_points[ind]);
+  if (a_aux > 0)
+    integral +=
+        ((trace->integral[ind + 1] -
+          trace->integral[ind]) / (trace->time_points[ind + 1] -
+                                   trace->time_points[ind])) * (a -
+                                                                trace->
+                                                                time_points
+                                                                [ind]);
+  XBT_DEBUG("Integral a %lf = %lf", a, integral);
+
+  return integral;
+}
+
+/**
+* \brief Calculate the time needed to execute "amount" on cpu.
+*
+* Here, amount can span multiple trace periods
+*
+* \param trace   CPU trace structure
+* \param a        Initial time
+* \param amount  Amount to be executed
+* \return  End time
+*/
+static double surf_cpu_ti_solve_trace(surf_cpu_ti_tgmr_t trace, double a,
+                                      double amount)
+{
+  int quotient;
+  double reduced_b;
+  double reduced_amount;
+  double reduced_a;
+  double b;
+
+/* Fix very small negative numbers */
+  if ((a < 0.0) && (a > -EPSILON)) {
+    a = 0.0;
+  }
+  if ((amount < 0.0) && (amount > -EPSILON)) {
+    amount = 0.0;
+  }
+
+/* Sanity checks */
+  if ((a < 0.0) || (amount < 0.0)) {
+    XBT_CRITICAL
+        ("Error, invalid parameters [a = %.2f, amount = %.2f]. You probably have a task executing with negative computation amount. Check your code.",
+         a, amount);
+    xbt_abort();
+  }
+
+/* At this point, a and amount are positive */
+
+  if (amount < EPSILON)
+    return a;
+
+/* Is the trace fixed ? */
+  if (trace->type == TRACE_FIXED) {
+    return (a + (amount / trace->value));
+  }
+
+  XBT_DEBUG("amount %lf total %lf", amount, trace->total);
+/* Reduce the problem to one where amount <= trace_total */
+  quotient = (int) (floor(amount / trace->total));
+  reduced_amount = (trace->total) * ((amount / trace->total) -
+                                     floor(amount / trace->total));
+  reduced_a = a - (trace->last_time) * (int) (floor(a / trace->last_time));
+
+  XBT_DEBUG("Quotient: %d reduced_amount: %lf reduced_a: %lf", quotient,
+         reduced_amount, reduced_a);
+
+/* Now solve for new_amount which is <= trace_total */
+/*
+   fprintf(stderr,"reduced_a = %.2f\n",reduced_a);
+   fprintf(stderr,"reduced_amount = %.2f\n",reduced_amount);
+ */
+  reduced_b =
+      surf_cpu_ti_solve_trace_somewhat_simple(trace, reduced_a,
+                                              reduced_amount);
+
+/* Re-map to the original b and amount */
+  b = (trace->last_time) * (int) (floor(a / trace->last_time)) +
+      (quotient * trace->last_time) + reduced_b;
+  return b;
+}
+
+/**
+* \brief Auxiliary function to solve integral
+*
+* Here, amount is <= trace->total
+* and a <=trace->last_time
+*
+*/
+static double surf_cpu_ti_solve_trace_somewhat_simple(surf_cpu_ti_tgmr_t
+                                                      trace, double a,
+                                                      double amount)
+{
+  double amount_till_end;
+  double b;
+
+  XBT_DEBUG("Solve integral: [%.2f, amount=%.2f]", a, amount);
+  amount_till_end =
+      surf_cpu_ti_integrate_trace(trace, a, trace->last_time);
+/*
+   fprintf(stderr,"amount_till_end=%.2f\n",amount_till_end);
+ */
+
+  if (amount_till_end > amount) {
+    b = surf_cpu_ti_solve_trace_simple(trace->trace, a, amount);
+  } else {
+    b = trace->last_time +
+        surf_cpu_ti_solve_trace_simple(trace->trace, 0.0,
+                                       amount - amount_till_end);
+  }
+  return b;
+}
+
+/**
+ * \brief Auxiliary function to solve integral.
+ *  It returns the date when the requested amount of flops is available
+ * \param trace    Trace structure
+ * \param a        Initial point
+ * \param amount  Amount of flops 
+ * \return The date when amount is available.
+*/
+static double surf_cpu_ti_solve_trace_simple(surf_cpu_ti_trace_t trace,
+                                             double a, double amount)
+{
+  double integral_a;
+  int ind;
+  double time;
+  integral_a = surf_cpu_ti_integrate_trace_simple_point(trace, a);
+  ind =
+      surf_cpu_ti_binary_search(trace->integral, integral_a + amount, 0,
+                                trace->nb_points - 1);
+  time = trace->time_points[ind];
+  time +=
+      (integral_a + amount -
+       trace->integral[ind]) / ((trace->integral[ind + 1] -
+                                 trace->integral[ind]) /
+                                (trace->time_points[ind + 1] -
+                                 trace->time_points[ind]));
+
+  return time;
+}
+
+/**
+* \brief Creates a new integration trace from a tmgr_trace_t
+*
+* \param  power_trace    CPU availability trace
+* \param  value          Percentage of CPU power available (useful to fixed tracing)
+* \param  spacing        Initial spacing
+* \return  Integration trace structure
+*/
+static surf_cpu_ti_tgmr_t cpu_ti_parse_trace(tmgr_trace_t power_trace,
+                                             double value)
+{
+  surf_cpu_ti_tgmr_t trace;
+  double total_time = 0.0;
+  s_tmgr_event_t val;
+  unsigned int cpt;
+  trace = xbt_new0(s_surf_cpu_ti_tgmr_t, 1);
+
+/* no availability file, fixed trace */
+  if (!power_trace) {
+    trace->type = TRACE_FIXED;
+    trace->value = value;
+    XBT_DEBUG("No availabily trace. Constant value = %lf", value);
+    return trace;
+  }
+
+  /* only one point available, fixed trace */
+  if (xbt_dynar_length(power_trace->s_list.event_list) == 1) {
+    xbt_dynar_get_cpy(power_trace->s_list.event_list, 0, &val);
+    trace->type = TRACE_FIXED;
+    trace->value = val.value;
+    return trace;
+  }
+
+  trace->type = TRACE_DYNAMIC;
+  trace->power_trace = power_trace;
+
+  /* count the total time of trace file */
+  xbt_dynar_foreach(power_trace->s_list.event_list, cpt, val) {
+    total_time += val.delta;
+  }
+  trace->trace = surf_cpu_ti_trace_new(power_trace);
+  trace->last_time = total_time;
+  trace->total =
+      surf_cpu_ti_integrate_trace_simple(trace->trace, 0, total_time);
+
+  XBT_DEBUG("Total integral %lf, last_time %lf ",
+         trace->total, trace->last_time);
+
+  return trace;
+}
+
+/**
+ * \brief Binary search in array.
+ *  It returns the first point of the interval in which "a" is. 
+ * \param array    Array
+ * \param a        Value to search
+ * \param low     Low bound to search in array
+ * \param high    Upper bound to search in array
+ * \return Index of point
+*/
+static int surf_cpu_ti_binary_search(double *array, double a, int low,
+                                     int high)
+{
+  xbt_assert(low < high, "Wrong parameters: low (%d) should be smaller than"
+      " high (%d)", low, high);
+
+  int mid;
+  do {
+    mid = low + (high - low) / 2;
+    XBT_DEBUG("a %lf low %d high %d mid %d value %lf", a, low, high, mid,
+        array[mid]);
+
+    if (array[mid] > a)
+      high = mid;
+    else
+      low = mid;
+  }
+  while (low < high - 1);
+
+  return low;
+}
+
+/*********
+ * Model *
+ *********/
+
+CpuTiModel::CpuTiModel() : CpuModel("cpu_ti")
+{
+  
+}
+
+CpuTiPtr CpuTiModel::createResource(string name,
+                          double powerPeak,
+                           double powerScale,
+                           tmgr_trace_t powerTrace,
+                           int core,
+                           e_surf_resource_state_t stateInitial,
+                           tmgr_trace_t stateTrace,
+                           xbt_dict_t cpuProperties)
+{
+  tmgr_trace_t empty_trace;
+  s_tmgr_event_t val;
+  CpuTiActionPtr cpuAction;
+  xbt_assert(core==1,"Multi-core not handled with this model yet");
+  /*TOREPAIR: xbt_assert(!surf_cpu_resource_priv(surf_cpu_resource_by_name(name)),
+              "Host '%s' declared several times in the platform file",
+              name);*/
+  CpuTiPtr cpu = new CpuTi(this, name, powerPeak, powerScale, powerTrace,
+                          core, stateInitial, stateTrace, cpuProperties);
+  xbt_lib_set(host_lib, name.c_str(), SURF_CPU_LEVEL, cpu);
+  return (CpuTiPtr) xbt_lib_get_elm_or_null(host_lib, name.c_str());
+}
+
+CpuTiActionPtr CpuTiModel::createAction(double cost, bool failed)
+{
+  return NULL;//new CpuTiAction(this, cost, failed);
+}
+
+void CpuTi::printCpuTiModel()
+{
+  std::cout << getModel()->getName() << "<<plop"<< std::endl;
+};
+
+/************
+ * Resource *
+ ************/
+CpuTi::CpuTi(CpuTiModelPtr model, string name, double powerPeak,
+        double powerScale, tmgr_trace_t powerTrace, int core,
+        e_surf_resource_state_t stateInitial, tmgr_trace_t stateTrace,
+       xbt_dict_t properties) :
+       Cpu(model, name, properties), m_powerPeak(powerPeak), m_powerScale(powerScale),
+        m_stateCurrent(stateInitial) {
+  tmgr_trace_t empty_trace;            
+  s_tmgr_event_t val;          
+  xbt_assert(core==1,"Multi-core not handled with this model yet");
+  XBT_DEBUG("power scale %lf", powerScale);
+  m_availTrace = cpu_ti_parse_trace(powerTrace, powerScale);
+  if (stateTrace)
+    /*TOREPAIR:m_stateEvent = tmgr_history_add_trace(history, stateTrace, 0.0, 0, this);*/
+  if (powerTrace && xbt_dynar_length(powerTrace->s_list.event_list) > 1) {
+    // add a fake trace event if periodicity == 0 
+    xbt_dynar_get_cpy(powerTrace->s_list.event_list,
+                      xbt_dynar_length(powerTrace->s_list.event_list) - 1, &val);
+    /*TOREPAIR:if (val.delta == 0) {
+      empty_trace = tmgr_empty_trace_new();
+       m_powerEvent =
+        tmgr_history_add_trace(history, empty_trace,
+                               m_availTrace->last_time, 0, this);
+    }*/
+  }
+};
+
+CpuTiModelPtr CpuTi::getModel() {
+  return static_cast<CpuTiModelPtr>(p_model);
+}; 
+
+double CpuTi::getSpeed(double load)
+{
+  return load * m_powerPeak;
+}
+
+double CpuTi::getAvailableSpeed()
+{
+  return 0;
+}
+
+/**********
+ * Action *
+ **********/
+
+double CpuTiAction::getRemains()
+{
+  return 0;
+}
+
+double CpuTiAction::getStartTime()
+{
+  return 0;
+}
+
+double CpuTiAction::getFinishTime()
+{
+  return 0;
+}
+
+#endif /* SURF_MODEL_CPUTI_H_ */
+
diff --git a/src/surf/cpu_ti.hpp b/src/surf/cpu_ti.hpp
new file mode 100644 (file)
index 0000000..ccf8def
--- /dev/null
@@ -0,0 +1,110 @@
+#include "cpu.hpp"
+#include "trace_mgr_private.h"
+#include "surf/surf_routing.h"
+
+/* Epsilon */
+#define EPSILON 0.000000001
+
+/***********
+ * Classes *
+ ***********/
+class CpuTiModel;
+typedef CpuTiModel *CpuTiModelPtr;
+
+class CpuTi;
+typedef CpuTi *CpuTiPtr;
+
+class CpuTiAction;
+typedef CpuTiAction *CpuTiActionPtr;
+
+/*********
+ * Trace *
+ *********/
+typedef struct surf_cpu_ti_trace {
+  double *time_points;
+  double *integral;
+  int nb_points;
+} s_surf_cpu_ti_trace_t, *surf_cpu_ti_trace_t;
+
+enum trace_type { 
+  TRACE_FIXED,                /*< Trace fixed, no availability file */
+  TRACE_DYNAMIC               /*< Dynamic, availability file disponible */
+};
+typedef struct surf_cpu_ti_tgmr {
+  trace_type type;
+
+  double value;                 /*< Percentage of cpu power disponible. Value fixed between 0 and 1 */
+
+  /* Dynamic */
+  double last_time;             /*< Integral interval last point (discret time) */
+  double total;                 /*< Integral total between 0 and last_pointn */
+
+  surf_cpu_ti_trace_t trace;
+  tmgr_trace_t power_trace;
+
+} s_surf_cpu_ti_tgmr_t, *surf_cpu_ti_tgmr_t;
+
+
+/*********
+ * Model *
+ *********/
+class CpuTiModel : public CpuModel {
+public:
+  CpuTiModel();
+  ~CpuTiModel() {}
+
+  CpuTiPtr createResource(string name, double power_peak, 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);
+  CpuTiActionPtr createAction(double cost, bool failed);
+
+protected:
+  void NotifyResourceTurnedOn(ResourcePtr r){};
+  void NotifyResourceTurnedOff(ResourcePtr r){};
+
+  void NotifyActionCancel(ActionPtr a){};
+  void NotifyActionResume(ActionPtr a){};
+  void NotifyActionSuspend(ActionPtr a){};
+};
+
+/************
+ * Resource *
+ ************/
+class CpuTi : public Cpu {
+public:
+  CpuTi(CpuTiModelPtr model, string name, double powerPeak,
+        double powerScale, tmgr_trace_t powerTrace, int core,
+        e_surf_resource_state_t stateInitial, tmgr_trace_t stateTrace,
+       xbt_dict_t properties) ;
+  ~CpuTi() {};
+  virtual double getSpeed (double load);
+  virtual double getAvailableSpeed ();
+  void printCpuTiModel();
+  CpuTiModelPtr getModel();
+  
+  double m_powerPeak;            /*< CPU power peak */
+  double m_powerScale;           /*< Percentage of CPU disponible */
+  surf_cpu_ti_tgmr_t m_availTrace;       /*< Structure with data needed to integrate trace file */
+  e_surf_resource_state_t m_stateCurrent;        /*< CPU current state (ON or OFF) */
+  tmgr_trace_event_t m_stateEvent;       /*< trace file with states events (ON or OFF) */
+  tmgr_trace_event_t m_powerEvent;       /*< trace file with availabitly events */
+  std::vector<CpuTiActionPtr> m_actionSet;        /*< set with all actions running on cpu */
+  s_xbt_swag_hookup_t m_modifiedCpuHookup;      /*< hookup to swag that indicacates whether share resources must be recalculated or not */
+  double m_sumPriority;          /*< the sum of actions' priority that are running on cpu */
+  double m_lastUpdate;           /*< last update of actions' remaining amount done */
+
+};
+
+/**********
+ * Action *
+ **********/
+class CpuTiAction: public CpuAction {
+public:
+  CpuTiAction(CpuTiModelPtr model, double cost, bool failed): CpuAction(model, cost, failed) {};
+
+  virtual double getRemains();
+  virtual double getStartTime();
+  virtual double getFinishTime();
+};
diff --git a/src/surf/surf.cpp b/src/surf/surf.cpp
new file mode 100644 (file)
index 0000000..501b8a2
--- /dev/null
@@ -0,0 +1,110 @@
+#include "surf.hpp"
+
+/*********
+ * Model *
+ *********/
+
+void Model::addTurnedOnCallback(ResourceCallback rc)
+{
+  m_resOnCB = rc;
+}
+
+void Model::notifyResourceTurnedOn(ResourcePtr r)
+{
+  m_resOnCB(r);
+}
+
+void Model::addTurnedOffCallback(ResourceCallback rc)
+{
+  m_resOffCB = rc;
+}
+
+void Model::notifyResourceTurnedOff(ResourcePtr r)
+{
+  m_resOffCB(r);
+}
+
+void Model::addActionCancelCallback(ActionCallback ac)
+{
+  m_actCancelCB = ac;
+}
+
+void Model::notifyActionCancel(ActionPtr a)
+{
+  m_actCancelCB(a);
+}
+
+void Model::addActionResumeCallback(ActionCallback ac)
+{
+  m_actResumeCB = ac;
+}
+
+void Model::notifyActionResume(ActionPtr a)
+{
+  m_actResumeCB(a);
+}
+
+void Model::addActionSuspendCallback(ActionCallback ac)
+{
+  m_actSuspendCB = ac;
+}
+
+void Model::notifyActionSuspend(ActionPtr a)
+{
+  m_actSuspendCB(a);
+}
+
+
+/************
+ * Resource *
+ ************/
+
+string Resource::getName() {
+  return m_name;
+}
+
+bool Resource::isOn()
+{
+  return m_running;
+}
+
+void Resource::turnOn()
+{
+  if (!m_running) {
+    m_running = true;
+    p_model->notifyResourceTurnedOn(this);
+  }
+}
+
+void Resource::turnOff()
+{
+  if (m_running) {
+    m_running = false;
+    p_model->notifyResourceTurnedOff(this);
+  }
+}
+
+/**********
+ * Action *
+ **********/
+
+void Action::cancel()
+{
+  p_model->notifyActionCancel(this);
+}
+
+void Action::suspend()
+{
+  p_model->notifyActionSuspend(this);
+}
+
+void Action::resume()
+{
+  p_model->notifyActionResume(this);
+}
+
+bool Action::isSuspended()
+{
+  return false;
+}
+
diff --git a/src/surf/surf.hpp b/src/surf/surf.hpp
new file mode 100644 (file)
index 0000000..d6c462e
--- /dev/null
@@ -0,0 +1,188 @@
+//using namespace generic;
+
+#ifndef SURF_MODEL_H_
+#define SURF_MODEL_H_
+
+#include <xbt.h>
+#include <string>
+#include <vector>
+#include <memory>
+#include <boost/smart_ptr.hpp>
+#include <boost/function.hpp>
+#include <boost/functional/factory.hpp>
+#include <boost/bind.hpp>
+#include "surf/trace_mgr.h"
+
+extern tmgr_history_t history;
+
+using namespace std;
+
+/***********
+ * Classes *
+ ***********/
+class Model;
+typedef Model* ModelPtr;
+
+class Resource;
+typedef Resource* ResourcePtr;
+typedef boost::function<void (ResourcePtr r)> ResourceCallback;
+                       
+class Action;
+typedef Action* ActionPtr;
+typedef boost::function<void (ActionPtr a)> ActionCallback;
+
+/*********
+ * Model *
+ *********/
+class Model {
+public:
+  Model(string name) {
+    m_name = name;
+    m_resOnCB = m_resOffCB= 0;
+    m_actSuspendCB = m_actCancelCB = m_actResumeCB = 0;
+  }
+  virtual ~Model() {}
+  ResourcePtr createResource(string name);
+  ActionPtr createAction(double _cost, bool _failed);
+
+  string getName() {return m_name;};
+
+  void addTurnedOnCallback(ResourceCallback rc);
+  void notifyResourceTurnedOn(ResourcePtr r);
+
+  void addTurnedOffCallback(ResourceCallback rc);  
+  void notifyResourceTurnedOff(ResourcePtr r);
+
+  void addActionCancelCallback(ActionCallback ac);
+  void notifyActionCancel(ActionPtr a);
+  void addActionResumeCallback(ActionCallback ac);
+  void notifyActionResume(ActionPtr a);
+  void addActionSuspendCallback(ActionCallback ac);  
+  void notifyActionSuspend(ActionPtr a);
+
+  xbt_swag_t p_readyActionSet; /**< Actions in state SURF_ACTION_READY */
+  xbt_swag_t runningActionSet; /**< Actions in state SURF_ACTION_RUNNING */
+  xbt_swag_t failedActionSet; /**< Actions in state SURF_ACTION_FAILED */
+  xbt_swag_t doneActionSet; /**< Actions in state SURF_ACTION_DONE */
+
+protected:
+  std::vector<ActionPtr> m_failedActions, m_runningActions;
+
+private:
+  string m_name;
+  ResourceCallback m_resOnCB, m_resOffCB;
+  ActionCallback m_actCancelCB, m_actSuspendCB, m_actResumeCB;
+};
+
+/************
+ * Resource *
+ ************/
+class Resource {
+public:
+  Resource(ModelPtr model, string name, xbt_dict_t properties):
+         m_name(name),m_running(true),p_model(model),m_properties(properties) {};
+  virtual ~Resource() {};
+
+  bool isOn();
+  void turnOn();
+  void turnOff();
+  void setName(string name);
+  string getName();
+  ModelPtr getModel() {return p_model;};
+  void printModel() { std::cout << p_model->getName() << "<<plop"<<std::endl;};
+protected:
+  ModelPtr p_model;
+  string m_name;
+  xbt_dict_t m_properties;
+
+private:
+  bool m_running;  
+};
+
+/**********
+ * Action *
+ **********/
+
+/** \ingroup SURF_actions
+ *  \brief Action states
+ *
+ *  Action states.
+ *
+ *  \see surf_action_t, surf_action_state_t
+ */
+typedef enum {
+  SURF_ACTION_READY = 0,        /**< Ready        */
+  SURF_ACTION_RUNNING,          /**< Running      */
+  SURF_ACTION_FAILED,           /**< Task Failure */
+  SURF_ACTION_DONE,             /**< Completed    */
+  SURF_ACTION_TO_FREE,          /**< Action to free in next cleanup */
+  SURF_ACTION_NOT_IN_THE_SYSTEM
+                                /**< Not in the system anymore. Why did you ask ? */
+} e_surf_action_state_t;
+
+typedef enum {
+  UM_FULL,
+  UM_LAZY,
+  UM_UNDEFINED
+} e_UM_t;
+
+class Action {
+public:
+  Action(ModelPtr model, double cost, bool failed):
+        m_cost(cost),p_model(model),m_failed(failed)
+  {
+    m_priority = m_start = m_finish = m_maxDuration = -1.0;
+    m_start = 10;//surf_get_clock();
+    m_suspended = false;
+  };
+  virtual ~Action() {};
+  
+  virtual e_surf_action_state_t getState()=0; /**< Return the state of an action */
+  virtual void setState(e_surf_action_state_t state)=0; /**< Change an action state*/
+  virtual double getStartTime()=0; /**< Return the start time of an action */
+  virtual double getFinishTime()=0; /**< Return the finish time of an action */
+  virtual int unref()=0;     /**< Specify that we don't use that action anymore. Returns true if the action was destroyed and false if someone still has references on it. */
+  virtual void cancel()=0;     /**< Cancel a running action */
+  virtual void recycle()=0;     /**< Recycle an action */
+  void suspend();     /**< Suspend an action */
+  void resume();     /**< Resume a suspended action */
+  bool isSuspended();     /**< Return whether an action is suspended */
+  void setMaxDuration(double duration);     /**< Set the max duration of an action*/
+  void setPriority(double priority);     /**< Set the priority of an action */
+#ifdef HAVE_TRACING
+  void setCategory(const char *category); /**< Set the category of an action */
+#endif
+  double getRemains();     /**< Get the remains of an action */
+#ifdef HAVE_LATENCY_BOUND_TRACKING
+  int getLatencyLimited();     /**< Return 1 if action is limited by latency, 0 otherwise */
+#endif
+
+
+protected:
+  ModelPtr p_model;  
+  int    m_cost;
+  bool   m_failed, m_suspended;
+  double m_priority;
+  double m_maxDuration;
+  double m_start, m_finish;
+
+private:
+  int resourceUsed(void *resource_id);
+  /* Share the resources to the actions and return in how much time
+     the next action may terminate */
+  double shareResources(double now);
+  /* Update the actions' state */
+  void updateActionsState(double now, double delta);
+  void updateResourceState(void *id, tmgr_trace_event_t event_type,
+                                 double value, double time);
+  void finalize(void);
+
+  lmm_system_t p_maxminSystem;
+  e_UM_t p_updateMechanism;
+  xbt_swag_t p_modifiedSet;
+  xbt_heap_t p_actionHeap;
+  int m_selectiveUpdate;
+};
+
+#endif /* SURF_MODEL_H_ */
diff --git a/src/surf/surf_c.h b/src/surf/surf_c.h
new file mode 100644 (file)
index 0000000..6731d82
--- /dev/null
@@ -0,0 +1,85 @@
+#include <xbt.h>
+
+#ifndef SURF_SOLVER_H_
+#define SURF_SOLVER_H_
+
+static double MAXMIN_PRECISION = 0.001;
+
+
+#ifdef __cplusplus
+#include <vector>
+#include <boost/smart_ptr.hpp>
+#include <boost/pool/object_pool.hpp>
+#include <boost/bind.hpp>
+
+static void double_update(double *variable, double value)
+{
+  *variable -= value;
+  if (*variable < MAXMIN_PRECISION)
+    *variable = 0.0;
+}
+
+using namespace std;
+
+class Solver;
+typedef boost::shared_ptr<Solver> SolverPtr;
+
+class Element;
+typedef boost::shared_ptr<Element> ElementPtr;
+
+class Constraint;
+typedef boost::shared_ptr<Constraint> ConstraintPtr;
+
+class ConstraintLight;
+typedef boost::shared_ptr<ConstraintLight> ConstraintLightPtr;
+
+class Variable;
+typedef boost::shared_ptr<Variable> VariablePtr;
+
+struct ElementPtrOps
+{
+  bool operator()( const ElementPtr & a, const ElementPtr & b )
+    { return true; } //a > b; }
+};
+
+#else
+  typedef struct Solver Solver;
+  typedef struct Element Element;
+  typedef struct Constraint Constraint;
+  typedef struct ConstraintLight ConstraintLight;
+  typedef struct Variable Variable;
+
+#endif
+
+typedef Element *lmm_element_t;
+typedef Variable *lmm_variable_t;
+typedef Constraint *lmm_constraint_t;
+typedef ConstraintLight *lmm_constraint_light_t;
+typedef Solver *lmm_system_t;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#if defined(__STDC__) || defined(__cplusplus)
+  extern lmm_system_t lmm_system_new(int selective_update);
+
+  extern void c_function(Solver*);   /* ANSI C prototypes */
+  extern Solver* cplusplus_callback_function(Solver*);
+
+#else
+  extern lmm_system_t lmm_system_new(int selective_update);
+
+  extern void c_function();        /* K&R style */
+  extern Solver* cplusplus_callback_function();
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+
+
+
+
+#endif /* SURF_SOLVER_H_ */