cpumap.h 1.8 KB

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