FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
branch_mispred.c
Go to the documentation of this file.
1 /*
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:
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 <perfmon/perfmon.h>
18 #include <perfmon/intel/core.h>
19 
20 static u8 *
21 format_branch_mispredictions (u8 *s, va_list *args)
22 {
23  perfmon_node_stats_t *ns = va_arg (*args, perfmon_node_stats_t *);
24  int row = va_arg (*args, int);
25 
26  switch (row)
27  {
28  case 0:
29  s = format (s, "%9.2f", ns->value[0] / (f64) ns->n_calls);
30  break;
31  case 1:
32  s = format (s, "%9.2f", ns->value[0] / (f64) ns->n_packets);
33  break;
34  case 2:
35  s = format (s, "%9.2f", ns->value[1] / (f64) ns->n_calls);
36  break;
37  case 3:
38  s = format (s, "%9.2f", ns->value[1] / (f64) ns->n_packets);
39  break;
40  case 4:
41  s = format (s, "%05.2f", (ns->value[2] / (f64) ns->value[0]) * 100);
42  break;
43  }
44  return s;
45 }
46 
47 PERFMON_REGISTER_BUNDLE (branch_mispredictions) = {
48  .name = "branch-mispred",
49  .description = "Branches, branches taken and mis-predictions",
50  .source = "intel-core",
52  .events[0] = INTEL_CORE_E_BR_INST_RETIRED_ALL_BRANCHES,
53  .events[1] = INTEL_CORE_E_BR_INST_RETIRED_NEAR_TAKEN,
54  .events[2] = INTEL_CORE_E_BR_MISP_RETIRED_ALL_BRANCHES,
55  .n_events = 3,
56  .format_fn = format_branch_mispredictions,
57  .column_headers = PERFMON_STRINGS ("Branches/call", "Branches/pkt",
58  "Taken/call", "Taken/pkt", "% MisPred"),
59 };
perfmon_node_stats_t
Definition: perfmon.h:140
perfmon_node_stats_t::n_packets
u64 n_packets
Definition: perfmon.h:144
PERFMON_BUNDLE_TYPE_NODE
@ PERFMON_BUNDLE_TYPE_NODE
Definition: perfmon.h:31
perfmon_node_stats_t::n_calls
u64 n_calls
Definition: perfmon.h:143
PERFMON_REGISTER_BUNDLE
PERFMON_REGISTER_BUNDLE(branch_mispredictions)
PERFMON_STRINGS
#define PERFMON_STRINGS(...)
Definition: perfmon.h:226
f64
double f64
Definition: types.h:142
format
description fragment has unexpected format
Definition: map.api:433
core.h
format_branch_mispredictions
static u8 * format_branch_mispredictions(u8 *s, va_list *args)
Definition: branch_mispred.c:21
u8
unsigned char u8
Definition: types.h:56
perfmon_node_stats_t::value
u64 value[PERF_MAX_EVENTS]
Definition: perfmon.h:149
vnet.h