2023-02-04 23:11:54 -05:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <pthread.h>
|
2025-01-12 14:55:04 -06:00
|
|
|
#ifdef __FreeBSD__
|
|
|
|
|
#include <pthread_np.h>
|
|
|
|
|
#endif
|
2023-02-04 23:11:54 -05:00
|
|
|
#include <sched.h>
|
|
|
|
|
|
|
|
|
|
#include <set>
|
|
|
|
|
#include <unordered_map>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CPU
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
typedef std::vector<pthread_t> ThreadIdVec;
|
|
|
|
|
typedef std::vector<int> CPUVec;
|
|
|
|
|
typedef std::unordered_map<int,int> CPU2CoreMap;
|
|
|
|
|
typedef std::unordered_map<int,std::set<int>> Core2CPUsMap;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
static int count();
|
2025-01-12 14:55:04 -06:00
|
|
|
static int getaffinity(cpu_set_t *cpuset);
|
2023-02-04 23:11:54 -05:00
|
|
|
static int setaffinity(const pthread_t thread_id, cpu_set_t *cpuset);
|
|
|
|
|
static int setaffinity(const pthread_t thread_id, const int cpu);
|
|
|
|
|
static int setaffinity(const pthread_t thread_id, const std::set<int> cpus);
|
|
|
|
|
|
|
|
|
|
static CPU::CPUVec cpus();
|
|
|
|
|
static CPU::CPU2CoreMap cpu2core();
|
|
|
|
|
static CPU::Core2CPUsMap core2cpus();
|
|
|
|
|
};
|