1 /* Copyright (c) 2004-2014. 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_
17 typedef CpuModel *CpuModelPtr;
23 typedef CpuAction *CpuActionPtr;
26 typedef CpuPlugin *CpuPluginPtr;
31 CpuPtr getActionCpu(CpuActionPtr action);
33 /** @ingroup SURF_callbacks
34 * @brief Callbacks handler which emit the callbacks after Cpu creation *
35 * @details Callback functions have the following signature: `void(CpuPtr)`
37 extern surf_callback(void, CpuPtr) cpuCreatedCallbacks;
39 /** @ingroup SURF_callbacks
40 * @brief Callbacks handler which emit the callbacks after Cpu destruction *
41 * @details Callback functions have the following signature: `void(CpuPtr)`
43 extern surf_callback(void, CpuPtr) cpuDestructedCallbacks;
45 /** @ingroup SURF_callbacks
46 * @brief Callbacks handler which emit the callbacks after Cpu State changed *
47 * @details Callback functions have the following signature: `void(CpuActionPtr)`
49 extern surf_callback(void, CpuPtr) cpuStateChangedCallbacks;
51 /** @ingroup SURF_callbacks
52 * @brief Callbacks handler which emit the callbacks after CpuAction State changed *
53 * @details Callback functions have the following signature: `void(CpuActionPtr)`
55 extern surf_callback(void, CpuActionPtr) cpuActionStateChangedCallbacks;
61 /** @ingroup SURF_cpu_interface
62 * @brief SURF cpu model interface class
63 * @details A model is an object which handle the interactions between its Resources and its Actions
65 class CpuModel : public Model {
68 * @brief CpuModel constructor
70 * @param name The name of the model
72 CpuModel(const char *name) : Model(name) {};
77 * @param name The name of the Cpu
79 * @return The created Cpu
81 CpuPtr createResource(string name);
83 void setState(e_surf_resource_state_t state);
85 void updateActionsStateLazy(double now, double delta);
86 void updateActionsStateFull(double now, double delta);
88 virtual void addTraces() =0;
95 /** @ingroup SURF_cpu_interface
96 * @brief SURF cpu resource interface class
97 * @details A Cpu represent a cpu associated to a workstation
99 class Cpu : public Resource {
102 * @brief Cpu constructor
107 * @brief Cpu constructor
109 * @param model The CpuModel associated to this Cpu
110 * @param name The name of the Cpu
111 * @param props Dictionary of properties associated to this Cpu
112 * @param constraint The lmm constraint associated to this Cpu if it is part of a LMM component
113 * @param core The number of core of this Cpu
114 * @param powerPeak The power peak of this Cpu
115 * @param powerScale The power scale of this Cpu
117 Cpu(ModelPtr model, const char *name, xbt_dict_t props,
118 lmm_constraint_t constraint, int core, double powerPeak, double powerScale);
121 * @brief Cpu constructor
123 * @param model The CpuModel associated to this Cpu
124 * @param name The name of the Cpu
125 * @param props Dictionary of properties associated to this Cpu
126 * @param core The number of core of this Cpu
127 * @param powerPeak The power peak of this Cpu in [TODO]
128 * @param powerScale The power scale of this Cpu in [TODO]
130 Cpu(ModelPtr model, const char *name, xbt_dict_t props,
131 int core, double powerPeak, double powerScale);
134 * @brief Cpu destructor
139 * @brief Execute some quantity of computation
141 * @param size The value of the processing amount (in flop) needed to process
142 * @return The CpuAction corresponding to the processing
144 virtual CpuActionPtr execute(double size)=0;
147 * @brief Make a process sleep for duration (in seconds)
149 * @param duration The number of seconds to sleep
150 * @return The CpuAction corresponding to the sleeping
152 virtual CpuActionPtr sleep(double duration)=0;
155 * @brief Get the number of cores of the current Cpu
157 * @return The number of cores of the current Cpu
159 virtual int getCore();
162 * @brief Get the speed of the current Cpu
163 * @details [TODO] load * m_powerPeak
167 * @return The speed of the current Cpu
169 virtual double getSpeed(double load);
172 * @brief Get the available speed of the current Cpu
175 * @return The available speed of the current Cpu
177 virtual double getAvailableSpeed();
180 * @brief Get the current Cpu power peak
182 * @return The current Cpu power peak
184 virtual double getCurrentPowerPeak()=0;
187 virtual double getPowerPeakAt(int pstate_index)=0;
189 virtual int getNbPstates()=0;
191 virtual void setPowerPeakAt(int pstate_index)=0;
193 void setState(e_surf_resource_state_t state);
195 void addTraces(void);
197 double m_powerPeak; /*< CPU power peak */
198 double m_powerScale; /*< Percentage of CPU disponible */
200 /* Note (hypervisor): */
201 lmm_constraint_t *p_constraintCore;
202 void **p_constraintCoreId;
209 /** @ingroup SURF_cpu_interface
210 * @brief SURF Cpu action interface class
211 * @details A CpuAction represent the execution of code on a Cpu
213 class CpuAction : public Action {
214 friend CpuPtr getActionCpu(CpuActionPtr action);
217 * @brief CpuAction constructor
222 * @brief CpuAction constructor
224 * @param model The CpuModel associated to this CpuAction
226 * @param failed [TODO]
228 CpuAction(ModelPtr model, double cost, bool failed)
229 : Action(model, cost, failed) {} //FIXME:REMOVE
232 * @brief CpuAction constructor
234 * @param model The CpuModel associated to this CpuAction
236 * @param failed [TODO]
237 * @param var The lmm variable associated to this CpuAction if it is part of a LMM component
239 CpuAction(ModelPtr model, double cost, bool failed, lmm_variable_t var)
240 : Action(model, cost, failed, var) {}
243 * @brief Set the affinity of the current CpuAction
249 virtual void setAffinity(CpuPtr cpu, unsigned long mask);
252 * @brief Set the bound of current CpuAction
255 * @param bound [TODO]
257 virtual void setBound(double bound);
259 void setState(e_surf_action_state_t state);
261 void updateRemainingLazy(double now);
265 #endif /* SURF_CPU_INTERFACE_HPP_ */