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 */
31 format_arm_branch_pred (u8 *s, va_list *args)
33 perfmon_node_stats_t *ns = va_arg (*args, perfmon_node_stats_t *);
34 int row = va_arg (*args, int);
39 s = format (s, "%.2f", (f64) ns->value[BR_RETIRED] / ns->n_calls);
43 s = format (s, "%.2f", (f64) ns->value[BR_RETIRED] / ns->n_packets);
48 format (s, "%.2f", (f64) ns->value[BR_MIS_PRED_RETIRED] / ns->n_calls);
52 s = format (s, "%.2f",
53 (f64) ns->value[BR_MIS_PRED_RETIRED] / ns->n_packets);
59 (ns->value[BR_RETIRED] ? (f64) ns->value[BR_MIS_PRED_RETIRED] /
60 ns->value[BR_RETIRED] * 100 :
65 s = format (s, "%.2f", (f64) ns->value[BR_PRED] / ns->n_calls);
69 s = format (s, "%.2f", (f64) ns->value[BR_PRED] / ns->n_packets);
73 s = format (s, "%.2f", (f64) ns->value[BR_MIS_PRED] / ns->n_calls);
77 s = format (s, "%.2f", (f64) ns->value[BR_MIS_PRED] / ns->n_packets);
81 s = format (s, "%.2f%%",
83 (f64) ns->value[BR_MIS_PRED] / ns->value[BR_PRED] * 100 :
88 s = format (s, "%llu", ns->n_packets);
94 PERFMON_REGISTER_BUNDLE (arm_branch_pred) = {
95 .name = "branch-pred",
96 .description = "Branch (mis)predictions per call/packet",
98 .type = PERFMON_BUNDLE_TYPE_NODE,
99 .events[0] = ARMV8_PMUV3_BR_RETIRED,
100 .events[1] = ARMV8_PMUV3_BR_MIS_PRED_RETIRED,
101 .events[2] = ARMV8_PMUV3_BR_PRED,
102 .events[3] = ARMV8_PMUV3_BR_MIS_PRED,
105 .format_fn = format_arm_branch_pred,
106 .column_headers = PERFMON_STRINGS ("[1.1]", "[1.2]", "[1.3]", "[1.4]", "\%",
107 "[2.1]", "[2.2]", "[2.3]", "[2.4]", "\%",
110 * set a bit for every event used in each column
111 * this allows us to disable columns at bundle registration if an
112 * event is not supported
114 .column_events = PERFMON_COLUMN_EVENTS (
115 SET_BIT (BR_RETIRED), SET_BIT (BR_RETIRED), SET_BIT (BR_MIS_PRED_RETIRED),
116 SET_BIT (BR_MIS_PRED_RETIRED),
117 SET_BIT (BR_RETIRED) | SET_BIT (BR_MIS_PRED_RETIRED), SET_BIT (BR_PRED),
118 SET_BIT (BR_PRED), SET_BIT (BR_MIS_PRED), SET_BIT (BR_MIS_PRED),
119 SET_BIT (BR_PRED) | SET_BIT (BR_MIS_PRED), 0),
121 "An instruction that has been executed and retired is defined to\n"
122 "be architecturally executed. When a PE can perform speculative\n"
123 "execution, an instruction is not architecturally executed if the\n"
124 "PE discards the results of the speculative execution.\n\n"
125 "Per node statistics:\n"
126 "[1] Branch instruction architecturally executed\n"
127 " [1.1] Branches/call\n"
128 " [1.2] Branches/pkt\n"
129 " [1.3] Mispredicted/call \n"
130 " [1.4] Mispredicted/pkt\n"
131 " [\%] Percentage of branches mispredicted\n"
132 "[2] Predictable branch speculatively executed\n"
133 " [2.1] Branches/call\n"
134 " [2.2] Branches/pkt\n"
135 " [2.3] Mispredicted/call \n"
136 " [2.4] Mispredicted/pkt\n"
137 " [\%] Percentage of branches mispredicted\n\n"
138 "- See Armv8-A Architecture Reference Manual, D7.10 PMU events and"
139 " event numbers for full description.\n"