cpumap.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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__read(FILE *file);
  17. size_t cpu_map__fprintf(struct cpu_map *map, FILE *fp);
  18. int cpu_map__get_socket_id(int cpu);
  19. int cpu_map__get_socket(struct cpu_map *map, int idx, void *data);
  20. int cpu_map__get_core_id(int cpu);
  21. int cpu_map__get_core(struct cpu_map *map, int idx, void *data);
  22. int cpu_map__build_socket_map(struct cpu_map *cpus, struct cpu_map **sockp);
  23. int cpu_map__build_core_map(struct cpu_map *cpus, struct cpu_map **corep);
  24. struct cpu_map *cpu_map__get(struct cpu_map *map);
  25. void cpu_map__put(struct cpu_map *map);
  26. static inline int cpu_map__socket(struct cpu_map *sock, int s)
  27. {
  28. if (!sock || s > sock->nr || s < 0)
  29. return 0;
  30. return sock->map[s];
  31. }
  32. static inline int cpu_map__id_to_socket(int id)
  33. {
  34. return id >> 16;
  35. }
  36. static inline int cpu_map__id_to_cpu(int id)
  37. {
  38. return id & 0xffff;
  39. }
  40. static inline int cpu_map__nr(const struct cpu_map *map)
  41. {
  42. return map ? map->nr : 1;
  43. }
  44. static inline bool cpu_map__empty(const struct cpu_map *map)
  45. {
  46. return map ? map->map[0] == -1 : true;
  47. }
  48. int max_cpu_num;
  49. int max_node_num;
  50. int *cpunode_map;
  51. int cpu__setup_cpunode_map(void);
  52. static inline int cpu__max_node(void)
  53. {
  54. if (unlikely(!max_node_num))
  55. pr_debug("cpu_map not initialized\n");
  56. return max_node_num;
  57. }
  58. static inline int cpu__max_cpu(void)
  59. {
  60. if (unlikely(!max_cpu_num))
  61. pr_debug("cpu_map not initialized\n");
  62. return max_cpu_num;
  63. }
  64. static inline int cpu__get_node(int cpu)
  65. {
  66. if (unlikely(cpunode_map == NULL)) {
  67. pr_debug("cpu_map not initialized\n");
  68. return -1;
  69. }
  70. return cpunode_map[cpu];
  71. }
  72. int cpu_map__build_map(struct cpu_map *cpus, struct cpu_map **res,
  73. int (*f)(struct cpu_map *map, int cpu, void *data),
  74. void *data);
  75. #endif /* __PERF_CPUMAP_H */