Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef __PERF_CPUMAP_H
0003 #define __PERF_CPUMAP_H
0004 
0005 #include <stdbool.h>
0006 #include <stdio.h>
0007 #include <internal/cpumap.h>
0008 #include <perf/cpumap.h>
0009 
0010 /** Identify where counts are aggregated, -1 implies not to aggregate. */
0011 struct aggr_cpu_id {
0012     /** A value in the range 0 to number of threads. */
0013     int thread;
0014     /** The numa node X as read from /sys/devices/system/node/nodeX. */
0015     int node;
0016     /**
0017      * The socket number as read from
0018      * /sys/devices/system/cpu/cpuX/topology/physical_package_id.
0019      */
0020     int socket;
0021     /** The die id as read from /sys/devices/system/cpu/cpuX/topology/die_id. */
0022     int die;
0023     /** The core id as read from /sys/devices/system/cpu/cpuX/topology/core_id. */
0024     int core;
0025     /** CPU aggregation, note there is one CPU for each SMT thread. */
0026     struct perf_cpu cpu;
0027 };
0028 
0029 /** A collection of aggr_cpu_id values, the "built" version is sorted and uniqued. */
0030 struct cpu_aggr_map {
0031     refcount_t refcnt;
0032     /** Number of valid entries. */
0033     int nr;
0034     /** The entries. */
0035     struct aggr_cpu_id map[];
0036 };
0037 
0038 struct perf_record_cpu_map_data;
0039 
0040 bool perf_record_cpu_map_data__test_bit(int i, const struct perf_record_cpu_map_data *data);
0041 
0042 struct perf_cpu_map *perf_cpu_map__empty_new(int nr);
0043 
0044 struct perf_cpu_map *cpu_map__new_data(const struct perf_record_cpu_map_data *data);
0045 size_t cpu_map__snprint(struct perf_cpu_map *map, char *buf, size_t size);
0046 size_t cpu_map__snprint_mask(struct perf_cpu_map *map, char *buf, size_t size);
0047 size_t cpu_map__fprintf(struct perf_cpu_map *map, FILE *fp);
0048 const struct perf_cpu_map *cpu_map__online(void); /* thread unsafe */
0049 
0050 int cpu__setup_cpunode_map(void);
0051 
0052 int cpu__max_node(void);
0053 struct perf_cpu cpu__max_cpu(void);
0054 struct perf_cpu cpu__max_present_cpu(void);
0055 
0056 /**
0057  * cpu_map__is_dummy - Events associated with a pid, rather than a CPU, use a single dummy map with an entry of -1.
0058  */
0059 static inline bool cpu_map__is_dummy(struct perf_cpu_map *cpus)
0060 {
0061     return perf_cpu_map__nr(cpus) == 1 && perf_cpu_map__cpu(cpus, 0).cpu == -1;
0062 }
0063 
0064 /**
0065  * cpu__get_node - Returns the numa node X as read from
0066  * /sys/devices/system/node/nodeX for the given CPU.
0067  */
0068 int cpu__get_node(struct perf_cpu cpu);
0069 /**
0070  * cpu__get_socket_id - Returns the socket number as read from
0071  * /sys/devices/system/cpu/cpuX/topology/physical_package_id for the given CPU.
0072  */
0073 int cpu__get_socket_id(struct perf_cpu cpu);
0074 /**
0075  * cpu__get_die_id - Returns the die id as read from
0076  * /sys/devices/system/cpu/cpuX/topology/die_id for the given CPU.
0077  */
0078 int cpu__get_die_id(struct perf_cpu cpu);
0079 /**
0080  * cpu__get_core_id - Returns the core id as read from
0081  * /sys/devices/system/cpu/cpuX/topology/core_id for the given CPU.
0082  */
0083 int cpu__get_core_id(struct perf_cpu cpu);
0084 
0085 /**
0086  * cpu_aggr_map__empty_new - Create a cpu_aggr_map of size nr with every entry
0087  * being empty.
0088  */
0089 struct cpu_aggr_map *cpu_aggr_map__empty_new(int nr);
0090 
0091 typedef struct aggr_cpu_id (*aggr_cpu_id_get_t)(struct perf_cpu cpu, void *data);
0092 
0093 /**
0094  * cpu_aggr_map__new - Create a cpu_aggr_map with an aggr_cpu_id for each cpu in
0095  * cpus. The aggr_cpu_id is created with 'get_id' that may have a data value
0096  * passed to it. The cpu_aggr_map is sorted with duplicate values removed.
0097  */
0098 struct cpu_aggr_map *cpu_aggr_map__new(const struct perf_cpu_map *cpus,
0099                        aggr_cpu_id_get_t get_id,
0100                        void *data);
0101 
0102 bool aggr_cpu_id__equal(const struct aggr_cpu_id *a, const struct aggr_cpu_id *b);
0103 bool aggr_cpu_id__is_empty(const struct aggr_cpu_id *a);
0104 struct aggr_cpu_id aggr_cpu_id__empty(void);
0105 
0106 
0107 /**
0108  * aggr_cpu_id__socket - Create an aggr_cpu_id with the socket populated with
0109  * the socket for cpu. The function signature is compatible with
0110  * aggr_cpu_id_get_t.
0111  */
0112 struct aggr_cpu_id aggr_cpu_id__socket(struct perf_cpu cpu, void *data);
0113 /**
0114  * aggr_cpu_id__die - Create an aggr_cpu_id with the die and socket populated
0115  * with the die and socket for cpu. The function signature is compatible with
0116  * aggr_cpu_id_get_t.
0117  */
0118 struct aggr_cpu_id aggr_cpu_id__die(struct perf_cpu cpu, void *data);
0119 /**
0120  * aggr_cpu_id__core - Create an aggr_cpu_id with the core, die and socket
0121  * populated with the core, die and socket for cpu. The function signature is
0122  * compatible with aggr_cpu_id_get_t.
0123  */
0124 struct aggr_cpu_id aggr_cpu_id__core(struct perf_cpu cpu, void *data);
0125 /**
0126  * aggr_cpu_id__core - Create an aggr_cpu_id with the cpu, core, die and socket
0127  * populated with the cpu, core, die and socket for cpu. The function signature
0128  * is compatible with aggr_cpu_id_get_t.
0129  */
0130 struct aggr_cpu_id aggr_cpu_id__cpu(struct perf_cpu cpu, void *data);
0131 /**
0132  * aggr_cpu_id__node - Create an aggr_cpu_id with the numa node populated for
0133  * cpu. The function signature is compatible with aggr_cpu_id_get_t.
0134  */
0135 struct aggr_cpu_id aggr_cpu_id__node(struct perf_cpu cpu, void *data);
0136 
0137 #endif /* __PERF_CPUMAP_H */