75075a1069c0d3961c7924480ba239b171cc0ea8
[samplevnf.git] / VNFs / DPPD-PROX / display_tasks.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_tasks.h"
18 #include "display.h"
19 #include "prox_globals.h"
20 #include "stats_task.h"
21 #include "stats_core.h"
22 #include "lconf.h"
23
24 struct task_stats_disp {
25         uint32_t lcore_id;
26         uint32_t task_id;
27         uint32_t lcore_stat_id;
28 };
29
30 static int col_offset;
31 static struct task_stats_disp task_stats_disp[RTE_MAX_LCORE * MAX_TASKS_PER_CORE];
32
33 static struct display_page display_page_tasks;
34
35 static struct display_column *nb_col;
36 static struct display_column *name_col;
37 static struct display_column *mode_col;
38 static struct display_column *rx_name_col;
39 static struct display_column *tx_name_col;
40 static struct display_column *idle_col;
41 static struct display_column *rx_col;
42 static struct display_column *tx_col;
43 static struct display_column *tx_fail_col;
44 static struct display_column *discard_col;
45 static struct display_column *handled_col;
46 static struct display_column *cpp_col;
47 static struct display_column *ghz_col;
48 static struct display_column *rx_col;
49 static struct display_column *tx_col;
50 static struct display_column *tx_fail_col;
51 static struct display_column *discard_col;
52 static struct display_column *handled_col;
53 static struct display_column *occup_col;
54 static struct display_column *mask_col;
55 static struct display_column *class_col;
56 static struct display_column *mbm_tot_col;
57 static struct display_column *mbm_loc_col;
58 static struct display_column *frac_col;
59
60 static void stats_display_core_task_entry(struct lcore_cfg *lconf, struct task_args *targ, unsigned row)
61 {
62         display_column_print_core_task(nb_col, row, lconf, targ);
63
64         display_column_print(name_col, row, "%s", targ->id == 0 ? lconf->name : "");
65         display_column_print(mode_col, row, "%s", targ->task_init->mode_str);
66
67         display_column_port_ring(rx_name_col, row, targ->rx_port_queue, targ->nb_rxports, targ->rx_rings, targ->nb_rxrings);
68         display_column_port_ring(tx_name_col, row, targ->tx_port_queue, targ->nb_txports, targ->tx_rings, targ->nb_txrings);
69 }
70
71 static void display_tasks_draw_frame(struct screen_state *state)
72 {
73         const uint32_t n_tasks_tot = stats_get_n_tasks_tot();
74
75         display_page_init(&display_page_tasks);
76
77         struct display_table *core_task = display_page_add_table(&display_page_tasks);
78         struct display_table *rx_tx = display_page_add_table(&display_page_tasks);
79
80         display_table_init(core_task, "Core/Task");
81
82         nb_col = display_table_add_col(core_task);
83         display_column_init(nb_col, "Nb", 4);
84         name_col = display_table_add_col(core_task);
85         display_column_init(name_col, "Name", 7);
86         mode_col = display_table_add_col(core_task);
87         display_column_init(mode_col, "Mode", 9);
88
89         display_table_init(rx_tx, "Port ID/Ring Name");
90         rx_name_col = display_table_add_col(rx_tx);
91         display_column_init(rx_name_col, "RX", 9);
92         tx_name_col = display_table_add_col(rx_tx);
93         display_column_init(tx_name_col, "TX", 9);
94
95         struct display_table *stats = display_page_add_table(&display_page_tasks);
96
97         if (state->toggle == 0) {
98                 display_table_init(stats, "Statistics per second");
99
100                 idle_col = display_table_add_col(stats);
101                 display_column_init(idle_col, "Idle (%)", 5);
102
103                 rx_col = display_table_add_col(stats);
104                 display_column_init(rx_col, "RX (K)", 9);
105
106                 tx_col = display_table_add_col(stats);
107                 display_column_init(tx_col, "TX (K)", 9);
108
109                 tx_fail_col = display_table_add_col(stats);
110                 display_column_init(tx_fail_col, "TX Fail (K)", 9);
111
112                 discard_col = display_table_add_col(stats);
113                 display_column_init(discard_col, "Discard (K)", 9);
114
115                 handled_col = display_table_add_col(stats);
116                 display_column_init(handled_col, "Handled (K)", 9);
117
118                 if (stats_cpu_freq_enabled()) {
119                         struct display_table *other = display_page_add_table(&display_page_tasks);
120
121                         display_table_init(other, "Other");
122
123                         cpp_col = display_table_add_col(other);
124                         display_column_init(cpp_col, "CPP", 9);
125
126                         ghz_col = display_table_add_col(other);
127                         display_column_init(ghz_col, "Clk (GHz)", 9);
128                 }
129                 if (stats_mbm_enabled()) {
130                         struct display_table *other = display_page_add_table(&display_page_tasks);
131                         mbm_tot_col = display_table_add_col(other);
132                         display_column_init(mbm_tot_col, "Tot Bdw(M)", 10);
133                         mbm_loc_col = display_table_add_col(other);
134                         display_column_init(mbm_loc_col, "Loc Bdw(M)", 10);
135                 }
136         } else {
137                 display_table_init(stats, "Total Statistics");
138
139                 rx_col = display_table_add_col(stats);
140                 display_column_init(rx_col, "RX (K)", 14);
141
142                 tx_col = display_table_add_col(stats);
143                 display_column_init(tx_col, "TX (K)", 14);
144
145                 tx_fail_col = display_table_add_col(stats);
146                 display_column_init(tx_fail_col, "TX Fail (K)", 14);
147
148                 discard_col = display_table_add_col(stats);
149                 display_column_init(discard_col, "Discard (K)", 14);
150
151                 handled_col = display_table_add_col(stats);
152                 display_column_init(handled_col, "Handled (K)", 14);
153
154                 if (stats_cmt_enabled()) {
155                         struct display_table *other = display_page_add_table(&display_page_tasks);
156
157                         display_table_init(other, "Cache QoS Monitoring");
158
159                         occup_col = display_table_add_col(other);
160                         display_column_init(occup_col, "Occupancy (KB)", 15);
161
162                         frac_col = display_table_add_col(other);
163                         display_column_init(frac_col, "Fraction", 9);
164                 }
165                 if (stats_cat_enabled()) {
166                         struct display_table *other = display_page_add_table(&display_page_tasks);
167                         mask_col = display_table_add_col(other);
168                         display_column_init(mask_col, "Cache mask", 10);
169                         class_col = display_table_add_col(other);
170                         display_column_init(class_col, "Class", 5);
171                 }
172         }
173         display_page_draw_frame(&display_page_tasks, n_tasks_tot);
174
175         uint16_t element_count = 0;
176
177         struct lcore_cfg *lconf = NULL;
178         struct task_args *targ;
179
180         while (core_targ_next(&lconf, &targ, 0) == 0) {
181                 PROX_ASSERT(element_count < RTE_MAX_LCORE * MAX_TASKS_PER_CORE);
182
183                 stats_display_core_task_entry(lconf, targ, element_count);
184
185                 task_stats_disp[element_count].lcore_id = lconf->id;
186                 task_stats_disp[element_count].task_id = targ->id;
187                 task_stats_disp[element_count].lcore_stat_id = stats_lcore_find_stat_id(lconf->id);
188                 element_count++;
189         }
190 }
191
192 static void print_kpps(struct display_column *col, int row, uint64_t nb_pkts, uint64_t delta_t)
193 {
194         nb_pkts *= tsc_hz;
195         if (nb_pkts && nb_pkts /100 < delta_t) {
196                 uint64_t int_part = nb_pkts/delta_t;
197                 uint64_t frac_part = (nb_pkts - int_part * delta_t) * 1000 /delta_t;
198                 display_column_print(col, row, "%2lu.%03lu", int_part, frac_part);
199         }
200         else {
201                 display_column_print(col, row, "%9lu", nb_pkts / delta_t);
202         }
203 }
204
205 static void display_core_task_stats_per_sec(const struct task_stats_disp *t, struct screen_state *state, int row)
206 {
207         struct task_stats_sample *last = stats_get_task_stats_sample(t->lcore_id, t->task_id, 1);
208         struct task_stats_sample *prev = stats_get_task_stats_sample(t->lcore_id, t->task_id, 0);
209
210         /* delta_t in units of clock ticks */
211         uint64_t delta_t = last->tsc - prev->tsc;
212
213         uint64_t empty_cycles = last->empty_cycles - prev->empty_cycles;
214
215         if (empty_cycles > delta_t) {
216                 empty_cycles = 10000;
217         }
218         else {
219                 empty_cycles = empty_cycles * 10000 / delta_t;
220         }
221
222         /* empty_cycles has 2 digits after point, (usefull when only a very small idle time) */
223
224         display_column_print(idle_col, row, "%3lu.%02lu", empty_cycles / 100, empty_cycles % 100);
225
226         // Display per second statistics in Kpps unit
227         delta_t *= state->pps_unit;
228
229         print_kpps(rx_col, row, last->rx_pkt_count - prev->rx_pkt_count, delta_t);
230         print_kpps(tx_col, row, last->tx_pkt_count - prev->tx_pkt_count, delta_t);
231         print_kpps(tx_fail_col, row, last->drop_tx_fail - prev->drop_tx_fail, delta_t);
232         print_kpps(discard_col, row, last->drop_discard - prev->drop_discard, delta_t);
233         print_kpps(handled_col, row, last->drop_handled - prev->drop_handled, delta_t);
234
235         if (stats_cpu_freq_enabled()) {
236                 uint8_t lcore_stat_id = t->lcore_stat_id;
237                 struct lcore_stats_sample *clast = stats_get_lcore_stats_sample(lcore_stat_id, 1);
238                 struct lcore_stats_sample *cprev = stats_get_lcore_stats_sample(lcore_stat_id, 0);
239
240                 uint64_t adiff = clast->afreq - cprev->afreq;
241                 uint64_t mdiff = clast->mfreq - cprev->mfreq;
242
243                 uint64_t cpp = 0;
244
245                 uint64_t pkt_diff_rx = last->rx_pkt_count - prev->rx_pkt_count;
246                 uint64_t pkt_diff_tx = last->tx_pkt_count - prev->tx_pkt_count;
247
248                 uint64_t pkt_diff = pkt_diff_tx > pkt_diff_rx? pkt_diff_tx : pkt_diff_rx;
249
250                 if (pkt_diff && mdiff) {
251                         cpp = delta_t/pkt_diff*adiff/mdiff/1000;
252                 }
253
254                 uint64_t mhz;
255                 if (mdiff)
256                         mhz = tsc_hz*adiff/mdiff/1000000;
257                 else
258                         mhz = 0;
259
260                 display_column_print(cpp_col, row, "%lu", cpp);
261                 display_column_print(ghz_col, row, "%lu.%03lu", mhz/1000, mhz%1000);
262         }
263         if (stats_mbm_enabled()) {
264                 struct lcore_stats *c = stats_get_lcore_stats(t->lcore_stat_id);
265                 uint8_t lcore_stat_id = t->lcore_stat_id;
266                 struct lcore_stats_sample *clast = stats_get_lcore_stats_sample(lcore_stat_id, 1);
267                 struct lcore_stats_sample *cprev = stats_get_lcore_stats_sample(lcore_stat_id, 0);
268                 if ((clast->mbm_tot_bytes - cprev->mbm_tot_bytes) >> 20)
269                         display_column_print(mbm_tot_col, row, "%lu", (clast->mbm_tot_bytes - cprev->mbm_tot_bytes) >> 20);
270                 else
271                         display_column_print(mbm_tot_col, row, "0.%03lu", (clast->mbm_tot_bytes - cprev->mbm_tot_bytes) >> 10);
272                 if( (clast->mbm_loc_bytes - cprev->mbm_loc_bytes) >> 20)
273                         display_column_print(mbm_loc_col, row, "%lu", (clast->mbm_loc_bytes - cprev->mbm_loc_bytes) >> 20);
274                 else
275                         display_column_print(mbm_loc_col, row, "0.%03lu", (clast->mbm_loc_bytes - cprev->mbm_loc_bytes) >> 10);
276         }
277 }
278
279 static void display_core_task_stats_tot(const struct task_stats_disp *t, struct screen_state *state, int row)
280 {
281         struct task_stats *ts = stats_get_task_stats(t->lcore_id, t->task_id);
282
283         display_column_print(rx_col, row, "%lu", ts->tot_rx_pkt_count);
284         display_column_print(tx_col, row, "%lu", ts->tot_tx_pkt_count);
285         display_column_print(tx_fail_col, row, "%lu", ts->tot_drop_tx_fail);
286         display_column_print(discard_col, row, "%lu", ts->tot_drop_discard);
287         display_column_print(handled_col, row, "%lu", ts->tot_drop_handled);
288
289         if (stats_cmt_enabled()) {
290                 struct lcore_stats *c = stats_get_lcore_stats(t->lcore_stat_id);
291                 display_column_print(occup_col, row, "%lu", c->cmt_bytes >> 10);
292                 display_column_print(frac_col, row, "%3lu.%02lu", c->cmt_fraction/100, c->cmt_fraction%100);
293         }
294         if (stats_cat_enabled()) {
295                 struct lcore_stats *c = stats_get_lcore_stats(t->lcore_stat_id);
296                 display_column_print(mask_col, row, "%x", c->cat_mask);
297                 display_column_print(class_col, row, "%x", c->class);
298         }
299 }
300
301 static void display_tasks_draw_stats(struct screen_state *state)
302 {
303         const uint32_t n_tasks_tot = stats_get_n_tasks_tot();
304
305         for (uint8_t i = 0; i < n_tasks_tot; ++i) {
306                 const struct task_stats_disp *disp = &task_stats_disp[i];
307
308                 if (state->toggle == 0) {
309                         display_core_task_stats_per_sec(disp, state, i);
310                 } else {
311                         display_core_task_stats_tot(disp, state, i);
312                 }
313         }
314 }
315
316 static int display_tasks_get_height(void)
317 {
318         return stats_get_n_tasks_tot();
319 }
320
321 static struct display_screen display_screen_tasks = {
322         .draw_frame = display_tasks_draw_frame,
323         .draw_stats = display_tasks_draw_stats,
324         .get_height = display_tasks_get_height,
325         .title = "tasks",
326 };
327
328 struct display_screen *display_tasks(void)
329 {
330         return &display_screen_tasks;
331 }