1 /* Copyright (c) 2004-2015. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #include "surf_interface.hpp"
8 #include "maxmin_private.hpp"
10 #ifndef SURF_CPU_INTERFACE_HPP_
11 #define SURF_CPU_INTERFACE_HPP_
28 XBT_PUBLIC(std::list<Cpu*>) getActionCpus(CpuAction *action);
34 /** @ingroup SURF_cpu_interface
35 * @brief SURF cpu model interface class
36 * @details A model is an object which handle the interactions between its Resources and its Actions
38 XBT_PUBLIC_CLASS CpuModel : public Model {
40 CpuModel() : Model() {};
45 * @param host The host that will have this CPU
46 * @param speedList The peak speed (max speed in Flops when no external load comes from a trace) for each pstate
47 * @param core The number of core of this Cpu
49 virtual Cpu *createCpu(simgrid::s4u::Host *host, xbt_dynar_t speedList, int core)=0;
51 void updateActionsStateLazy(double now, double delta);
52 void updateActionsStateFull(double now, double delta);
53 bool next_occuring_event_isIdempotent() {return true;}
60 /** @ingroup SURF_cpu_interface
61 * @brief SURF cpu resource interface class
62 * @details A Cpu represent a cpu associated to a host
64 XBT_PUBLIC_CLASS Cpu : public simgrid::surf::Resource {
67 * @brief Cpu constructor
69 * @param model The CpuModel associated to this Cpu
70 * @param host The host in which this Cpu should be plugged
71 * @param constraint The lmm constraint associated to this Cpu if it is part of a LMM component
72 * @param speedList [TODO]
73 * @param core The number of core of this Cpu
74 * @param speedPeak The speed peak of this Cpu in flops (max speed)
76 Cpu(simgrid::surf::Model *model, simgrid::s4u::Host *host,
77 lmm_constraint_t constraint, xbt_dynar_t speedPeakList, int core, double speedPeak);
80 * @brief Cpu constructor
82 * @param model The CpuModel associated to this Cpu
83 * @param host The host in which this Cpu should be plugged
84 * @param speedPeakList [TODO]
85 * @param core The number of core of this Cpu
86 * @param speedPeak The speed peak of this Cpu in flops (max speed)
88 Cpu(simgrid::surf::Model *model, simgrid::s4u::Host *host,
89 xbt_dynar_t speedPeakList, int core, double speedPeak);
94 * @brief Execute some quantity of computation
96 * @param size The value of the processing amount (in flop) needed to process
97 * @return The CpuAction corresponding to the processing
99 virtual simgrid::surf::Action *execution_start(double size)=0;
102 * @brief Make a process sleep for duration (in seconds)
104 * @param duration The number of seconds to sleep
105 * @return The CpuAction corresponding to the sleeping
107 virtual simgrid::surf::Action *sleep(double duration)=0;
109 /** @brief Get the amount of cores */
110 virtual int getCore();
112 /** @brief Get the speed, accounting for the trace load and provided process load instead of the real current one */
113 virtual double getSpeed(double load);
116 /** @brief Take speed changes (either load or max) into account */
117 virtual void onSpeedChange();
120 /** @brief Get the available speed of the current Cpu */
121 virtual double getAvailableSpeed();
123 /** @brief Get the current Cpu power peak */
124 virtual double getCurrentPowerPeak();
126 virtual double getPowerPeakAt(int pstate_index);
128 virtual int getNbPStates();
129 virtual void setPState(int pstate_index);
130 virtual int getPState();
132 simgrid::s4u::Host* getHost() { return host_; }
135 int coresAmount_ = 1;
136 simgrid::s4u::Host* host_;
138 xbt_dynar_t speedPeakList_ = NULL; /*< List of supported CPU capacities (pstate related) */
139 int pstate_ = 0; /*< Current pstate (index in the speedPeakList)*/
141 /* Note (hypervisor): */
142 lmm_constraint_t *p_constraintCore=NULL;
143 void **p_constraintCoreId=NULL;
146 virtual void setStateTrace(tmgr_trace_t trace); /*< setup the trace file with states events (ON or OFF). Trace must contain boolean values (0 or 1). */
147 virtual void setSpeedTrace(tmgr_trace_t trace); /*< setup the trace file with availability events (peak speed changes due to external load). Trace must contain relative values (ratio between 0 and 1) */
149 tmgr_trace_iterator_t stateEvent_ = nullptr;
150 s_surf_metric_t speed_ = {1.0, 0, nullptr};
157 /** @ingroup SURF_cpu_interface
158 * @brief SURF Cpu action interface class
159 * @details A CpuAction represent the execution of code on a Cpu
161 XBT_PUBLIC_CLASS CpuAction : public simgrid::surf::Action {
162 friend XBT_PUBLIC(Cpu*) getActionCpu(CpuAction *action);
164 /** @brief Callbacks handler which emit the callbacks after CpuAction State changed *
165 * @details Callback functions have the following signature: `void(CpuAction *action, e_surf_action_state_t previous)`
167 static simgrid::xbt::signal<void(simgrid::surf::CpuAction*, e_surf_action_state_t)> onStateChange;
169 /** @brief CpuAction constructor */
170 CpuAction(simgrid::surf::Model *model, double cost, bool failed)
171 : Action(model, cost, failed) {} //FIXME:DEADCODE?
173 /** @brief CpuAction constructor */
174 CpuAction(simgrid::surf::Model *model, double cost, bool failed, lmm_variable_t var)
175 : Action(model, cost, failed, var) {}
178 * @brief Set the affinity of the current CpuAction
181 virtual void setAffinity(Cpu *cpu, unsigned long mask);
183 void setState(e_surf_action_state_t state);
185 void updateRemainingLazy(double now);
192 #endif /* SURF_CPU_INTERFACE_HPP_ */