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(std::list<Cpu*>) getActionCpus(CpuAction *action);
34 /** @ingroup SURF_cpu_interface
35 * @brief SURF cpu model interface class
36 * @details A model is an object which handle the interactions between its Resources and its Actions
38 XBT_PUBLIC_CLASS CpuModel : public Model {
40 CpuModel() : Model() {};
45 * @param host The host that will have this CPU
46 * @param speedPeak The peak spead (max speed in Flops when no external load comes from a trace)
47 * @param speedTrace Trace variations
48 * @param core The number of core of this Cpu
50 virtual Cpu *createCpu(simgrid::s4u::Host *host, xbt_dynar_t speedPeak, tmgr_trace_t speedTrace, int core)=0;
52 void updateActionsStateLazy(double now, double delta);
53 void updateActionsStateFull(double now, double delta);
54 bool next_occuring_event_isIdempotent() {return true;}
61 /** @ingroup SURF_cpu_interface
62 * @brief SURF cpu resource interface class
63 * @details A Cpu represent a cpu associated to a host
65 XBT_PUBLIC_CLASS Cpu : public simgrid::surf::Resource {
68 * @brief Cpu constructor
70 * @param model The CpuModel associated to this Cpu
71 * @param host The host in which this Cpu should be plugged
72 * @param constraint The lmm constraint associated to this Cpu if it is part of a LMM component
73 * @param speedPeakList [TODO]
74 * @param core The number of core of this Cpu
75 * @param speedPeak The speed peak of this Cpu in flops (max speed)
77 Cpu(simgrid::surf::Model *model, simgrid::s4u::Host *host,
78 lmm_constraint_t constraint, xbt_dynar_t speedPeakList, int core, double speedPeak);
81 * @brief Cpu constructor
83 * @param model The CpuModel associated to this Cpu
84 * @param host The host in which this Cpu should be plugged
85 * @param speedPeakList [TODO]
86 * @param core The number of core of this Cpu
87 * @param speedPeak The speed peak of this Cpu in flops (max speed)
89 Cpu(simgrid::surf::Model *model, simgrid::s4u::Host *host,
90 xbt_dynar_t speedPeakList, int core, double speedPeak);
95 * @brief Execute some quantity of computation
97 * @param size The value of the processing amount (in flop) needed to process
98 * @return The CpuAction corresponding to the processing
100 virtual simgrid::surf::Action *execution_start(double size)=0;
103 * @brief Make a process sleep for duration (in seconds)
105 * @param duration The number of seconds to sleep
106 * @return The CpuAction corresponding to the sleeping
108 virtual simgrid::surf::Action *sleep(double duration)=0;
110 /** @brief Get the amount of cores */
111 virtual int getCore();
113 /** @brief Get the speed, accounting for the trace load and provided process load instead of the real current one */
114 virtual double getSpeed(double load);
117 /** @brief Take speed changes (either load or max) into account */
118 virtual void onSpeedChange();
121 /** @brief Get the available speed of the current Cpu */
122 virtual double getAvailableSpeed();
124 /** @brief Get the current Cpu power peak */
125 virtual double getCurrentPowerPeak();
127 virtual double getPowerPeakAt(int pstate_index);
129 virtual int getNbPStates();
130 virtual void setPState(int pstate_index);
131 virtual int getPState();
133 simgrid::s4u::Host* getHost() { return host_; }
136 int coresAmount_ = 1;
137 simgrid::s4u::Host* host_;
139 xbt_dynar_t speedPeakList_ = NULL; /*< List of supported CPU capacities (pstate related) */
140 int pstate_ = 0; /*< Current pstate (index in the speedPeakList)*/
142 /* Note (hypervisor): */
143 lmm_constraint_t *p_constraintCore=NULL;
144 void **p_constraintCoreId=NULL;
147 virtual void setStateTrace(tmgr_trace_t trace); /*< setup the trace file with states events (ON or OFF). Trace must contain boolean values (0 or 1). */
148 virtual void setSpeedTrace(tmgr_trace_t trace); /*< setup the trace file with availability events (peak speed changes due to external load). Trace must contain relative values (ratio between 0 and 1) */
150 tmgr_trace_iterator_t stateEvent_ = nullptr;
151 s_surf_metric_t speed_ = {1.0, 0, nullptr};
158 /** @ingroup SURF_cpu_interface
159 * @brief SURF Cpu action interface class
160 * @details A CpuAction represent the execution of code on a Cpu
162 XBT_PUBLIC_CLASS CpuAction : public simgrid::surf::Action {
163 friend XBT_PUBLIC(Cpu*) getActionCpu(CpuAction *action);
165 /** @brief Callbacks handler which emit the callbacks after CpuAction State changed *
166 * @details Callback functions have the following signature: `void(CpuAction *action, e_surf_action_state_t previous)`
168 static simgrid::xbt::signal<void(simgrid::surf::CpuAction*, e_surf_action_state_t)> onStateChange;
170 /** @brief CpuAction constructor */
171 CpuAction(simgrid::surf::Model *model, double cost, bool failed)
172 : Action(model, cost, failed) {} //FIXME:DEADCODE?
174 /** @brief CpuAction constructor */
175 CpuAction(simgrid::surf::Model *model, double cost, bool failed, lmm_variable_t var)
176 : Action(model, cost, failed, var) {}
179 * @brief Set the affinity of the current CpuAction
182 virtual void setAffinity(Cpu *cpu, unsigned long mask);
184 void setState(e_surf_action_state_t state);
186 void updateRemainingLazy(double now);
193 #endif /* SURF_CPU_INTERFACE_HPP_ */