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_
24 XBT_PUBLIC(Cpu*) getActionCpu(CpuAction *action);
26 /** @ingroup SURF_callbacks
27 * @brief Callbacks handler which emit the callbacks after Cpu creation *
28 * @details Callback functions have the following signature: `void(CpuPtr)`
30 XBT_PUBLIC_DATA( surf_callback(void, Cpu*)) cpuCreatedCallbacks;
32 /** @ingroup SURF_callbacks
33 * @brief Callbacks handler which emit the callbacks after Cpu destruction *
34 * @details Callback functions have the following signature: `void(CpuPtr)`
36 XBT_PUBLIC_DATA( surf_callback(void, Cpu*)) cpuDestructedCallbacks;
38 /** @ingroup SURF_callbacks
39 * @brief Callbacks handler which emit the callbacks after Cpu State changed *
40 * @details Callback functions have the following signature: `void(CpuAction *action, e_surf_resource_state_t old, e_surf_resource_state_t current)`
42 XBT_PUBLIC_DATA( surf_callback(void, Cpu*, e_surf_resource_state_t, e_surf_resource_state_t)) cpuStateChangedCallbacks;
44 /** @ingroup SURF_callbacks
45 * @brief Callbacks handler which emit the callbacks after CpuAction State changed *
46 * @details Callback functions have the following signature: `void(CpuAction *action, e_surf_action_state_t old, e_surf_action_state_t current)`
48 XBT_PUBLIC_DATA( surf_callback(void, CpuAction*, e_surf_action_state_t, e_surf_action_state_t)) cpuActionStateChangedCallbacks;
50 XBT_PUBLIC(void) cpu_parse_init(sg_platf_host_cbarg_t host);
52 XBT_PUBLIC(void) cpu_add_traces();
58 /** @ingroup SURF_cpu_interface
59 * @brief SURF cpu model interface class
60 * @details A model is an object which handle the interactions between its Resources and its Actions
62 XBT_PUBLIC_CLASS CpuModel : public Model {
65 * @brief CpuModel constructor
67 * @param name The name of the model
69 CpuModel(const char *name) : Model(name) {};
74 * @param name The name of the Cpu
75 * @param power_peak The power peak of this Cpu
76 * @param pstate [TODO]
77 * @param power_scale The power scale of this Cpu
78 * @param power_trace [TODO]
79 * @param core The number of core of this Cpu
80 * @param state_initial [TODO]
81 * @param state_trace [TODO]
82 * @param cpu_properties Dictionary of properties associated to this Cpu
84 virtual Cpu *createCpu(const char *name, xbt_dynar_t power_peak,
85 int pstate, double power_scale,
86 tmgr_trace_t power_trace, int core,
87 e_surf_resource_state_t state_initial,
88 tmgr_trace_t state_trace,
89 xbt_dict_t cpu_properties)=0;
91 void updateActionsStateLazy(double now, double delta);
92 void updateActionsStateFull(double now, double delta);
99 /** @ingroup SURF_cpu_interface
100 * @brief SURF cpu resource interface class
101 * @details A Cpu represent a cpu associated to a host
103 XBT_PUBLIC_CLASS Cpu : public Resource {
106 * @brief Cpu constructor
111 * @brief Cpu constructor
113 * @param model The CpuModel associated to this Cpu
114 * @param name The name of the Cpu
115 * @param props Dictionary of properties associated to this Cpu
116 * @param constraint The lmm constraint associated to this Cpu if it is part of a LMM component
117 * @param core The number of core of this Cpu
118 * @param powerPeak The power peak of this Cpu
119 * @param powerScale The power scale of this Cpu
121 Cpu(Model *model, const char *name, xbt_dict_t props,
122 lmm_constraint_t constraint, int core, double powerPeak, double powerScale);
125 * @brief Cpu constructor
127 * @param model The CpuModel associated to this Cpu
128 * @param name The name of the Cpu
129 * @param props Dictionary of properties associated to this Cpu
130 * @param core The number of core of this Cpu
131 * @param powerPeak The power peak of this Cpu in [TODO]
132 * @param powerScale The power scale of this Cpu in [TODO]
134 Cpu(Model *model, const char *name, xbt_dict_t props,
135 int core, double powerPeak, double powerScale);
138 * @brief Cpu destructor
143 * @brief Execute some quantity of computation
145 * @param size The value of the processing amount (in flop) needed to process
146 * @return The CpuAction corresponding to the processing
148 virtual CpuAction *execute(double size)=0;
151 * @brief Make a process sleep for duration (in seconds)
153 * @param duration The number of seconds to sleep
154 * @return The CpuAction corresponding to the sleeping
156 virtual CpuAction *sleep(double duration)=0;
159 * @brief Get the number of cores of the current Cpu
161 * @return The number of cores of the current Cpu
163 virtual int getCore();
166 * @brief Get the speed of the current Cpu
167 * @details [TODO] load * m_powerPeak
171 * @return The speed of the current Cpu
173 virtual double getSpeed(double load);
176 * @brief Get the available speed of the current Cpu
179 * @return The available speed of the current Cpu
181 virtual double getAvailableSpeed();
184 * @brief Get the current Cpu power peak
186 * @return The current Cpu power peak
188 virtual double getCurrentPowerPeak();
191 virtual double getPowerPeakAt(int pstate_index)=0;
193 virtual int getNbPstates()=0;
195 virtual void setPstate(int pstate_index)=0;
196 virtual int getPstate()=0;
198 void setState(e_surf_resource_state_t state);
200 void addTraces(void);
202 double m_powerPeak; /*< CPU power peak */
203 double m_powerScale; /*< Percentage of CPU disponible */
205 /* Note (hypervisor): */
206 lmm_constraint_t *p_constraintCore;
207 void **p_constraintCoreId;
214 /** @ingroup SURF_cpu_interface
215 * @brief SURF Cpu action interface class
216 * @details A CpuAction represent the execution of code on a Cpu
218 XBT_PUBLIC_CLASS CpuAction : public Action {
219 friend XBT_PUBLIC(Cpu*) getActionCpu(CpuAction *action);
222 * @brief CpuAction constructor
224 * @param model The CpuModel associated to this CpuAction
226 * @param failed [TODO]
228 CpuAction(Model *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(Model *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(Cpu *cpu, unsigned long mask);
251 void setState(e_surf_action_state_t state);
253 void updateRemainingLazy(double now);
257 #endif /* SURF_CPU_INTERFACE_HPP_ */