build: use static deps for pkg-config libs.private
[dpdk.git] / examples / qos_sched / stats.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2014 Intel Corporation
3  */
4
5 #include <unistd.h>
6 #include <string.h>
7
8 #include "main.h"
9
10 int
11 qavg_q(uint16_t port_id, uint32_t subport_id, uint32_t pipe_id, uint8_t tc,
12                 uint8_t q)
13 {
14         struct rte_sched_queue_stats stats;
15         struct rte_sched_port *port;
16         uint16_t qlen;
17         uint32_t queue_id, count, i;
18         uint32_t average;
19
20         for (i = 0; i < nb_pfc; i++) {
21                 if (qos_conf[i].tx_port == port_id)
22                         break;
23         }
24         if (i == nb_pfc || subport_id >= port_params.n_subports_per_port || pipe_id >= port_params.n_pipes_per_subport
25                         || tc >= RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE || q >= RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS)
26                 return -1;
27
28         port = qos_conf[i].sched_port;
29
30         queue_id = RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE * RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS * (subport_id * port_params.n_pipes_per_subport + pipe_id);
31         queue_id = queue_id + (tc * RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS + q);
32
33         average = 0;
34
35         for (count = 0; count < qavg_ntimes; count++) {
36                 rte_sched_queue_read_stats(port, queue_id, &stats, &qlen);
37                 average += qlen;
38                 usleep(qavg_period);
39         }
40
41         average /= qavg_ntimes;
42
43         printf("\nAverage queue size: %" PRIu32 " bytes.\n\n", average);
44
45         return 0;
46 }
47
48 int
49 qavg_tcpipe(uint16_t port_id, uint32_t subport_id, uint32_t pipe_id,
50              uint8_t tc)
51 {
52         struct rte_sched_queue_stats stats;
53         struct rte_sched_port *port;
54         uint16_t qlen;
55         uint32_t queue_id, count, i;
56         uint32_t average, part_average;
57
58         for (i = 0; i < nb_pfc; i++) {
59                 if (qos_conf[i].tx_port == port_id)
60                         break;
61         }
62         if (i == nb_pfc || subport_id >= port_params.n_subports_per_port || pipe_id >= port_params.n_pipes_per_subport
63                         || tc >= RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE)
64                 return -1;
65
66         port = qos_conf[i].sched_port;
67
68         queue_id = RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE * RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS * (subport_id * port_params.n_pipes_per_subport + pipe_id);
69
70         average = 0;
71
72         for (count = 0; count < qavg_ntimes; count++) {
73                 part_average = 0;
74                 for (i = 0; i < RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS; i++) {
75                         rte_sched_queue_read_stats(port, queue_id + (tc * RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS + i), &stats, &qlen);
76                         part_average += qlen;
77                 }
78                 average += part_average / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS;
79                 usleep(qavg_period);
80         }
81
82         average /= qavg_ntimes;
83
84         printf("\nAverage queue size: %" PRIu32 " bytes.\n\n", average);
85
86         return 0;
87 }
88
89 int
90 qavg_pipe(uint16_t port_id, uint32_t subport_id, uint32_t pipe_id)
91 {
92         struct rte_sched_queue_stats stats;
93         struct rte_sched_port *port;
94         uint16_t qlen;
95         uint32_t queue_id, count, i;
96         uint32_t average, part_average;
97
98         for (i = 0; i < nb_pfc; i++) {
99                 if (qos_conf[i].tx_port == port_id)
100                         break;
101         }
102         if (i == nb_pfc || subport_id >= port_params.n_subports_per_port || pipe_id >= port_params.n_pipes_per_subport)
103                 return -1;
104
105         port = qos_conf[i].sched_port;
106
107         queue_id = RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE * RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS * (subport_id * port_params.n_pipes_per_subport + pipe_id);
108
109         average = 0;
110
111         for (count = 0; count < qavg_ntimes; count++) {
112                 part_average = 0;
113                 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE * RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS; i++) {
114                         rte_sched_queue_read_stats(port, queue_id + i, &stats, &qlen);
115                         part_average += qlen;
116                 }
117                 average += part_average / (RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE * RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS);
118                 usleep(qavg_period);
119         }
120
121         average /= qavg_ntimes;
122
123         printf("\nAverage queue size: %" PRIu32 " bytes.\n\n", average);
124
125         return 0;
126 }
127
128 int
129 qavg_tcsubport(uint16_t port_id, uint32_t subport_id, uint8_t tc)
130 {
131         struct rte_sched_queue_stats stats;
132         struct rte_sched_port *port;
133         uint16_t qlen;
134         uint32_t queue_id, count, i, j;
135         uint32_t average, part_average;
136
137         for (i = 0; i < nb_pfc; i++) {
138                 if (qos_conf[i].tx_port == port_id)
139                         break;
140         }
141         if (i == nb_pfc || subport_id >= port_params.n_subports_per_port || tc >= RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE)
142                 return -1;
143
144         port = qos_conf[i].sched_port;
145
146         average = 0;
147
148         for (count = 0; count < qavg_ntimes; count++) {
149                 part_average = 0;
150                 for (i = 0; i < port_params.n_pipes_per_subport; i++) {
151                         queue_id = RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE * RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS * (subport_id * port_params.n_pipes_per_subport + i);
152
153                         for (j = 0; j < RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS; j++) {
154                                 rte_sched_queue_read_stats(port, queue_id + (tc * RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS + j), &stats, &qlen);
155                                 part_average += qlen;
156                         }
157                 }
158
159                 average += part_average / (port_params.n_pipes_per_subport * RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS);
160                 usleep(qavg_period);
161         }
162
163         average /= qavg_ntimes;
164
165         printf("\nAverage queue size: %" PRIu32 " bytes.\n\n", average);
166
167         return 0;
168 }
169
170 int
171 qavg_subport(uint16_t port_id, uint32_t subport_id)
172 {
173         struct rte_sched_queue_stats stats;
174         struct rte_sched_port *port;
175         uint16_t qlen;
176         uint32_t queue_id, count, i, j;
177         uint32_t average, part_average;
178
179         for (i = 0; i < nb_pfc; i++) {
180                 if (qos_conf[i].tx_port == port_id)
181                         break;
182         }
183         if (i == nb_pfc || subport_id >= port_params.n_subports_per_port)
184                 return -1;
185
186         port = qos_conf[i].sched_port;
187
188         average = 0;
189
190         for (count = 0; count < qavg_ntimes; count++) {
191                 part_average = 0;
192                 for (i = 0; i < port_params.n_pipes_per_subport; i++) {
193                         queue_id = RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE * RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS * (subport_id * port_params.n_pipes_per_subport + i);
194
195                         for (j = 0; j < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE * RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS; j++) {
196                                 rte_sched_queue_read_stats(port, queue_id + j, &stats, &qlen);
197                                 part_average += qlen;
198                         }
199                 }
200
201                 average += part_average / (port_params.n_pipes_per_subport * RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE * RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS);
202                 usleep(qavg_period);
203         }
204
205         average /= qavg_ntimes;
206
207         printf("\nAverage queue size: %" PRIu32 " bytes.\n\n", average);
208
209         return 0;
210 }
211
212 int
213 subport_stat(uint16_t port_id, uint32_t subport_id)
214 {
215         struct rte_sched_subport_stats stats;
216         struct rte_sched_port *port;
217         uint32_t tc_ov[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
218         uint8_t i;
219
220         for (i = 0; i < nb_pfc; i++) {
221                 if (qos_conf[i].tx_port == port_id)
222                         break;
223         }
224         if (i == nb_pfc || subport_id >= port_params.n_subports_per_port)
225                 return -1;
226
227         port = qos_conf[i].sched_port;
228         memset (tc_ov, 0, sizeof(tc_ov));
229
230         rte_sched_subport_read_stats(port, subport_id, &stats, tc_ov);
231
232         printf("\n");
233         printf("+----+-------------+-------------+-------------+-------------+-------------+\n");
234         printf("| TC |   Pkts OK   |Pkts Dropped |  Bytes OK   |Bytes Dropped|  OV Status  |\n");
235         printf("+----+-------------+-------------+-------------+-------------+-------------+\n");
236
237         for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++) {
238                 printf("|  %d | %11" PRIu32 " | %11" PRIu32 " | %11" PRIu32 " | %11" PRIu32 " | %11" PRIu32 " |\n", i,
239                                 stats.n_pkts_tc[i], stats.n_pkts_tc_dropped[i],
240                                 stats.n_bytes_tc[i], stats.n_bytes_tc_dropped[i], tc_ov[i]);
241                 printf("+----+-------------+-------------+-------------+-------------+-------------+\n");
242         }
243         printf("\n");
244
245         return 0;
246 }
247
248 int
249 pipe_stat(uint16_t port_id, uint32_t subport_id, uint32_t pipe_id)
250 {
251         struct rte_sched_queue_stats stats;
252         struct rte_sched_port *port;
253         uint16_t qlen;
254         uint8_t i, j;
255         uint32_t queue_id;
256
257         for (i = 0; i < nb_pfc; i++) {
258                 if (qos_conf[i].tx_port == port_id)
259                         break;
260         }
261         if (i == nb_pfc || subport_id >= port_params.n_subports_per_port || pipe_id >= port_params.n_pipes_per_subport)
262                 return -1;
263
264         port = qos_conf[i].sched_port;
265
266         queue_id = RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE * RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS * (subport_id * port_params.n_pipes_per_subport + pipe_id);
267
268         printf("\n");
269         printf("+----+-------+-------------+-------------+-------------+-------------+-------------+\n");
270         printf("| TC | Queue |   Pkts OK   |Pkts Dropped |  Bytes OK   |Bytes Dropped|    Length   |\n");
271         printf("+----+-------+-------------+-------------+-------------+-------------+-------------+\n");
272
273         for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++) {
274                 for (j = 0; j < RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS; j++) {
275
276                         rte_sched_queue_read_stats(port, queue_id + (i * RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS + j), &stats, &qlen);
277
278                         printf("|  %d |   %d   | %11" PRIu32 " | %11" PRIu32 " | %11" PRIu32 " | %11" PRIu32 " | %11i |\n", i, j,
279                                         stats.n_pkts, stats.n_pkts_dropped, stats.n_bytes, stats.n_bytes_dropped, qlen);
280                         printf("+----+-------+-------------+-------------+-------------+-------------+-------------+\n");
281                 }
282                 if (i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE - 1)
283                         printf("+----+-------+-------------+-------------+-------------+-------------+-------------+\n");
284         }
285         printf("\n");
286
287         return 0;
288 }