blob: 0af9cecb4c519d44da13d392baa9abca37ebe6ec [file] [log] [blame]
Paul Mackerrasa12b51c2010-03-10 20:36:09 +11001#ifndef __PERF_CPUMAP_H
2#define __PERF_CPUMAP_H
3
Arnaldo Carvalho de Melo9ae7d332012-01-19 14:07:23 -02004#include <stdio.h>
Arnaldo Carvalho de Meloa14bb7a2012-09-26 12:41:14 -03005#include <stdbool.h>
Jiri Olsaf30a79b2015-06-23 00:36:04 +02006#include <linux/atomic.h>
Arnaldo Carvalho de Melo9ae7d332012-01-19 14:07:23 -02007
Don Zickus7780c252014-04-07 14:55:21 -04008#include "perf.h"
9#include "util/debug.h"
10
Arnaldo Carvalho de Melo60d567e2011-01-03 17:49:48 -020011struct cpu_map {
Jiri Olsaf30a79b2015-06-23 00:36:04 +020012 atomic_t refcnt;
Arnaldo Carvalho de Melo60d567e2011-01-03 17:49:48 -020013 int nr;
14 int map[];
15};
16
17struct cpu_map *cpu_map__new(const char *cpu_list);
18struct cpu_map *cpu_map__dummy_new(void);
Yan, Zheng7ae92e72012-09-10 15:53:50 +080019struct cpu_map *cpu_map__read(FILE *file);
Arnaldo Carvalho de Melo9ae7d332012-01-19 14:07:23 -020020size_t cpu_map__fprintf(struct cpu_map *map, FILE *fp);
Stephane Eranian5ac59a82013-02-06 15:46:01 +010021int cpu_map__get_socket(struct cpu_map *map, int idx);
Stephane Eranian12c08a92013-02-14 13:57:29 +010022int cpu_map__get_core(struct cpu_map *map, int idx);
Stephane Eranian5ac59a82013-02-06 15:46:01 +010023int cpu_map__build_socket_map(struct cpu_map *cpus, struct cpu_map **sockp);
Stephane Eranian12c08a92013-02-14 13:57:29 +010024int cpu_map__build_core_map(struct cpu_map *cpus, struct cpu_map **corep);
Stephane Eranian5ac59a82013-02-06 15:46:01 +010025
Jiri Olsaf30a79b2015-06-23 00:36:04 +020026struct cpu_map *cpu_map__get(struct cpu_map *map);
27void cpu_map__put(struct cpu_map *map);
28
Stephane Eranian5ac59a82013-02-06 15:46:01 +010029static inline int cpu_map__socket(struct cpu_map *sock, int s)
30{
31 if (!sock || s > sock->nr || s < 0)
32 return 0;
33 return sock->map[s];
34}
Arnaldo Carvalho de Melo9ae7d332012-01-19 14:07:23 -020035
Stephane Eranian12c08a92013-02-14 13:57:29 +010036static inline int cpu_map__id_to_socket(int id)
37{
38 return id >> 16;
39}
40
41static inline int cpu_map__id_to_cpu(int id)
42{
43 return id & 0xffff;
44}
45
Arnaldo Carvalho de Meloa14bb7a2012-09-26 12:41:14 -030046static inline int cpu_map__nr(const struct cpu_map *map)
47{
48 return map ? map->nr : 1;
49}
50
Sukadev Bhattiproluec1e7e42013-05-22 17:42:38 -070051static inline bool cpu_map__empty(const struct cpu_map *map)
Arnaldo Carvalho de Meloa14bb7a2012-09-26 12:41:14 -030052{
53 return map ? map->map[0] == -1 : true;
54}
55
Don Zickus7780c252014-04-07 14:55:21 -040056int max_cpu_num;
57int max_node_num;
58int *cpunode_map;
59
60int cpu__setup_cpunode_map(void);
61
62static inline int cpu__max_node(void)
63{
64 if (unlikely(!max_node_num))
65 pr_debug("cpu_map not initialized\n");
66
67 return max_node_num;
68}
69
70static inline int cpu__max_cpu(void)
71{
72 if (unlikely(!max_cpu_num))
73 pr_debug("cpu_map not initialized\n");
74
75 return max_cpu_num;
76}
77
78static inline int cpu__get_node(int cpu)
79{
80 if (unlikely(cpunode_map == NULL)) {
81 pr_debug("cpu_map not initialized\n");
82 return -1;
83 }
84
85 return cpunode_map[cpu];
86}
87
Paul Mackerrasa12b51c2010-03-10 20:36:09 +110088#endif /* __PERF_CPUMAP_H */