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 XBT_PUBLIC(void) cpu_add_traces();
36 /** @ingroup SURF_cpu_interface
37 * @brief SURF cpu model interface class
38 * @details A model is an object which handle the interactions between its Resources and its Actions
40 XBT_PUBLIC_CLASS CpuModel : public Model {
42 CpuModel() : Model() {};
47 * @param name The name of the Cpu
48 * @param speedPeak The peak spead (max speed in Flops)
49 * @param pstate [TODO]
50 * @param speedScale The speed scale (in [O;1] available speed from peak)
51 * @param speedTrace Trace variations
52 * @param core The number of core of this Cpu
53 * @param state_initial [TODO]
54 * @param state_trace [TODO]
56 virtual Cpu *createCpu(simgrid::Host *host, xbt_dynar_t speedPeak,
57 int pstate, double speedScale,
58 tmgr_trace_t speedTrace, int core,
59 e_surf_resource_state_t state_initial,
60 tmgr_trace_t state_trace)=0;
62 void updateActionsStateLazy(double now, double delta);
63 void updateActionsStateFull(double now, double delta);
64 bool shareResourcesIsIdempotent() {return true;}
71 /** @ingroup SURF_cpu_interface
72 * @brief SURF cpu resource interface class
73 * @details A Cpu represent a cpu associated to a host
75 XBT_PUBLIC_CLASS Cpu : public simgrid::surf::Resource {
77 static simgrid::xbt::Extension<simgrid::Host, Cpu> EXTENSION_ID;
78 static void classInit();
82 * @brief Cpu constructor
84 * @param model The CpuModel associated to this Cpu
85 * @param host The host in which this Cpu should be plugged
86 * @param constraint The lmm constraint associated to this Cpu if it is part of a LMM component
87 * @param core The number of core of this Cpu
88 * @param speedPeak The speed peak of this Cpu in flops (max speed)
89 * @param speedScale The speed scale of this Cpu in [0;1] (available amount)
90 * @param stateInitial whether it is created running or crashed
92 Cpu(simgrid::surf::Model *model, simgrid::Host *host,
93 lmm_constraint_t constraint, int core, double speedPeak, double speedScale,
94 e_surf_resource_state_t stateInitial);
97 * @brief Cpu constructor
99 * @param model The CpuModel associated to this Cpu
100 * @param host The host in which this Cpu should be plugged
101 * @param core The number of core of this Cpu
102 * @param speedPeak The speed peak of this Cpu in flops (max speed)
103 * @param speedScale The speed scale of this Cpu in [0;1] (available amount)
104 * @param stateInitial whether it is created running or crashed
106 Cpu(simgrid::surf::Model *model, simgrid::Host *host,
107 int core, double speedPeak, double speedScale,
108 e_surf_resource_state_t stateInitial);
110 Cpu(simgrid::surf::Model *model, simgrid::Host *host,
111 lmm_constraint_t constraint, int core, double speedPeak, double speedScale);
112 Cpu(simgrid::surf::Model *model, simgrid::Host *host,
113 int core, double speedPeak, double speedScale);
118 * @brief Execute some quantity of computation
120 * @param size The value of the processing amount (in flop) needed to process
121 * @return The CpuAction corresponding to the processing
123 virtual simgrid::surf::Action *execute(double size)=0;
126 * @brief Make a process sleep for duration (in seconds)
128 * @param duration The number of seconds to sleep
129 * @return The CpuAction corresponding to the sleeping
131 virtual simgrid::surf::Action *sleep(double duration)=0;
133 /** @brief Get the amount of cores */
134 virtual int getCore();
136 /** @brief Get the speed, accounting for the trace load and provided process load instead of the real current one */
137 virtual double getSpeed(double load);
139 /** @brief Get the available speed of the current Cpu */
140 virtual double getAvailableSpeed();
142 /** @brief Get the current Cpu power peak */
143 virtual double getCurrentPowerPeak();
145 virtual double getPowerPeakAt(int pstate_index)=0;
147 virtual int getNbPstates()=0;
148 virtual void setPstate(int pstate_index)=0;
149 virtual int getPstate()=0;
151 void addTraces(void);
152 simgrid::Host* getHost() { return m_host; }
155 int m_core = 1; /* Amount of cores */
156 double m_speedPeak; /*< CPU speed peak, ie max value */
157 double m_speedScale; /*< Percentage of CPU available according to the trace, in [O,1] */
158 simgrid::Host* m_host;
160 /* Note (hypervisor): */
161 lmm_constraint_t *p_constraintCore=NULL;
162 void **p_constraintCoreId=NULL;
170 /** @ingroup SURF_cpu_interface
171 * @brief SURF Cpu action interface class
172 * @details A CpuAction represent the execution of code on a Cpu
174 XBT_PUBLIC_CLASS CpuAction : public simgrid::surf::Action {
175 friend XBT_PUBLIC(Cpu*) getActionCpu(CpuAction *action);
177 /** @brief Callbacks handler which emit the callbacks after CpuAction State changed *
178 * @details Callback functions have the following signature: `void(CpuAction *action, e_surf_action_state_t old, e_surf_action_state_t current)`
180 static simgrid::surf::signal<void(simgrid::surf::CpuAction*, e_surf_action_state_t, e_surf_action_state_t)> onStateChange;
182 /** @brief CpuAction constructor */
183 CpuAction(simgrid::surf::Model *model, double cost, bool failed)
184 : Action(model, cost, failed) {} //FIXME:REMOVE
186 /** @brief CpuAction constructor */
187 CpuAction(simgrid::surf::Model *model, double cost, bool failed, lmm_variable_t var)
188 : Action(model, cost, failed, var) {}
191 * @brief Set the affinity of the current CpuAction
194 virtual void setAffinity(Cpu *cpu, unsigned long mask);
196 void setState(e_surf_action_state_t state);
198 void updateRemainingLazy(double now);
205 #endif /* SURF_CPU_INTERFACE_HPP_ */