5e5835a7868dea35bc4ea2d211fc5c57929b9902
[vpp.git] / src / plugins / perfmon / intel / bundle / frontend_bound_bw.c
1 /*
2  * Copyright (c) 2022 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 <perfmon/perfmon.h>
17 #include <perfmon/intel/core.h>
18
19 enum
20 {
21   DSB_UOPS,
22   MS_UOPS,
23   MITE_UOPS,
24   LSD_UOPS,
25 };
26
27 static u8 *
28 format_intel_frontend_bound_bw (u8 *s, va_list *args)
29 {
30   perfmon_node_stats_t *ss = va_arg (*args, perfmon_node_stats_t *);
31   int row = va_arg (*args, int);
32   f64 sv = 0;
33   f64 uops = ss->value[DSB_UOPS] + ss->value[MS_UOPS] + ss->value[MITE_UOPS] +
34              ss->value[LSD_UOPS];
35
36   if (!ss->n_packets)
37     return s;
38
39   if (row == 0)
40     {
41       sv = uops / ss->n_packets;
42       s = format (s, "%.0f", sv);
43
44       return s;
45     }
46
47   switch (row)
48     {
49     case 1:
50       sv = (ss->value[DSB_UOPS] / uops) * 100;
51       break;
52     case 2:
53       sv = (ss->value[MS_UOPS] / uops) * 100;
54       break;
55     case 3:
56       sv = (ss->value[MITE_UOPS] / uops) * 100;
57       break;
58     case 4:
59       sv = (ss->value[LSD_UOPS] / uops) * 100;
60       break;
61     }
62
63   s = format (s, "%04.1f", sv);
64
65   return s;
66 }
67
68 static perfmon_cpu_supports_t frontend_bound_bw_cpu_supports[] = {
69   { clib_cpu_supports_avx512_bitalg, PERFMON_BUNDLE_TYPE_NODE },
70 };
71
72 PERFMON_REGISTER_BUNDLE (intel_core_frontend_bound_bw) = {
73   .name = "td-frontend-bw",
74   .description =
75     "Topdown FrontEnd-bound BandWidth - % uops from each uop fetch source",
76   .source = "intel-core",
77   .events[0] = INTEL_CORE_E_IDQ_DSB_UOPS,  /* 0x0F */
78   .events[1] = INTEL_CORE_E_IDQ_MS_UOPS,   /* 0x0F */
79   .events[2] = INTEL_CORE_E_IDQ_MITE_UOPS, /* 0x0F */
80   .events[3] = INTEL_CORE_E_LSD_UOPS,      /* 0x0F */
81   .n_events = 4,
82   .format_fn = format_intel_frontend_bound_bw,
83   .cpu_supports = frontend_bound_bw_cpu_supports,
84   .n_cpu_supports = ARRAY_LEN (frontend_bound_bw_cpu_supports),
85   .column_headers = PERFMON_STRINGS ("UOPs/PKT", "% DSB UOPS", "% MS UOPS",
86                                      "% MITE UOPS", "% LSD UOPS"),
87   .footer =
88     "For more information, see the Intel(R) 64 and IA-32 Architectures\n"
89     "Optimization Reference Manual section on the Front End.",
90 };