1 /* Copyright (c) 2004-2017. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #ifndef SURF_CPU_INTERFACE_HPP_
7 #define SURF_CPU_INTERFACE_HPP_
9 #include "simgrid/s4u/Host.hpp"
10 #include "src/kernel/lmm/maxmin.hpp"
21 /** @ingroup SURF_cpu_interface
22 * @brief SURF cpu model interface class
23 * @details A model is an object which handle the interactions between its Resources and its Actions
25 XBT_PUBLIC_CLASS CpuModel : public Model {
30 * @param host The host that will have this CPU
31 * @param speedPerPstate Processor speed (in Flops) of each pstate. This ignores any potential external load coming from a trace.
32 * @param core The number of core of this Cpu
34 virtual Cpu *createCpu(simgrid::s4u::Host *host, std::vector<double> *speedPerPstate, int core)=0;
36 void updateActionsStateLazy(double now, double delta) override;
37 void updateActionsStateFull(double now, double delta) override;
44 /** @ingroup SURF_cpu_interface
45 * @brief SURF cpu resource interface class
46 * @details A Cpu represent a cpu associated to a host
48 XBT_PUBLIC_CLASS Cpu : public simgrid::kernel::model::Resource
52 * @brief Cpu constructor
54 * @param model The CpuModel associated to this Cpu
55 * @param host The host in which this Cpu should be plugged
56 * @param constraint The lmm constraint associated to this Cpu if it is part of a LMM component
57 * @param speedPerPstate Processor speed (in flop per second) for each pstate
58 * @param core The number of core of this Cpu
60 Cpu(simgrid::surf::Model * model, simgrid::s4u::Host * host, kernel::lmm::Constraint * constraint,
61 std::vector<double> * speedPerPstate, int core);
64 * @brief Cpu constructor
66 * @param model The CpuModel associated to this Cpu
67 * @param host The host in which this Cpu should be plugged
68 * @param speedPerPstate Processor speed (in flop per second) for each pstate
69 * @param core The number of core of this Cpu
71 Cpu(simgrid::surf::Model* model, simgrid::s4u::Host* host, std::vector<double>* speedPerPstate, int core);
76 * @brief Execute some quantity of computation
78 * @param size The value of the processing amount (in flop) needed to process
79 * @return The CpuAction corresponding to the processing
81 virtual simgrid::surf::Action *execution_start(double size)=0;
84 * @brief Execute some quantity of computation on more than one core
86 * @param size The value of the processing amount (in flop) needed to process
87 * @param requestedCores The desired amount of cores. Must be >= 1
88 * @return The CpuAction corresponding to the processing
90 virtual simgrid::surf::Action* execution_start(double size, int requestedCores)
97 * @brief Make a process sleep for duration (in seconds)
99 * @param duration The number of seconds to sleep
100 * @return The CpuAction corresponding to the sleeping
102 virtual simgrid::surf::Action *sleep(double duration)=0;
104 /** @brief Get the amount of cores */
105 virtual int coreCount();
107 /** @brief Get the speed, accounting for the trace load and provided process load instead of the real current one */
108 virtual double getSpeed(double load);
111 /** @brief Take speed changes (either load or max) into account */
112 virtual void onSpeedChange();
115 /** @brief Get the available speed of the current Cpu */
116 virtual double getAvailableSpeed();
118 /** @brief Get the current Cpu computational speed */
119 virtual double getPstateSpeed(int pstate_index);
121 virtual int getNbPStates();
122 virtual void setPState(int pstate_index);
123 virtual int getPState();
125 simgrid::s4u::Host* getHost() { return host_; }
127 int coresAmount_ = 1;
128 simgrid::s4u::Host* host_;
130 std::vector<double> speedPerPstate_; /*< List of supported CPU capacities (pstate related) */
131 int pstate_ = 0; /*< Current pstate (index in the speedPeakList)*/
133 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). */
134 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) */
136 tmgr_trace_event_t stateEvent_ = nullptr;
137 s_surf_metric_t speed_ = {1.0, 0, nullptr};
144 /** @ingroup SURF_cpu_interface
145 * @brief A CpuAction represents the execution of code on one or several Cpus
147 XBT_PUBLIC_CLASS CpuAction : public simgrid::surf::Action {
148 friend XBT_PUBLIC(Cpu*) getActionCpu(CpuAction* action);
151 /** @brief Signal emitted when the action state changes (ready/running/done, etc)
152 * Signature: `void(CpuAction *action, simgrid::surf::Action::State previous)`
154 static simgrid::xbt::signal<void(simgrid::surf::CpuAction*, simgrid::surf::Action::State)> onStateChange;
155 /** @brief Signal emitted when the action share changes (amount of flops it gets)
156 * Signature: `void(CpuAction *action)`
158 static simgrid::xbt::signal<void(simgrid::surf::CpuAction*)> onShareChange;
160 CpuAction(simgrid::surf::Model* model, double cost, bool failed) : Action(model, cost, failed) {}
161 CpuAction(simgrid::surf::Model * model, double cost, bool failed, kernel::lmm::Variable* var)
162 : Action(model, cost, failed, var)
166 void setState(simgrid::surf::Action::State state) override;
168 void updateRemainingLazy(double now) override;
169 std::list<Cpu*> cpus();
171 void suspend() override;
172 void resume() override;
178 #endif /* SURF_CPU_INTERFACE_HPP_ */