dpdk/examples/qos_sched/stats.c
<<
>>
Prefs
   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
  10int
  11qavg_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 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;
  54}
  55
  56int
  57qavg_tcpipe(uint16_t port_id, uint32_t subport_id, uint32_t pipe_id,
  58                uint8_t tc)
  59{
  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;
 110}
 111
 112int
 113qavg_pipe(uint16_t port_id, uint32_t subport_id, uint32_t pipe_id)
 114{
 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        }
 125
 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;
 130
 131        port = qos_conf[i].sched_port;
 132
 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;
 136
 137        queue_id += pipe_id * RTE_SCHED_QUEUES_PER_PIPE;
 138
 139        average = 0;
 140
 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        }
 151
 152        average /= qavg_ntimes;
 153
 154        printf("\nAverage queue size: %" PRIu32 " bytes.\n\n", average);
 155
 156        return 0;
 157}
 158
 159int
 160qavg_tcsubport(uint16_t port_id, uint32_t subport_id, uint8_t tc)
 161{
 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;
 227}
 228
 229int
 230qavg_subport(uint16_t port_id, uint32_t subport_id)
 231{
 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;
 248
 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;
 252
 253        average = 0;
 254
 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;
 258
 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;
 262
 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                }
 269
 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        }
 275
 276        average /= qavg_ntimes;
 277
 278        printf("\nAverage queue size: %" PRIu32 " bytes.\n\n", average);
 279
 280        return 0;
 281}
 282
 283int
 284subport_stat(uint16_t port_id, uint32_t subport_id)
 285{
 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;
 318}
 319
 320int
 321pipe_stat(uint16_t port_id, uint32_t subport_id, uint32_t pipe_id)
 322{
 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;
 372}
 373