]> git.proxmox.com Git - ceph.git/blame - ceph/src/spdk/dpdk/examples/qos_sched/stats.c
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / spdk / dpdk / examples / qos_sched / stats.c
CommitLineData
11fdf7f2
TL
1/* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
3 */
7c673cae
FG
4
5#include <unistd.h>
6#include <string.h>
7
8#include "main.h"
9
10int
11fdf7f2
TL
11qavg_q(uint16_t port_id, uint32_t subport_id, uint32_t pipe_id, uint8_t tc,
12 uint8_t q)
7c673cae 13{
f67539c2
TL
14 struct rte_sched_queue_stats stats;
15 struct rte_sched_port *port;
16 uint16_t qlen;
17 uint32_t count, i, queue_id = 0;
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
25 if (i == nb_pfc ||
26 subport_id >= port_params.n_subports_per_port ||
27 pipe_id >= subport_params[subport_id].n_pipes_per_subport_enabled ||
28 tc >= RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE ||
29 q >= RTE_SCHED_BE_QUEUES_PER_PIPE ||
30 (tc < RTE_SCHED_TRAFFIC_CLASS_BE && q > 0))
31 return -1;
32
33 port = qos_conf[i].sched_port;
34 for (i = 0; i < subport_id; i++)
35 queue_id += subport_params[i].n_pipes_per_subport_enabled *
36 RTE_SCHED_QUEUES_PER_PIPE;
37 if (tc < RTE_SCHED_TRAFFIC_CLASS_BE)
38 queue_id += pipe_id * RTE_SCHED_QUEUES_PER_PIPE + tc;
39 else
40 queue_id += pipe_id * RTE_SCHED_QUEUES_PER_PIPE + tc + q;
41
42 average = 0;
43 for (count = 0; count < qavg_ntimes; count++) {
44 rte_sched_queue_read_stats(port, queue_id, &stats, &qlen);
45 average += qlen;
46 usleep(qavg_period);
47 }
48
49 average /= qavg_ntimes;
50
51 printf("\nAverage queue size: %" PRIu32 " bytes.\n\n", average);
52
53 return 0;
7c673cae
FG
54}
55
56int
11fdf7f2 57qavg_tcpipe(uint16_t port_id, uint32_t subport_id, uint32_t pipe_id,
f67539c2 58 uint8_t tc)
7c673cae 59{
f67539c2
TL
60 struct rte_sched_queue_stats stats;
61 struct rte_sched_port *port;
62 uint16_t qlen;
63 uint32_t count, i, queue_id = 0;
64 uint32_t average, part_average;
65
66 for (i = 0; i < nb_pfc; i++) {
67 if (qos_conf[i].tx_port == port_id)
68 break;
69 }
70
71 if (i == nb_pfc || subport_id >= port_params.n_subports_per_port ||
72 pipe_id >= subport_params[subport_id].n_pipes_per_subport_enabled ||
73 tc >= RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE)
74 return -1;
75
76 port = qos_conf[i].sched_port;
77
78 for (i = 0; i < subport_id; i++)
79 queue_id +=
80 subport_params[i].n_pipes_per_subport_enabled *
81 RTE_SCHED_QUEUES_PER_PIPE;
82
83 queue_id += pipe_id * RTE_SCHED_QUEUES_PER_PIPE + tc;
84
85 average = 0;
86
87 for (count = 0; count < qavg_ntimes; count++) {
88 part_average = 0;
89
90 if (tc < RTE_SCHED_TRAFFIC_CLASS_BE) {
91 rte_sched_queue_read_stats(port, queue_id,
92 &stats, &qlen);
93 part_average += qlen;
94 } else {
95 for (i = 0; i < RTE_SCHED_BE_QUEUES_PER_PIPE; i++) {
96 rte_sched_queue_read_stats(port, queue_id + i,
97 &stats, &qlen);
98 part_average += qlen;
99 }
100 average += part_average / RTE_SCHED_BE_QUEUES_PER_PIPE;
101 }
102 usleep(qavg_period);
103 }
104
105 average /= qavg_ntimes;
106
107 printf("\nAverage queue size: %" PRIu32 " bytes.\n\n", average);
108
109 return 0;
7c673cae
FG
110}
111
112int
11fdf7f2 113qavg_pipe(uint16_t port_id, uint32_t subport_id, uint32_t pipe_id)
7c673cae 114{
f67539c2
TL
115 struct rte_sched_queue_stats stats;
116 struct rte_sched_port *port;
117 uint16_t qlen;
118 uint32_t count, i, queue_id = 0;
119 uint32_t average, part_average;
120
121 for (i = 0; i < nb_pfc; i++) {
122 if (qos_conf[i].tx_port == port_id)
123 break;
124 }
7c673cae 125
f67539c2
TL
126 if (i == nb_pfc ||
127 subport_id >= port_params.n_subports_per_port ||
128 pipe_id >= subport_params[subport_id].n_pipes_per_subport_enabled)
129 return -1;
7c673cae 130
f67539c2 131 port = qos_conf[i].sched_port;
7c673cae 132
f67539c2
TL
133 for (i = 0; i < subport_id; i++)
134 queue_id += subport_params[i].n_pipes_per_subport_enabled *
135 RTE_SCHED_QUEUES_PER_PIPE;
7c673cae 136
f67539c2 137 queue_id += pipe_id * RTE_SCHED_QUEUES_PER_PIPE;
7c673cae 138
f67539c2 139 average = 0;
7c673cae 140
f67539c2
TL
141 for (count = 0; count < qavg_ntimes; count++) {
142 part_average = 0;
143 for (i = 0; i < RTE_SCHED_QUEUES_PER_PIPE; i++) {
144 rte_sched_queue_read_stats(port, queue_id + i,
145 &stats, &qlen);
146 part_average += qlen;
147 }
148 average += part_average / RTE_SCHED_QUEUES_PER_PIPE;
149 usleep(qavg_period);
150 }
7c673cae 151
f67539c2 152 average /= qavg_ntimes;
7c673cae 153
f67539c2
TL
154 printf("\nAverage queue size: %" PRIu32 " bytes.\n\n", average);
155
156 return 0;
7c673cae
FG
157}
158
159int
11fdf7f2 160qavg_tcsubport(uint16_t port_id, uint32_t subport_id, uint8_t tc)
7c673cae 161{
f67539c2
TL
162 struct rte_sched_queue_stats stats;
163 struct rte_sched_port *port;
164 uint16_t qlen;
165 uint32_t queue_id, count, i, j, subport_queue_id = 0;
166 uint32_t average, part_average;
167
168 for (i = 0; i < nb_pfc; i++) {
169 if (qos_conf[i].tx_port == port_id)
170 break;
171 }
172
173 if (i == nb_pfc ||
174 subport_id >= port_params.n_subports_per_port ||
175 tc >= RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE)
176 return -1;
177
178 port = qos_conf[i].sched_port;
179
180 for (i = 0; i < subport_id; i++)
181 subport_queue_id +=
182 subport_params[i].n_pipes_per_subport_enabled *
183 RTE_SCHED_QUEUES_PER_PIPE;
184
185 average = 0;
186
187 for (count = 0; count < qavg_ntimes; count++) {
188 uint32_t n_pipes_per_subport =
189 subport_params[subport_id].n_pipes_per_subport_enabled;
190
191 part_average = 0;
192 for (i = 0; i < n_pipes_per_subport; i++) {
193 if (tc < RTE_SCHED_TRAFFIC_CLASS_BE) {
194 queue_id = subport_queue_id +
195 i * RTE_SCHED_QUEUES_PER_PIPE + tc;
196 rte_sched_queue_read_stats(port, queue_id,
197 &stats, &qlen);
198 part_average += qlen;
199 } else {
200 for (j = 0; j < RTE_SCHED_BE_QUEUES_PER_PIPE; j++) {
201 queue_id = subport_queue_id +
202 i * RTE_SCHED_QUEUES_PER_PIPE +
203 tc + j;
204 rte_sched_queue_read_stats(port, queue_id,
205 &stats, &qlen);
206 part_average += qlen;
207 }
208 }
209 }
210
211 if (tc < RTE_SCHED_TRAFFIC_CLASS_BE)
212 average += part_average /
213 (subport_params[subport_id].n_pipes_per_subport_enabled);
214 else
215 average += part_average /
216 (subport_params[subport_id].n_pipes_per_subport_enabled) *
217 RTE_SCHED_BE_QUEUES_PER_PIPE;
218
219 usleep(qavg_period);
220 }
221
222 average /= qavg_ntimes;
223
224 printf("\nAverage queue size: %" PRIu32 " bytes.\n\n", average);
225
226 return 0;
7c673cae
FG
227}
228
229int
11fdf7f2 230qavg_subport(uint16_t port_id, uint32_t subport_id)
7c673cae 231{
f67539c2
TL
232 struct rte_sched_queue_stats stats;
233 struct rte_sched_port *port;
234 uint16_t qlen;
235 uint32_t queue_id, count, i, j, subport_queue_id = 0;
236 uint32_t average, part_average;
237
238 for (i = 0; i < nb_pfc; i++) {
239 if (qos_conf[i].tx_port == port_id)
240 break;
241 }
242
243 if (i == nb_pfc ||
244 subport_id >= port_params.n_subports_per_port)
245 return -1;
246
247 port = qos_conf[i].sched_port;
7c673cae 248
f67539c2
TL
249 for (i = 0; i < subport_id; i++)
250 subport_queue_id += subport_params[i].n_pipes_per_subport_enabled *
251 RTE_SCHED_QUEUES_PER_PIPE;
7c673cae 252
f67539c2 253 average = 0;
7c673cae 254
f67539c2
TL
255 for (count = 0; count < qavg_ntimes; count++) {
256 uint32_t n_pipes_per_subport =
257 subport_params[subport_id].n_pipes_per_subport_enabled;
7c673cae 258
f67539c2
TL
259 part_average = 0;
260 for (i = 0; i < n_pipes_per_subport; i++) {
261 queue_id = subport_queue_id + i * RTE_SCHED_QUEUES_PER_PIPE;
7c673cae 262
f67539c2
TL
263 for (j = 0; j < RTE_SCHED_QUEUES_PER_PIPE; j++) {
264 rte_sched_queue_read_stats(port, queue_id + j,
265 &stats, &qlen);
266 part_average += qlen;
267 }
268 }
7c673cae 269
f67539c2
TL
270 average += part_average /
271 (subport_params[subport_id].n_pipes_per_subport_enabled *
272 RTE_SCHED_QUEUES_PER_PIPE);
273 usleep(qavg_period);
274 }
7c673cae 275
f67539c2 276 average /= qavg_ntimes;
7c673cae 277
f67539c2 278 printf("\nAverage queue size: %" PRIu32 " bytes.\n\n", average);
7c673cae 279
f67539c2 280 return 0;
7c673cae
FG
281}
282
283int
11fdf7f2 284subport_stat(uint16_t port_id, uint32_t subport_id)
7c673cae 285{
f67539c2
TL
286 struct rte_sched_subport_stats stats;
287 struct rte_sched_port *port;
288 uint32_t tc_ov[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
289 uint8_t i;
290
291 for (i = 0; i < nb_pfc; i++) {
292 if (qos_conf[i].tx_port == port_id)
293 break;
294 }
295
296 if (i == nb_pfc || subport_id >= port_params.n_subports_per_port)
297 return -1;
298
299 port = qos_conf[i].sched_port;
300 memset(tc_ov, 0, sizeof(tc_ov));
301
302 rte_sched_subport_read_stats(port, subport_id, &stats, tc_ov);
303
304 printf("\n");
305 printf("+----+-------------+-------------+-------------+-------------+-------------+\n");
306 printf("| TC | Pkts OK |Pkts Dropped | Bytes OK |Bytes Dropped| OV Status |\n");
307 printf("+----+-------------+-------------+-------------+-------------+-------------+\n");
308
309 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++) {
310 printf("| %d | %11" PRIu64 " | %11" PRIu64 " | %11" PRIu64 " | %11" PRIu64 " | %11" PRIu32 " |\n",
311 i, stats.n_pkts_tc[i], stats.n_pkts_tc_dropped[i],
312 stats.n_bytes_tc[i], stats.n_bytes_tc_dropped[i], tc_ov[i]);
313 printf("+----+-------------+-------------+-------------+-------------+-------------+\n");
314 }
315 printf("\n");
316
317 return 0;
7c673cae
FG
318}
319
320int
11fdf7f2 321pipe_stat(uint16_t port_id, uint32_t subport_id, uint32_t pipe_id)
7c673cae 322{
f67539c2
TL
323 struct rte_sched_queue_stats stats;
324 struct rte_sched_port *port;
325 uint16_t qlen;
326 uint8_t i, j;
327 uint32_t queue_id = 0;
328
329 for (i = 0; i < nb_pfc; i++) {
330 if (qos_conf[i].tx_port == port_id)
331 break;
332 }
333
334 if (i == nb_pfc ||
335 subport_id >= port_params.n_subports_per_port ||
336 pipe_id >= subport_params[subport_id].n_pipes_per_subport_enabled)
337 return -1;
338
339 port = qos_conf[i].sched_port;
340 for (i = 0; i < subport_id; i++)
341 queue_id += subport_params[i].n_pipes_per_subport_enabled *
342 RTE_SCHED_QUEUES_PER_PIPE;
343
344 queue_id += pipe_id * RTE_SCHED_QUEUES_PER_PIPE;
345
346 printf("\n");
347 printf("+----+-------+-------------+-------------+-------------+-------------+-------------+\n");
348 printf("| TC | Queue | Pkts OK |Pkts Dropped | Bytes OK |Bytes Dropped| Length |\n");
349 printf("+----+-------+-------------+-------------+-------------+-------------+-------------+\n");
350
351 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++) {
352 if (i < RTE_SCHED_TRAFFIC_CLASS_BE) {
353 rte_sched_queue_read_stats(port, queue_id + i, &stats, &qlen);
354 printf("| %d | %d | %11" PRIu64 " | %11" PRIu64 " | %11" PRIu64 " | %11" PRIu64 " | %11i |\n",
355 i, 0, stats.n_pkts, stats.n_pkts_dropped, stats.n_bytes,
356 stats.n_bytes_dropped, qlen);
357 printf("+----+-------+-------------+-------------+-------------+-------------+-------------+\n");
358 } else {
359 for (j = 0; j < RTE_SCHED_BE_QUEUES_PER_PIPE; j++) {
360 rte_sched_queue_read_stats(port, queue_id + i + j,
361 &stats, &qlen);
362 printf("| %d | %d | %11" PRIu64 " | %11" PRIu64 " | %11" PRIu64 " | %11" PRIu64 " | %11i |\n",
363 i, j, stats.n_pkts, stats.n_pkts_dropped, stats.n_bytes,
364 stats.n_bytes_dropped, qlen);
365 printf("+----+-------+-------------+-------------+-------------+-------------+-------------+\n");
366 }
367 }
368 }
369 printf("\n");
370
371 return 0;
7c673cae 372}