cpumap.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __PERF_CPUMAP_H
  3. #define __PERF_CPUMAP_H
  4. #include <stdio.h>
  5. #include <stdbool.h>
  6. #include <linux/refcount.h>
  7. #include "perf.h"
  8. #include "util/debug.h"
  9. struct cpu_map {
  10. refcount_t refcnt;
  11. int nr;
  12. int map[];
  13. };
  14. struct cpu_map *cpu_map__new(const char *cpu_list);
  15. struct cpu_map *cpu_map__empty_new(int nr);
  16. struct cpu_map *cpu_map__dummy_new(void);
  17. struct cpu_map *cpu_map__new_data(struct cpu_map_data *data);
  18. struct cpu_map *cpu_map__read(FILE *file);
  19. size_t cpu_map__snprint(struct cpu_map *map, char *buf, size_t size);
  20. size_t cpu_map__snprint_mask(struct cpu_map *map, char *buf, size_t size);
  21. size_t cpu_map__fprintf(struct cpu_map *map, FILE *fp);
  22. int cpu_map__get_socket_id(int cpu);
  23. int cpu_map__get_socket(struct cpu_map *map, int idx, void *data);
  24. int cpu_map__get_core_id(int cpu);
  25. int cpu_map__get_core(struct cpu_map *map, int idx, void *data);
  26. int cpu_map__build_socket_map(struct cpu_map *cpus, struct cpu_map **sockp);
  27. int cpu_map__build_core_map(struct cpu_map *cpus, struct cpu_map **corep);
  28. struct cpu_map *cpu_map__get(struct cpu_map *map);
  29. void cpu_map__put(struct cpu_map *map);
  30. static inline int cpu_map__socket(struct cpu_map *sock, int s)
  31. {
  32. if (!sock || s > sock->nr || s < 0)
  33. return 0;
  34. return sock->map[s];
  35. }
  36. static inline int cpu_map__id_to_socket(int id)
  37. {
  38. return id >> 16;
  39. }
  40. static inline int cpu_map__id_to_cpu(int id)
  41. {
  42. return id & 0xffff;
  43. }
  44. static inline int cpu_map__nr(const struct cpu_map *map)
  45. {
  46. return map ? map->nr : 1;
  47. }
  48. static inline bool cpu_map__empty(const struct cpu_map *map)
  49. {
  50. return map ? map->map[0] == -1 : true;
  51. }
  52. int cpu__setup_cpunode_map(void);
  53. int cpu__max_node(void);
  54. int cpu__max_cpu(void);
  55. int cpu__max_present_cpu(void);
  56. int cpu__get_node(int cpu);
  57. int cpu_map__build_map(struct cpu_map *cpus, struct cpu_map **res,
  58. int (*f)(struct cpu_map *map, int cpu, void *data),
  59. void *data);
  60. int cpu_map__cpu(struct cpu_map *cpus, int idx);
  61. bool cpu_map__has(struct cpu_map *cpus, int cpu);
  62. int cpu_map__idx(struct cpu_map *cpus, int cpu);
  63. #endif /* __PERF_CPUMAP_H */