perfmon: add Arm event bundles
[vpp.git] / src / plugins / perfmon / arm / bundle / cache_data.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   L1D_CACHE,
25   L1D_CACHE_REFILL,
26   L2D_CACHE,
27   L2D_CACHE_REFILL,
28   L3D_CACHE,
29   L3D_CACHE_REFILL
30 };
31
32 static u8 *
33 format_arm_cache_data (u8 *s, va_list *args)
34 {
35   perfmon_node_stats_t *ns = va_arg (*args, perfmon_node_stats_t *);
36   int row = va_arg (*args, int);
37
38   switch (row)
39     {
40     case 0:
41       s = format (s, "%.2f", (f64) ns->value[L1D_CACHE] / ns->n_packets);
42       break;
43
44     case 1:
45       s =
46         format (s, "%.2f", (f64) ns->value[L1D_CACHE_REFILL] / ns->n_packets);
47       break;
48
49     case 2:
50       s = format (s, "%.2f%%",
51                   (ns->value[L1D_CACHE] ? (f64) ns->value[L1D_CACHE_REFILL] /
52                                             ns->value[L1D_CACHE] * 100 :
53                                                 0));
54       break;
55
56     case 3:
57       s = format (s, "%.2f", (f64) ns->value[L2D_CACHE] / ns->n_packets);
58       break;
59
60     case 4:
61       s =
62         format (s, "%.2f", (f64) ns->value[L2D_CACHE_REFILL] / ns->n_packets);
63       break;
64
65     case 5:
66       s = format (s, "%.2f%%",
67                   (ns->value[L2D_CACHE] ? (f64) ns->value[L2D_CACHE_REFILL] /
68                                             ns->value[L2D_CACHE] * 100 :
69                                                 0));
70       break;
71
72     case 6:
73       s = format (s, "%.2f", (f64) ns->value[L3D_CACHE] / ns->n_packets);
74       break;
75
76     case 7:
77       s =
78         format (s, "%.2f", (f64) ns->value[L3D_CACHE_REFILL] / ns->n_packets);
79       break;
80
81     case 8:
82       s = format (s, "%.2f%%",
83                   (ns->value[L3D_CACHE] ? (f64) ns->value[L3D_CACHE_REFILL] /
84                                             ns->value[L3D_CACHE] * 100 :
85                                                 0));
86       break;
87
88     case 9:
89       s = format (s, "%llu", ns->n_packets);
90       break;
91     }
92   return s;
93 }
94
95 PERFMON_REGISTER_BUNDLE (arm_cache_data) = {
96   .name = "cache-data",
97   .description = "L1D/L2D/L3D data cache accesses and refills per packet",
98   .source = "arm",
99   .type = PERFMON_BUNDLE_TYPE_NODE,
100   .events[0] = ARMV8_PMUV3_L1D_CACHE,
101   .events[1] = ARMV8_PMUV3_L1D_CACHE_REFILL,
102   .events[2] = ARMV8_PMUV3_L2D_CACHE,
103   .events[3] = ARMV8_PMUV3_L2D_CACHE_REFILL,
104   .events[4] = ARMV8_PMUV3_L3D_CACHE,
105   .events[5] = ARMV8_PMUV3_L3D_CACHE_REFILL,
106   .n_events = 6,
107   .n_columns = 10,
108   .format_fn = format_arm_cache_data,
109   .column_headers = PERFMON_STRINGS ("L1D: access", "refill", "\%*",
110                                      "L2D: access", "refill", "\%*",
111                                      "L3D: access", "refill", "\%*", "pkts"),
112   /*
113    * set a bit for every event used in each column
114    * this allows us to disable columns at bundle registration if an
115    * event is not supported
116    */
117   .column_events = PERFMON_COLUMN_EVENTS (
118     SET_BIT (L1D_CACHE), SET_BIT (L1D_CACHE_REFILL),
119     SET_BIT (L1D_CACHE) | SET_BIT (L1D_CACHE_REFILL), SET_BIT (L2D_CACHE),
120     SET_BIT (L2D_CACHE_REFILL),
121     SET_BIT (L2D_CACHE) | SET_BIT (L2D_CACHE_REFILL), SET_BIT (L3D_CACHE),
122     SET_BIT (L3D_CACHE_REFILL),
123     SET_BIT (L3D_CACHE) | SET_BIT (L3D_CACHE_REFILL), 0),
124   .footer = "all stats are per packet except refill rate (\%)\n"
125             "*\% percentage shown is total refills/accesses\n\n"
126             "- See Armv8-A Architecture Reference Manual, D7.10 PMU events and"
127             " event numbers for full description.\n"
128 };