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(Cpu*) getActionCpu(CpuAction *action);
30 /** @ingroup SURF_callbacks
31 * @brief Callbacks handler which emit the callbacks after Cpu creation *
32 * @details Callback functions have the following signature: `void(CpuPtr)`
34 XBT_PUBLIC_DATA( surf_callback(void, Cpu*)) cpuCreatedCallbacks;
36 /** @ingroup SURF_callbacks
37 * @brief Callbacks handler which emit the callbacks after Cpu destruction *
38 * @details Callback functions have the following signature: `void(CpuPtr)`
40 XBT_PUBLIC_DATA( surf_callback(void, Cpu*)) cpuDestructedCallbacks;
42 /** @ingroup SURF_callbacks
43 * @brief Callbacks handler which emit the callbacks after Cpu State changed *
44 * @details Callback functions have the following signature: `void(CpuAction *action, e_surf_resource_state_t old, e_surf_resource_state_t current)`
46 XBT_PUBLIC_DATA( surf_callback(void, Cpu*, e_surf_resource_state_t, e_surf_resource_state_t)) cpuStateChangedCallbacks;
48 /** @ingroup SURF_callbacks
49 * @brief Callbacks handler which emit the callbacks after CpuAction State changed *
50 * @details Callback functions have the following signature: `void(CpuAction *action, e_surf_action_state_t old, e_surf_action_state_t current)`
52 XBT_PUBLIC_DATA( surf_callback(void, CpuAction*, e_surf_action_state_t, e_surf_action_state_t)) cpuActionStateChangedCallbacks;
54 XBT_PUBLIC(void) cpu_add_traces();
60 /** @ingroup SURF_cpu_interface
61 * @brief SURF cpu model interface class
62 * @details A model is an object which handle the interactions between its Resources and its Actions
64 XBT_PUBLIC_CLASS CpuModel : public Model {
66 CpuModel() : Model() {};
71 * @param name The name of the Cpu
72 * @param speedPeak The peak spead (max speed in Flops)
73 * @param pstate [TODO]
74 * @param speedScale The speed scale (in [O;1] available speed from peak)
75 * @param speedTrace Trace variations
76 * @param core The number of core of this Cpu
77 * @param state_initial [TODO]
78 * @param state_trace [TODO]
79 * @param cpu_properties Dictionary of properties associated to this Cpu
81 virtual Cpu *createCpu(const char *name, xbt_dynar_t speedPeak,
82 int pstate, double speedScale,
83 tmgr_trace_t speedTrace, int core,
84 e_surf_resource_state_t state_initial,
85 tmgr_trace_t state_trace,
86 xbt_dict_t cpu_properties)=0;
88 void updateActionsStateLazy(double now, double delta);
89 void updateActionsStateFull(double now, double delta);
90 bool shareResourcesIsIdempotent() {return true;}
97 /** @ingroup SURF_cpu_interface
98 * @brief SURF cpu resource interface class
99 * @details A Cpu represent a cpu associated to a host
101 XBT_PUBLIC_CLASS Cpu : public simgrid::surf::Resource {
103 static simgrid::xbt::FacetLevel<simgrid::Host, Cpu> LEVEL;
108 * @brief Cpu constructor
110 * @param model The CpuModel associated to this Cpu
111 * @param name The name of the Cpu
112 * @param props Dictionary of properties associated to this Cpu
113 * @param constraint The lmm constraint associated to this Cpu if it is part of a LMM component
114 * @param core The number of core of this Cpu
115 * @param speedPeak The speed peak of this Cpu in flops (max speed)
116 * @param speedScale The speed scale of this Cpu in [0;1] (available amount)
117 * @param stateInitial whether it is created running or crashed
119 Cpu(simgrid::surf::Model *model, const char *name, xbt_dict_t props,
120 lmm_constraint_t constraint, int core, double speedPeak, double speedScale,
121 e_surf_resource_state_t stateInitial);
124 * @brief Cpu constructor
126 * @param model The CpuModel associated to this Cpu
127 * @param name The name of the Cpu
128 * @param props Dictionary of properties associated to this Cpu
129 * @param core The number of core of this Cpu
130 * @param speedPeak The speed peak of this Cpu in flops (max speed)
131 * @param speedScale The speed scale of this Cpu in [0;1] (available amount)
132 * @param stateInitial whether it is created running or crashed
134 Cpu(simgrid::surf::Model *model, const char *name, xbt_dict_t props,
135 int core, double speedPeak, double speedScale,
136 e_surf_resource_state_t stateInitial);
138 Cpu(simgrid::surf::Model *model, const char *name, xbt_dict_t props,
139 lmm_constraint_t constraint, int core, double speedPeak, double speedScale);
140 Cpu(simgrid::surf::Model *model, const char *name, xbt_dict_t props,
141 int core, double speedPeak, double speedScale);
146 * @brief Execute some quantity of computation
148 * @param size The value of the processing amount (in flop) needed to process
149 * @return The CpuAction corresponding to the processing
151 virtual simgrid::surf::Action *execute(double size)=0;
154 * @brief Make a process sleep for duration (in seconds)
156 * @param duration The number of seconds to sleep
157 * @return The CpuAction corresponding to the sleeping
159 virtual simgrid::surf::Action *sleep(double duration)=0;
161 /** @brief Get the amount of cores */
162 virtual int getCore();
164 /** @brief Get the speed, accounting for the trace load and provided process load instead of the real current one */
165 virtual double getSpeed(double load);
167 /** @brief Get the available speed of the current Cpu */
168 virtual double getAvailableSpeed();
170 /** @brief Get the current Cpu power peak */
171 virtual double getCurrentPowerPeak();
173 virtual double getPowerPeakAt(int pstate_index)=0;
175 virtual int getNbPstates()=0;
176 virtual void setPstate(int pstate_index)=0;
177 virtual int getPstate()=0;
179 void setState(e_surf_resource_state_t state);
180 void plug(simgrid::Host* host);
182 void addTraces(void);
183 int m_core = 1; /* Amount of cores */
184 double m_speedPeak; /*< CPU speed peak, ie max value */
185 double m_speedScale; /*< Percentage of CPU available according to the trace, in [O,1] */
186 simgrid::Host* m_host = nullptr;
188 simgrid::Host* getHost() { return m_host; }
190 /* Note (hypervisor): */
191 lmm_constraint_t *p_constraintCore=NULL;
192 void **p_constraintCoreId=NULL;
200 /** @ingroup SURF_cpu_interface
201 * @brief SURF Cpu action interface class
202 * @details A CpuAction represent the execution of code on a Cpu
204 XBT_PUBLIC_CLASS CpuAction : public simgrid::surf::Action {
205 friend XBT_PUBLIC(Cpu*) getActionCpu(CpuAction *action);
207 /** @brief CpuAction constructor */
208 CpuAction(simgrid::surf::Model *model, double cost, bool failed)
209 : Action(model, cost, failed) {} //FIXME:REMOVE
211 /** @brief CpuAction constructor */
212 CpuAction(simgrid::surf::Model *model, double cost, bool failed, lmm_variable_t var)
213 : Action(model, cost, failed, var) {}
216 * @brief Set the affinity of the current CpuAction
219 virtual void setAffinity(Cpu *cpu, unsigned long mask);
221 void setState(e_surf_action_state_t state);
223 void updateRemainingLazy(double now);
230 #endif /* SURF_CPU_INTERFACE_HPP_ */