Skip to content

Commit f4a77cd

Browse files
Zainullin DamirZainullin Damir
authored andcommitted
++
1 parent 4556446 commit f4a77cd

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

include/ipfixprobe/outputPlugin/outputStorage/threadAffinitySetter.hpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace ipxp::output {
1212

1313
class ThreadAffinitySetter {
1414
public:
15-
static void setNumaNode(const size_t nodeIndex)
15+
static void setExactCoreOnNumaNode(const size_t nodeIndex)
1616
{
1717
const uint16_t threadIndex = getThreadId();
1818
const std::size_t numaIndex = nodeIndex % m_architectureInfo.cpusByNumaNode.size();
@@ -30,6 +30,21 @@ class ThreadAffinitySetter {
3030
}
3131
}
3232

33+
static void setNumaNode(const size_t nodeIndex)
34+
{
35+
const std::size_t numaIndex = nodeIndex % m_architectureInfo.cpusByNumaNode.size();
36+
cpu_set_t cpuset;
37+
CPU_ZERO(&cpuset);
38+
for (const int cpuToBind : m_architectureInfo.cpusByNumaNode[numaIndex]) {
39+
CPU_SET(cpuToBind, &cpuset);
40+
}
41+
const pthread_t current_thread = pthread_self();
42+
const int errCode = pthread_setaffinity_np(current_thread, sizeof(cpu_set_t), &cpuset);
43+
if (errCode != 0) {
44+
throw std::system_error(errCode, std::generic_category(), "Failed to pin thread");
45+
}
46+
}
47+
3348
private:
3449
struct ArchitectureInfo {
3550
ArchitectureInfo()

0 commit comments

Comments
 (0)