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
32// C.
33#include <cstdint>
34
35namespace join
36{
41 {
42 int id;
43 int core;
44 int socket;
45 int numa;
46 };
47
52 {
53 int id;
54 int socket;
55 int numa;
56 std::vector<LogicalCpu> threads;
62 int primaryThread () const noexcept
63 {
64 return threads.empty () ? -1 : threads[0].id;
65 }
66 };
67
71 struct NumaNode
72 {
73 int id;
74 std::vector<int> cores;
75 };
76
81 {
82 public:
87 static const CpuTopology* instance ();
88
93 CpuTopology (const CpuTopology& other) = delete;
94
100 CpuTopology& operator= (const CpuTopology& other) = delete;
101
106 const std::vector<PhysicalCore>& cores () const noexcept;
107
112 const std::vector<NumaNode>& nodes () const noexcept;
113
117#ifdef DEBUG
118 void dump () const;
119#endif
120
121 private:
125 CpuTopology ();
126
130 ~CpuTopology () = default;
131
137 static int readInt (const std::string& path);
138
144 static int findNuma (const std::string& cpuPath);
145
149 void detect ();
150
152 std::vector<PhysicalCore> _cores;
153
155 std::vector<NumaNode> _nodes;
156 };
157}
158
159#endif
CPU topology detector.
Definition cpu.hpp:81
static const CpuTopology * instance()
get instance.
Definition cpu.cpp:50
const std::vector< PhysicalCore > & cores() const noexcept
get all physical cores.
Definition cpu.cpp:60
const std::vector< NumaNode > & nodes() const noexcept
get all NUMA nodes.
Definition cpu.cpp:69
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:356
Definition error.hpp:137
logical CPU (hardware thread).
Definition cpu.hpp:41
int id
Definition cpu.hpp:42
int numa
Definition cpu.hpp:45
int core
Definition cpu.hpp:43
int socket
Definition cpu.hpp:44
NUMA node containing multiple cores.
Definition cpu.hpp:72
int id
Definition cpu.hpp:73
std::vector< int > cores
Definition cpu.hpp:74
physical CPU core (may have multiple logical CPU).
Definition cpu.hpp:52
int id
Definition cpu.hpp:53
int socket
Definition cpu.hpp:54
int primaryThread() const noexcept
get primary thread (first hardware thread, avoids HT).
Definition cpu.hpp:62
int numa
Definition cpu.hpp:55
std::vector< LogicalCpu > threads
Definition cpu.hpp:56
std::string path
Definition unixstreamacceptor_test.cpp:34