34#if defined(__linux__) || defined(__FreeBSD__)
35#define DISPENSO_CPUSET_LINUXY
38#if defined(DISPENSO_CPUSET_LINUXY)
42#define DISPENSO_CPUSET_WINDOWS
60#ifndef DISPENSO_MAX_GROUP_SIZE
61#define DISPENSO_MAX_GROUP_SIZE 16
77constexpr int32_t kDefaultMaxGroupSize = DISPENSO_MAX_GROUP_SIZE;
155 DISPENSO_DLL_ACCESS
void add(int32_t hardwareThread);
162 DISPENSO_DLL_ACCESS
void addRange(int32_t start, int32_t end);
168 DISPENSO_DLL_ACCESS
void remove(int32_t hardwareThread);
182 DISPENSO_DLL_ACCESS
bool contains(int32_t hardwareThread)
const;
187 DISPENSO_DLL_ACCESS int32_t
count()
const;
235 static constexpr uint32_t kRefreshPeriod = 32;
236 static DISPENSO_THREAD_LOCAL int32_t cachedCpu = -1;
237 static DISPENSO_THREAD_LOCAL uint32_t counter = 0;
238 if ((counter++ & (kRefreshPeriod - 1)) == 0) {
249 DISPENSO_DLL_ACCESS
static const CpuSet&
node(int32_t numaNode);
328 int32_t maxGroupSize = kDefaultMaxGroupSize);
331#if defined(DISPENSO_CPUSET_LINUXY)
339 static constexpr int32_t kMaxCpus = 1024;
340 static constexpr int32_t kBitsPerWord = 64;
341 static constexpr int32_t kNumWords = kMaxCpus / kBitsPerWord;
342 uint64_t words_[kNumWords];
372DISPENSO_DLL_ACCESS
CpuSet parseLinuxCpuList(
const char* input);
A set of CPU IDs for affinity manipulation and topology queries.
static int32_t currentHardwareThreadApprox()
Approximate CPU ID for the calling thread, refreshed periodically.
static DISPENSO_DLL_ACCESS const std::vector< CacheGroup > & l3CacheGroups()
Returns the L3 cache sharing groups.
DISPENSO_DLL_ACCESS void add(int32_t hardwareThread)
Adds a single CPU to the set.
static DISPENSO_DLL_ACCESS const CpuSet & node(int32_t numaNode)
Returns the CPU set for a specific NUMA node.
DISPENSO_DLL_ACCESS bool contains(int32_t hardwareThread) const
Tests whether a CPU is in the set.
DISPENSO_DLL_ACCESS int32_t count() const
Returns the number of CPUs in the set.
DISPENSO_DLL_ACCESS void addRange(int32_t start, int32_t end)
Adds a range of CPUs to the set.
static DISPENSO_DLL_ACCESS int32_t availableCount()
Returns the number of hardware threads available to this process.
DISPENSO_DLL_ACCESS void clear()
Removes all CPUs from the set.
DISPENSO_DLL_ACCESS bool bindCurrentThread() const
Binds the calling thread to the CPUs in this set.
static DISPENSO_DLL_ACCESS std::vector< ThreadGroup > buildThreadGroups(int32_t maxGroupSize=kDefaultMaxGroupSize)
Builds scheduling thread groups from cache topology.
static DISPENSO_DLL_ACCESS int32_t totalNumaNodes()
Returns the total number of NUMA nodes detected.
static DISPENSO_DLL_ACCESS const CpuSet & all()
Returns a CPU set containing all online CPUs.
static DISPENSO_DLL_ACCESS int32_t currentHardwareThread()
Returns the CPU ID of the calling thread's current core.
static DISPENSO_DLL_ACCESS const std::vector< CacheGroup > & l2CacheGroups()
Returns the L2 cache sharing groups.
DISPENSO_DLL_ACCESS CpuSet()
Constructs an empty CPU set.
DISPENSO_DLL_ACCESS void removeRange(int32_t start, int32_t end)
Removes a range of CPUs from the set.
DISPENSO_DLL_ACCESS void remove(int32_t hardwareThread)
Removes a single CPU from the set.
Describes a group of CPUs that share a cache level.
std::vector< int32_t > cpus
CPU IDs in this group.
int32_t cacheId
Unique cache instance ID from sysfs.
A scheduling group of CPUs for fork-join thread pool assignment.
std::vector< int32_t > cpus
CPU IDs in this group (sorted)
CpuSet affinityMask
Pre-built CpuSet for binding threads in this group.