Linux Audio

Check our new training course

Yocto / OpenEmbedded training

Feb 10-13, 2025
Register
Loading...
v4.17
 1/* SPDX-License-Identifier: GPL-2.0 */
 2#ifndef __PERF_CPUMAP_H
 3#define __PERF_CPUMAP_H
 4
 5#include <stdio.h>
 6#include <stdbool.h>
 7#include <linux/refcount.h>
 
 8
 9#include "perf.h"
10#include "util/debug.h"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
12struct cpu_map {
13	refcount_t refcnt;
 
14	int nr;
15	int map[];
 
16};
17
18struct cpu_map *cpu_map__new(const char *cpu_list);
19struct cpu_map *cpu_map__empty_new(int nr);
20struct cpu_map *cpu_map__dummy_new(void);
21struct cpu_map *cpu_map__new_data(struct cpu_map_data *data);
22struct cpu_map *cpu_map__read(FILE *file);
23size_t cpu_map__snprint(struct cpu_map *map, char *buf, size_t size);
24size_t cpu_map__snprint_mask(struct cpu_map *map, char *buf, size_t size);
25size_t cpu_map__fprintf(struct cpu_map *map, FILE *fp);
26int cpu_map__get_socket_id(int cpu);
27int cpu_map__get_socket(struct cpu_map *map, int idx, void *data);
28int cpu_map__get_core_id(int cpu);
29int cpu_map__get_core(struct cpu_map *map, int idx, void *data);
30int cpu_map__build_socket_map(struct cpu_map *cpus, struct cpu_map **sockp);
31int cpu_map__build_core_map(struct cpu_map *cpus, struct cpu_map **corep);
32
33struct cpu_map *cpu_map__get(struct cpu_map *map);
34void cpu_map__put(struct cpu_map *map);
35
36static inline int cpu_map__socket(struct cpu_map *sock, int s)
37{
38	if (!sock || s > sock->nr || s < 0)
39		return 0;
40	return sock->map[s];
41}
42
43static inline int cpu_map__id_to_socket(int id)
44{
45	return id >> 16;
46}
47
48static inline int cpu_map__id_to_cpu(int id)
49{
50	return id & 0xffff;
51}
 
52
53static inline int cpu_map__nr(const struct cpu_map *map)
54{
55	return map ? map->nr : 1;
56}
 
57
58static inline bool cpu_map__empty(const struct cpu_map *map)
 
 
 
59{
60	return map ? map->map[0] == -1 : true;
61}
62
63int cpu__setup_cpunode_map(void);
64
65int cpu__max_node(void);
66int cpu__max_cpu(void);
67int cpu__max_present_cpu(void);
68int cpu__get_node(int cpu);
69
70int cpu_map__build_map(struct cpu_map *cpus, struct cpu_map **res,
71		       int (*f)(struct cpu_map *map, int cpu, void *data),
72		       void *data);
73
74int cpu_map__cpu(struct cpu_map *cpus, int idx);
75bool cpu_map__has(struct cpu_map *cpus, int cpu);
76int cpu_map__idx(struct cpu_map *cpus, int cpu);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77#endif /* __PERF_CPUMAP_H */
v6.13.7
  1/* SPDX-License-Identifier: GPL-2.0 */
  2#ifndef __PERF_CPUMAP_H
  3#define __PERF_CPUMAP_H
  4
 
  5#include <stdbool.h>
  6#include <stdio.h>
  7#include <perf/cpumap.h>
  8
  9/** Identify where counts are aggregated, -1 implies not to aggregate. */
 10struct aggr_cpu_id {
 11	/** A value in the range 0 to number of threads. */
 12	int thread_idx;
 13	/** The numa node X as read from /sys/devices/system/node/nodeX. */
 14	int node;
 15	/**
 16	 * The socket number as read from
 17	 * /sys/devices/system/cpu/cpuX/topology/physical_package_id.
 18	 */
 19	int socket;
 20	/** The die id as read from /sys/devices/system/cpu/cpuX/topology/die_id. */
 21	int die;
 22	/** The cluster id as read from /sys/devices/system/cpu/cpuX/topology/cluster_id */
 23	int cluster;
 24	/** The cache level as read from /sys/devices/system/cpu/cpuX/cache/indexY/level */
 25	int cache_lvl;
 26	/**
 27	 * The cache instance ID, which is the first CPU in the
 28	 * /sys/devices/system/cpu/cpuX/cache/indexY/shared_cpu_list
 29	 */
 30	int cache;
 31	/** The core id as read from /sys/devices/system/cpu/cpuX/topology/core_id. */
 32	int core;
 33	/** CPU aggregation, note there is one CPU for each SMT thread. */
 34	struct perf_cpu cpu;
 35};
 36
 37/** A collection of aggr_cpu_id values, the "built" version is sorted and uniqued. */
 38struct cpu_aggr_map {
 39	/** Number of valid entries. */
 40	int nr;
 41	/** The entries. */
 42	struct aggr_cpu_id map[];
 43};
 44
 45#define cpu_aggr_map__for_each_idx(idx, aggr_map)				\
 46	for ((idx) = 0; (idx) < aggr_map->nr; (idx)++)
 
 
 
 
 
 
 
 
 
 
 
 
 47
 48struct perf_record_cpu_map_data;
 
 49
 50bool perf_record_cpu_map_data__test_bit(int i, const struct perf_record_cpu_map_data *data);
 
 
 
 
 
 51
 52struct perf_cpu_map *perf_cpu_map__empty_new(int nr);
 
 
 
 53
 54struct perf_cpu_map *cpu_map__new_data(const struct perf_record_cpu_map_data *data);
 55size_t cpu_map__snprint(struct perf_cpu_map *map, char *buf, size_t size);
 56size_t cpu_map__snprint_mask(struct perf_cpu_map *map, char *buf, size_t size);
 57size_t cpu_map__fprintf(struct perf_cpu_map *map, FILE *fp);
 58struct perf_cpu_map *cpu_map__online(void); /* thread unsafe */
 59
 60int cpu__setup_cpunode_map(void);
 61
 62int cpu__max_node(void);
 63struct perf_cpu cpu__max_cpu(void);
 64struct perf_cpu cpu__max_present_cpu(void);
 65
 66/**
 67 * cpu_map__is_dummy - Events associated with a pid, rather than a CPU, use a single dummy map with an entry of -1.
 68 */
 69static inline bool cpu_map__is_dummy(const struct perf_cpu_map *cpus)
 70{
 71	return perf_cpu_map__nr(cpus) == 1 && perf_cpu_map__cpu(cpus, 0).cpu == -1;
 72}
 73
 74/**
 75 * cpu__get_node - Returns the numa node X as read from
 76 * /sys/devices/system/node/nodeX for the given CPU.
 77 */
 78int cpu__get_node(struct perf_cpu cpu);
 79/**
 80 * cpu__get_socket_id - Returns the socket number as read from
 81 * /sys/devices/system/cpu/cpuX/topology/physical_package_id for the given CPU.
 82 */
 83int cpu__get_socket_id(struct perf_cpu cpu);
 84/**
 85 * cpu__get_die_id - Returns the die id as read from
 86 * /sys/devices/system/cpu/cpuX/topology/die_id for the given CPU.
 87 */
 88int cpu__get_die_id(struct perf_cpu cpu);
 89/**
 90 * cpu__get_cluster_id - Returns the cluster id as read from
 91 * /sys/devices/system/cpu/cpuX/topology/cluster_id for the given CPU
 92 */
 93int cpu__get_cluster_id(struct perf_cpu cpu);
 94/**
 95 * cpu__get_core_id - Returns the core id as read from
 96 * /sys/devices/system/cpu/cpuX/topology/core_id for the given CPU.
 97 */
 98int cpu__get_core_id(struct perf_cpu cpu);
 99
100/**
101 * cpu_aggr_map__empty_new - Create a cpu_aggr_map of size nr with every entry
102 * being empty.
103 */
104struct cpu_aggr_map *cpu_aggr_map__empty_new(int nr);
105
106typedef struct aggr_cpu_id (*aggr_cpu_id_get_t)(struct perf_cpu cpu, void *data);
107
108/**
109 * cpu_aggr_map__new - Create a cpu_aggr_map with an aggr_cpu_id for each cpu in
110 * cpus. The aggr_cpu_id is created with 'get_id' that may have a data value
111 * passed to it. The cpu_aggr_map is sorted with duplicate values removed.
112 */
113struct cpu_aggr_map *cpu_aggr_map__new(const struct perf_cpu_map *cpus,
114				       aggr_cpu_id_get_t get_id,
115				       void *data, bool needs_sort);
116
117bool aggr_cpu_id__equal(const struct aggr_cpu_id *a, const struct aggr_cpu_id *b);
118bool aggr_cpu_id__is_empty(const struct aggr_cpu_id *a);
119struct aggr_cpu_id aggr_cpu_id__empty(void);
120
121
122/**
123 * aggr_cpu_id__socket - Create an aggr_cpu_id with the socket populated with
124 * the socket for cpu. The function signature is compatible with
125 * aggr_cpu_id_get_t.
126 */
127struct aggr_cpu_id aggr_cpu_id__socket(struct perf_cpu cpu, void *data);
128/**
129 * aggr_cpu_id__die - Create an aggr_cpu_id with the die and socket populated
130 * with the die and socket for cpu. The function signature is compatible with
131 * aggr_cpu_id_get_t.
132 */
133struct aggr_cpu_id aggr_cpu_id__die(struct perf_cpu cpu, void *data);
134/**
135 * aggr_cpu_id__cluster - Create an aggr_cpu_id with cluster, die and socket
136 * populated with the cluster, die and socket for cpu. The function signature
137 * is compatible with aggr_cpu_id_get_t.
138 */
139struct aggr_cpu_id aggr_cpu_id__cluster(struct perf_cpu cpu, void *data);
140/**
141 * aggr_cpu_id__core - Create an aggr_cpu_id with the core, cluster, die and
142 * socket populated with the core, die and socket for cpu. The function
143 * signature is compatible with aggr_cpu_id_get_t.
144 */
145struct aggr_cpu_id aggr_cpu_id__core(struct perf_cpu cpu, void *data);
146/**
147 * aggr_cpu_id__core - Create an aggr_cpu_id with the cpu, core, die and socket
148 * populated with the cpu, core, die and socket for cpu. The function signature
149 * is compatible with aggr_cpu_id_get_t.
150 */
151struct aggr_cpu_id aggr_cpu_id__cpu(struct perf_cpu cpu, void *data);
152/**
153 * aggr_cpu_id__node - Create an aggr_cpu_id with the numa node populated for
154 * cpu. The function signature is compatible with aggr_cpu_id_get_t.
155 */
156struct aggr_cpu_id aggr_cpu_id__node(struct perf_cpu cpu, void *data);
157/**
158 * aggr_cpu_id__global - Create an aggr_cpu_id for global aggregation.
159 * The function signature is compatible with aggr_cpu_id_get_t.
160 */
161struct aggr_cpu_id aggr_cpu_id__global(struct perf_cpu cpu, void *data);
162#endif /* __PERF_CPUMAP_H */