cpumap.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 cpu__setup_cpunode_map(void);
  50. int cpu__max_node(void);
  51. int cpu__max_cpu(void);
  52. int cpu__get_node(int cpu);
  53. int cpu_map__build_map(struct cpu_map *cpus, struct cpu_map **res,
  54. int (*f)(struct cpu_map *map, int cpu, void *data),
  55. void *data);
  56. #endif /* __PERF_CPUMAP_H */