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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #include <vnet/vnet.h>
17 #include <vppinfra/linux/sysfs.h>
18 #include <perfmon/perfmon.h>
19 #include <perfmon/arm/events.h>
21 /* as per .events[n] in PERFMON_REGISTER_BUNDLE */
33 format_arm_cache_data (u8 *s, va_list *args)
35 perfmon_node_stats_t *ns = va_arg (*args, perfmon_node_stats_t *);
36 int row = va_arg (*args, int);
41 s = format (s, "%.2f", (f64) ns->value[L1D_CACHE] / ns->n_packets);
46 format (s, "%.2f", (f64) ns->value[L1D_CACHE_REFILL] / ns->n_packets);
50 s = format (s, "%.2f%%",
51 (ns->value[L1D_CACHE] ? (f64) ns->value[L1D_CACHE_REFILL] /
52 ns->value[L1D_CACHE] * 100 :
57 s = format (s, "%.2f", (f64) ns->value[L2D_CACHE] / ns->n_packets);
62 format (s, "%.2f", (f64) ns->value[L2D_CACHE_REFILL] / ns->n_packets);
66 s = format (s, "%.2f%%",
67 (ns->value[L2D_CACHE] ? (f64) ns->value[L2D_CACHE_REFILL] /
68 ns->value[L2D_CACHE] * 100 :
73 s = format (s, "%.2f", (f64) ns->value[L3D_CACHE] / ns->n_packets);
78 format (s, "%.2f", (f64) ns->value[L3D_CACHE_REFILL] / ns->n_packets);
82 s = format (s, "%.2f%%",
83 (ns->value[L3D_CACHE] ? (f64) ns->value[L3D_CACHE_REFILL] /
84 ns->value[L3D_CACHE] * 100 :
89 s = format (s, "%llu", ns->n_packets);
95 PERFMON_REGISTER_BUNDLE (arm_cache_data) = {
97 .description = "L1D/L2D/L3D data cache accesses and refills per packet",
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,
108 .format_fn = format_arm_cache_data,
109 .column_headers = PERFMON_STRINGS ("L1D: access", "refill", "\%*",
110 "L2D: access", "refill", "\%*",
111 "L3D: access", "refill", "\%*", "pkts"),
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
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"