topology.hpp
1 
9 #ifndef MAMMUT_TOPOLOGY_HPP_
10 #define MAMMUT_TOPOLOGY_HPP_
11 
12 #include "../communicator.hpp"
13 #include "../module.hpp"
14 
15 #include "stdint.h"
16 #include "vector"
17 
18 namespace mammut{
19 namespace topology{
20 
21 class VirtualCore;
22 class PhysicalCore;
23 class Cpu;
24 
25 typedef uint32_t CpuId;
26 typedef uint32_t PhysicalCoreId;
27 typedef uint32_t VirtualCoreId;
28 
29 // @cond HIDDEN_SYMBOLS
30 typedef struct{
31  CpuId cpuId;
32  PhysicalCoreId physicalCoreId;
33  VirtualCoreId virtualCoreId;
34 }VirtualCoreCoordinates;
35 // @endcond
36 
40 class Unit{
41 public:
42  inline virtual ~Unit(){;}
43 
48  virtual void maximizeUtilization() const = 0;
49 
53  virtual void resetUtilization() const = 0;
54 };
55 
56 class Topology: public Module, public Unit{
57  MAMMUT_MODULE_DECL(Topology)
58 protected:
59  std::vector<Cpu*> _cpus;
60  std::vector<PhysicalCore*> _physicalCores;
61  std::vector<VirtualCore*> _virtualCores;
62  Communicator* const _communicator;
63 
64  Topology();
65  Topology(Communicator* const communicator);
66  virtual ~Topology();
67 private:
68  void buildCpuVector(std::vector<VirtualCoreCoordinates> coord);
69  std::vector<PhysicalCore*> buildPhysicalCoresVector(std::vector<VirtualCoreCoordinates> coord, CpuId cpuId);
70  std::vector<VirtualCore*> buildVirtualCoresVector(std::vector<VirtualCoreCoordinates> coord, CpuId cpuId, PhysicalCoreId physicalCoreId);
71  bool processMessage(const std::string& messageIdIn, const std::string& messageIn,
72  std::string& messageIdOut, std::string& messageOut);
73 public:
78  std::vector<Cpu*> getCpus() const;
79 
84  std::vector<PhysicalCore*> getPhysicalCores() const;
85 
90  std::vector<VirtualCore*> getVirtualCores() const;
91 
97  std::vector<PhysicalCore*> virtualToPhysical(const std::vector<VirtualCore*>& virtualCores) const;
98 
104  Cpu* getCpu(CpuId cpuId) const;
105 
111  PhysicalCore* getPhysicalCore(PhysicalCoreId physicalCoreId) const;
112 
118  VirtualCore* getVirtualCore(VirtualCoreId virtualCoreId) const;
119 
124  VirtualCore* getVirtualCore() const;
125 };
126 
127 class Cpu: public Unit{
128 private:
129  std::vector<VirtualCore*> virtualCoresFromPhysicalCores();
130 protected:
131  Cpu(CpuId cpuId, std::vector<PhysicalCore*> physicalCores);
132  const CpuId _cpuId;
133  const std::vector<PhysicalCore*> _physicalCores;
134  const std::vector<VirtualCore*> _virtualCores;
135 public:
140  CpuId getCpuId() const;
141 
146  std::vector<PhysicalCore*> getPhysicalCores() const;
147 
152  std::vector<VirtualCore*> getVirtualCores() const;
153 
159  PhysicalCore* getPhysicalCore(PhysicalCoreId physicalCoreId) const;
160 
166  VirtualCore* getVirtualCore(VirtualCoreId virtualCoreId) const;
167 
172  VirtualCore* getVirtualCore() const;
173 
178  virtual std::string getVendorId() const = 0;
179 
184  virtual std::string getFamily() const = 0;
185 
190  virtual std::string getModel() const = 0;
191 
196  virtual void maximizeUtilization() const = 0;
197 
201  virtual void resetUtilization() const = 0;
202 
203  /*****************************************************/
204  /* HotPlug Support */
205  /*****************************************************/
206 
213  bool isHotPluggable() const;
214 
222  bool isHotPlugged() const;
223 
228  void hotPlug() const;
229 
234  void hotUnplug() const;
235 
236  virtual inline ~Cpu(){;}
237 };
238 
239 class PhysicalCore: public Unit{
240 protected:
241  PhysicalCore(CpuId cpuId, PhysicalCoreId physicalCoreId, std::vector<VirtualCore*> virtualCores);
242  const CpuId _cpuId;
243  const PhysicalCoreId _physicalCoreId;
244  const std::vector<VirtualCore*> _virtualCores;
245 public:
250  PhysicalCoreId getPhysicalCoreId() const;
251 
258  CpuId getCpuId() const;
259 
266  std::vector<VirtualCore*> getVirtualCores() const;
267 
273  VirtualCore* getVirtualCore(VirtualCoreId virtualCoreId) const;
274 
279  VirtualCore* getVirtualCore() const;
280 
285  virtual void maximizeUtilization() const = 0;
286 
290  virtual void resetUtilization() const = 0;
291 
292  /*****************************************************/
293  /* HotPlug Support */
294  /*****************************************************/
295 
302  bool isHotPluggable() const;
303 
311  bool isHotPlugged() const;
312 
317  void hotPlug() const;
318 
323  void hotUnplug() const;
324 
325  virtual inline ~PhysicalCore(){;}
326 };
327 
329 protected:
330  const VirtualCoreId _virtualCoreId;
331  const uint _levelId;
332 
333  VirtualCoreIdleLevel(VirtualCoreId virtualCoreId, uint levelId);
334 public:
339  VirtualCoreId getVirtualCoreId() const;
340 
345  uint getLevelId() const;
346 
351  virtual std::string getName() const = 0;
352 
357  virtual std::string getDesc() const = 0;
358 
365  virtual bool isEnableable() const = 0;
366 
371  virtual bool isEnabled() const = 0;
372 
376  virtual void enable() const = 0;
377 
381  virtual void disable() const = 0;
382 
387  virtual uint getExitLatency() const = 0;
388 
393  virtual uint getConsumedPower() const = 0;
394 
401  virtual uint getAbsoluteTime() const = 0;
402 
411  virtual uint getTime() const = 0;
412 
416  virtual void resetTime() = 0;
417 
424  virtual uint getAbsoluteCount() const = 0;
425 
434  virtual uint getCount() const = 0;
435 
439  virtual void resetCount() = 0;
440 
441 
442  virtual inline ~VirtualCoreIdleLevel(){;}
443 };
444 
445 class VirtualCore: public Unit{
446 protected:
447  VirtualCore(CpuId cpuId, PhysicalCoreId physicalCoreId, VirtualCoreId virtualCoreId);
448  const CpuId _cpuId;
449  const PhysicalCoreId _physicalCoreId;
450  const VirtualCoreId _virtualCoreId;
451 public:
452 
457  VirtualCoreId getVirtualCoreId() const;
458 
465  PhysicalCoreId getPhysicalCoreId() const;
466 
473  CpuId getCpuId() const;
474 
475  /*****************************************************/
476  /* Various utilities */
477  /*****************************************************/
478 
482  virtual bool hasFlag(const std::string& flagName) const = 0;
483 
494  virtual uint64_t getAbsoluteTicks() const = 0;
495 
500  virtual bool areTicksConstant() const;
501 
506  virtual void maximizeUtilization() const = 0;
507 
511  virtual void resetUtilization() const = 0;
512 
520  virtual double getIdleTime() const = 0;
521 
526  virtual void resetIdleTime() = 0;
527 
528  /*****************************************************/
529  /* HotPlug Support */
530  /*****************************************************/
531 
537  virtual bool isHotPluggable() const = 0;
538 
545  virtual bool isHotPlugged() const = 0;
546 
551  virtual void hotPlug() const = 0;
552 
557  virtual void hotUnplug() const = 0;
558 
559  /*****************************************************/
560  /* CpuIdle Support */
561  /*****************************************************/
562 
568  virtual std::vector<VirtualCoreIdleLevel*> getIdleLevels() const = 0;
569 
570  virtual inline ~VirtualCore(){;}
571 };
572 
579 size_t getNumPhysicalCores(const std::vector<VirtualCore*>& virtualCores);
580 
587 std::vector<VirtualCore*> getOneVirtualPerPhysical(const std::vector<VirtualCore*>& virtualCores);
588 
598 inline bool operator==(const Cpu& lhs, const Cpu& rhs){return lhs.getCpuId() == rhs.getCpuId();}
599 
609 inline bool operator!=(const Cpu& lhs, const Cpu& rhs){return !operator==(lhs,rhs);}
610 
620 inline bool operator==(const PhysicalCore& lhs, const PhysicalCore& rhs){return lhs.getPhysicalCoreId() == rhs.getPhysicalCoreId();}
621 
631 inline bool operator!=(const PhysicalCore& lhs, const PhysicalCore& rhs){return !operator==(lhs,rhs);}
632 
642 inline bool operator==(const VirtualCore& lhs, const VirtualCore& rhs){return lhs.getVirtualCoreId() == rhs.getVirtualCoreId();}
643 
653 inline bool operator!=(const VirtualCore& lhs, const VirtualCore& rhs){return !operator==(lhs,rhs);}
654 
655 }
656 }
657 
658 #endif /* MAMMUT_TOPOLOGY_HPP_ */
virtual void maximizeUtilization() const =0
void hotUnplug() const
VirtualCore * getVirtualCore() const
VirtualCore * getVirtualCore() const
Definition: topology.hpp:328
virtual void maximizeUtilization() const =0
Definition: topology.hpp:445
virtual uint getExitLatency() const =0
std::vector< VirtualCore * > getVirtualCores() const
virtual bool hasFlag(const std::string &flagName) const =0
std::vector< PhysicalCore * > getPhysicalCores() const
Definition: topology.hpp:127
virtual uint getConsumedPower() const =0
std::vector< Cpu * > getCpus() const
bool isHotPlugged() const
virtual double getIdleTime() const =0
virtual void maximizeUtilization() const =0
virtual bool isHotPlugged() const =0
virtual void resetUtilization() const =0
VirtualCore * getVirtualCore() const
Definition: topology.hpp:40
virtual bool isEnabled() const =0
Cpu * getCpu(CpuId cpuId) const
virtual void resetUtilization() const =0
PhysicalCoreId getPhysicalCoreId() const
virtual void hotPlug() const =0
virtual uint getCount() const =0
virtual std::string getDesc() const =0
virtual void maximizeUtilization() const =0
virtual void resetUtilization() const =0
Definition: topology.hpp:56
virtual bool isEnableable() const =0
Definition: topology.hpp:239
PhysicalCore * getPhysicalCore(PhysicalCoreId physicalCoreId) const
std::vector< VirtualCore * > getVirtualCores() const
virtual std::string getName() const =0
VirtualCoreId getVirtualCoreId() const
virtual std::vector< VirtualCoreIdleLevel * > getIdleLevels() const =0
std::vector< VirtualCore * > getVirtualCores() const
virtual uint getAbsoluteTime() const =0
virtual uint64_t getAbsoluteTicks() const =0
virtual bool isHotPluggable() const =0
virtual bool areTicksConstant() const
virtual void resetIdleTime()=0
void hotPlug() const
bool isHotPluggable() const
PhysicalCore * getPhysicalCore(PhysicalCoreId physicalCoreId) const
PhysicalCoreId getPhysicalCoreId() const
virtual void hotUnplug() const =0
VirtualCoreId getVirtualCoreId() const
virtual std::string getVendorId() const =0
virtual void resetUtilization() const =0
CpuId getCpuId() const
virtual std::string getModel() const =0
std::vector< PhysicalCore * > getPhysicalCores() const
virtual uint getAbsoluteCount() const =0
std::vector< PhysicalCore * > virtualToPhysical(const std::vector< VirtualCore * > &virtualCores) const
virtual std::string getFamily() const =0