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:
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>
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 */
25 #define FIXED_COUNTER_SLOTS 3
26 #define METRIC_COUNTER_TOPDOWN_L1 0
30 TOPDOWN_E_METRIC_RETIRING = 0,
31 TOPDOWN_E_METRIC_BAD_SPEC,
32 TOPDOWN_E_METRIC_FE_BOUND,
33 TOPDOWN_E_METRIC_BE_BOUND,
34 } topdown_lvl1_counters_t;
40 } topdown_lvl1_metrics_t;
42 static_always_inline f32
43 topdown_lvl1_parse_row (perfmon_node_stats_t *ns, topdown_lvl1_counters_t e)
46 ns->t[0].value[TOPDOWN_SLOTS] *
47 ((f64) GET_METRIC (ns->t[0].value[TOPDOWN_METRICS], e) / 0xff);
49 ns->t[1].value[TOPDOWN_SLOTS] *
50 ((f64) GET_METRIC (ns->t[1].value[TOPDOWN_METRICS], e) / 0xff);
52 ns->t[1].value[TOPDOWN_SLOTS] - ns->t[0].value[TOPDOWN_SLOTS];
54 slots_t1 = slots_t1 - slots_t0;
56 return (slots_t1 / slots_delta) * 100;
60 format_topdown_lvl1 (u8 *s, va_list *args)
62 perfmon_node_stats_t *st = va_arg (*args, perfmon_node_stats_t *);
63 u64 row = va_arg (*args, int);
69 topdown_lvl1_parse_row (st, TOPDOWN_E_METRIC_BAD_SPEC) +
70 topdown_lvl1_parse_row (st, TOPDOWN_E_METRIC_RETIRING));
74 topdown_lvl1_parse_row (st, TOPDOWN_E_METRIC_BE_BOUND) +
75 topdown_lvl1_parse_row (st, TOPDOWN_E_METRIC_FE_BOUND));
79 topdown_lvl1_parse_row (st, TOPDOWN_E_METRIC_RETIRING));
83 topdown_lvl1_parse_row (st, TOPDOWN_E_METRIC_BAD_SPEC));
87 topdown_lvl1_parse_row (st, TOPDOWN_E_METRIC_FE_BOUND));
91 topdown_lvl1_parse_row (st, TOPDOWN_E_METRIC_BE_BOUND));
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,
106 .metrics[1] = RDPMC_L1_METRICS | METRIC_COUNTER_TOPDOWN_L1,
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)",