perfmon: add Arm event bundles
[vpp.git] / src / plugins / perfmon / arm / bundle / mem_access.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   MEM_ACCESS,
25   BUS_ACCESS,
26   MEMORY_ERROR
27 };
28
29 static u8 *
30 format_arm_memory_access (u8 *s, va_list *args)
31 {
32   perfmon_node_stats_t *ns = va_arg (*args, perfmon_node_stats_t *);
33   int row = va_arg (*args, int);
34
35   switch (row)
36     {
37     case 0:
38       s = format (s, "%.2f", (f64) ns->value[MEM_ACCESS] / ns->n_packets);
39       break;
40
41     case 1:
42       s = format (s, "%.3f", (f64) ns->value[BUS_ACCESS] / ns->n_packets);
43       break;
44
45     case 2:
46       s = format (s, "%llu", ns->value[MEMORY_ERROR]);
47       break;
48
49     case 3:
50       s = format (s, "%llu", ns->n_packets);
51       break;
52     }
53   return s;
54 }
55
56 PERFMON_REGISTER_BUNDLE (arm_memory_access) = {
57   .name = "memory-access",
58   .description = "Memory/bus accesses per pkt + total memory errors",
59   .source = "arm",
60   .type = PERFMON_BUNDLE_TYPE_NODE,
61   .events[0] = ARMV8_PMUV3_MEM_ACCESS,
62   .events[1] = ARMV8_PMUV3_BUS_ACCESS,
63   .events[2] = ARMV8_PMUV3_MEMORY_ERROR,
64   .n_events = 3,
65   .n_columns = 4,
66   .format_fn = format_arm_memory_access,
67   .column_headers = PERFMON_STRINGS ("Mem-access/pkt", "Bus-access/pkt",
68                                      "Total-mem-errors", "pkts"),
69   /*
70    * set a bit for every event used in each column
71    * this allows us to disable columns at bundle registration if an
72    * event is not supported
73    */
74   .column_events = PERFMON_COLUMN_EVENTS (SET_BIT (MEM_ACCESS),
75                                           SET_BIT (BUS_ACCESS),
76                                           SET_BIT (MEMORY_ERROR), 0),
77   .footer =
78     "Mem-access: The counter counts Memory-read operations and Memory-write"
79     " operations that the PE made\n"
80     "Bus-access: The counter counts Memory-read operations and Memory-write"
81     " operations that access outside of the boundary of the PE and its "
82     "closely-coupled caches\n"
83     "Mem-error: Memory error refers to a physical error in memory closely "
84     "coupled to this PE, and detected by the hardware, such as a parity or"
85     " ECC error\n"
86     "- See Armv8-A Architecture Reference Manual, D7.10 PMU events and"
87     " event numbers for full description.\n"
88 };