Linux Audio

Check our new training course

Linux BSP upgrade and security maintenance

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