ThreadPinning reads the sibling groups from the kernel topology and pins the calling thread to a cpu set. It is stateless and per-thread: a caller reads the groups, picks the cpus for a thread and pins it, so any mapping of threads to cpus is expressible.
13 lines
310 B
C++
13 lines
310 B
C++
#pragma once
|
|
|
|
#include <vector>
|
|
|
|
namespace tp {
|
|
|
|
class ThreadPinning {
|
|
public:
|
|
[[nodiscard]] static std::vector<int> allowedCpus();
|
|
[[nodiscard]] static std::vector<std::vector<int>> siblingGroups(const std::vector<int>& allowed = {});
|
|
static void pinCallingThread(const std::vector<int>& cpus);
|
|
};
|
|
}
|