cpumap.h 2.1 KB

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