2 /* SPDX-License-Identifier: GPL-2.0 */
3 /* THIS FILE WAS AUTOGENERATED BY jevents.py arch=none model=none ! */
5 #include <pmu-events/pmu-events.h>
6 #include "util/header.h"
11 struct compact_pmu_event
{
15 struct pmu_table_entry
{
16 const struct compact_pmu_event
*entries
;
18 struct compact_pmu_event pmu_name
;
21 static const char *const big_c_string
=
22 /* offset=0 */ "tool\000"
23 /* offset=5 */ "duration_time\000tool\000Wall clock interval time in nanoseconds\000config=1\000\00000\000\000"
24 /* offset=78 */ "user_time\000tool\000User (non-kernel) time in nanoseconds\000config=2\000\00000\000\000"
25 /* offset=145 */ "system_time\000tool\000System/kernel time in nanoseconds\000config=3\000\00000\000\000"
26 /* offset=210 */ "has_pmem\000tool\0001 if persistent memory installed otherwise 0\000config=4\000\00000\000\000"
27 /* offset=283 */ "num_cores\000tool\000Number of cores. A core consists of 1 or more thread, with each thread being associated with a logical Linux CPU\000config=5\000\00000\000\000"
28 /* offset=425 */ "num_cpus\000tool\000Number of logical Linux CPUs. There may be multiple such CPUs on a core\000config=6\000\00000\000\000"
29 /* offset=525 */ "num_cpus_online\000tool\000Number of online logical Linux CPUs. There may be multiple such CPUs on a core\000config=7\000\00000\000\000"
30 /* offset=639 */ "num_dies\000tool\000Number of dies. Each die has 1 or more cores\000config=8\000\00000\000\000"
31 /* offset=712 */ "num_packages\000tool\000Number of packages. Each package has 1 or more die\000config=9\000\00000\000\000"
32 /* offset=795 */ "slots\000tool\000Number of functional units that in parallel can execute parts of an instruction\000config=0xa\000\00000\000\000"
33 /* offset=902 */ "smt_on\000tool\0001 if simultaneous multithreading (aka hyperthreading) is enable otherwise 0\000config=0xb\000\00000\000\000"
34 /* offset=1006 */ "system_tsc_freq\000tool\000The amount a Time Stamp Counter (TSC) increases per second\000config=0xc\000\00000\000\000"
35 /* offset=1102 */ "default_core\000"
36 /* offset=1115 */ "bp_l1_btb_correct\000branch\000L1 BTB Correction\000event=0x8a\000\00000\000\000"
37 /* offset=1174 */ "bp_l2_btb_correct\000branch\000L2 BTB Correction\000event=0x8b\000\00000\000\000"
38 /* offset=1233 */ "l3_cache_rd\000cache\000L3 cache access, read\000event=0x40\000\00000\000Attributable Level 3 cache access, read\000"
39 /* offset=1328 */ "segment_reg_loads.any\000other\000Number of segment register loads\000event=6,period=200000,umask=0x80\000\00000\000\000"
40 /* offset=1427 */ "dispatch_blocked.any\000other\000Memory cluster signals to block micro-op dispatch for any reason\000event=9,period=200000,umask=0x20\000\00000\000\000"
41 /* offset=1557 */ "eist_trans\000other\000Number of Enhanced Intel SpeedStep(R) Technology (EIST) transitions\000event=0x3a,period=200000\000\00000\000\000"
42 /* offset=1672 */ "hisi_sccl,ddrc\000"
43 /* offset=1687 */ "uncore_hisi_ddrc.flux_wcmd\000uncore\000DDRC write commands\000event=2\000\00000\000DDRC write commands\000"
44 /* offset=1773 */ "uncore_cbox\000"
45 /* offset=1785 */ "unc_cbo_xsnp_response.miss_eviction\000uncore\000A cross-core snoop resulted from L3 Eviction which misses in some processor core\000event=0x22,umask=0x81\000\00000\000A cross-core snoop resulted from L3 Eviction which misses in some processor core\000"
46 /* offset=2016 */ "event-hyphen\000uncore\000UNC_CBO_HYPHEN\000event=0xe0\000\00000\000UNC_CBO_HYPHEN\000"
47 /* offset=2081 */ "event-two-hyph\000uncore\000UNC_CBO_TWO_HYPH\000event=0xc0\000\00000\000UNC_CBO_TWO_HYPH\000"
48 /* offset=2152 */ "hisi_sccl,l3c\000"
49 /* offset=2166 */ "uncore_hisi_l3c.rd_hit_cpipe\000uncore\000Total read hits\000event=7\000\00000\000Total read hits\000"
50 /* offset=2246 */ "uncore_imc_free_running\000"
51 /* offset=2270 */ "uncore_imc_free_running.cache_miss\000uncore\000Total cache misses\000event=0x12\000\00000\000Total cache misses\000"
52 /* offset=2365 */ "uncore_imc\000"
53 /* offset=2376 */ "uncore_imc.cache_hits\000uncore\000Total cache hits\000event=0x34\000\00000\000Total cache hits\000"
54 /* offset=2454 */ "uncore_sys_ddr_pmu\000"
55 /* offset=2473 */ "sys_ddr_pmu.write_cycles\000uncore\000ddr write-cycles event\000event=0x2b\000v8\00000\000\000"
56 /* offset=2546 */ "uncore_sys_ccn_pmu\000"
57 /* offset=2565 */ "sys_ccn_pmu.read_cycles\000uncore\000ccn read-cycles event\000config=0x2c\0000x01\00000\000\000"
58 /* offset=2639 */ "uncore_sys_cmn_pmu\000"
59 /* offset=2658 */ "sys_cmn_pmu.hnf_cache_miss\000uncore\000Counts total cache misses in first lookup result (high priority)\000eventid=1,type=5\000(434|436|43c|43a).*\00000\000\000"
60 /* offset=2798 */ "CPI\000\0001 / IPC\000\000\000\000\000\000\000\00000"
61 /* offset=2820 */ "IPC\000group1\000inst_retired.any / cpu_clk_unhalted.thread\000\000\000\000\000\000\000\00000"
62 /* offset=2883 */ "Frontend_Bound_SMT\000\000idq_uops_not_delivered.core / (4 * (cpu_clk_unhalted.thread / 2 * (1 + cpu_clk_unhalted.one_thread_active / cpu_clk_unhalted.ref_xclk)))\000\000\000\000\000\000\000\00000"
63 /* offset=3049 */ "dcache_miss_cpi\000\000l1d\\-loads\\-misses / inst_retired.any\000\000\000\000\000\000\000\00000"
64 /* offset=3113 */ "icache_miss_cycles\000\000l1i\\-loads\\-misses / inst_retired.any\000\000\000\000\000\000\000\00000"
65 /* offset=3180 */ "cache_miss_cycles\000group1\000dcache_miss_cpi + icache_miss_cycles\000\000\000\000\000\000\000\00000"
66 /* offset=3251 */ "DCache_L2_All_Hits\000\000l2_rqsts.demand_data_rd_hit + l2_rqsts.pf_hit + l2_rqsts.rfo_hit\000\000\000\000\000\000\000\00000"
67 /* offset=3345 */ "DCache_L2_All_Miss\000\000max(l2_rqsts.all_demand_data_rd - l2_rqsts.demand_data_rd_hit, 0) + l2_rqsts.pf_miss + l2_rqsts.rfo_miss\000\000\000\000\000\000\000\00000"
68 /* offset=3479 */ "DCache_L2_All\000\000DCache_L2_All_Hits + DCache_L2_All_Miss\000\000\000\000\000\000\000\00000"
69 /* offset=3543 */ "DCache_L2_Hits\000\000d_ratio(DCache_L2_All_Hits, DCache_L2_All)\000\000\000\000\000\000\000\00000"
70 /* offset=3611 */ "DCache_L2_Misses\000\000d_ratio(DCache_L2_All_Miss, DCache_L2_All)\000\000\000\000\000\000\000\00000"
71 /* offset=3681 */ "M1\000\000ipc + M2\000\000\000\000\000\000\000\00000"
72 /* offset=3703 */ "M2\000\000ipc + M1\000\000\000\000\000\000\000\00000"
73 /* offset=3725 */ "M3\000\0001 / M3\000\000\000\000\000\000\000\00000"
74 /* offset=3745 */ "L1D_Cache_Fill_BW\000\00064 * l1d.replacement / 1e9 / duration_time\000\000\000\000\000\000\000\00000"
77 static const struct compact_pmu_event pmu_events__common_tool
[] = {
78 { 5 }, /* duration_time\000tool\000Wall clock interval time in nanoseconds\000config=1\000\00000\000\000 */
79 { 210 }, /* has_pmem\000tool\0001 if persistent memory installed otherwise 0\000config=4\000\00000\000\000 */
80 { 283 }, /* num_cores\000tool\000Number of cores. A core consists of 1 or more thread, with each thread being associated with a logical Linux CPU\000config=5\000\00000\000\000 */
81 { 425 }, /* num_cpus\000tool\000Number of logical Linux CPUs. There may be multiple such CPUs on a core\000config=6\000\00000\000\000 */
82 { 525 }, /* num_cpus_online\000tool\000Number of online logical Linux CPUs. There may be multiple such CPUs on a core\000config=7\000\00000\000\000 */
83 { 639 }, /* num_dies\000tool\000Number of dies. Each die has 1 or more cores\000config=8\000\00000\000\000 */
84 { 712 }, /* num_packages\000tool\000Number of packages. Each package has 1 or more die\000config=9\000\00000\000\000 */
85 { 795 }, /* slots\000tool\000Number of functional units that in parallel can execute parts of an instruction\000config=0xa\000\00000\000\000 */
86 { 902 }, /* smt_on\000tool\0001 if simultaneous multithreading (aka hyperthreading) is enable otherwise 0\000config=0xb\000\00000\000\000 */
87 { 145 }, /* system_time\000tool\000System/kernel time in nanoseconds\000config=3\000\00000\000\000 */
88 { 1006 }, /* system_tsc_freq\000tool\000The amount a Time Stamp Counter (TSC) increases per second\000config=0xc\000\00000\000\000 */
89 { 78 }, /* user_time\000tool\000User (non-kernel) time in nanoseconds\000config=2\000\00000\000\000 */
93 const struct pmu_table_entry pmu_events__common
[] = {
95 .entries
= pmu_events__common_tool
,
96 .num_entries
= ARRAY_SIZE(pmu_events__common_tool
),
97 .pmu_name
= { 0 /* tool\000 */ },
101 static const struct compact_pmu_event pmu_events__test_soc_cpu_default_core
[] = {
102 { 1115 }, /* bp_l1_btb_correct\000branch\000L1 BTB Correction\000event=0x8a\000\00000\000\000 */
103 { 1174 }, /* bp_l2_btb_correct\000branch\000L2 BTB Correction\000event=0x8b\000\00000\000\000 */
104 { 1427 }, /* dispatch_blocked.any\000other\000Memory cluster signals to block micro-op dispatch for any reason\000event=9,period=200000,umask=0x20\000\00000\000\000 */
105 { 1557 }, /* eist_trans\000other\000Number of Enhanced Intel SpeedStep(R) Technology (EIST) transitions\000event=0x3a,period=200000\000\00000\000\000 */
106 { 1233 }, /* l3_cache_rd\000cache\000L3 cache access, read\000event=0x40\000\00000\000Attributable Level 3 cache access, read\000 */
107 { 1328 }, /* segment_reg_loads.any\000other\000Number of segment register loads\000event=6,period=200000,umask=0x80\000\00000\000\000 */
109 static const struct compact_pmu_event pmu_events__test_soc_cpu_hisi_sccl_ddrc
[] = {
110 { 1687 }, /* uncore_hisi_ddrc.flux_wcmd\000uncore\000DDRC write commands\000event=2\000\00000\000DDRC write commands\000 */
112 static const struct compact_pmu_event pmu_events__test_soc_cpu_hisi_sccl_l3c
[] = {
113 { 2166 }, /* uncore_hisi_l3c.rd_hit_cpipe\000uncore\000Total read hits\000event=7\000\00000\000Total read hits\000 */
115 static const struct compact_pmu_event pmu_events__test_soc_cpu_uncore_cbox
[] = {
116 { 2016 }, /* event-hyphen\000uncore\000UNC_CBO_HYPHEN\000event=0xe0\000\00000\000UNC_CBO_HYPHEN\000 */
117 { 2081 }, /* event-two-hyph\000uncore\000UNC_CBO_TWO_HYPH\000event=0xc0\000\00000\000UNC_CBO_TWO_HYPH\000 */
118 { 1785 }, /* unc_cbo_xsnp_response.miss_eviction\000uncore\000A cross-core snoop resulted from L3 Eviction which misses in some processor core\000event=0x22,umask=0x81\000\00000\000A cross-core snoop resulted from L3 Eviction which misses in some processor core\000 */
120 static const struct compact_pmu_event pmu_events__test_soc_cpu_uncore_imc
[] = {
121 { 2376 }, /* uncore_imc.cache_hits\000uncore\000Total cache hits\000event=0x34\000\00000\000Total cache hits\000 */
123 static const struct compact_pmu_event pmu_events__test_soc_cpu_uncore_imc_free_running
[] = {
124 { 2270 }, /* uncore_imc_free_running.cache_miss\000uncore\000Total cache misses\000event=0x12\000\00000\000Total cache misses\000 */
128 const struct pmu_table_entry pmu_events__test_soc_cpu
[] = {
130 .entries
= pmu_events__test_soc_cpu_default_core
,
131 .num_entries
= ARRAY_SIZE(pmu_events__test_soc_cpu_default_core
),
132 .pmu_name
= { 1102 /* default_core\000 */ },
135 .entries
= pmu_events__test_soc_cpu_hisi_sccl_ddrc
,
136 .num_entries
= ARRAY_SIZE(pmu_events__test_soc_cpu_hisi_sccl_ddrc
),
137 .pmu_name
= { 1672 /* hisi_sccl,ddrc\000 */ },
140 .entries
= pmu_events__test_soc_cpu_hisi_sccl_l3c
,
141 .num_entries
= ARRAY_SIZE(pmu_events__test_soc_cpu_hisi_sccl_l3c
),
142 .pmu_name
= { 2152 /* hisi_sccl,l3c\000 */ },
145 .entries
= pmu_events__test_soc_cpu_uncore_cbox
,
146 .num_entries
= ARRAY_SIZE(pmu_events__test_soc_cpu_uncore_cbox
),
147 .pmu_name
= { 1773 /* uncore_cbox\000 */ },
150 .entries
= pmu_events__test_soc_cpu_uncore_imc
,
151 .num_entries
= ARRAY_SIZE(pmu_events__test_soc_cpu_uncore_imc
),
152 .pmu_name
= { 2365 /* uncore_imc\000 */ },
155 .entries
= pmu_events__test_soc_cpu_uncore_imc_free_running
,
156 .num_entries
= ARRAY_SIZE(pmu_events__test_soc_cpu_uncore_imc_free_running
),
157 .pmu_name
= { 2246 /* uncore_imc_free_running\000 */ },
161 static const struct compact_pmu_event pmu_metrics__test_soc_cpu_default_core
[] = {
162 { 2798 }, /* CPI\000\0001 / IPC\000\000\000\000\000\000\000\00000 */
163 { 3479 }, /* DCache_L2_All\000\000DCache_L2_All_Hits + DCache_L2_All_Miss\000\000\000\000\000\000\000\00000 */
164 { 3251 }, /* DCache_L2_All_Hits\000\000l2_rqsts.demand_data_rd_hit + l2_rqsts.pf_hit + l2_rqsts.rfo_hit\000\000\000\000\000\000\000\00000 */
165 { 3345 }, /* DCache_L2_All_Miss\000\000max(l2_rqsts.all_demand_data_rd - l2_rqsts.demand_data_rd_hit, 0) + l2_rqsts.pf_miss + l2_rqsts.rfo_miss\000\000\000\000\000\000\000\00000 */
166 { 3543 }, /* DCache_L2_Hits\000\000d_ratio(DCache_L2_All_Hits, DCache_L2_All)\000\000\000\000\000\000\000\00000 */
167 { 3611 }, /* DCache_L2_Misses\000\000d_ratio(DCache_L2_All_Miss, DCache_L2_All)\000\000\000\000\000\000\000\00000 */
168 { 2883 }, /* Frontend_Bound_SMT\000\000idq_uops_not_delivered.core / (4 * (cpu_clk_unhalted.thread / 2 * (1 + cpu_clk_unhalted.one_thread_active / cpu_clk_unhalted.ref_xclk)))\000\000\000\000\000\000\000\00000 */
169 { 2820 }, /* IPC\000group1\000inst_retired.any / cpu_clk_unhalted.thread\000\000\000\000\000\000\000\00000 */
170 { 3745 }, /* L1D_Cache_Fill_BW\000\00064 * l1d.replacement / 1e9 / duration_time\000\000\000\000\000\000\000\00000 */
171 { 3681 }, /* M1\000\000ipc + M2\000\000\000\000\000\000\000\00000 */
172 { 3703 }, /* M2\000\000ipc + M1\000\000\000\000\000\000\000\00000 */
173 { 3725 }, /* M3\000\0001 / M3\000\000\000\000\000\000\000\00000 */
174 { 3180 }, /* cache_miss_cycles\000group1\000dcache_miss_cpi + icache_miss_cycles\000\000\000\000\000\000\000\00000 */
175 { 3049 }, /* dcache_miss_cpi\000\000l1d\\-loads\\-misses / inst_retired.any\000\000\000\000\000\000\000\00000 */
176 { 3113 }, /* icache_miss_cycles\000\000l1i\\-loads\\-misses / inst_retired.any\000\000\000\000\000\000\000\00000 */
180 const struct pmu_table_entry pmu_metrics__test_soc_cpu
[] = {
182 .entries
= pmu_metrics__test_soc_cpu_default_core
,
183 .num_entries
= ARRAY_SIZE(pmu_metrics__test_soc_cpu_default_core
),
184 .pmu_name
= { 1102 /* default_core\000 */ },
188 static const struct compact_pmu_event pmu_events__test_soc_sys_uncore_sys_ccn_pmu
[] = {
189 { 2565 }, /* sys_ccn_pmu.read_cycles\000uncore\000ccn read-cycles event\000config=0x2c\0000x01\00000\000\000 */
191 static const struct compact_pmu_event pmu_events__test_soc_sys_uncore_sys_cmn_pmu
[] = {
192 { 2658 }, /* sys_cmn_pmu.hnf_cache_miss\000uncore\000Counts total cache misses in first lookup result (high priority)\000eventid=1,type=5\000(434|436|43c|43a).*\00000\000\000 */
194 static const struct compact_pmu_event pmu_events__test_soc_sys_uncore_sys_ddr_pmu
[] = {
195 { 2473 }, /* sys_ddr_pmu.write_cycles\000uncore\000ddr write-cycles event\000event=0x2b\000v8\00000\000\000 */
199 const struct pmu_table_entry pmu_events__test_soc_sys
[] = {
201 .entries
= pmu_events__test_soc_sys_uncore_sys_ccn_pmu
,
202 .num_entries
= ARRAY_SIZE(pmu_events__test_soc_sys_uncore_sys_ccn_pmu
),
203 .pmu_name
= { 2546 /* uncore_sys_ccn_pmu\000 */ },
206 .entries
= pmu_events__test_soc_sys_uncore_sys_cmn_pmu
,
207 .num_entries
= ARRAY_SIZE(pmu_events__test_soc_sys_uncore_sys_cmn_pmu
),
208 .pmu_name
= { 2639 /* uncore_sys_cmn_pmu\000 */ },
211 .entries
= pmu_events__test_soc_sys_uncore_sys_ddr_pmu
,
212 .num_entries
= ARRAY_SIZE(pmu_events__test_soc_sys_uncore_sys_ddr_pmu
),
213 .pmu_name
= { 2454 /* uncore_sys_ddr_pmu\000 */ },
218 /* Struct used to make the PMU event table implementation opaque to callers. */
219 struct pmu_events_table
{
220 const struct pmu_table_entry
*pmus
;
224 /* Struct used to make the PMU metric table implementation opaque to callers. */
225 struct pmu_metrics_table
{
226 const struct pmu_table_entry
*pmus
;
231 * Map a CPU to its table of PMU events. The CPU is identified by the
232 * cpuid field, which is an arch-specific identifier for the CPU.
233 * The identifier specified in tools/perf/pmu-events/arch/xxx/mapfile
234 * must match the get_cpuid_str() in tools/perf/arch/xxx/util/header.c)
236 * The cpuid can contain any character other than the comma.
238 struct pmu_events_map
{
241 struct pmu_events_table event_table
;
242 struct pmu_metrics_table metric_table
;
246 * Global table mapping each known CPU for the architecture to its
247 * table of PMU events.
249 const struct pmu_events_map pmu_events_map
[] = {
254 .pmus
= pmu_events__common
,
255 .num_pmus
= ARRAY_SIZE(pmu_events__common
),
263 .pmus
= pmu_events__test_soc_cpu
,
264 .num_pmus
= ARRAY_SIZE(pmu_events__test_soc_cpu
),
267 .pmus
= pmu_metrics__test_soc_cpu
,
268 .num_pmus
= ARRAY_SIZE(pmu_metrics__test_soc_cpu
),
274 .event_table
= { 0, 0 },
275 .metric_table
= { 0, 0 },
279 struct pmu_sys_events
{
281 struct pmu_events_table event_table
;
282 struct pmu_metrics_table metric_table
;
285 static const struct pmu_sys_events pmu_sys_event_tables
[] = {
288 .pmus
= pmu_events__test_soc_sys
,
289 .num_pmus
= ARRAY_SIZE(pmu_events__test_soc_sys
)
291 .name
= "pmu_events__test_soc_sys",
294 .event_table
= { 0, 0 },
295 .metric_table
= { 0, 0 },
299 static void decompress_event(int offset
, struct pmu_event
*pe
)
301 const char *p
= &big_c_string
[offset
];
303 pe
->name
= (*p
== '\0' ? NULL
: p
);
305 pe
->topic
= (*p
== '\0' ? NULL
: p
);
307 pe
->desc
= (*p
== '\0' ? NULL
: p
);
309 pe
->event
= (*p
== '\0' ? NULL
: p
);
311 pe
->compat
= (*p
== '\0' ? NULL
: p
);
313 pe
->deprecated
= *p
- '0';
315 pe
->perpkg
= *p
- '0';
317 pe
->unit
= (*p
== '\0' ? NULL
: p
);
319 pe
->long_desc
= (*p
== '\0' ? NULL
: p
);
322 static void decompress_metric(int offset
, struct pmu_metric
*pm
)
324 const char *p
= &big_c_string
[offset
];
326 pm
->metric_name
= (*p
== '\0' ? NULL
: p
);
328 pm
->metric_group
= (*p
== '\0' ? NULL
: p
);
330 pm
->metric_expr
= (*p
== '\0' ? NULL
: p
);
332 pm
->metric_threshold
= (*p
== '\0' ? NULL
: p
);
334 pm
->desc
= (*p
== '\0' ? NULL
: p
);
336 pm
->long_desc
= (*p
== '\0' ? NULL
: p
);
338 pm
->unit
= (*p
== '\0' ? NULL
: p
);
340 pm
->compat
= (*p
== '\0' ? NULL
: p
);
342 pm
->metricgroup_no_group
= (*p
== '\0' ? NULL
: p
);
344 pm
->default_metricgroup_name
= (*p
== '\0' ? NULL
: p
);
346 pm
->aggr_mode
= *p
- '0';
348 pm
->event_grouping
= *p
- '0';
351 static int pmu_events_table__for_each_event_pmu(const struct pmu_events_table
*table
,
352 const struct pmu_table_entry
*pmu
,
353 pmu_event_iter_fn fn
,
357 struct pmu_event pe
= {
358 .pmu
= &big_c_string
[pmu
->pmu_name
.offset
],
361 for (uint32_t i
= 0; i
< pmu
->num_entries
; i
++) {
362 decompress_event(pmu
->entries
[i
].offset
, &pe
);
365 ret
= fn(&pe
, table
, data
);
372 static int pmu_events_table__find_event_pmu(const struct pmu_events_table
*table
,
373 const struct pmu_table_entry
*pmu
,
375 pmu_event_iter_fn fn
,
378 struct pmu_event pe
= {
379 .pmu
= &big_c_string
[pmu
->pmu_name
.offset
],
381 int low
= 0, high
= pmu
->num_entries
- 1;
383 while (low
<= high
) {
384 int cmp
, mid
= (low
+ high
) / 2;
386 decompress_event(pmu
->entries
[mid
].offset
, &pe
);
388 if (!pe
.name
&& !name
)
391 if (!pe
.name
&& name
) {
395 if (pe
.name
&& !name
) {
400 cmp
= strcasecmp(pe
.name
, name
);
410 return fn
? fn(&pe
, table
, data
) : 0;
412 return PMU_EVENTS__NOT_FOUND
;
415 int pmu_events_table__for_each_event(const struct pmu_events_table
*table
,
416 struct perf_pmu
*pmu
,
417 pmu_event_iter_fn fn
,
420 for (size_t i
= 0; i
< table
->num_pmus
; i
++) {
421 const struct pmu_table_entry
*table_pmu
= &table
->pmus
[i
];
422 const char *pmu_name
= &big_c_string
[table_pmu
->pmu_name
.offset
];
425 if (pmu
&& !pmu__name_match(pmu
, pmu_name
))
428 ret
= pmu_events_table__for_each_event_pmu(table
, table_pmu
, fn
, data
);
435 int pmu_events_table__find_event(const struct pmu_events_table
*table
,
436 struct perf_pmu
*pmu
,
438 pmu_event_iter_fn fn
,
441 for (size_t i
= 0; i
< table
->num_pmus
; i
++) {
442 const struct pmu_table_entry
*table_pmu
= &table
->pmus
[i
];
443 const char *pmu_name
= &big_c_string
[table_pmu
->pmu_name
.offset
];
446 if (!pmu__name_match(pmu
, pmu_name
))
449 ret
= pmu_events_table__find_event_pmu(table
, table_pmu
, name
, fn
, data
);
450 if (ret
!= PMU_EVENTS__NOT_FOUND
)
453 return PMU_EVENTS__NOT_FOUND
;
456 size_t pmu_events_table__num_events(const struct pmu_events_table
*table
,
457 struct perf_pmu
*pmu
)
461 for (size_t i
= 0; i
< table
->num_pmus
; i
++) {
462 const struct pmu_table_entry
*table_pmu
= &table
->pmus
[i
];
463 const char *pmu_name
= &big_c_string
[table_pmu
->pmu_name
.offset
];
465 if (pmu__name_match(pmu
, pmu_name
))
466 count
+= table_pmu
->num_entries
;
471 static int pmu_metrics_table__for_each_metric_pmu(const struct pmu_metrics_table
*table
,
472 const struct pmu_table_entry
*pmu
,
473 pmu_metric_iter_fn fn
,
477 struct pmu_metric pm
= {
478 .pmu
= &big_c_string
[pmu
->pmu_name
.offset
],
481 for (uint32_t i
= 0; i
< pmu
->num_entries
; i
++) {
482 decompress_metric(pmu
->entries
[i
].offset
, &pm
);
485 ret
= fn(&pm
, table
, data
);
492 int pmu_metrics_table__for_each_metric(const struct pmu_metrics_table
*table
,
493 pmu_metric_iter_fn fn
,
496 for (size_t i
= 0; i
< table
->num_pmus
; i
++) {
497 int ret
= pmu_metrics_table__for_each_metric_pmu(table
, &table
->pmus
[i
],
506 static const struct pmu_events_map
*map_for_cpu(struct perf_cpu cpu
)
509 const struct pmu_events_map
*map
;
513 const struct pmu_events_map
*map
;
516 static bool has_last_result
, has_last_map_search
;
517 const struct pmu_events_map
*map
= NULL
;
521 if (has_last_result
&& last_result
.cpu
.cpu
== cpu
.cpu
)
522 return last_result
.map
;
524 cpuid
= get_cpuid_allow_env_override(cpu
);
527 * On some platforms which uses cpus map, cpuid can be NULL for
528 * PMUs other than CORE PMUs.
531 goto out_update_last_result
;
533 if (has_last_map_search
&& !strcmp(last_map_search
.cpuid
, cpuid
)) {
534 map
= last_map_search
.map
;
539 map
= &pmu_events_map
[i
++];
546 if (!strcmp_cpuid_str(map
->cpuid
, cpuid
))
549 free(last_map_search
.cpuid
);
550 last_map_search
.cpuid
= cpuid
;
551 last_map_search
.map
= map
;
552 has_last_map_search
= true;
554 out_update_last_result
:
555 last_result
.cpu
= cpu
;
556 last_result
.map
= map
;
557 has_last_result
= true;
561 static const struct pmu_events_map
*map_for_pmu(struct perf_pmu
*pmu
)
563 struct perf_cpu cpu
= {-1};
566 cpu
= perf_cpu_map__min(pmu
->cpus
);
567 return map_for_cpu(cpu
);
570 const struct pmu_events_table
*perf_pmu__find_events_table(struct perf_pmu
*pmu
)
572 const struct pmu_events_map
*map
= map_for_pmu(pmu
);
578 return &map
->event_table
;
580 for (size_t i
= 0; i
< map
->event_table
.num_pmus
; i
++) {
581 const struct pmu_table_entry
*table_pmu
= &map
->event_table
.pmus
[i
];
582 const char *pmu_name
= &big_c_string
[table_pmu
->pmu_name
.offset
];
584 if (pmu__name_match(pmu
, pmu_name
))
585 return &map
->event_table
;
590 const struct pmu_metrics_table
*pmu_metrics_table__find(void)
592 struct perf_cpu cpu
= {-1};
593 const struct pmu_events_map
*map
= map_for_cpu(cpu
);
595 return map
? &map
->metric_table
: NULL
;
598 const struct pmu_events_table
*find_core_events_table(const char *arch
, const char *cpuid
)
600 for (const struct pmu_events_map
*tables
= &pmu_events_map
[0];
603 if (!strcmp(tables
->arch
, arch
) && !strcmp_cpuid_str(tables
->cpuid
, cpuid
))
604 return &tables
->event_table
;
609 const struct pmu_metrics_table
*find_core_metrics_table(const char *arch
, const char *cpuid
)
611 for (const struct pmu_events_map
*tables
= &pmu_events_map
[0];
614 if (!strcmp(tables
->arch
, arch
) && !strcmp_cpuid_str(tables
->cpuid
, cpuid
))
615 return &tables
->metric_table
;
620 int pmu_for_each_core_event(pmu_event_iter_fn fn
, void *data
)
622 for (const struct pmu_events_map
*tables
= &pmu_events_map
[0];
625 int ret
= pmu_events_table__for_each_event(&tables
->event_table
,
626 /*pmu=*/ NULL
, fn
, data
);
634 int pmu_for_each_core_metric(pmu_metric_iter_fn fn
, void *data
)
636 for (const struct pmu_events_map
*tables
= &pmu_events_map
[0];
639 int ret
= pmu_metrics_table__for_each_metric(&tables
->metric_table
, fn
, data
);
647 const struct pmu_events_table
*find_sys_events_table(const char *name
)
649 for (const struct pmu_sys_events
*tables
= &pmu_sys_event_tables
[0];
652 if (!strcmp(tables
->name
, name
))
653 return &tables
->event_table
;
658 int pmu_for_each_sys_event(pmu_event_iter_fn fn
, void *data
)
660 for (const struct pmu_sys_events
*tables
= &pmu_sys_event_tables
[0];
663 int ret
= pmu_events_table__for_each_event(&tables
->event_table
,
664 /*pmu=*/ NULL
, fn
, data
);
672 int pmu_for_each_sys_metric(pmu_metric_iter_fn fn
, void *data
)
674 for (const struct pmu_sys_events
*tables
= &pmu_sys_event_tables
[0];
677 int ret
= pmu_metrics_table__for_each_metric(&tables
->metric_table
, fn
, data
);
685 static const int metricgroups
[][2] = {
689 const char *describe_metricgroup(const char *group
)
691 int low
= 0, high
= (int)ARRAY_SIZE(metricgroups
) - 1;
693 while (low
<= high
) {
694 int mid
= (low
+ high
) / 2;
695 const char *mgroup
= &big_c_string
[metricgroups
[mid
][0]];
696 int cmp
= strcmp(mgroup
, group
);
699 return &big_c_string
[metricgroups
[mid
][1]];
700 } else if (cmp
< 0) {