cpumap.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #ifndef __PERF_CPUMAP_H
  2. #define __PERF_CPUMAP_H
  3. #include <stdio.h>
  4. #include <stdbool.h>
  5. #include "perf.h"
  6. #include "util/debug.h"
  7. struct cpu_map {
  8. int nr;
  9. int map[];
  10. };
  11. struct cpu_map *cpu_map__new(const char *cpu_list);
  12. struct cpu_map *cpu_map__dummy_new(void);
  13. void cpu_map__delete(struct cpu_map *map);
  14. struct cpu_map *cpu_map__read(FILE *file);
  15. size_t cpu_map__fprintf(struct cpu_map *map, FILE *fp);
  16. int cpu_map__get_socket(struct cpu_map *map, int idx);
  17. int cpu_map__get_core(struct cpu_map *map, int idx);
  18. int cpu_map__build_socket_map(struct cpu_map *cpus, struct cpu_map **sockp);
  19. int cpu_map__build_core_map(struct cpu_map *cpus, struct cpu_map **corep);
  20. static inline int cpu_map__socket(struct cpu_map *sock, int s)
  21. {
  22. if (!sock || s > sock->nr || s < 0)
  23. return 0;
  24. return sock->map[s];
  25. }
  26. static inline int cpu_map__id_to_socket(int id)
  27. {
  28. return id >> 16;
  29. }
  30. static inline int cpu_map__id_to_cpu(int id)
  31. {
  32. return id & 0xffff;
  33. }
  34. static inline int cpu_map__nr(const struct cpu_map *map)
  35. {
  36. return map ? map->nr : 1;
  37. }
  38. static inline bool cpu_map__empty(const struct cpu_map *map)
  39. {
  40. return map ? map->map[0] == -1 : true;
  41. }
  42. int max_cpu_num;
  43. int max_node_num;
  44. int *cpunode_map;
  45. int cpu__setup_cpunode_map(void);
  46. static inline int cpu__max_node(void)
  47. {
  48. if (unlikely(!max_node_num))
  49. pr_debug("cpu_map not initialized\n");
  50. return max_node_num;
  51. }
  52. static inline int cpu__max_cpu(void)
  53. {
  54. if (unlikely(!max_cpu_num))
  55. pr_debug("cpu_map not initialized\n");
  56. return max_cpu_num;
  57. }
  58. static inline int cpu__get_node(int cpu)
  59. {
  60. if (unlikely(cpunode_map == NULL)) {
  61. pr_debug("cpu_map not initialized\n");
  62. return -1;
  63. }
  64. return cpunode_map[cpu];
  65. }
  66. #endif /* __PERF_CPUMAP_H */