cpumap.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #ifndef __PERF_CPUMAP_H
  2. #define __PERF_CPUMAP_H
  3. #include <stdio.h>
  4. #include <stdbool.h>
  5. #include <linux/atomic.h>
  6. #include "perf.h"
  7. #include "util/debug.h"
  8. struct cpu_map {
  9. atomic_t refcnt;
  10. int nr;
  11. int map[];
  12. };
  13. struct cpu_map *cpu_map__new(const char *cpu_list);
  14. struct cpu_map *cpu_map__empty_new(int nr);
  15. struct cpu_map *cpu_map__dummy_new(void);
  16. struct cpu_map *cpu_map__new_data(struct cpu_map_data *data);
  17. struct cpu_map *cpu_map__read(FILE *file);
  18. size_t cpu_map__snprint(struct cpu_map *map, char *buf, size_t size);
  19. size_t cpu_map__fprintf(struct cpu_map *map, FILE *fp);
  20. int cpu_map__get_socket_id(int cpu);
  21. int cpu_map__get_socket(struct cpu_map *map, int idx, void *data);
  22. int cpu_map__get_core_id(int cpu);
  23. int cpu_map__get_core(struct cpu_map *map, int idx, void *data);
  24. int cpu_map__build_socket_map(struct cpu_map *cpus, struct cpu_map **sockp);
  25. int cpu_map__build_core_map(struct cpu_map *cpus, struct cpu_map **corep);
  26. struct cpu_map *cpu_map__get(struct cpu_map *map);
  27. void cpu_map__put(struct cpu_map *map);
  28. static inline int cpu_map__socket(struct cpu_map *sock, int s)
  29. {
  30. if (!sock || s > sock->nr || s < 0)
  31. return 0;
  32. return sock->map[s];
  33. }
  34. static inline int cpu_map__id_to_socket(int id)
  35. {
  36. return id >> 16;
  37. }
  38. static inline int cpu_map__id_to_cpu(int id)
  39. {
  40. return id & 0xffff;
  41. }
  42. static inline int cpu_map__nr(const struct cpu_map *map)
  43. {
  44. return map ? map->nr : 1;
  45. }
  46. static inline bool cpu_map__empty(const struct cpu_map *map)
  47. {
  48. return map ? map->map[0] == -1 : true;
  49. }
  50. int cpu__setup_cpunode_map(void);
  51. int cpu__max_node(void);
  52. int cpu__max_cpu(void);
  53. int cpu__get_node(int cpu);
  54. int cpu_map__build_map(struct cpu_map *cpus, struct cpu_map **res,
  55. int (*f)(struct cpu_map *map, int cpu, void *data),
  56. void *data);
  57. int cpu_map__cpu(struct cpu_map *cpus, int idx);
  58. bool cpu_map__has(struct cpu_map *cpus, int cpu);
  59. int cpu_map__idx(struct cpu_map *cpus, int cpu);
  60. #endif /* __PERF_CPUMAP_H */