Added support for reporting packet (mis)order.
[samplevnf.git] / VNFs / DPPD-PROX / display_latency.c
1 /*
2 // Copyright (c) 2010-2017 Intel Corporation
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 */
16
17 #include "display.h"
18 #include "display_latency.h"
19 #include "stats_latency.h"
20 #include "lconf.h"
21
22 static struct display_column *min_col;
23 static struct display_column *max_col;
24 static struct display_column *avg_col;
25 static struct display_column *stddev_col;
26 static struct display_column *accuracy_limit_col;
27 static struct display_column *used_col;
28 static struct display_column *lost_col;
29 static struct display_column *mis_ordered_col;
30 static struct display_column *extent_col;
31 static struct display_column *duplicate_col;
32 static struct display_page display_page_latency;
33
34 static void display_latency_draw_frame(struct screen_state *screen_state)
35 {
36         const uint32_t n_latency = stats_get_n_latency();
37         struct display_column *core_col;
38         struct display_column *port_col;
39
40         display_page_init(&display_page_latency);
41
42         struct display_table *core = display_page_add_table(&display_page_latency);
43         struct display_table *port = display_page_add_table(&display_page_latency);
44         struct display_table *lat = display_page_add_table(&display_page_latency);
45         struct display_table *acc = display_page_add_table(&display_page_latency);
46         struct display_table *other = display_page_add_table(&display_page_latency);
47
48         display_table_init(core, "Core");
49         core_col = display_table_add_col(core);
50         display_column_init(core_col, "Nb", 4);
51
52         display_table_init(port, "Port Nb");
53         port_col = display_table_add_col(port);
54         display_column_init(port_col, "RX", 8);
55
56         if (screen_state->toggle == 0)
57                 display_table_init(lat, "Measured Latency per interval");
58         else
59                 display_table_init(lat, "Measured Latency since reset");
60
61         min_col = display_table_add_col(lat);
62         display_column_init(min_col, "Min (us)", 20);
63         max_col = display_table_add_col(lat);
64         display_column_init(max_col, "Max (us)", 20);
65         avg_col = display_table_add_col(lat);
66         display_column_init(avg_col, "Avg (us)", 20);
67         stddev_col = display_table_add_col(lat);
68         display_column_init(stddev_col, "Stddev (us)", 20);
69
70         display_table_init(acc, "Accuracy ");
71         used_col = display_table_add_col(acc);
72         display_column_init(used_col, "Used Packets (%)", 16);
73         accuracy_limit_col = display_table_add_col(acc);
74         display_column_init(accuracy_limit_col, "limit (us)", 12);
75
76         display_table_init(other, "Other");
77
78         lost_col = display_table_add_col(other);
79         display_column_init(lost_col, "Lost", 12);
80         mis_ordered_col = display_table_add_col(other);
81         display_column_init(mis_ordered_col, "mis-ordered", 12);
82         extent_col = display_table_add_col(other);
83         display_column_init(extent_col, "extent", 12);
84         duplicate_col = display_table_add_col(other);
85         display_column_init(duplicate_col, "duplicate", 12);
86
87         display_page_draw_frame(&display_page_latency, n_latency);
88
89         for (uint16_t i = 0; i < n_latency; ++i) {
90                 uint32_t lcore_id = stats_latency_get_core_id(i);
91                 uint32_t task_id = stats_latency_get_task_id(i);
92                 struct task_args *targ = &lcore_cfg[lcore_id].targs[task_id];
93
94                 display_column_print(core_col, i, "%2u/%1u", lcore_id, task_id);
95                 display_column_port_ring(port_col, i, targ->rx_port_queue, targ->nb_rxports, targ->rx_rings, targ->nb_rxrings);
96         }
97 }
98
99 #define AFTER_POINT 1000000
100
101 static void display_stats_latency_entry(int row, struct stats_latency *stats_latency)
102 {
103         struct time_unit_err avg = stats_latency->avg;
104         struct time_unit_err min = stats_latency->min;
105         struct time_unit_err max = stats_latency->max;
106         struct time_unit_err stddev = stats_latency->stddev;
107         struct time_unit accuracy_limit = stats_latency->accuracy_limit;
108
109         uint32_t used = 0;
110
111         if (stats_latency->tot_all_packets)
112                 used = stats_latency->tot_packets * (100 * AFTER_POINT) / stats_latency->tot_all_packets;
113
114         char dst[32];
115
116         if (stats_latency->tot_packets) {
117                 display_column_print(min_col, row, "%s", print_time_unit_err_usec(dst, &min));
118                 display_column_print(max_col, row, "%s", print_time_unit_err_usec(dst, &max));
119                 display_column_print(avg_col, row, "%s", print_time_unit_err_usec(dst, &avg));
120                 display_column_print(stddev_col, row, "%s", print_time_unit_err_usec(dst, &stddev));
121         } else {
122                 display_column_print(min_col, row, "%s", "N/A");
123                 display_column_print(max_col, row, "%s", "N/A");
124                 display_column_print(avg_col, row, "%s", "N/A");
125                 display_column_print(stddev_col, row, "%s", "N/A");
126         }
127
128         display_column_print(accuracy_limit_col, row, "%s", print_time_unit_usec(dst, &accuracy_limit));
129         display_column_print(lost_col, row, "%12"PRIu64"", stats_latency->lost_packets);
130         display_column_print(used_col, row, "%3u.%06u", used / AFTER_POINT, used % AFTER_POINT);
131         display_column_print(mis_ordered_col, row, "%12"PRIu64"", stats_latency->mis_ordered);
132         display_column_print(extent_col, row, "%12"PRIu64"", stats_latency->extent);
133         display_column_print(duplicate_col, row, "%12"PRIu64"", stats_latency->duplicate);
134 }
135
136 static void display_latency_draw_stats(struct screen_state *screen_state)
137 {
138         const uint32_t n_latency = stats_get_n_latency();
139         struct stats_latency *stats_latency;
140
141         for (uint16_t i = 0; i < n_latency; ++i) {
142                 if (screen_state->toggle == 0)
143                         stats_latency = stats_latency_get(i);
144                 else
145                         stats_latency = stats_latency_tot_get(i);
146
147                 display_stats_latency_entry(i, stats_latency);
148         }
149 }
150
151 static int display_latency_get_height(void)
152 {
153         return stats_get_n_latency();
154 }
155
156 static struct display_screen display_screen_latency = {
157         .draw_frame = display_latency_draw_frame,
158         .draw_stats = display_latency_draw_stats,
159         .get_height = display_latency_get_height,
160         .title = "latency",
161 };
162
163 struct display_screen *display_latency(void)
164 {
165         return &display_screen_latency;
166 }