blob: 6b8bff87481d090a0e72f7391772bb307d0e1f7c [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>
Elena Reshetovaec09a422017-02-21 17:34:56 +02006#include <linux/refcount.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 {
Elena Reshetovaec09a422017-02-21 17:34:56 +020012 refcount_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);
Jiri Olsa2322f572015-10-25 15:51:17 +010018struct cpu_map *cpu_map__empty_new(int nr);
Arnaldo Carvalho de Melo60d567e2011-01-03 17:49:48 -020019struct cpu_map *cpu_map__dummy_new(void);
Jiri Olsaf77b57a2015-10-25 15:51:25 +010020struct cpu_map *cpu_map__new_data(struct cpu_map_data *data);
Yan, Zheng7ae92e72012-09-10 15:53:50 +080021struct cpu_map *cpu_map__read(FILE *file);
Jiri Olsaa24020e2016-06-28 13:29:04 +020022size_t cpu_map__snprint(struct cpu_map *map, char *buf, size_t size);
Namhyung Kim4400ac82017-02-24 10:12:49 +090023size_t cpu_map__snprint_mask(struct cpu_map *map, char *buf, size_t size);
Arnaldo Carvalho de Melo9ae7d332012-01-19 14:07:23 -020024size_t cpu_map__fprintf(struct cpu_map *map, FILE *fp);
Kan Liang193b6bd2015-09-01 09:58:11 -040025int cpu_map__get_socket_id(int cpu);
Jiri Olsa1fe7a302015-10-16 12:41:15 +020026int cpu_map__get_socket(struct cpu_map *map, int idx, void *data);
Kan Liang193b6bd2015-09-01 09:58:11 -040027int cpu_map__get_core_id(int cpu);
Jiri Olsa1fe7a302015-10-16 12:41:15 +020028int cpu_map__get_core(struct cpu_map *map, int idx, void *data);
Stephane Eranian5ac59a82013-02-06 15:46:01 +010029int cpu_map__build_socket_map(struct cpu_map *cpus, struct cpu_map **sockp);
Stephane Eranian12c08a92013-02-14 13:57:29 +010030int cpu_map__build_core_map(struct cpu_map *cpus, struct cpu_map **corep);
Stephane Eranian5ac59a82013-02-06 15:46:01 +010031
Jiri Olsaf30a79b2015-06-23 00:36:04 +020032struct cpu_map *cpu_map__get(struct cpu_map *map);
33void cpu_map__put(struct cpu_map *map);
34
Stephane Eranian5ac59a82013-02-06 15:46:01 +010035static inline int cpu_map__socket(struct cpu_map *sock, int s)
36{
37 if (!sock || s > sock->nr || s < 0)
38 return 0;
39 return sock->map[s];
40}
Arnaldo Carvalho de Melo9ae7d332012-01-19 14:07:23 -020041
Stephane Eranian12c08a92013-02-14 13:57:29 +010042static inline int cpu_map__id_to_socket(int id)
43{
44 return id >> 16;
45}
46
47static inline int cpu_map__id_to_cpu(int id)
48{
49 return id & 0xffff;
50}
51
Arnaldo Carvalho de Meloa14bb7a2012-09-26 12:41:14 -030052static inline int cpu_map__nr(const struct cpu_map *map)
53{
54 return map ? map->nr : 1;
55}
56
Sukadev Bhattiproluec1e7e42013-05-22 17:42:38 -070057static inline bool cpu_map__empty(const struct cpu_map *map)
Arnaldo Carvalho de Meloa14bb7a2012-09-26 12:41:14 -030058{
59 return map ? map->map[0] == -1 : true;
60}
61
Don Zickus7780c252014-04-07 14:55:21 -040062int cpu__setup_cpunode_map(void);
63
Arnaldo Carvalho de Melo5ac76282016-01-26 15:51:46 -030064int cpu__max_node(void);
65int cpu__max_cpu(void);
Jan Stancek92a7e122017-02-17 12:10:24 +010066int cpu__max_present_cpu(void);
Arnaldo Carvalho de Melo5ac76282016-01-26 15:51:46 -030067int cpu__get_node(int cpu);
Don Zickus7780c252014-04-07 14:55:21 -040068
Jiri Olsaf1cbb8f2015-10-16 12:41:14 +020069int cpu_map__build_map(struct cpu_map *cpus, struct cpu_map **res,
Jiri Olsa1fe7a302015-10-16 12:41:15 +020070 int (*f)(struct cpu_map *map, int cpu, void *data),
71 void *data);
Jiri Olsae632aa62016-04-12 15:29:25 +020072
Mark Rutland9a6c5822016-07-15 11:08:11 +010073int cpu_map__cpu(struct cpu_map *cpus, int idx);
Jiri Olsae632aa62016-04-12 15:29:25 +020074bool cpu_map__has(struct cpu_map *cpus, int cpu);
Mark Rutland9a6c5822016-07-15 11:08:11 +010075int cpu_map__idx(struct cpu_map *cpus, int cpu);
Paul Mackerrasa12b51c2010-03-10 20:36:09 +110076#endif /* __PERF_CPUMAP_H */