You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
810 B

  1. #pragma once
  2. #ifndef _GNU_SOURCE
  3. #define _GNU_SOURCE
  4. #endif
  5. #include <pthread.h>
  6. #include <sched.h>
  7. #include <set>
  8. #include <unordered_map>
  9. #include <vector>
  10. class CPU
  11. {
  12. public:
  13. typedef std::vector<pthread_t> ThreadIdVec;
  14. typedef std::vector<int> CPUVec;
  15. typedef std::unordered_map<int,int> CPU2CoreMap;
  16. typedef std::unordered_map<int,std::set<int>> Core2CPUsMap;
  17. public:
  18. static int count();
  19. static int getaffinity(const pthread_t thread_id, cpu_set_t *cpuset);
  20. static int setaffinity(const pthread_t thread_id, cpu_set_t *cpuset);
  21. static int setaffinity(const pthread_t thread_id, const int cpu);
  22. static int setaffinity(const pthread_t thread_id, const std::set<int> cpus);
  23. static CPU::CPUVec cpus();
  24. static CPU::CPU2CoreMap cpu2core();
  25. static CPU::Core2CPUsMap core2cpus();
  26. };