blob: 1265f0e339204b23c9203782d8e1500699a8b9c9 [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>
Arnaldo Carvalho de Melo9ae7d332012-01-19 14:07:23 -02008
Don Zickus7780c252014-04-07 14:55:21 -04009#include "perf.h"
10#include "util/debug.h"
11
Arnaldo Carvalho de Melo60d567e2011-01-03 17:49:48 -020012struct cpu_map {
Elena Reshetovaec09a422017-02-21 17:34:56 +020013 refcount_t refcnt;
Arnaldo Carvalho de Melo60d567e2011-01-03 17:49:48 -020014 int nr;
15 int map[];
16};
17
18struct cpu_map *cpu_map__new(const char *cpu_list);
Jiri Olsa2322f572015-10-25 15:51:17 +010019struct cpu_map *cpu_map__empty_new(int nr);
Arnaldo Carvalho de Melo60d567e2011-01-03 17:49:48 -020020struct cpu_map *cpu_map__dummy_new(void);
Jiri Olsaf77b57a2015-10-25 15:51:25 +010021struct cpu_map *cpu_map__new_data(struct cpu_map_data *data);
Yan, Zheng7ae92e72012-09-10 15:53:50 +080022struct cpu_map *cpu_map__read(FILE *file);
Jiri Olsaa24020e2016-06-28 13:29:04 +020023size_t cpu_map__snprint(struct cpu_map *map, char *buf, size_t size);
Namhyung Kim4400ac82017-02-24 10:12:49 +090024size_t cpu_map__snprint_mask(struct cpu_map *map, char *buf, size_t size);
Arnaldo Carvalho de Melo9ae7d332012-01-19 14:07:23 -020025size_t cpu_map__fprintf(struct cpu_map *map, FILE *fp);
Kan Liang193b6bd2015-09-01 09:58:11 -040026int cpu_map__get_socket_id(int cpu);
Jiri Olsa1fe7a302015-10-16 12:41:15 +020027int cpu_map__get_socket(struct cpu_map *map, int idx, void *data);
Kan Liangb74d8682019-06-04 15:50:40 -070028int cpu_map__get_die_id(int cpu);
Kan Liangdb5742b2019-06-04 15:50:42 -070029int cpu_map__get_die(struct cpu_map *map, int idx, void *data);
Kan Liang193b6bd2015-09-01 09:58:11 -040030int cpu_map__get_core_id(int cpu);
Jiri Olsa1fe7a302015-10-16 12:41:15 +020031int cpu_map__get_core(struct cpu_map *map, int idx, void *data);
Stephane Eranian5ac59a82013-02-06 15:46:01 +010032int cpu_map__build_socket_map(struct cpu_map *cpus, struct cpu_map **sockp);
Kan Liangdb5742b2019-06-04 15:50:42 -070033int cpu_map__build_die_map(struct cpu_map *cpus, struct cpu_map **diep);
Stephane Eranian12c08a92013-02-14 13:57:29 +010034int cpu_map__build_core_map(struct cpu_map *cpus, struct cpu_map **corep);
Alexey Budankovf13de662019-01-22 20:50:57 +030035const struct cpu_map *cpu_map__online(void); /* thread unsafe */
Stephane Eranian5ac59a82013-02-06 15:46:01 +010036
Jiri Olsaf30a79b2015-06-23 00:36:04 +020037struct cpu_map *cpu_map__get(struct cpu_map *map);
38void cpu_map__put(struct cpu_map *map);
39
Stephane Eranian5ac59a82013-02-06 15:46:01 +010040static inline int cpu_map__socket(struct cpu_map *sock, int s)
41{
42 if (!sock || s > sock->nr || s < 0)
43 return 0;
44 return sock->map[s];
45}
Arnaldo Carvalho de Melo9ae7d332012-01-19 14:07:23 -020046
Stephane Eranian12c08a92013-02-14 13:57:29 +010047static inline int cpu_map__id_to_socket(int id)
48{
Kan Liangdb5742b2019-06-04 15:50:42 -070049 return id >> 24;
50}
51
52static inline int cpu_map__id_to_die(int id)
53{
54 return (id >> 16) & 0xff;
Stephane Eranian12c08a92013-02-14 13:57:29 +010055}
56
57static inline int cpu_map__id_to_cpu(int id)
58{
59 return id & 0xffff;
60}
61
Arnaldo Carvalho de Meloa14bb7a2012-09-26 12:41:14 -030062static inline int cpu_map__nr(const struct cpu_map *map)
63{
64 return map ? map->nr : 1;
65}
66
Sukadev Bhattiproluec1e7e42013-05-22 17:42:38 -070067static inline bool cpu_map__empty(const struct cpu_map *map)
Arnaldo Carvalho de Meloa14bb7a2012-09-26 12:41:14 -030068{
69 return map ? map->map[0] == -1 : true;
70}
71
Don Zickus7780c252014-04-07 14:55:21 -040072int cpu__setup_cpunode_map(void);
73
Arnaldo Carvalho de Melo5ac76282016-01-26 15:51:46 -030074int cpu__max_node(void);
75int cpu__max_cpu(void);
Jan Stancek92a7e122017-02-17 12:10:24 +010076int cpu__max_present_cpu(void);
Arnaldo Carvalho de Melo5ac76282016-01-26 15:51:46 -030077int cpu__get_node(int cpu);
Don Zickus7780c252014-04-07 14:55:21 -040078
Jiri Olsaf1cbb8f2015-10-16 12:41:14 +020079int cpu_map__build_map(struct cpu_map *cpus, struct cpu_map **res,
Jiri Olsa1fe7a302015-10-16 12:41:15 +020080 int (*f)(struct cpu_map *map, int cpu, void *data),
81 void *data);
Jiri Olsae632aa692016-04-12 15:29:25 +020082
Mark Rutland9a6c5822016-07-15 11:08:11 +010083int cpu_map__cpu(struct cpu_map *cpus, int idx);
Jiri Olsae632aa692016-04-12 15:29:25 +020084bool cpu_map__has(struct cpu_map *cpus, int cpu);
Mark Rutland9a6c5822016-07-15 11:08:11 +010085int cpu_map__idx(struct cpu_map *cpus, int cpu);
Paul Mackerrasa12b51c2010-03-10 20:36:09 +110086#endif /* __PERF_CPUMAP_H */