Preparation for packet mis-ordering stats
[samplevnf.git] / VNFs / DPPD-PROX / display_irq.c
1 /*
2 // Copyright (c) 2010-2018 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_irq.h"
18 #include "stats_irq.h"
19 #include "display.h"
20 #include "lconf.h"
21
22 static struct display_page display_page_irq;
23 static struct display_column *stats_irq[IRQ_BUCKETS_COUNT];
24 static struct display_column *stats_max;
25 static struct display_column *core_col;
26 static struct display_column *name_col;
27
28 static void display_irq_draw_frame(struct screen_state *state)
29 {
30         uint32_t n_tasks = stats_get_n_irq_tasks();
31         struct lcore_cfg *lconf = NULL;
32         struct task_args *targ;
33         char name[32];
34         char *ptr;
35
36         display_page_init(&display_page_irq);
37
38         struct display_table *core_name = display_page_add_table(&display_page_irq);
39
40         display_table_init(core_name, "Core/task");
41         core_col = display_table_add_col(core_name);
42         name_col = display_table_add_col(core_name);
43         display_column_init(core_col, "Nb", 4);
44         display_column_init(name_col, "Name", 5);
45
46         struct display_table *stats = display_page_add_table(&display_page_irq);
47         if (state->toggle == 0) {
48                 display_table_init(stats, "Statistics per second");
49
50                 char title[64];
51                 stats_max = display_table_add_col(stats);
52                 snprintf(title, sizeof(title), " MAXIMUM(mic)");
53                 display_column_init(stats_max, title, 11);
54
55                 stats_irq[0] = display_table_add_col(stats);
56                 if (irq_bucket_maxtime_micro[0] < 1000)
57                         snprintf(title, sizeof(title), " %d-%ld mic", 0, irq_bucket_maxtime_micro[0]);
58                 else
59                         snprintf(title, sizeof(title), " %d-%ld ms", 0, irq_bucket_maxtime_micro[0] / 1000);
60                 display_column_init(stats_irq[0], title, 9);
61                 for (uint i = 1; i < IRQ_BUCKETS_COUNT - 1; ++i) {
62                         stats_irq[i] = display_table_add_col(stats);
63                         if (irq_bucket_maxtime_micro[i-1] < 1000)
64                                 snprintf(title, sizeof(title), " %ld-%ld mic", irq_bucket_maxtime_micro[i-1], irq_bucket_maxtime_micro[i]);
65                         else
66                                 snprintf(title, sizeof(title), " %ld-%ld ms", irq_bucket_maxtime_micro[i-1] / 1000, irq_bucket_maxtime_micro[i] / 1000);
67                         display_column_init(stats_irq[i], title, 9);
68                 }
69                 stats_irq[IRQ_BUCKETS_COUNT - 1] = display_table_add_col(stats);
70                 if (irq_bucket_maxtime_micro[IRQ_BUCKETS_COUNT - 2] < 1000)
71                         snprintf(title, sizeof(title), "  > %ld mic ", irq_bucket_maxtime_micro[IRQ_BUCKETS_COUNT - 2]);
72                 else
73                         snprintf(title, sizeof(title), " > %ld ms   ", irq_bucket_maxtime_micro[IRQ_BUCKETS_COUNT - 2] / 1000);
74                 display_column_init(stats_irq[IRQ_BUCKETS_COUNT - 1], title, 9);
75         } else {
76                 display_table_init(stats, "Total statistics");
77
78                 char title[64];
79                 stats_max = display_table_add_col(stats);
80                 snprintf(title, sizeof(title), " MAXIMUM(mic)");
81                 display_column_init(stats_max, title, 9);
82
83                 stats_irq[0] = display_table_add_col(stats);
84                 if (irq_bucket_maxtime_micro[0] < 1000)
85                         snprintf(title, sizeof(title), " %d-%ld   ", 0, irq_bucket_maxtime_micro[0]);
86                 else
87                         snprintf(title, sizeof(title), " %d-%ld ms", 0, irq_bucket_maxtime_micro[0] / 1000);
88                 display_column_init(stats_irq[0], title, 9);
89                 for (uint i = 1; i < IRQ_BUCKETS_COUNT - 1; ++i) {
90                         stats_irq[i] = display_table_add_col(stats);
91                         if (irq_bucket_maxtime_micro[i-1] < 1000)
92                                 snprintf(title, sizeof(title), " %ld-%ld  ", irq_bucket_maxtime_micro[i-1], irq_bucket_maxtime_micro[i]);
93                         else
94                                 snprintf(title, sizeof(title), " %ld-%ld ms", irq_bucket_maxtime_micro[i-1] / 1000, irq_bucket_maxtime_micro[i] / 1000);
95                         display_column_init(stats_irq[i], title, 9);
96                 }
97                 stats_irq[IRQ_BUCKETS_COUNT - 1] = display_table_add_col(stats);
98                 if (irq_bucket_maxtime_micro[IRQ_BUCKETS_COUNT - 2] < 1000)
99                         snprintf(title, sizeof(title), " > %ld ", irq_bucket_maxtime_micro[IRQ_BUCKETS_COUNT - 2]);
100                 else
101                         snprintf(title, sizeof(title), " > %ld  ", irq_bucket_maxtime_micro[IRQ_BUCKETS_COUNT - 2] / 1000);
102                 display_column_init(stats_irq[IRQ_BUCKETS_COUNT - 1], title, 9);
103         }
104
105         display_page_draw_frame(&display_page_irq, n_tasks);
106
107         uint32_t count = 0;
108         lconf = NULL;
109         while (core_targ_next(&lconf, &targ, 0) == 0) {
110                 if (strcmp(targ->task_init->mode_str, "irq") == 0) {
111                         display_column_print_core_task(core_col, count, lconf, targ);
112                         if (targ->id == 0)
113                                 display_column_print(name_col, count, "%s", lconf->name);
114                         count++;
115                 }
116         }
117 }
118
119 static void display_irq_draw_stats(struct screen_state *state)
120 {
121         struct lcore_cfg *lconf = NULL;
122         struct task_args *targ;
123         const uint32_t n_stats_irq = stats_get_n_irq_tasks();
124
125         if (state->toggle == 0) {
126                 for (uint32_t count = 0; count < n_stats_irq; ++count) {
127                         struct irq_sample *last = get_irq_sample(count, 1);
128                         struct irq_sample *prev = get_irq_sample(count, 0);
129
130                         display_column_print(stats_max, count, "%9lu", (last->max_irq * 1000000L) / rte_get_tsc_hz());
131                         for (uint i = 0; i < IRQ_BUCKETS_COUNT; ++i) {
132                                 display_column_print(stats_irq[i], count, "%9lu", last->irq[i] - prev->irq[i]);
133                         }
134                 }
135         } else {
136                 for (uint32_t count = 0; count < n_stats_irq; ++count) {
137                         display_column_print(stats_max, count, "%9lu", get_max_irq_stats(count));
138                         for (uint i = 0; i < IRQ_BUCKETS_COUNT; ++i) {
139                                 display_column_print(stats_irq[i], count, "%9lu", get_irq_stats(count, i));
140                         }
141                 }
142         }
143 }
144
145 static int display_irq_get_height(void)
146 {
147         return stats_get_n_irq_tasks();
148 }
149
150 static struct display_screen display_screen_irq = {
151         .draw_frame = display_irq_draw_frame,
152         .draw_stats = display_irq_draw_stats,
153         .get_height = display_irq_get_height,
154         .title = "irq",
155 };
156
157 struct display_screen *display_irq(void)
158 {
159         return &display_screen_irq;
160 }