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