perfmon: add Arm event bundles
[vpp.git] / src / plugins / perfmon / arm / bundle / stall.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   STALL_BACKEND,
25   STALL_FRONTEND
26 };
27
28 static u8 *
29 format_arm_stall (u8 *s, va_list *args)
30 {
31   perfmon_node_stats_t *ns = va_arg (*args, perfmon_node_stats_t *);
32   int row = va_arg (*args, int);
33
34   switch (row)
35     {
36     case 0:
37       s = format (s, "%llu", ns->value[STALL_BACKEND] / ns->n_packets);
38       break;
39
40     case 1:
41       s = format (s, "%llu", ns->value[STALL_FRONTEND] / ns->n_packets);
42       break;
43
44     case 2:
45       s = format (s, "%llu", ns->value[STALL_BACKEND] / ns->n_calls);
46       break;
47
48     case 3:
49       s = format (s, "%llu", ns->value[STALL_FRONTEND] / ns->n_calls);
50       break;
51
52     case 4:
53       s = format (s, "%llu", ns->n_packets);
54       break;
55
56     case 5:
57       s = format (s, "%llu", ns->n_calls);
58       break;
59     }
60   return s;
61 }
62
63 PERFMON_REGISTER_BUNDLE (arm_stall) = {
64   .name = "stall",
65   .description = "PE cycle stalls per pkt/call",
66   .source = "arm",
67   .type = PERFMON_BUNDLE_TYPE_NODE,
68   .events[0] = ARMV8_PMUV3_STALL_BACKEND,
69   .events[1] = ARMV8_PMUV3_STALL_FRONTEND,
70   .n_events = 2,
71   .n_columns = 6,
72   .format_fn = format_arm_stall,
73   .column_headers = PERFMON_STRINGS ("Backend/pkt", "Frontend/pkt",
74                                      "Backend/call", "Frontend/call",
75                                      "packets", "calls"),
76   /*
77    * set a bit for every event used in each column
78    * this allows us to disable columns at bundle registration if an
79    * event is not supported
80    */
81   .column_events = PERFMON_COLUMN_EVENTS (SET_BIT (STALL_BACKEND),
82                                           SET_BIT (STALL_FRONTEND),
83                                           SET_BIT (STALL_BACKEND),
84                                           SET_BIT (STALL_FRONTEND), 0, 0),
85   .footer =
86     "The stall counter counts every Attributable cycle on which no\n"
87     "Attributable instruction or operation was sent for execution\n"
88     "on this PE.\n\n"
89     "     Stall backend: No operation issued due to the backend\n"
90     "     Stall frontend: No operation issued due to the frontend\n"
91     "The division between frontend and backend is IMPLEMENTATION DEFINED\n\n"
92     "- See Armv8-A Architecture Reference Manual, D7.10 PMU events and"
93     " event numbers for full description.\n"
94 };