blob: b7af2cb68c1948276e325a8dfa7b86d6ed7bb6cc [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Paul Mackerrasa12b51c2010-03-10 20:36:09 +11002#ifndef __PERF_CPUMAP_H
3#define __PERF_CPUMAP_H
4
Arnaldo Carvalho de Melo9ae7d332012-01-19 14:07:23 -02005#include <stdio.h>
Arnaldo Carvalho de Meloa14bb7a2012-09-26 12:41:14 -03006#include <stdbool.h>
Elena Reshetovaec09a422017-02-21 17:34:56 +02007#include <linux/refcount.h>
Jiri Olsa959b83c2019-07-21 13:24:15 +02008#include <internal/cpumap.h>
Jiri Olsa397721e2019-07-21 13:24:16 +02009#include <perf/cpumap.h>
Arnaldo Carvalho de Melo9ae7d332012-01-19 14:07:23 -020010
Don Zickus7780c252014-04-07 14:55:21 -040011#include "perf.h"
12#include "util/debug.h"
13
Jiri Olsaf8548392019-07-21 13:23:49 +020014struct perf_cpu_map *cpu_map__new(const char *cpu_list);
15struct perf_cpu_map *cpu_map__empty_new(int nr);
Jiri Olsaf8548392019-07-21 13:23:49 +020016struct perf_cpu_map *cpu_map__new_data(struct cpu_map_data *data);
17struct perf_cpu_map *cpu_map__read(FILE *file);
18size_t cpu_map__snprint(struct perf_cpu_map *map, char *buf, size_t size);
19size_t cpu_map__snprint_mask(struct perf_cpu_map *map, char *buf, size_t size);
20size_t cpu_map__fprintf(struct perf_cpu_map *map, FILE *fp);
Kan Liang193b6bd2015-09-01 09:58:11 -040021int cpu_map__get_socket_id(int cpu);
Jiri Olsaf8548392019-07-21 13:23:49 +020022int cpu_map__get_socket(struct perf_cpu_map *map, int idx, void *data);
Kan Liangb74d8682019-06-04 15:50:40 -070023int cpu_map__get_die_id(int cpu);
Jiri Olsaf8548392019-07-21 13:23:49 +020024int cpu_map__get_die(struct perf_cpu_map *map, int idx, void *data);
Kan Liang193b6bd2015-09-01 09:58:11 -040025int cpu_map__get_core_id(int cpu);
Jiri Olsaf8548392019-07-21 13:23:49 +020026int cpu_map__get_core(struct perf_cpu_map *map, int idx, void *data);
27int cpu_map__build_socket_map(struct perf_cpu_map *cpus, struct perf_cpu_map **sockp);
28int cpu_map__build_die_map(struct perf_cpu_map *cpus, struct perf_cpu_map **diep);
29int cpu_map__build_core_map(struct perf_cpu_map *cpus, struct perf_cpu_map **corep);
30const struct perf_cpu_map *cpu_map__online(void); /* thread unsafe */
Stephane Eranian5ac59a82013-02-06 15:46:01 +010031
Jiri Olsaf8548392019-07-21 13:23:49 +020032static inline int cpu_map__socket(struct perf_cpu_map *sock, int s)
Stephane Eranian5ac59a82013-02-06 15:46:01 +010033{
34 if (!sock || s > sock->nr || s < 0)
35 return 0;
36 return sock->map[s];
37}
Arnaldo Carvalho de Melo9ae7d332012-01-19 14:07:23 -020038
Stephane Eranian12c08a92013-02-14 13:57:29 +010039static inline int cpu_map__id_to_socket(int id)
40{
Kan Liangdb5742b2019-06-04 15:50:42 -070041 return id >> 24;
42}
43
44static inline int cpu_map__id_to_die(int id)
45{
46 return (id >> 16) & 0xff;
Stephane Eranian12c08a92013-02-14 13:57:29 +010047}
48
49static inline int cpu_map__id_to_cpu(int id)
50{
51 return id & 0xffff;
52}
53
Jiri Olsaf8548392019-07-21 13:23:49 +020054static inline int cpu_map__nr(const struct perf_cpu_map *map)
Arnaldo Carvalho de Meloa14bb7a2012-09-26 12:41:14 -030055{
56 return map ? map->nr : 1;
57}
58
Jiri Olsaf8548392019-07-21 13:23:49 +020059static inline bool cpu_map__empty(const struct perf_cpu_map *map)
Arnaldo Carvalho de Meloa14bb7a2012-09-26 12:41:14 -030060{
61 return map ? map->map[0] == -1 : true;
62}
63
Don Zickus7780c252014-04-07 14:55:21 -040064int cpu__setup_cpunode_map(void);
65
Arnaldo Carvalho de Melo5ac76282016-01-26 15:51:46 -030066int cpu__max_node(void);
67int cpu__max_cpu(void);
Jan Stancek92a7e122017-02-17 12:10:24 +010068int cpu__max_present_cpu(void);
Arnaldo Carvalho de Melo5ac76282016-01-26 15:51:46 -030069int cpu__get_node(int cpu);
Don Zickus7780c252014-04-07 14:55:21 -040070
Jiri Olsaf8548392019-07-21 13:23:49 +020071int cpu_map__build_map(struct perf_cpu_map *cpus, struct perf_cpu_map **res,
72 int (*f)(struct perf_cpu_map *map, int cpu, void *data),
Jiri Olsa1fe7a302015-10-16 12:41:15 +020073 void *data);
Jiri Olsae632aa62016-04-12 15:29:25 +020074
Jiri Olsaf8548392019-07-21 13:23:49 +020075int cpu_map__cpu(struct perf_cpu_map *cpus, int idx);
76bool cpu_map__has(struct perf_cpu_map *cpus, int cpu);
77int cpu_map__idx(struct perf_cpu_map *cpus, int cpu);
Paul Mackerrasa12b51c2010-03-10 20:36:09 +110078#endif /* __PERF_CPUMAP_H */