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;
22 typedef CpuAction *CpuActionPtr;
25 typedef CpuPlugin *CpuPluginPtr;
30 XBT_PUBLIC(CpuPtr) getActionCpu(CpuActionPtr action);
32 /** @ingroup SURF_callbacks
33 * @brief Callbacks handler which emit the callbacks after Cpu creation *
34 * @details Callback functions have the following signature: `void(CpuPtr)`
36 XBT_PUBLIC_DATA( surf_callback(void, CpuPtr)) cpuCreatedCallbacks;
38 /** @ingroup SURF_callbacks
39 * @brief Callbacks handler which emit the callbacks after Cpu destruction *
40 * @details Callback functions have the following signature: `void(CpuPtr)`
42 XBT_PUBLIC_DATA( surf_callback(void, CpuPtr)) cpuDestructedCallbacks;
44 /** @ingroup SURF_callbacks
45 * @brief Callbacks handler which emit the callbacks after Cpu State changed *
46 * @details Callback functions have the following signature: `void(CpuActionPtr action, e_surf_resource_state_t old, e_surf_resource_state_t current)`
48 XBT_PUBLIC_DATA( surf_callback(void, CpuPtr, e_surf_resource_state_t, e_surf_resource_state_t)) cpuStateChangedCallbacks;
50 /** @ingroup SURF_callbacks
51 * @brief Callbacks handler which emit the callbacks after CpuAction State changed *
52 * @details Callback functions have the following signature: `void(CpuActionPtr action, e_surf_action_state_t old, e_surf_action_state_t current)`
54 XBT_PUBLIC_DATA( surf_callback(void, CpuActionPtr, e_surf_action_state_t, e_surf_action_state_t)) cpuActionStateChangedCallbacks;
56 XBT_PUBLIC(void) cpu_parse_init(sg_platf_host_cbarg_t host);
58 XBT_PUBLIC(void) cpu_add_traces();
64 /** @ingroup SURF_cpu_interface
65 * @brief SURF cpu model interface class
66 * @details A model is an object which handle the interactions between its Resources and its Actions
68 XBT_PUBLIC_CLASS CpuModel : public Model {
71 * @brief CpuModel constructor
73 * @param name The name of the model
75 CpuModel(const char *name) : Model(name) {};
80 * @param name The name of the Cpu
81 * @param power_peak The power peak of this Cpu
82 * @param pstate [TODO]
83 * @param power_scale The power scale of this Cpu
84 * @param power_trace [TODO]
85 * @param core The number of core of this Cpu
86 * @param state_initial [TODO]
87 * @param state_trace [TODO]
88 * @param cpu_properties Dictionary of properties associated to this Cpu
90 virtual CpuPtr createCpu(const char *name, xbt_dynar_t power_peak,
91 int pstate, double power_scale,
92 tmgr_trace_t power_trace, int core,
93 e_surf_resource_state_t state_initial,
94 tmgr_trace_t state_trace,
95 xbt_dict_t cpu_properties)=0;
97 void updateActionsStateLazy(double now, double delta);
98 void updateActionsStateFull(double now, double delta);
105 /** @ingroup SURF_cpu_interface
106 * @brief SURF cpu resource interface class
107 * @details A Cpu represent a cpu associated to a host
109 XBT_PUBLIC_CLASS Cpu : public Resource {
112 * @brief Cpu constructor
117 * @brief Cpu constructor
119 * @param model The CpuModel associated to this Cpu
120 * @param name The name of the Cpu
121 * @param props Dictionary of properties associated to this Cpu
122 * @param constraint The lmm constraint associated to this Cpu if it is part of a LMM component
123 * @param core The number of core of this Cpu
124 * @param powerPeak The power peak of this Cpu
125 * @param powerScale The power scale of this Cpu
127 Cpu(ModelPtr model, const char *name, xbt_dict_t props,
128 lmm_constraint_t constraint, int core, double powerPeak, double powerScale);
131 * @brief Cpu constructor
133 * @param model The CpuModel associated to this Cpu
134 * @param name The name of the Cpu
135 * @param props Dictionary of properties associated to this Cpu
136 * @param core The number of core of this Cpu
137 * @param powerPeak The power peak of this Cpu in [TODO]
138 * @param powerScale The power scale of this Cpu in [TODO]
140 Cpu(ModelPtr model, const char *name, xbt_dict_t props,
141 int core, double powerPeak, double powerScale);
144 * @brief Cpu destructor
149 * @brief Execute some quantity of computation
151 * @param size The value of the processing amount (in flop) needed to process
152 * @return The CpuAction corresponding to the processing
154 virtual CpuActionPtr execute(double size)=0;
157 * @brief Make a process sleep for duration (in seconds)
159 * @param duration The number of seconds to sleep
160 * @return The CpuAction corresponding to the sleeping
162 virtual CpuActionPtr sleep(double duration)=0;
165 * @brief Get the number of cores of the current Cpu
167 * @return The number of cores of the current Cpu
169 virtual int getCore();
172 * @brief Get the speed of the current Cpu
173 * @details [TODO] load * m_powerPeak
177 * @return The speed of the current Cpu
179 virtual double getSpeed(double load);
182 * @brief Get the available speed of the current Cpu
185 * @return The available speed of the current Cpu
187 virtual double getAvailableSpeed();
190 * @brief Get the current Cpu power peak
192 * @return The current Cpu power peak
194 virtual double getCurrentPowerPeak();
197 virtual double getPowerPeakAt(int pstate_index)=0;
199 virtual int getNbPstates()=0;
201 virtual void setPstate(int pstate_index)=0;
202 virtual int getPstate()=0;
204 void setState(e_surf_resource_state_t state);
206 void addTraces(void);
208 double m_powerPeak; /*< CPU power peak */
209 double m_powerScale; /*< Percentage of CPU disponible */
211 /* Note (hypervisor): */
212 lmm_constraint_t *p_constraintCore;
213 void **p_constraintCoreId;
220 /** @ingroup SURF_cpu_interface
221 * @brief SURF Cpu action interface class
222 * @details A CpuAction represent the execution of code on a Cpu
224 XBT_PUBLIC_CLASS CpuAction : public Action {
225 friend XBT_PUBLIC(CpuPtr) getActionCpu(CpuActionPtr action);
228 * @brief CpuAction constructor
230 * @param model The CpuModel associated to this CpuAction
232 * @param failed [TODO]
234 CpuAction(ModelPtr model, double cost, bool failed)
235 : Action(model, cost, failed) {} //FIXME:REMOVE
238 * @brief CpuAction constructor
240 * @param model The CpuModel associated to this CpuAction
242 * @param failed [TODO]
243 * @param var The lmm variable associated to this CpuAction if it is part of a LMM component
245 CpuAction(ModelPtr model, double cost, bool failed, lmm_variable_t var)
246 : Action(model, cost, failed, var) {}
249 * @brief Set the affinity of the current CpuAction
255 virtual void setAffinity(CpuPtr cpu, unsigned long mask);
257 void setState(e_surf_action_state_t state);
259 void updateRemainingLazy(double now);
263 #endif /* SURF_CPU_INTERFACE_HPP_ */