2 * Copyright (c) 2020 Cisco 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 <perfmon/perfmon.h>
18 #include <perfmon/intel/core.h>
21 format_branch_mispredictions (u8 *s, va_list *args)
23 perfmon_node_stats_t *ns = va_arg (*args, perfmon_node_stats_t *);
24 int row = va_arg (*args, int);
29 s = format (s, "%9.2f", ns->value[0] / (f64) ns->n_calls);
32 s = format (s, "%9.2f", ns->value[0] / (f64) ns->n_packets);
35 s = format (s, "%9.2f", ns->value[1] / (f64) ns->n_calls);
38 s = format (s, "%9.2f", ns->value[1] / (f64) ns->n_packets);
41 s = format (s, "%05.2f", (ns->value[2] / (f64) ns->value[0]) * 100);
44 s = format (s, "%9f", (f64) ns->value[0]);
47 s = format (s, "%9f", (f64) ns->value[1]);
50 s = format (s, "%9f", (f64) ns->value[2]);
56 PERFMON_REGISTER_BUNDLE (branch_mispredictions) = {
57 .name = "branch-mispred",
58 .description = "Branches, branches taken and mis-predictions",
59 .source = "intel-core",
60 .type = PERFMON_BUNDLE_TYPE_NODE,
61 .events[0] = INTEL_CORE_E_BR_INST_RETIRED_ALL_BRANCHES,
62 .events[1] = INTEL_CORE_E_BR_INST_RETIRED_NEAR_TAKEN,
63 .events[2] = INTEL_CORE_E_BR_MISP_RETIRED_ALL_BRANCHES,
65 .format_fn = format_branch_mispredictions,
66 .column_headers = PERFMON_STRINGS ("Branches/call", "Branches/pkt",
67 "Taken/call", "Taken/pkt", "% MisPred"),
68 .raw_column_headers = PERFMON_STRINGS ("branches", "taken", "misses"),