cpufreq.hpp
1 #ifndef MAMMUT_CPUFREQ_HPP_
2 #define MAMMUT_CPUFREQ_HPP_
3 
4 #include "../communicator.hpp"
5 #include "../module.hpp"
6 #include "../topology/topology.hpp"
7 #include "../utils.hpp"
8 
9 #include "map"
10 #include "stddef.h"
11 #include "stdint.h"
12 #include "string"
13 #include "vector"
14 
15 namespace mammut{
16 namespace cpufreq{
17 
18 typedef enum{
19  GOVERNOR_CONSERVATIVE,
20  GOVERNOR_ONDEMAND,
21  GOVERNOR_INTERACTIVE,
22  GOVERNOR_USERSPACE,
23  GOVERNOR_POWERSAVE,
24  GOVERNOR_PERFORMANCE,
25  GOVERNOR_NUM
26 }Governor;
27 
28 typedef uint32_t Frequency;
29 typedef double Voltage;
30 typedef uint32_t DomainId;
31 
32 typedef std::pair<topology::VirtualCoreId, Frequency> VoltageTableKey;
33 typedef std::map<VoltageTableKey, Voltage> VoltageTable;
34 typedef std::map<VoltageTableKey, Voltage>::const_iterator VoltageTableIterator;
35 
41  DomainId domainId;
42  Frequency frequency;
43  Frequency lowerBound;
44  Frequency upperBound;
45  Governor governor;
46 };
47 
53 class Domain{
54  const DomainId _domainIdentifier;
55 protected:
56  const std::vector<topology::VirtualCore*> _virtualCores;
57 
58  Domain(DomainId domainIdentifier, std::vector<topology::VirtualCore*> virtualCores);
59 public:
60  virtual inline ~Domain(){;}
61 
66  std::vector<topology::VirtualCore*> getVirtualCores() const;
67 
72  std::vector<topology::VirtualCoreId> getVirtualCoresIdentifiers() const;
73 
80  bool contains(const topology::VirtualCore* virtualCore) const;
81 
86  DomainId getId() const;
87 
94 
99  void rollback(const RollbackPoint& rollbackPoint) const;
100 
105  virtual std::vector<Frequency> getAvailableFrequencies() const = 0;
106 
111  virtual std::vector<Governor> getAvailableGovernors() const = 0;
112 
118  bool isGovernorAvailable(Governor governor) const;
119 
124  virtual Frequency getCurrentFrequency() const = 0;
125 
131  virtual Frequency getCurrentFrequencyUserspace() const = 0;
132 
139  virtual bool setFrequencyUserspace(Frequency frequency) const = 0;
140 
145  bool setHighestFrequencyUserspace() const;
146 
151  bool setLowestFrequencyUserspace() const;
152 
157  virtual Governor getCurrentGovernor() const = 0;
158 
164  virtual bool setGovernor(Governor governor) const = 0;
165 
171  virtual void getHardwareFrequencyBounds(Frequency& lowerBound, Frequency& upperBound) const = 0;
172 
179  virtual bool getCurrentGovernorBounds(Frequency& lowerBound, Frequency& upperBound) const = 0;
180 
187  virtual bool setGovernorBounds(Frequency lowerBound, Frequency upperBound) const = 0;
188 
194  virtual int getTransitionLatency() const = 0;
195 
202  virtual Voltage getCurrentVoltage() const = 0;
203 
204 
216  virtual VoltageTable getVoltageTable(bool onlyPhysicalCores = true) const = 0;
217 
231  virtual VoltageTable getVoltageTable(uint numVirtualCores,
232  bool onlyPhysicalCores) const = 0;
233 };
234 
235 class CpuFreq: public Module{
236  MAMMUT_MODULE_DECL(CpuFreq)
237 private:
238  bool processMessage(const std::string& messageIdIn, const std::string& messageIn,
239  std::string& messageIdOut, std::string& messageOut);
240 protected:
241  virtual ~CpuFreq(){;}
248  static std::vector<topology::VirtualCore*> filterVirtualCores(const std::vector<topology::VirtualCore*>& virtualCores,
249  const std::vector<topology::VirtualCoreId>& identifiers);
250 public:
255  virtual std::vector<Domain*> getDomains() const = 0;
256 
262  Domain* getDomain(const topology::VirtualCore* virtualCore) const;
263 
269  std::vector<Domain*> getDomains(const std::vector<topology::VirtualCore*>& virtualCores) const;
270 
277  std::vector<Domain*> getDomains(const topology::PhysicalCore* physicalCore) const;
278 
285  std::vector<Domain*> getDomains(const topology::Cpu* cpu) const;
286 
296  std::vector<Domain*> getDomainsComplete(const std::vector<topology::VirtualCore*>& virtualCores) const;
297 
303  std::vector<RollbackPoint> getRollbackPoints() const;
304 
309  void rollback(const std::vector<RollbackPoint>& rollbackPoints) const;
310 
316  bool isGovernorAvailable(Governor governor) const;
317 
322  virtual bool isBoostingSupported() const = 0;
323 
328  virtual bool isBoostingEnabled() const = 0;
329 
333  virtual void enableBoosting() const = 0;
334 
338  virtual void disableBoosting() const = 0;
339 
345  static std::string getGovernorNameFromGovernor(Governor governor);
346 
353  static Governor getGovernorFromGovernorName(const std::string& governorName);
354 };
355 
356 
362 void loadVoltageTable(VoltageTable& voltageTable, std::string fileName);
363 
369 void dumpVoltageTable(const VoltageTable& voltageTable, std::string fileName);
370 
371 }
372 }
373 
374 #endif /* MAMMUT_CPUFREQ_HPP_ */
virtual void enableBoosting() const =0
std::vector< topology::VirtualCore * > getVirtualCores() const
virtual bool setGovernor(Governor governor) const =0
virtual std::vector< Governor > getAvailableGovernors() const =0
void rollback(const RollbackPoint &rollbackPoint) const
virtual Voltage getCurrentVoltage() const =0
bool setLowestFrequencyUserspace() const
virtual bool setGovernorBounds(Frequency lowerBound, Frequency upperBound) const =0
Definition: topology.hpp:445
Definition: cpufreq.hpp:235
Definition: topology.hpp:127
bool contains(const topology::VirtualCore *virtualCore) const
static std::vector< topology::VirtualCore * > filterVirtualCores(const std::vector< topology::VirtualCore * > &virtualCores, const std::vector< topology::VirtualCoreId > &identifiers)
static std::string getGovernorNameFromGovernor(Governor governor)
virtual std::vector< Frequency > getAvailableFrequencies() const =0
virtual void disableBoosting() const =0
virtual bool setFrequencyUserspace(Frequency frequency) const =0
std::vector< RollbackPoint > getRollbackPoints() const
virtual Frequency getCurrentFrequency() const =0
Definition: topology.hpp:239
std::vector< Domain * > getDomainsComplete(const std::vector< topology::VirtualCore * > &virtualCores) const
virtual bool isBoostingSupported() const =0
virtual bool isBoostingEnabled() const =0
Definition: cpufreq.hpp:53
virtual int getTransitionLatency() const =0
bool isGovernorAvailable(Governor governor) const
virtual Governor getCurrentGovernor() const =0
Definition: cpufreq.hpp:40
static Governor getGovernorFromGovernorName(const std::string &governorName)
Domain * getDomain(const topology::VirtualCore *virtualCore) const
bool isGovernorAvailable(Governor governor) const
bool setHighestFrequencyUserspace() const
virtual std::vector< Domain * > getDomains() const =0
virtual VoltageTable getVoltageTable(bool onlyPhysicalCores=true) const =0
virtual void getHardwareFrequencyBounds(Frequency &lowerBound, Frequency &upperBound) const =0
std::vector< topology::VirtualCoreId > getVirtualCoresIdentifiers() const
virtual Frequency getCurrentFrequencyUserspace() const =0
virtual bool getCurrentGovernorBounds(Frequency &lowerBound, Frequency &upperBound) const =0
RollbackPoint getRollbackPoint() const
void rollback(const std::vector< RollbackPoint > &rollbackPoints) const
DomainId getId() const