summaryrefslogtreecommitdiffstats
path: root/src/plugins/perfmon/intel/bundle/topdown_tremont.c
blob: b2626eb04800fc99a52a91b593ccd71dee6c83c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
 * Copyright (c) 2021 Intel and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <vnet/vnet.h>
#include <perfmon/perfmon.h>
#include <perfmon/intel/core.h>

typedef enum
{
  TOPDOWN_E_RETIRING = 0,
  TOPDOWN_E_BAD_SPEC,
  TOPDOWN_E_FE_BOUND,
  TOPDOWN_E_BE_BOUND,
  TOPDOWN_E_MAX,
} topdown_lvl1_t;

static u8 *
format_topdown_lvl1 (u8 *s, va_list *args)
{
  perfmon_reading_t *ss = va_arg (*args, perfmon_reading_t *);
  u64 idx = va_arg (*args, int);
  f64 sv = 0;
  u64 total = 0;

  for (int i = 0; i < TOPDOWN_E_MAX; i++)
    total += ss->value[i];

  switch (idx)
    {
    case 0:
      sv = (f64) ss->value[TOPDOWN_E_RETIRING] + ss->value[TOPDOWN_E_BAD_SPEC];
      break;
    case 1:
      sv = (f64) ss->value[TOPDOWN_E_FE_BOUND] + ss->value[TOPDOWN_E_BE_BOUND];
      break;
    default:
      sv = (f64) ss->value[idx - 2];
      break;
    }

  sv = (sv / total) * 100;
  s = format (s, "%f", sv);
  return s;
}

static int
is_tremont ()
{
  return clib_cpu_supports_movdir64b () && !clib_cpu_supports_avx2 ();
}

static perfmon_cpu_supports_t topdown_lvl1_cpu_supports[] = {
  { is_tremont, PERFMON_BUNDLE_TYPE_THREAD }
};

PERFMON_REGISTER_BUNDLE (topdown_lvl1_tremont) = {
  .name = "topdown-level1",
  .description = "Top-down Microarchitecture Analysis Level 1",
  .source = "intel-core",
  .events[0] = INTEL_CORE_E_TOPDOWN_L1_RETIRING_TREMONT,
  .events[1] = INTEL_CORE_E_TOPDOWN_L1_BAD_SPEC_TREMONT,
  .events[2] = INTEL_CORE_E_TOPDOWN_L1_FE_BOUND_TREMONT,
  .events[3] = INTEL_CORE_E_TOPDOWN_L1_BE_BOUND_TREMONT,
  .n_events = 4,
  .cpu_supports = topdown_lvl1_cpu_supports,
  .n_cpu_supports = ARRAY_LEN (topdown_lvl1_cpu_supports),
  .format_fn = format_topdown_lvl1,
  .column_headers = PERFMON_STRINGS ("% NS", "% ST", "% NS.RT", "% NS.BS",
				     "% ST.FE", "% ST.BE"),
  .footer = "Not Stalled (NS),STalled (ST),\n"
	    " Retiring (RT), Bad Speculation (BS),\n"
	    " FrontEnd bound (FE), BackEnd bound (BE)",
};