FD.io VPP  v21.10.1-2-g0a485f517
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 {
40 };
41 
43 
44 /* Parse thread level states from perfmon_reading */
47 {
49 
50  /* slots are at value[0], everthing else follows at +1 */
51  return ((f64) ss->value[e + 1] / ss->value[0]) * 100;
52 }
53 
56 {
58  f64 slots_t0 =
59  ss->t[0].value[TOPDOWN_E_RDPMC_SLOTS] *
60  ((f64) GET_METRIC (ss->t[0].value[TOPDOWN_E_RDPMC_METRICS], e) / 0xff);
61  f64 slots_t1 =
62  ss->t[1].value[TOPDOWN_E_RDPMC_SLOTS] *
63  ((f64) GET_METRIC (ss->t[1].value[TOPDOWN_E_RDPMC_METRICS], e) / 0xff);
64  u64 slots_delta = ss->t[1].value[TOPDOWN_E_RDPMC_SLOTS] -
65  ss->t[0].value[TOPDOWN_E_RDPMC_SLOTS];
66 
67  slots_t1 = slots_t1 - slots_t0;
68 
69  return (slots_t1 / slots_delta) * 100;
70 }
71 
72 static u8 *
73 format_topdown_lvl1 (u8 *s, va_list *args)
74 {
75  void *ps = va_arg (*args, void *);
76  u64 idx = va_arg (*args, int);
78  f64 sv = 0;
79 
80  topdown_lvl1_parse_fn_t *parse_fn,
83  parse_fn = parse_fns[type];
84  ASSERT (parse_fn);
85 
86  switch (idx)
87  {
88  case 0:
89  sv =
90  parse_fn (ps, TOPDOWN_E_BAD_SPEC) + parse_fn (ps, TOPDOWN_E_RETIRING);
91  break;
92  case 1:
93  sv =
94  parse_fn (ps, TOPDOWN_E_BE_BOUND) + parse_fn (ps, TOPDOWN_E_FE_BOUND);
95  break;
96  default:
97  sv = parse_fn (ps, (topdown_lvl1_t) idx - 2);
98  break;
99  }
100 
101  s = format (s, "%f", sv);
102 
103  return s;
104 }
105 
107  /* Intel SNR supports papi/thread only */
108  { clib_cpu_supports_movdiri, PERFMON_BUNDLE_TYPE_THREAD },
109  /* Intel ICX supports papi/thread or rdpmc/node */
110  { clib_cpu_supports_avx512_bitalg, PERFMON_BUNDLE_TYPE_NODE }
111 };
112 
113 PERFMON_REGISTER_BUNDLE (topdown_lvl1_metric) = {
114  .name = "topdown-level1",
115  .description = "Top-down Microarchitecture Analysis Level 1",
116  .source = "intel-core",
117  .offset_type = PERFMON_OFFSET_TYPE_METRICS,
118  .events[0] = INTEL_CORE_E_TOPDOWN_SLOTS,
119  .events[1] = INTEL_CORE_E_TOPDOWN_L1_RETIRING_METRIC,
120  .events[2] = INTEL_CORE_E_TOPDOWN_L1_BAD_SPEC_METRIC,
121  .events[3] = INTEL_CORE_E_TOPDOWN_L1_FE_BOUND_METRIC,
122  .events[4] = INTEL_CORE_E_TOPDOWN_L1_BE_BOUND_METRIC,
123  .n_events = 5,
124  .metrics[0] = RDPMC_FIXED_SLOTS | FIXED_COUNTER_SLOTS,
126  .n_metrics = 2,
127  .cpu_supports = topdown_lvl1_cpu_supports,
128  .n_cpu_supports = ARRAY_LEN (topdown_lvl1_cpu_supports),
129  .format_fn = format_topdown_lvl1,
130  .column_headers = PERFMON_STRINGS ("% NS", "% ST", "% NS.RT", "% NS.BS",
131  "% ST.FE", "% ST.BE"),
132  .footer = "Not Stalled (NS),STalled (ST),\n"
133  " Retiring (RT), Bad Speculation (BS),\n"
134  " FrontEnd bound (FE), BackEnd bound (BE)",
135 };
TOPDOWN_E_RDPMC_SLOTS
@ TOPDOWN_E_RDPMC_SLOTS
Definition: topdown_metrics.c:38
perfmon_node_stats_t
Definition: perfmon.h:140
PERFMON_OFFSET_TYPE_METRICS
@ PERFMON_OFFSET_TYPE_METRICS
Definition: perfmon.h:40
TOPDOWN_E_BAD_SPEC
@ TOPDOWN_E_BAD_SPEC
Definition: topdown_metrics.c:31
PERFMON_BUNDLE_TYPE_NODE
@ PERFMON_BUNDLE_TYPE_NODE
Definition: perfmon.h:31
perfmon_reading_t::value
u64 value[PERF_MAX_EVENTS]
Definition: perfmon.h:137
PERFMON_BUNDLE_TYPE_MAX
@ PERFMON_BUNDLE_TYPE_MAX
Definition: perfmon.h:34
perfmon_reading_t
Definition: perfmon.h:132
TOPDOWN_E_FE_BOUND
@ TOPDOWN_E_FE_BOUND
Definition: topdown_metrics.c:32
METRIC_COUNTER_TOPDOWN_L1
#define METRIC_COUNTER_TOPDOWN_L1
Definition: topdown_metrics.c:26
topdown_lvl1_t
topdown_lvl1_t
Definition: topdown_metrics.c:28
TOPDOWN_E_BE_BOUND
@ TOPDOWN_E_BE_BOUND
Definition: topdown_metrics.c:33
perfmon_node_stats_t::t
struct perfmon_node_stats_t::@769::@771 t[2]
TOPDOWN_E_RETIRING
@ TOPDOWN_E_RETIRING
Definition: topdown_metrics.c:30
PERFMON_BUNDLE_TYPE_THREAD
@ PERFMON_BUNDLE_TYPE_THREAD
Definition: perfmon.h:32
PERFMON_STRINGS
#define PERFMON_STRINGS(...)
Definition: perfmon.h:226
ARRAY_LEN
#define ARRAY_LEN(x)
Definition: clib.h:70
static_always_inline
#define static_always_inline
Definition: clib.h:112
perfmon_cpu_supports_t
Definition: perfmon.h:99
f64
double f64
Definition: types.h:142
topdown_lvl1_parse_fn_t
f64() topdown_lvl1_parse_fn_t(void *, topdown_lvl1_t)
Definition: topdown_metrics.c:42
PERFMON_REGISTER_BUNDLE
PERFMON_REGISTER_BUNDLE(topdown_lvl1_metric)
topdown_lvl1_perf_reading
static_always_inline f64 topdown_lvl1_perf_reading(void *ps, topdown_lvl1_t e)
Definition: topdown_metrics.c:46
u64
unsigned long u64
Definition: types.h:89
format
description fragment has unexpected format
Definition: map.api:433
ASSERT
#define ASSERT(truth)
Definition: error_bootstrap.h:69
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
vnet.h
perfmon_bundle_type_t
perfmon_bundle_type_t
Definition: perfmon.h:28
topdown_lvl1_rdpmc_metric
static_always_inline f64 topdown_lvl1_rdpmc_metric(void *ps, topdown_lvl1_t e)
Definition: topdown_metrics.c:55
format_topdown_lvl1
static u8 * format_topdown_lvl1(u8 *s, va_list *args)
Definition: topdown_metrics.c:73
RDPMC_L1_METRICS
#define RDPMC_L1_METRICS
Definition: topdown_metrics.c:23
type
vl_api_fib_path_type_t type
Definition: fib_types.api:123
RDPMC_FIXED_SLOTS
#define RDPMC_FIXED_SLOTS
Definition: topdown_metrics.c:22
TOPDOWN_E_RDPMC_METRICS
@ TOPDOWN_E_RDPMC_METRICS
Definition: topdown_metrics.c:39
topdown_lvl1_cpu_supports
static perfmon_cpu_supports_t topdown_lvl1_cpu_supports[]
Definition: topdown_metrics.c:106