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 CpuAction State changed *
32 * @details Callback functions have the following signature: `void(CpuAction *action, e_surf_action_state_t old, e_surf_action_state_t current)`
34 XBT_PUBLIC_DATA(simgrid::surf::signal<void(CpuAction*, e_surf_action_state_t, e_surf_action_state_t)>) cpuActionStateChangedCallbacks;
36 XBT_PUBLIC(void) cpu_add_traces();
42 /** @ingroup SURF_cpu_interface
43 * @brief SURF cpu model interface class
44 * @details A model is an object which handle the interactions between its Resources and its Actions
46 XBT_PUBLIC_CLASS CpuModel : public Model {
48 CpuModel() : Model() {};
53 * @param name The name of the Cpu
54 * @param speedPeak The peak spead (max speed in Flops)
55 * @param pstate [TODO]
56 * @param speedScale The speed scale (in [O;1] available speed from peak)
57 * @param speedTrace Trace variations
58 * @param core The number of core of this Cpu
59 * @param state_initial [TODO]
60 * @param state_trace [TODO]
62 virtual Cpu *createCpu(const char *name, xbt_dynar_t speedPeak,
63 int pstate, double speedScale,
64 tmgr_trace_t speedTrace, int core,
65 e_surf_resource_state_t state_initial,
66 tmgr_trace_t state_trace)=0;
68 void updateActionsStateLazy(double now, double delta);
69 void updateActionsStateFull(double now, double delta);
70 bool shareResourcesIsIdempotent() {return true;}
77 /** @ingroup SURF_cpu_interface
78 * @brief SURF cpu resource interface class
79 * @details A Cpu represent a cpu associated to a host
81 XBT_PUBLIC_CLASS Cpu : public simgrid::surf::Resource {
83 static simgrid::xbt::Extension<simgrid::Host, Cpu> EXTENSION_ID;
88 * @brief Cpu constructor
90 * @param model The CpuModel associated to this Cpu
91 * @param name The name of the Cpu
92 * @param constraint The lmm constraint associated to this Cpu if it is part of a LMM component
93 * @param core The number of core of this Cpu
94 * @param speedPeak The speed peak of this Cpu in flops (max speed)
95 * @param speedScale The speed scale of this Cpu in [0;1] (available amount)
96 * @param stateInitial whether it is created running or crashed
98 Cpu(simgrid::surf::Model *model, const char *name,
99 lmm_constraint_t constraint, int core, double speedPeak, double speedScale,
100 e_surf_resource_state_t stateInitial);
103 * @brief Cpu constructor
105 * @param model The CpuModel associated to this Cpu
106 * @param name The name of the Cpu
107 * @param core The number of core of this Cpu
108 * @param speedPeak The speed peak of this Cpu in flops (max speed)
109 * @param speedScale The speed scale of this Cpu in [0;1] (available amount)
110 * @param stateInitial whether it is created running or crashed
112 Cpu(simgrid::surf::Model *model, const char *name,
113 int core, double speedPeak, double speedScale,
114 e_surf_resource_state_t stateInitial);
116 Cpu(simgrid::surf::Model *model, const char *name,
117 lmm_constraint_t constraint, int core, double speedPeak, double speedScale);
118 Cpu(simgrid::surf::Model *model, const char *name,
119 int core, double speedPeak, double speedScale);
124 * @brief Execute some quantity of computation
126 * @param size The value of the processing amount (in flop) needed to process
127 * @return The CpuAction corresponding to the processing
129 virtual simgrid::surf::Action *execute(double size)=0;
132 * @brief Make a process sleep for duration (in seconds)
134 * @param duration The number of seconds to sleep
135 * @return The CpuAction corresponding to the sleeping
137 virtual simgrid::surf::Action *sleep(double duration)=0;
139 /** @brief Get the amount of cores */
140 virtual int getCore();
142 /** @brief Get the speed, accounting for the trace load and provided process load instead of the real current one */
143 virtual double getSpeed(double load);
145 /** @brief Get the available speed of the current Cpu */
146 virtual double getAvailableSpeed();
148 /** @brief Get the current Cpu power peak */
149 virtual double getCurrentPowerPeak();
151 virtual double getPowerPeakAt(int pstate_index)=0;
153 virtual int getNbPstates()=0;
154 virtual void setPstate(int pstate_index)=0;
155 virtual int getPstate()=0;
157 void plug(simgrid::Host* host);
159 void addTraces(void);
160 simgrid::Host* getHost() { return m_host; }
163 int m_core = 1; /* Amount of cores */
164 double m_speedPeak; /*< CPU speed peak, ie max value */
165 double m_speedScale; /*< Percentage of CPU available according to the trace, in [O,1] */
166 simgrid::Host* m_host = nullptr;
168 /* Note (hypervisor): */
169 lmm_constraint_t *p_constraintCore=NULL;
170 void **p_constraintCoreId=NULL;
178 /** @ingroup SURF_cpu_interface
179 * @brief SURF Cpu action interface class
180 * @details A CpuAction represent the execution of code on a Cpu
182 XBT_PUBLIC_CLASS CpuAction : public simgrid::surf::Action {
183 friend XBT_PUBLIC(Cpu*) getActionCpu(CpuAction *action);
185 /** @brief CpuAction constructor */
186 CpuAction(simgrid::surf::Model *model, double cost, bool failed)
187 : Action(model, cost, failed) {} //FIXME:REMOVE
189 /** @brief CpuAction constructor */
190 CpuAction(simgrid::surf::Model *model, double cost, bool failed, lmm_variable_t var)
191 : Action(model, cost, failed, var) {}
194 * @brief Set the affinity of the current CpuAction
197 virtual void setAffinity(Cpu *cpu, unsigned long mask);
199 void setState(e_surf_action_state_t state);
201 void updateRemainingLazy(double now);
208 #endif /* SURF_CPU_INTERFACE_HPP_ */