join 1.0
lightweight network framework library
Loading...
Searching...
No Matches
cpu.hpp
Go to the documentation of this file.
1
25#ifndef JOIN_CORE_CPU_HPP
26#define JOIN_CORE_CPU_HPP
27
28// C++.
29#include <string>
30#include <vector>
31
32namespace join
33{
38 {
39 int id;
40 int core;
41 int socket;
42 int numa;
43 };
44
49 {
50 int id;
51 int socket;
52 int numa;
53 std::vector<LogicalCpu> threads;
59 int primaryThread () const noexcept
60 {
61 return threads.empty () ? -1 : threads[0].id;
62 }
63 };
64
68 struct NumaNode
69 {
70 int id;
71 std::vector<int> cores;
72 };
73
78 {
79 public:
84 static const CpuTopology* instance ();
85
90 CpuTopology (const CpuTopology& other) = delete;
91
97 CpuTopology& operator= (const CpuTopology& other) = delete;
98
103 const std::vector<PhysicalCore>& cores () const noexcept;
104
109 const std::vector<NumaNode>& nodes () const noexcept;
110
114#ifdef DEBUG
115 void dump () const;
116#endif
117
118 private:
122 CpuTopology ();
123
127 ~CpuTopology () = default;
128
134 static int readInt (const std::string& path);
135
141 static int findNuma (const std::string& cpuPath);
142
146 void detect ();
147
149 std::vector<PhysicalCore> _cores;
150
152 std::vector<NumaNode> _nodes;
153 };
154}
155
156#endif
CPU topology detector.
Definition cpu.hpp:78
static const CpuTopology * instance()
get instance.
Definition cpu.cpp:49
const std::vector< PhysicalCore > & cores() const noexcept
get all physical cores.
Definition cpu.cpp:59
const std::vector< NumaNode > & nodes() const noexcept
get all NUMA nodes.
Definition cpu.cpp:68
CpuTopology(const CpuTopology &other)=delete
copy constructor.
CpuTopology & operator=(const CpuTopology &other)=delete
copy assignment operator.
Definition acceptor.hpp:32
void dump(const void *data, unsigned long size, std::ostream &out=std::cout)
dump data to standard output stream.
Definition utils.hpp:387
Definition error.hpp:144
logical CPU (hardware thread).
Definition cpu.hpp:38
int id
Definition cpu.hpp:39
int numa
Definition cpu.hpp:42
int core
Definition cpu.hpp:40
int socket
Definition cpu.hpp:41
NUMA node containing multiple cores.
Definition cpu.hpp:69
int id
Definition cpu.hpp:70
std::vector< int > cores
Definition cpu.hpp:71
physical CPU core (may have multiple logical CPU).
Definition cpu.hpp:49
int id
Definition cpu.hpp:50
int socket
Definition cpu.hpp:51
int primaryThread() const noexcept
get primary thread (first hardware thread, avoids HT).
Definition cpu.hpp:59
int numa
Definition cpu.hpp:52
std::vector< LogicalCpu > threads
Definition cpu.hpp:53
std::string path
Definition unix_acceptor_test.cpp:37