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_
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_add_traces();
56 /** @ingroup SURF_cpu_interface
57 * @brief SURF cpu model interface class
58 * @details A model is an object which handle the interactions between its Resources and its Actions
60 XBT_PUBLIC_CLASS CpuModel : public Model {
62 CpuModel() : Model() {};
67 * @param name The name of the Cpu
68 * @param speedPeak The peak spead (max speed in Flops)
69 * @param pstate [TODO]
70 * @param speedScale The speed scale (in [O;1] available speed from peak)
71 * @param speedTrace Trace variations
72 * @param core The number of core of this Cpu
73 * @param state_initial [TODO]
74 * @param state_trace [TODO]
75 * @param cpu_properties Dictionary of properties associated to this Cpu
77 virtual Cpu *createCpu(const char *name, xbt_dynar_t speedPeak,
78 int pstate, double speedScale,
79 tmgr_trace_t speedTrace, int core,
80 e_surf_resource_state_t state_initial,
81 tmgr_trace_t state_trace,
82 xbt_dict_t cpu_properties)=0;
84 void updateActionsStateLazy(double now, double delta);
85 void updateActionsStateFull(double now, double delta);
86 bool shareResourcesIsIdempotent() {return true;}
93 /** @ingroup SURF_cpu_interface
94 * @brief SURF cpu resource interface class
95 * @details A Cpu represent a cpu associated to a host
97 XBT_PUBLIC_CLASS Cpu : public Resource {
102 * @brief Cpu constructor
104 * @param model The CpuModel associated to this Cpu
105 * @param name The name of the Cpu
106 * @param props Dictionary of properties associated to this Cpu
107 * @param constraint The lmm constraint associated to this Cpu if it is part of a LMM component
108 * @param core The number of core of this Cpu
109 * @param speedPeak The speed peak of this Cpu in flops (max speed)
110 * @param speedScale The speed scale of this Cpu in [0;1] (available amount)
111 * @param stateInitial whether it is created running or crashed
113 Cpu(Model *model, const char *name, xbt_dict_t props,
114 lmm_constraint_t constraint, int core, double speedPeak, double speedScale,
115 e_surf_resource_state_t stateInitial);
118 * @brief Cpu constructor
120 * @param model The CpuModel associated to this Cpu
121 * @param name The name of the Cpu
122 * @param props Dictionary of properties associated to this Cpu
123 * @param core The number of core of this Cpu
124 * @param speedPeak The speed peak of this Cpu in flops (max speed)
125 * @param speedScale The speed scale of this Cpu in [0;1] (available amount)
126 * @param stateInitial whether it is created running or crashed
128 Cpu(Model *model, const char *name, xbt_dict_t props,
129 int core, double speedPeak, double speedScale,
130 e_surf_resource_state_t stateInitial);
132 Cpu(Model *model, const char *name, xbt_dict_t props,
133 lmm_constraint_t constraint, int core, double speedPeak, double speedScale);
134 Cpu(Model *model, const char *name, xbt_dict_t props,
135 int core, double speedPeak, double speedScale);
140 * @brief Execute some quantity of computation
142 * @param size The value of the processing amount (in flop) needed to process
143 * @return The CpuAction corresponding to the processing
145 virtual Action *execute(double size)=0;
148 * @brief Make a process sleep for duration (in seconds)
150 * @param duration The number of seconds to sleep
151 * @return The CpuAction corresponding to the sleeping
153 virtual Action *sleep(double duration)=0;
155 /** @brief Get the amount of cores */
156 virtual int getCore();
158 /** @brief Get the speed, accounting for the trace load and provided process load instead of the real current one */
159 virtual double getSpeed(double load);
161 /** @brief Get the available speed of the current Cpu */
162 virtual double getAvailableSpeed();
164 /** @brief Get the current Cpu power peak */
165 virtual double getCurrentPowerPeak();
167 virtual double getPowerPeakAt(int pstate_index)=0;
169 virtual int getNbPstates()=0;
170 virtual void setPstate(int pstate_index)=0;
171 virtual int getPstate()=0;
173 void setState(e_surf_resource_state_t state);
175 void addTraces(void);
176 int m_core = 1; /* Amount of cores */
177 double m_speedPeak; /*< CPU speed peak, ie max value */
178 double m_speedScale; /*< Percentage of CPU available according to the trace, in [O,1] */
180 /* Note (hypervisor): */
181 lmm_constraint_t *p_constraintCore;
182 void **p_constraintCoreId;
189 /** @ingroup SURF_cpu_interface
190 * @brief SURF Cpu action interface class
191 * @details A CpuAction represent the execution of code on a Cpu
193 XBT_PUBLIC_CLASS CpuAction : public Action {
194 friend XBT_PUBLIC(Cpu*) getActionCpu(CpuAction *action);
196 /** @brief CpuAction constructor */
197 CpuAction(Model *model, double cost, bool failed)
198 : Action(model, cost, failed) {} //FIXME:REMOVE
200 /** @brief CpuAction constructor */
201 CpuAction(Model *model, double cost, bool failed, lmm_variable_t var)
202 : Action(model, cost, failed, var) {}
205 * @brief Set the affinity of the current CpuAction
208 virtual void setAffinity(Cpu *cpu, unsigned long mask);
210 void setState(e_surf_action_state_t state);
212 void updateRemainingLazy(double now);
216 #endif /* SURF_CPU_INTERFACE_HPP_ */