perfmon: add Arm event bundles
[vpp.git] / src / plugins / perfmon / arm / bundle / cache_inst.c
1 /*
2  * Copyright (c) 2022 Arm and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15
16 #include <vnet/vnet.h>
17 #include <vppinfra/linux/sysfs.h>
18 #include <perfmon/perfmon.h>
19 #include <perfmon/arm/events.h>
20
21 /* as per .events[n] in PERFMON_REGISTER_BUNDLE */
22 enum
23 {
24   L1I_CACHE,
25   L1I_CACHE_REFILL,
26   L2I_CACHE,
27   L2I_CACHE_REFILL
28 };
29
30 static u8 *
31 format_arm_cache_inst (u8 *s, va_list *args)
32 {
33   perfmon_node_stats_t *ns = va_arg (*args, perfmon_node_stats_t *);
34   int row = va_arg (*args, int);
35
36   switch (row)
37     {
38     case 0:
39       s = format (s, "%.2f", (f64) ns->value[L1I_CACHE] / ns->n_packets);
40       break;
41
42     case 1:
43       s =
44         format (s, "%.2f", (f64) ns->value[L1I_CACHE_REFILL] / ns->n_packets);
45       break;
46
47     case 2:
48       s = format (s, "%.2f%%",
49                   (ns->value[L1I_CACHE] ? (f64) ns->value[L1I_CACHE_REFILL] /
50                                             ns->value[L1I_CACHE] * 100 :
51                                                 0));
52       break;
53
54     case 3:
55       s = format (s, "%.2f", (f64) ns->value[L2I_CACHE] / ns->n_packets);
56       break;
57
58     case 4:
59       s =
60         format (s, "%.2f", (f64) ns->value[L2I_CACHE_REFILL] / ns->n_packets);
61       break;
62
63     case 5:
64       s = format (s, "%.2f%%",
65                   (ns->value[L2I_CACHE] ? (f64) ns->value[L2I_CACHE_REFILL] /
66                                             ns->value[L2I_CACHE] * 100 :
67                                                 0));
68       break;
69
70     case 6:
71       s = format (s, "%llu", ns->n_packets);
72       break;
73     }
74   return s;
75 }
76
77 PERFMON_REGISTER_BUNDLE (arm_cache_inst) = {
78   .name = "cache-inst",
79   .description = "L1I/L2I instruction cache accesses and refills per packet",
80   .source = "arm",
81   .type = PERFMON_BUNDLE_TYPE_NODE,
82   .events[0] = ARMV8_PMUV3_L1I_CACHE,
83   .events[1] = ARMV8_PMUV3_L1I_CACHE_REFILL,
84   .events[2] = ARMV8_PMUV3_L2I_CACHE,
85   .events[3] = ARMV8_PMUV3_L2I_CACHE_REFILL,
86   .n_events = 4,
87   .n_columns = 7,
88   .format_fn = format_arm_cache_inst,
89   .column_headers = PERFMON_STRINGS ("L1I: access", "refill", "\%*",
90                                      "L2I: access", "refill", "\%*", "pkts"),
91   /*
92    * set a bit for every event used in each column
93    * this allows us to disable columns at bundle registration if an
94    * event is not supported
95    */
96   .column_events = PERFMON_COLUMN_EVENTS (
97     SET_BIT (L1I_CACHE), SET_BIT (L1I_CACHE_REFILL),
98     SET_BIT (L1I_CACHE) | SET_BIT (L1I_CACHE_REFILL), SET_BIT (L2I_CACHE),
99     SET_BIT (L2I_CACHE_REFILL),
100     SET_BIT (L2I_CACHE) | SET_BIT (L2I_CACHE_REFILL), 0),
101   .footer = "all stats are per packet except refill rate (\%)\n"
102             "*\% percentage shown is total refills/accesses\n"
103 };