blob: 61a6548490025e209f6232293578e662e62d610a [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>
Arnaldo Carvalho de Melo9ae7d332012-01-19 14:07:23 -02006
Don Zickus7780c252014-04-07 14:55:21 -04007#include "perf.h"
8#include "util/debug.h"
9
Arnaldo Carvalho de Melo60d567e2011-01-03 17:49:48 -020010struct cpu_map {
11 int nr;
12 int map[];
13};
14
15struct cpu_map *cpu_map__new(const char *cpu_list);
16struct cpu_map *cpu_map__dummy_new(void);
Arnaldo Carvalho de Melo915fce22011-01-14 16:19:12 -020017void cpu_map__delete(struct cpu_map *map);
Yan, Zheng7ae92e72012-09-10 15:53:50 +080018struct cpu_map *cpu_map__read(FILE *file);
Arnaldo Carvalho de Melo9ae7d332012-01-19 14:07:23 -020019size_t cpu_map__fprintf(struct cpu_map *map, FILE *fp);
Stephane Eranian5ac59a82013-02-06 15:46:01 +010020int cpu_map__get_socket(struct cpu_map *map, int idx);
Stephane Eranian12c08a92013-02-14 13:57:29 +010021int cpu_map__get_core(struct cpu_map *map, int idx);
Stephane Eranian5ac59a82013-02-06 15:46:01 +010022int cpu_map__build_socket_map(struct cpu_map *cpus, struct cpu_map **sockp);
Stephane Eranian12c08a92013-02-14 13:57:29 +010023int cpu_map__build_core_map(struct cpu_map *cpus, struct cpu_map **corep);
Stephane Eranian5ac59a82013-02-06 15:46:01 +010024
25static inline int cpu_map__socket(struct cpu_map *sock, int s)
26{
27 if (!sock || s > sock->nr || s < 0)
28 return 0;
29 return sock->map[s];
30}
Arnaldo Carvalho de Melo9ae7d332012-01-19 14:07:23 -020031
Stephane Eranian12c08a92013-02-14 13:57:29 +010032static inline int cpu_map__id_to_socket(int id)
33{
34 return id >> 16;
35}
36
37static inline int cpu_map__id_to_cpu(int id)
38{
39 return id & 0xffff;
40}
41
Arnaldo Carvalho de Meloa14bb7a2012-09-26 12:41:14 -030042static inline int cpu_map__nr(const struct cpu_map *map)
43{
44 return map ? map->nr : 1;
45}
46
Sukadev Bhattiproluec1e7e42013-05-22 17:42:38 -070047static inline bool cpu_map__empty(const struct cpu_map *map)
Arnaldo Carvalho de Meloa14bb7a2012-09-26 12:41:14 -030048{
49 return map ? map->map[0] == -1 : true;
50}
51
Don Zickus7780c252014-04-07 14:55:21 -040052int max_cpu_num;
53int max_node_num;
54int *cpunode_map;
55
56int cpu__setup_cpunode_map(void);
57
58static inline int cpu__max_node(void)
59{
60 if (unlikely(!max_node_num))
61 pr_debug("cpu_map not initialized\n");
62
63 return max_node_num;
64}
65
66static inline int cpu__max_cpu(void)
67{
68 if (unlikely(!max_cpu_num))
69 pr_debug("cpu_map not initialized\n");
70
71 return max_cpu_num;
72}
73
74static inline int cpu__get_node(int cpu)
75{
76 if (unlikely(cpunode_map == NULL)) {
77 pr_debug("cpu_map not initialized\n");
78 return -1;
79 }
80
81 return cpunode_map[cpu];
82}
83
Paul Mackerrasa12b51c2010-03-10 20:36:09 +110084#endif /* __PERF_CPUMAP_H */