File: cpu.hpp

package info (click to toggle)
mergerfs 2.40.2-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,000 kB
  • sloc: cpp: 58,559; ansic: 17,241; makefile: 348; python: 156; sh: 119
file content (33 lines) | stat: -rw-r--r-- 810 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#pragma once

#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif

#include <pthread.h>
#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();
  static int getaffinity(const pthread_t thread_id, cpu_set_t *cpuset);
  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();
};