FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
topdown_metrics.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021 Intel 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 #define GET_METRIC(m, i) (((m) >> (i * 8)) & 0xff)
21 #define GET_RATIO(m, i) (((m) >> (i * 32)) & 0xffffffff)
22 #define RDPMC_FIXED_SLOTS (1 << 30) /* fixed slots */
23 #define RDPMC_L1_METRICS (1 << 29) /* l1 metric counters */
24 
25 #define FIXED_COUNTER_SLOTS 3
26 #define METRIC_COUNTER_TOPDOWN_L1 0
27 
28 typedef enum
29 {
35 
36 enum
37 {
41 
44 {
45  f64 slots_t0 =
46  ns->t[0].value[TOPDOWN_SLOTS] *
47  ((f64) GET_METRIC (ns->t[0].value[TOPDOWN_METRICS], e) / 0xff);
48  f64 slots_t1 =
49  ns->t[1].value[TOPDOWN_SLOTS] *
50  ((f64) GET_METRIC (ns->t[1].value[TOPDOWN_METRICS], e) / 0xff);
51  u64 slots_delta =
52  ns->t[1].value[TOPDOWN_SLOTS] - ns->t[0].value[TOPDOWN_SLOTS];
53 
54  slots_t1 = slots_t1 - slots_t0;
55 
56  return (slots_t1 / slots_delta) * 100;
57 }
58 
59 static u8 *
60 format_topdown_lvl1 (u8 *s, va_list *args)
61 {
62  perfmon_node_stats_t *st = va_arg (*args, perfmon_node_stats_t *);
63  u64 row = va_arg (*args, int);
64 
65  switch (row)
66  {
67  case 0:
68  s = format (s, "%f",
71  break;
72  case 1:
73  s = format (s, "%f",
76  break;
77  case 2:
78  s = format (s, "%f",
80  break;
81  case 3:
82  s = format (s, "%f",
84  break;
85  case 4:
86  s = format (s, "%f",
88  break;
89  case 5:
90  s = format (s, "%f",
92  break;
93  }
94  return s;
95 }
96 
97 PERFMON_REGISTER_BUNDLE (topdown_lvl1) = {
98  .name = "topdown-level1",
99  .description = "Top-down Microarchitecture Analysis Level 1",
100  .source = "intel-core",
101  .type = PERFMON_BUNDLE_TYPE_NODE,
102  .offset_type = PERFMON_OFFSET_TYPE_METRICS,
103  .events[0] = INTEL_CORE_E_TOPDOWN_SLOTS,
104  .events[1] = INTEL_CORE_E_TOPDOWN_L1_METRICS,
105  .metrics[0] = RDPMC_FIXED_SLOTS | FIXED_COUNTER_SLOTS,
107  .n_events = 2,
108  .cpu_supports = clib_cpu_supports_avx512_bitalg,
109  .format_fn = format_topdown_lvl1,
110  .column_headers = PERFMON_STRINGS ("% NS", "% ST", "% NS.RT", "% NS.BS",
111  "% ST.FE", "% ST.BE"),
112  .footer = "Not Stalled (NS),STalled (ST),\n"
113  " Retiring (RT), Bad Speculation (BS),\n"
114  " FrontEnd bound (FE), BackEnd bound (BE)",
115 };
perfmon_node_stats_t
Definition: perfmon.h:129
PERFMON_OFFSET_TYPE_METRICS
@ PERFMON_OFFSET_TYPE_METRICS
Definition: perfmon.h:39
PERFMON_BUNDLE_TYPE_NODE
@ PERFMON_BUNDLE_TYPE_NODE
Definition: perfmon.h:31
TOPDOWN_E_METRIC_RETIRING
@ TOPDOWN_E_METRIC_RETIRING
Definition: topdown_metrics.c:30
perfmon_node_stats_t::t
struct perfmon_node_stats_t::@759::@761 t[2]
METRIC_COUNTER_TOPDOWN_L1
#define METRIC_COUNTER_TOPDOWN_L1
Definition: topdown_metrics.c:26
f32
float f32
Definition: types.h:143
TOPDOWN_E_METRIC_FE_BOUND
@ TOPDOWN_E_METRIC_FE_BOUND
Definition: topdown_metrics.c:32
TOPDOWN_SLOTS
@ TOPDOWN_SLOTS
Definition: topdown_metrics.c:38
PERFMON_STRINGS
#define PERFMON_STRINGS(...)
Definition: perfmon.h:195
static_always_inline
#define static_always_inline
Definition: clib.h:112
topdown_lvl1_parse_row
static_always_inline f32 topdown_lvl1_parse_row(perfmon_node_stats_t *ns, topdown_lvl1_counters_t e)
Definition: topdown_metrics.c:43
f64
double f64
Definition: types.h:142
topdown_lvl1_metrics_t
enum @756 topdown_lvl1_metrics_t
TOPDOWN_E_METRIC_BAD_SPEC
@ TOPDOWN_E_METRIC_BAD_SPEC
Definition: topdown_metrics.c:31
u64
unsigned long u64
Definition: types.h:89
format
description fragment has unexpected format
Definition: map.api:433
TOPDOWN_METRICS
@ TOPDOWN_METRICS
Definition: topdown_metrics.c:39
core.h
GET_METRIC
#define GET_METRIC(m, i)
Definition: topdown_metrics.c:20
u8
unsigned char u8
Definition: types.h:56
FIXED_COUNTER_SLOTS
#define FIXED_COUNTER_SLOTS
Definition: topdown_metrics.c:25
PERFMON_REGISTER_BUNDLE
PERFMON_REGISTER_BUNDLE(topdown_lvl1)
topdown_lvl1_counters_t
topdown_lvl1_counters_t
Definition: topdown_metrics.c:28
TOPDOWN_E_METRIC_BE_BOUND
@ TOPDOWN_E_METRIC_BE_BOUND
Definition: topdown_metrics.c:33
vnet.h
format_topdown_lvl1
static u8 * format_topdown_lvl1(u8 *s, va_list *args)
Definition: topdown_metrics.c:60
RDPMC_L1_METRICS
#define RDPMC_L1_METRICS
Definition: topdown_metrics.c:23
RDPMC_FIXED_SLOTS
#define RDPMC_FIXED_SLOTS
Definition: topdown_metrics.c:22