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 power_peak The power peak of this Cpu
69 * @param pstate [TODO]
70 * @param power_scale The power scale of this Cpu
71 * @param power_trace [TODO]
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 power_peak,
78 int pstate, double power_scale,
79 tmgr_trace_t power_trace, 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 powerPeak The power peak of this Cpu
110 * @param powerScale The power scale of this Cpu
112 Cpu(Model *model, const char *name, xbt_dict_t props,
113 lmm_constraint_t constraint, int core, double powerPeak, double powerScale,
114 e_surf_resource_state_t stateInitial);
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 core The number of core of this Cpu
123 * @param powerPeak The power peak of this Cpu in [TODO]
124 * @param powerScale The power scale of this Cpu in [TODO]
126 Cpu(Model *model, const char *name, xbt_dict_t props,
127 int core, double powerPeak, double powerScale,
128 e_surf_resource_state_t stateInitial);
130 Cpu(Model *model, const char *name, xbt_dict_t props,
131 lmm_constraint_t constraint, int core, double powerPeak, double powerScale);
132 Cpu(Model *model, const char *name, xbt_dict_t props,
133 int core, double powerPeak, double powerScale);
138 * @brief Execute some quantity of computation
140 * @param size The value of the processing amount (in flop) needed to process
141 * @return The CpuAction corresponding to the processing
143 virtual Action *execute(double size)=0;
146 * @brief Make a process sleep for duration (in seconds)
148 * @param duration The number of seconds to sleep
149 * @return The CpuAction corresponding to the sleeping
151 virtual Action *sleep(double duration)=0;
153 /** @brief Get the number of cores of the current Cpu */
154 virtual int getCore();
156 /** @brief Get the speed of the current Cpu */
157 virtual double getSpeed(double load);
159 /** @brief Get the available speed of the current Cpu */
160 virtual double getAvailableSpeed();
162 /** @brief Get the current Cpu power peak */
163 virtual double getCurrentPowerPeak();
165 virtual double getPowerPeakAt(int pstate_index)=0;
167 virtual int getNbPstates()=0;
168 virtual void setPstate(int pstate_index)=0;
169 virtual int getPstate()=0;
171 void setState(e_surf_resource_state_t state);
173 void addTraces(void);
175 double m_powerPeak; /*< CPU power peak */
176 double m_powerScale; /*< Percentage of CPU available */
178 /* Note (hypervisor): */
179 lmm_constraint_t *p_constraintCore;
180 void **p_constraintCoreId;
187 /** @ingroup SURF_cpu_interface
188 * @brief SURF Cpu action interface class
189 * @details A CpuAction represent the execution of code on a Cpu
191 XBT_PUBLIC_CLASS CpuAction : public Action {
192 friend XBT_PUBLIC(Cpu*) getActionCpu(CpuAction *action);
194 /** @brief CpuAction constructor */
195 CpuAction(Model *model, double cost, bool failed)
196 : Action(model, cost, failed) {} //FIXME:REMOVE
198 /** @brief CpuAction constructor */
199 CpuAction(Model *model, double cost, bool failed, lmm_variable_t var)
200 : Action(model, cost, failed, var) {}
203 * @brief Set the affinity of the current CpuAction
206 virtual void setAffinity(Cpu *cpu, unsigned long mask);
208 void setState(e_surf_action_state_t state);
210 void updateRemainingLazy(double now);
214 #endif /* SURF_CPU_INTERFACE_HPP_ */