LCOV - code coverage report
Current view: top level - drivers/event/sw - sw_evdev.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 259 436 59.4 %
Date: 2026-11-01 19:11:22 Functions: 25 36 69.4 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 130 250 52.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2016-2017 Intel Corporation
       3                 :            :  */
       4                 :            : 
       5                 :            : #include <inttypes.h>
       6                 :            : #include <stdlib.h>
       7                 :            : #include <string.h>
       8                 :            : 
       9                 :            : #include <bus_vdev_driver.h>
      10                 :            : #include <rte_kvargs.h>
      11                 :            : #include <rte_ring.h>
      12                 :            : #include <rte_errno.h>
      13                 :            : #include <rte_event_ring.h>
      14                 :            : #include <rte_service_component.h>
      15                 :            : 
      16                 :            : #include "sw_evdev.h"
      17                 :            : #include "iq_chunk.h"
      18                 :            : #include "event_ring.h"
      19                 :            : 
      20                 :            : #define EVENTDEV_NAME_SW_PMD event_sw
      21                 :            : #define NUMA_NODE_ARG "numa_node"
      22                 :            : #define SCHED_QUANTA_ARG "sched_quanta"
      23                 :            : #define CREDIT_QUANTA_ARG "credit_quanta"
      24                 :            : #define MIN_BURST_SIZE_ARG "min_burst"
      25                 :            : #define DEQ_BURST_SIZE_ARG "deq_burst"
      26                 :            : #define REFIL_ONCE_ARG "refill_once"
      27                 :            : 
      28                 :            : static void
      29                 :            : sw_info_get(struct rte_eventdev *dev, struct rte_event_dev_info *info);
      30                 :            : 
      31                 :            : static int
      32                 :         88 : sw_port_link(struct rte_eventdev *dev, void *port, const uint8_t queues[],
      33                 :            :                 const uint8_t priorities[], uint16_t num)
      34                 :            : {
      35                 :            :         struct sw_port *p = port;
      36                 :            :         struct sw_evdev *sw = sw_pmd_priv(dev);
      37                 :            :         int i;
      38                 :            : 
      39                 :            :         RTE_SET_USED(priorities);
      40         [ +  + ]:        180 :         for (i = 0; i < num; i++) {
      41                 :         92 :                 struct sw_qid *q = &sw->qids[queues[i]];
      42                 :            :                 unsigned int j;
      43                 :            : 
      44                 :            :                 /* check for qid map overflow */
      45         [ -  + ]:         92 :                 if (q->cq_num_mapped_cqs >= RTE_DIM(q->cq_map)) {
      46                 :          0 :                         rte_errno = EDQUOT;
      47                 :          0 :                         break;
      48                 :            :                 }
      49                 :            : 
      50   [ -  +  -  - ]:         92 :                 if (p->is_directed && p->num_qids_mapped > 0) {
      51                 :          0 :                         rte_errno = EDQUOT;
      52                 :          0 :                         break;
      53                 :            :                 }
      54                 :            : 
      55         [ +  + ]:        111 :                 for (j = 0; j < q->cq_num_mapped_cqs; j++) {
      56         [ +  - ]:         19 :                         if (q->cq_map[j] == p->id)
      57                 :            :                                 break;
      58                 :            :                 }
      59                 :            : 
      60                 :            :                 /* check if port is already linked */
      61         [ -  + ]:         92 :                 if (j < q->cq_num_mapped_cqs)
      62                 :          0 :                         continue;
      63                 :            : 
      64         [ +  + ]:         92 :                 if (q->type == SW_SCHED_TYPE_DIRECT) {
      65                 :            :                         /* check directed qids only map to one port */
      66         [ -  + ]:          9 :                         if (p->num_qids_mapped > 0) {
      67                 :          0 :                                 rte_errno = EDQUOT;
      68                 :          0 :                                 break;
      69                 :            :                         }
      70                 :            :                         /* check port only takes a directed flow */
      71         [ -  + ]:          9 :                         if (num > 1) {
      72                 :          0 :                                 rte_errno = EDQUOT;
      73                 :          0 :                                 break;
      74                 :            :                         }
      75                 :            : 
      76                 :          9 :                         p->is_directed = 1;
      77                 :          9 :                         p->num_qids_mapped = 1;
      78         [ +  + ]:         83 :                 } else if (q->type == RTE_SCHED_TYPE_ORDERED) {
      79                 :         14 :                         p->num_ordered_qids++;
      80                 :         14 :                         p->num_qids_mapped++;
      81         [ +  - ]:         69 :                 } else if (q->type == RTE_SCHED_TYPE_ATOMIC ||
      82                 :            :                                 q->type == RTE_SCHED_TYPE_PARALLEL) {
      83                 :         69 :                         p->num_qids_mapped++;
      84                 :            :                 }
      85                 :            : 
      86                 :         92 :                 q->cq_map[q->cq_num_mapped_cqs] = p->id;
      87                 :            :                 /* Release publishes the map entry before the new count */
      88                 :         92 :                 rte_atomic_store_explicit((uint32_t __rte_atomic *)&q->cq_num_mapped_cqs,
      89                 :            :                         q->cq_num_mapped_cqs + 1, rte_memory_order_release);
      90                 :            :         }
      91                 :         88 :         return i;
      92                 :            : }
      93                 :            : 
      94                 :            : static int
      95                 :        118 : sw_port_unlink(struct rte_eventdev *dev, void *port, uint8_t queues[],
      96                 :            :                 uint16_t nb_unlinks)
      97                 :            : {
      98                 :            :         struct sw_port *p = port;
      99                 :            :         struct sw_evdev *sw = sw_pmd_priv(dev);
     100                 :            :         unsigned int i, j;
     101                 :            : 
     102                 :            :         int unlinked = 0;
     103         [ +  + ]:        209 :         for (i = 0; i < nb_unlinks; i++) {
     104                 :         91 :                 struct sw_qid *q = &sw->qids[queues[i]];
     105         [ +  + ]:         96 :                 for (j = 0; j < q->cq_num_mapped_cqs; j++) {
     106         [ +  - ]:          5 :                         if (q->cq_map[j] == p->id) {
     107                 :          5 :                                 q->cq_map[j] =
     108                 :          5 :                                         q->cq_map[q->cq_num_mapped_cqs - 1];
     109                 :            :                                 /* Release publishes the map update before the new count */
     110                 :          5 :                                 rte_atomic_store_explicit(
     111                 :            :                                         (uint32_t __rte_atomic *)&q->cq_num_mapped_cqs,
     112                 :            :                                         q->cq_num_mapped_cqs - 1,
     113                 :            :                                         rte_memory_order_release);
     114                 :          5 :                                 unlinked++;
     115                 :            : 
     116                 :          5 :                                 p->num_qids_mapped--;
     117                 :            : 
     118         [ +  + ]:          5 :                                 if (q->type == RTE_SCHED_TYPE_ORDERED)
     119                 :          1 :                                         p->num_ordered_qids--;
     120                 :            : 
     121                 :          5 :                                 continue;
     122                 :            :                         }
     123                 :            :                 }
     124                 :            :         }
     125                 :            : 
     126                 :            :         /* Pairs with the acquire exchange in the scheduler */
     127                 :        118 :         rte_atomic_fetch_add_explicit(&p->unlinks_in_progress, unlinked,
     128                 :            :                                       rte_memory_order_release);
     129                 :            : 
     130                 :        118 :         return unlinked;
     131                 :            : }
     132                 :            : 
     133                 :            : static int
     134                 :          2 : sw_port_unlinks_in_progress(struct rte_eventdev *dev, void *port)
     135                 :            : {
     136                 :            :         RTE_SET_USED(dev);
     137                 :            :         struct sw_port *p = port;
     138                 :          2 :         return rte_atomic_load_explicit(&p->unlinks_in_progress,
     139                 :            :                                         rte_memory_order_acquire);
     140                 :            : }
     141                 :            : 
     142                 :            : static int
     143         [ +  + ]:        116 : sw_port_setup(struct rte_eventdev *dev, uint8_t port_id,
     144                 :            :                 const struct rte_event_port_conf *conf)
     145                 :            : {
     146                 :            :         struct sw_evdev *sw = sw_pmd_priv(dev);
     147                 :        116 :         struct sw_port *p = &sw->ports[port_id];
     148                 :            :         char buf[RTE_RING_NAMESIZE];
     149                 :            :         unsigned int i;
     150                 :            : 
     151                 :            :         struct rte_event_dev_info info;
     152                 :            :         sw_info_get(dev, &info);
     153                 :            : 
     154                 :            :         /* detect re-configuring and return credits to instance if needed */
     155         [ +  + ]:        116 :         if (p->initialized) {
     156                 :            :                 /* taking credits from pool is done one quanta at a time, and
     157                 :            :                  * credits may be spend (counted in p->inflights) or still
     158                 :            :                  * available in the port (p->inflight_credits). We must return
     159                 :            :                  * the sum to no leak credits
     160                 :            :                  */
     161                 :         38 :                 int possible_inflights = p->inflight_credits + p->inflights;
     162                 :         38 :                 rte_atomic_fetch_sub_explicit(&sw->inflights,
     163                 :            :                                               possible_inflights,
     164                 :            :                                               rte_memory_order_release);
     165                 :            :         }
     166                 :            : 
     167                 :        116 :         *p = (struct sw_port){0}; /* zero entire structure */
     168                 :        116 :         p->id = port_id;
     169                 :        116 :         p->sw = sw;
     170                 :            : 
     171                 :            :         /* check to see if rings exists - port_setup() can be called multiple
     172                 :            :          * times legally (assuming device is stopped). If ring exists, free it
     173                 :            :          * to so it gets re-created with the correct size
     174                 :            :          */
     175                 :        116 :         snprintf(buf, sizeof(buf), "sw%d_p%u_%s", dev->data->dev_id,
     176                 :            :                         port_id, "rx_worker_ring");
     177                 :        116 :         struct rte_event_ring *existing_ring = rte_event_ring_lookup(buf);
     178                 :        116 :         rte_event_ring_free(existing_ring);
     179                 :            : 
     180                 :        232 :         p->rx_worker_ring = rte_event_ring_create(buf, MAX_SW_PROD_Q_DEPTH,
     181                 :        116 :                         dev->data->socket_id,
     182                 :            :                         RING_F_SP_ENQ | RING_F_SC_DEQ | RING_F_EXACT_SZ);
     183         [ -  + ]:        116 :         if (p->rx_worker_ring == NULL) {
     184                 :          0 :                 SW_LOG_ERR("Error creating RX worker ring for port %d",
     185                 :            :                                 port_id);
     186                 :          0 :                 return -1;
     187                 :            :         }
     188                 :            : 
     189                 :        116 :         p->inflight_max = conf->new_event_threshold;
     190                 :        116 :         p->implicit_release = !(conf->event_port_cfg &
     191                 :            :                                 RTE_EVENT_PORT_CFG_DISABLE_IMPL_REL);
     192                 :            : 
     193                 :            :         /* check if ring exists, same as rx_worker above */
     194                 :        116 :         snprintf(buf, sizeof(buf), "sw%d_p%u, %s", dev->data->dev_id,
     195                 :            :                         port_id, "cq_worker_ring");
     196                 :        116 :         existing_ring = rte_event_ring_lookup(buf);
     197                 :        116 :         rte_event_ring_free(existing_ring);
     198                 :            : 
     199                 :        232 :         p->cq_worker_ring = rte_event_ring_create(buf, conf->dequeue_depth,
     200                 :        116 :                         dev->data->socket_id,
     201                 :            :                         RING_F_SP_ENQ | RING_F_SC_DEQ | RING_F_EXACT_SZ);
     202         [ -  + ]:        116 :         if (p->cq_worker_ring == NULL) {
     203                 :          0 :                 rte_event_ring_free(p->rx_worker_ring);
     204                 :          0 :                 SW_LOG_ERR("Error creating CQ worker ring for port %d",
     205                 :            :                                 port_id);
     206                 :          0 :                 return -1;
     207                 :            :         }
     208                 :        116 :         sw->cq_ring_space[port_id] = conf->dequeue_depth;
     209                 :            : 
     210                 :            :         /* set hist list contents to empty */
     211         [ +  + ]:     475252 :         for (i = 0; i < SW_PORT_HIST_LIST; i++) {
     212                 :     475136 :                 p->hist_list[i].fid = -1;
     213                 :     475136 :                 p->hist_list[i].qid = -1;
     214                 :            :         }
     215                 :        116 :         dev->data->ports[port_id] = p;
     216                 :            : 
     217                 :            :         /* Release publishes the port setup before initialized flag */
     218                 :        116 :         rte_atomic_store_explicit((uint8_t __rte_atomic *)&p->initialized, 1,
     219                 :            :                 rte_memory_order_release);
     220                 :        116 :         return 0;
     221                 :            : }
     222                 :            : 
     223                 :            : static void
     224                 :         92 : sw_port_release(void *port)
     225                 :            : {
     226                 :            :         struct sw_port *p = (void *)port;
     227         [ +  - ]:         92 :         if (p == NULL)
     228                 :            :                 return;
     229                 :            : 
     230                 :         92 :         rte_event_ring_free(p->rx_worker_ring);
     231                 :         92 :         rte_event_ring_free(p->cq_worker_ring);
     232                 :            :         memset(p, 0, sizeof(*p));
     233                 :            : }
     234                 :            : 
     235                 :            : static int32_t
     236                 :         79 : qid_init(struct sw_evdev *sw, unsigned int idx, int type,
     237                 :            :                 const struct rte_event_queue_conf *queue_conf)
     238                 :            : {
     239                 :            :         unsigned int i;
     240                 :         79 :         int socket_id = sw->data->socket_id;
     241                 :            :         struct sw_qid *qid = &sw->qids[idx];
     242                 :            : 
     243                 :            :         /* Initialize the FID structures to no pinning (-1), and zero packets */
     244                 :            :         const struct sw_fid_t fid = {.cq = -1, .pcount = 0};
     245         [ +  + ]:    1294415 :         for (i = 0; i < RTE_DIM(qid->fids); i++)
     246                 :    1294336 :                 qid->fids[i] = fid;
     247                 :            : 
     248                 :         79 :         qid->id = idx;
     249                 :         79 :         qid->type = type;
     250                 :         79 :         qid->priority = queue_conf->priority;
     251                 :            : 
     252         [ +  + ]:         79 :         if (qid->type == RTE_SCHED_TYPE_ORDERED) {
     253                 :            :                 uint32_t window_size;
     254                 :            : 
     255                 :            :                 /* rte_ring and window_size_mask require window_size to
     256                 :            :                  * be a power-of-2.
     257                 :            :                  */
     258                 :            :                 window_size = rte_align32pow2(
     259         [ -  + ]:         12 :                                 queue_conf->nb_atomic_order_sequences);
     260                 :            : 
     261                 :         12 :                 qid->window_size = window_size - 1;
     262                 :            : 
     263         [ -  + ]:         12 :                 if (!window_size) {
     264                 :          0 :                         SW_LOG_DBG(
     265                 :            :                                 "invalid reorder_window_size for ordered queue"
     266                 :            :                                 );
     267                 :          0 :                         goto cleanup;
     268                 :            :                 }
     269                 :            : 
     270                 :         12 :                 qid->reorder_buffer = rte_zmalloc_socket(NULL,
     271                 :            :                                 window_size * sizeof(qid->reorder_buffer[0]),
     272                 :            :                                 0, socket_id);
     273         [ -  + ]:         12 :                 if (!qid->reorder_buffer) {
     274                 :          0 :                         SW_LOG_DBG("reorder_buffer malloc failed");
     275                 :          0 :                         goto cleanup;
     276                 :            :                 }
     277                 :            : 
     278                 :            :                 memset(&qid->reorder_buffer[0],
     279                 :            :                        0,
     280                 :            :                        window_size * sizeof(qid->reorder_buffer[0]));
     281                 :            : 
     282                 :         12 :                 qid->reorder_buffer_freelist = rob_ring_create(window_size,
     283                 :            :                                 socket_id);
     284         [ -  + ]:         12 :                 if (!qid->reorder_buffer_freelist) {
     285                 :          0 :                         SW_LOG_DBG("freelist ring create failed");
     286                 :          0 :                         goto cleanup;
     287                 :            :                 }
     288                 :            : 
     289                 :            :                 /* Populate the freelist with reorder buffer entries. Enqueue
     290                 :            :                  * 'window_size - 1' entries because the rte_ring holds only
     291                 :            :                  * that many.
     292                 :            :                  */
     293         [ +  + ]:      12288 :                 for (i = 0; i < window_size - 1; i++) {
     294                 :            :                         if (rob_ring_enqueue(qid->reorder_buffer_freelist,
     295         [ -  + ]:      12276 :                                                 &qid->reorder_buffer[i]) != 1)
     296                 :          0 :                                 goto cleanup;
     297                 :            :                 }
     298                 :            : 
     299                 :         12 :                 qid->reorder_buffer_index = 0;
     300                 :         12 :                 qid->cq_next_tx = 0;
     301                 :            :         }
     302                 :            : 
     303                 :         79 :         qid->initialized = 1;
     304                 :            : 
     305                 :         79 :         return 0;
     306                 :            : 
     307                 :          0 : cleanup:
     308         [ #  # ]:          0 :         if (qid->reorder_buffer) {
     309                 :          0 :                 rte_free(qid->reorder_buffer);
     310                 :          0 :                 qid->reorder_buffer = NULL;
     311                 :            :         }
     312                 :            : 
     313         [ #  # ]:          0 :         if (qid->reorder_buffer_freelist) {
     314                 :            :                 rob_ring_free(qid->reorder_buffer_freelist);
     315                 :          0 :                 qid->reorder_buffer_freelist = NULL;
     316                 :            :         }
     317                 :            : 
     318                 :            :         return -EINVAL;
     319                 :            : }
     320                 :            : 
     321                 :            : static void
     322         [ +  + ]:         86 : sw_queue_release(struct rte_eventdev *dev, uint8_t id)
     323                 :            : {
     324                 :            :         struct sw_evdev *sw = sw_pmd_priv(dev);
     325                 :         86 :         struct sw_qid *qid = &sw->qids[id];
     326                 :            : 
     327         [ +  + ]:         86 :         if (qid->type == RTE_SCHED_TYPE_ORDERED) {
     328                 :         19 :                 rte_free(qid->reorder_buffer);
     329                 :         19 :                 rob_ring_free(qid->reorder_buffer_freelist);
     330                 :            :         }
     331                 :            :         memset(qid, 0, sizeof(*qid));
     332                 :         86 : }
     333                 :            : 
     334                 :            : static int
     335                 :         79 : sw_queue_setup(struct rte_eventdev *dev, uint8_t queue_id,
     336                 :            :                 const struct rte_event_queue_conf *conf)
     337                 :            : {
     338                 :            :         int type;
     339                 :            : 
     340                 :         79 :         type = conf->schedule_type;
     341                 :            : 
     342         [ +  + ]:         79 :         if (RTE_EVENT_QUEUE_CFG_SINGLE_LINK & conf->event_queue_cfg) {
     343                 :            :                 type = SW_SCHED_TYPE_DIRECT;
     344                 :         70 :         } else if (RTE_EVENT_QUEUE_CFG_ALL_TYPES
     345         [ -  + ]:         70 :                         & conf->event_queue_cfg) {
     346                 :          0 :                 SW_LOG_ERR("QUEUE_CFG_ALL_TYPES not supported");
     347                 :          0 :                 return -ENOTSUP;
     348                 :            :         }
     349                 :            : 
     350                 :            :         struct sw_evdev *sw = sw_pmd_priv(dev);
     351                 :            : 
     352         [ +  + ]:         79 :         if (sw->qids[queue_id].initialized)
     353                 :         38 :                 sw_queue_release(dev, queue_id);
     354                 :            : 
     355                 :         79 :         return qid_init(sw, queue_id, type, conf);
     356                 :            : }
     357                 :            : 
     358                 :            : static void
     359                 :         59 : sw_init_qid_iqs(struct sw_evdev *sw)
     360                 :            : {
     361                 :            :         int i, j;
     362                 :            : 
     363                 :            :         /* Initialize the IQ memory of all configured qids */
     364         [ +  + ]:      15104 :         for (i = 0; i < RTE_EVENT_MAX_QUEUES_PER_DEV; i++) {
     365                 :            :                 struct sw_qid *qid = &sw->qids[i];
     366                 :            : 
     367         [ +  + ]:      15045 :                 if (!qid->initialized)
     368                 :      14973 :                         continue;
     369                 :            : 
     370         [ +  + ]:        360 :                 for (j = 0; j < SW_IQS_MAX; j++)
     371                 :            :                         iq_init(sw, &qid->iq[j]);
     372                 :            :         }
     373                 :         59 : }
     374                 :            : 
     375                 :            : static int
     376                 :            : sw_qids_empty(struct sw_evdev *sw)
     377                 :            : {
     378                 :            :         unsigned int i, j;
     379                 :            : 
     380         [ +  + ]:        174 :         for (i = 0; i < sw->qid_count; i++) {
     381         [ +  + ]:        472 :                 for (j = 0; j < SW_IQS_MAX; j++) {
     382         [ +  + ]:        378 :                         if (iq_count(&sw->qids[i].iq[j]))
     383                 :            :                                 return 0;
     384                 :            :                 }
     385                 :            :         }
     386                 :            : 
     387                 :            :         return 1;
     388                 :            : }
     389                 :            : 
     390                 :            : static int
     391                 :         78 : sw_ports_empty(struct sw_evdev *sw)
     392                 :            : {
     393                 :            :         unsigned int i;
     394                 :            : 
     395         [ +  + ]:        193 :         for (i = 0; i < sw->port_count; i++) {
     396   [ +  +  +  + ]:        134 :                 if ((rte_event_ring_count(sw->ports[i].rx_worker_ring)) ||
     397         [ +  + ]:        119 :                      rte_event_ring_count(sw->ports[i].cq_worker_ring))
     398                 :            :                         return 0;
     399                 :            :         }
     400                 :            : 
     401                 :            :         return 1;
     402                 :            : }
     403                 :            : 
     404                 :            : static void
     405                 :         21 : sw_drain_ports(struct rte_eventdev *dev)
     406                 :            : {
     407                 :            :         struct sw_evdev *sw = sw_pmd_priv(dev);
     408                 :            :         eventdev_stop_flush_t flush;
     409                 :            :         unsigned int i;
     410                 :            :         uint8_t dev_id;
     411                 :            :         void *arg;
     412                 :            : 
     413                 :         21 :         flush = dev->dev_ops->dev_stop_flush;
     414                 :         21 :         dev_id = dev->data->dev_id;
     415                 :         21 :         arg = dev->data->dev_stop_flush_arg;
     416                 :            : 
     417         [ +  + ]:         65 :         for (i = 0; i < sw->port_count; i++) {
     418                 :            :                 struct rte_event ev;
     419                 :            : 
     420         [ +  + ]:        129 :                 while (rte_event_dequeue_burst(dev_id, i, &ev, 1, 0)) {
     421         [ +  + ]:         85 :                         if (flush)
     422                 :         32 :                                 flush(dev_id, ev, arg);
     423                 :            : 
     424                 :         85 :                         ev.op = RTE_EVENT_OP_RELEASE;
     425                 :            :                         rte_event_enqueue_burst(dev_id, i, &ev, 1);
     426                 :            :                 }
     427                 :            :         }
     428                 :         21 : }
     429                 :            : 
     430                 :            : static void
     431                 :         96 : sw_drain_queue(struct rte_eventdev *dev, struct sw_iq *iq)
     432                 :            : {
     433                 :            :         struct sw_evdev *sw = sw_pmd_priv(dev);
     434                 :            :         eventdev_stop_flush_t flush;
     435                 :            :         uint8_t dev_id;
     436                 :            :         void *arg;
     437                 :            : 
     438                 :         96 :         flush = dev->dev_ops->dev_stop_flush;
     439                 :         96 :         dev_id = dev->data->dev_id;
     440                 :         96 :         arg = dev->data->dev_stop_flush_arg;
     441                 :            : 
     442         [ +  + ]:        194 :         while (iq_count(iq) > 0) {
     443                 :            :                 struct rte_event ev;
     444                 :            : 
     445                 :            :                 iq_dequeue_burst(sw, iq, &ev, 1);
     446                 :            : 
     447         [ +  + ]:         98 :                 if (flush)
     448                 :         97 :                         flush(dev_id, ev, arg);
     449                 :            :         }
     450                 :         96 : }
     451                 :            : 
     452                 :            : static void
     453                 :         21 : sw_drain_queues(struct rte_eventdev *dev)
     454                 :            : {
     455                 :            :         struct sw_evdev *sw = sw_pmd_priv(dev);
     456                 :            :         unsigned int i, j;
     457                 :            : 
     458         [ +  + ]:         45 :         for (i = 0; i < sw->qid_count; i++) {
     459         [ +  + ]:        120 :                 for (j = 0; j < SW_IQS_MAX; j++)
     460                 :         96 :                         sw_drain_queue(dev, &sw->qids[i].iq[j]);
     461                 :            :         }
     462                 :         21 : }
     463                 :            : 
     464                 :            : static void
     465                 :         59 : sw_clean_qid_iqs(struct rte_eventdev *dev)
     466                 :            : {
     467                 :            :         struct sw_evdev *sw = sw_pmd_priv(dev);
     468                 :            :         int i, j;
     469                 :            : 
     470                 :            :         /* Release the IQ memory of all configured qids */
     471         [ +  + ]:      15104 :         for (i = 0; i < RTE_EVENT_MAX_QUEUES_PER_DEV; i++) {
     472                 :            :                 struct sw_qid *qid = &sw->qids[i];
     473                 :            : 
     474         [ +  + ]:      75225 :                 for (j = 0; j < SW_IQS_MAX; j++) {
     475         [ +  + ]:      60180 :                         if (!qid->iq[j].head)
     476                 :      59892 :                                 continue;
     477                 :            :                         iq_free_chunk_list(sw, qid->iq[j].head);
     478                 :        288 :                         qid->iq[j].head = NULL;
     479                 :            :                 }
     480                 :            :         }
     481                 :         59 : }
     482                 :            : 
     483                 :            : static void
     484                 :          0 : sw_queue_def_conf(struct rte_eventdev *dev, uint8_t queue_id,
     485                 :            :                                  struct rte_event_queue_conf *conf)
     486                 :            : {
     487                 :            :         RTE_SET_USED(dev);
     488                 :            :         RTE_SET_USED(queue_id);
     489                 :            : 
     490                 :            :         static const struct rte_event_queue_conf default_conf = {
     491                 :            :                 .nb_atomic_flows = 4096,
     492                 :            :                 .nb_atomic_order_sequences = 1,
     493                 :            :                 .schedule_type = RTE_SCHED_TYPE_ATOMIC,
     494                 :            :                 .priority = RTE_EVENT_DEV_PRIORITY_NORMAL,
     495                 :            :         };
     496                 :            : 
     497                 :          0 :         *conf = default_conf;
     498                 :          0 : }
     499                 :            : 
     500                 :            : static void
     501                 :          8 : sw_port_def_conf(struct rte_eventdev *dev, uint8_t port_id,
     502                 :            :                  struct rte_event_port_conf *port_conf)
     503                 :            : {
     504                 :            :         RTE_SET_USED(dev);
     505                 :            :         RTE_SET_USED(port_id);
     506                 :            : 
     507                 :          8 :         port_conf->new_event_threshold = 1024;
     508                 :          8 :         port_conf->dequeue_depth = 16;
     509                 :          8 :         port_conf->enqueue_depth = 16;
     510                 :          8 :         port_conf->event_port_cfg = 0;
     511                 :          8 : }
     512                 :            : 
     513                 :            : static int
     514                 :         42 : sw_dev_configure(const struct rte_eventdev *dev)
     515                 :            : {
     516                 :            :         struct sw_evdev *sw = sw_pmd_priv(dev);
     517                 :            :         const struct rte_eventdev_data *data = dev->data;
     518                 :            :         const struct rte_event_dev_config *conf = &data->dev_conf;
     519                 :            :         int num_chunks, i;
     520                 :            : 
     521                 :         42 :         sw->qid_count = conf->nb_event_queues;
     522                 :         42 :         sw->port_count = conf->nb_event_ports;
     523                 :         42 :         sw->nb_events_limit = conf->nb_events_limit;
     524                 :         42 :         sw->inflights = 0;
     525                 :            : 
     526                 :            :         /* Number of chunks sized for worst-case spread of events across IQs */
     527                 :         42 :         num_chunks = ((SW_INFLIGHT_EVENTS_TOTAL/SW_EVS_PER_Q_CHUNK)+1) +
     528                 :         42 :                         sw->qid_count*SW_IQS_MAX*2;
     529                 :            : 
     530                 :            :         /* If this is a reconfiguration, free the previous IQ allocation. All
     531                 :            :          * IQ chunk references were cleaned out of the QIDs in sw_stop(), and
     532                 :            :          * will be reinitialized in sw_start().
     533                 :            :          */
     534                 :         42 :         rte_free(sw->chunks);
     535                 :            : 
     536                 :         84 :         sw->chunks = rte_malloc_socket(NULL,
     537                 :            :                                        sizeof(struct sw_queue_chunk) *
     538                 :            :                                        num_chunks,
     539                 :            :                                        0,
     540                 :         42 :                                        sw->data->socket_id);
     541         [ +  - ]:         42 :         if (!sw->chunks)
     542                 :            :                 return -ENOMEM;
     543                 :            : 
     544                 :         42 :         sw->chunk_list_head = NULL;
     545         [ +  + ]:       1196 :         for (i = 0; i < num_chunks; i++)
     546                 :       1154 :                 iq_free_chunk(sw, &sw->chunks[i]);
     547                 :            : 
     548         [ -  + ]:         42 :         if (conf->event_dev_cfg & RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT)
     549                 :          0 :                 return -ENOTSUP;
     550                 :            : 
     551                 :            :         return 0;
     552                 :            : }
     553                 :            : 
     554                 :            : struct rte_eth_dev;
     555                 :            : 
     556                 :            : static int
     557                 :          0 : sw_eth_rx_adapter_caps_get(const struct rte_eventdev *dev,
     558                 :            :                         const struct rte_eth_dev *eth_dev,
     559                 :            :                         uint32_t *caps)
     560                 :            : {
     561                 :            :         RTE_SET_USED(dev);
     562                 :            :         RTE_SET_USED(eth_dev);
     563                 :          0 :         *caps = RTE_EVENT_ETH_RX_ADAPTER_SW_CAP;
     564                 :          0 :         return 0;
     565                 :            : }
     566                 :            : 
     567                 :            : static int
     568                 :          0 : sw_timer_adapter_caps_get(const struct rte_eventdev *dev, uint64_t flags,
     569                 :            :                           uint32_t *caps,
     570                 :            :                           const struct event_timer_adapter_ops **ops)
     571                 :            : {
     572                 :            :         RTE_SET_USED(dev);
     573                 :            :         RTE_SET_USED(flags);
     574                 :          0 :         *caps = RTE_EVENT_TIMER_ADAPTER_SW_CAP;
     575                 :            : 
     576                 :            :         /* Use default SW ops */
     577                 :          0 :         *ops = NULL;
     578                 :            : 
     579                 :          0 :         return 0;
     580                 :            : }
     581                 :            : 
     582                 :            : static int
     583                 :          0 : sw_crypto_adapter_caps_get(const struct rte_eventdev *dev,
     584                 :            :                            const struct rte_cryptodev *cdev,
     585                 :            :                            uint32_t *caps)
     586                 :            : {
     587                 :            :         RTE_SET_USED(dev);
     588                 :            :         RTE_SET_USED(cdev);
     589                 :          0 :         *caps = RTE_EVENT_CRYPTO_ADAPTER_SW_CAP;
     590                 :          0 :         return 0;
     591                 :            : }
     592                 :            : 
     593                 :            : static void
     594                 :        264 : sw_info_get(struct rte_eventdev *dev, struct rte_event_dev_info *info)
     595                 :            : {
     596                 :            :         RTE_SET_USED(dev);
     597                 :            : 
     598                 :            :         static const struct rte_event_dev_info evdev_sw_info = {
     599                 :            :                         .driver_name = SW_PMD_NAME,
     600                 :            :                         .max_event_queues = RTE_EVENT_MAX_QUEUES_PER_DEV,
     601                 :            :                         .max_event_queue_flows = SW_QID_NUM_FIDS,
     602                 :            :                         .max_event_queue_priority_levels = SW_Q_PRIORITY_MAX,
     603                 :            :                         .max_event_priority_levels = SW_IQS_MAX,
     604                 :            :                         .max_event_ports = SW_PORTS_MAX,
     605                 :            :                         .max_event_port_dequeue_depth = MAX_SW_CONS_Q_DEPTH,
     606                 :            :                         .max_event_port_enqueue_depth = MAX_SW_PROD_Q_DEPTH,
     607                 :            :                         .max_num_events = SW_INFLIGHT_EVENTS_TOTAL,
     608                 :            :                         .event_dev_cap = (
     609                 :            :                                 RTE_EVENT_DEV_CAP_ATOMIC |
     610                 :            :                                 RTE_EVENT_DEV_CAP_ORDERED |
     611                 :            :                                 RTE_EVENT_DEV_CAP_PARALLEL |
     612                 :            :                                 RTE_EVENT_DEV_CAP_QUEUE_QOS |
     613                 :            :                                 RTE_EVENT_DEV_CAP_BURST_MODE |
     614                 :            :                                 RTE_EVENT_DEV_CAP_EVENT_QOS |
     615                 :            :                                 RTE_EVENT_DEV_CAP_IMPLICIT_RELEASE_DISABLE|
     616                 :            :                                 RTE_EVENT_DEV_CAP_RUNTIME_PORT_LINK |
     617                 :            :                                 RTE_EVENT_DEV_CAP_MULTIPLE_QUEUE_PORT |
     618                 :            :                                 RTE_EVENT_DEV_CAP_NONSEQ_MODE |
     619                 :            :                                 RTE_EVENT_DEV_CAP_CARRY_FLOW_ID |
     620                 :            :                                 RTE_EVENT_DEV_CAP_MAINTENANCE_FREE),
     621                 :            :                         .max_profiles_per_port = 1,
     622                 :            :         };
     623                 :            : 
     624                 :        264 :         *info = evdev_sw_info;
     625                 :        264 : }
     626                 :            : 
     627                 :            : static void
     628                 :          0 : sw_dump(struct rte_eventdev *dev, FILE *f)
     629                 :            : {
     630                 :            :         const struct sw_evdev *sw = sw_pmd_priv(dev);
     631                 :            : 
     632                 :            :         static const char * const q_type_strings[] = {
     633                 :            :                         "Ordered", "Atomic", "Parallel", "Directed"
     634                 :            :         };
     635                 :            :         uint32_t i;
     636                 :            :         fprintf(f, "EventDev %s: ports %d, qids %d\n",
     637                 :          0 :                 dev->data->name, sw->port_count, sw->qid_count);
     638                 :            : 
     639                 :            :         fprintf(f, "\trx   %"PRIu64"\n\tdrop %"PRIu64"\n\ttx   %"PRIu64"\n",
     640                 :          0 :                 sw->stats.rx_pkts, sw->stats.rx_dropped, sw->stats.tx_pkts);
     641                 :          0 :         fprintf(f, "\tsched calls: %"PRIu64"\n", sw->sched_called);
     642                 :          0 :         fprintf(f, "\tsched cq/qid call: %"PRIu64"\n", sw->sched_cq_qid_called);
     643                 :          0 :         fprintf(f, "\tsched no IQ enq: %"PRIu64"\n", sw->sched_no_iq_enqueues);
     644                 :          0 :         fprintf(f, "\tsched no CQ enq: %"PRIu64"\n", sw->sched_no_cq_enqueues);
     645                 :          0 :         uint32_t inflights = rte_atomic_load_explicit(&sw->inflights, rte_memory_order_relaxed);
     646                 :          0 :         uint32_t credits = sw->nb_events_limit - inflights;
     647                 :            :         fprintf(f, "\tinflight %d, credits: %d\n", inflights, credits);
     648                 :            : 
     649                 :            : #define COL_RED "\x1b[31m"
     650                 :            : #define COL_RESET "\x1b[0m"
     651                 :            : 
     652         [ #  # ]:          0 :         for (i = 0; i < sw->port_count; i++) {
     653                 :            :                 int max, j;
     654                 :            :                 const struct sw_port *p = &sw->ports[i];
     655         [ #  # ]:          0 :                 if (!p->initialized) {
     656                 :            :                         fprintf(f, "  %sPort %d not initialized.%s\n",
     657                 :            :                                 COL_RED, i, COL_RESET);
     658                 :          0 :                         continue;
     659                 :            :                 }
     660                 :          0 :                 fprintf(f, "  Port %d %s\n", i,
     661         [ #  # ]:          0 :                         p->is_directed ? " (SingleCons)" : "");
     662                 :          0 :                 fprintf(f, "\trx   %"PRIu64"\tdrop %"PRIu64"\ttx   %"PRIu64
     663                 :          0 :                         "\t%sinflight %d%s\n", sw->ports[i].stats.rx_pkts,
     664                 :          0 :                         sw->ports[i].stats.rx_dropped,
     665                 :          0 :                         sw->ports[i].stats.tx_pkts,
     666                 :          0 :                         (p->inflights == p->inflight_max) ?
     667                 :            :                                 COL_RED : COL_RESET,
     668         [ #  # ]:          0 :                         sw->ports[i].inflights, COL_RESET);
     669                 :            : 
     670                 :          0 :                 fprintf(f, "\tMax New: %u"
     671                 :            :                         "\tAvg cycles PP: %"PRIu64"\tCredits: %u\n",
     672                 :          0 :                         sw->ports[i].inflight_max,
     673                 :          0 :                         sw->ports[i].avg_pkt_ticks,
     674                 :          0 :                         sw->ports[i].inflight_credits);
     675                 :            :                 fprintf(f, "\tReceive burst distribution:\n");
     676                 :          0 :                 float zp_percent = p->zero_polls * 100.0 / p->total_polls;
     677         [ #  # ]:          0 :                 fprintf(f, zp_percent < 10 ? "\t\t0:%.02f%% " : "\t\t0:%.0f%% ",
     678                 :            :                                 zp_percent);
     679         [ #  # ]:          0 :                 for (max = (int)RTE_DIM(p->poll_buckets); max-- > 0;)
     680         [ #  # ]:          0 :                         if (p->poll_buckets[max] != 0)
     681                 :            :                                 break;
     682         [ #  # ]:          0 :                 for (j = 0; j <= max; j++) {
     683         [ #  # ]:          0 :                         if (p->poll_buckets[j] != 0) {
     684                 :          0 :                                 float poll_pc = p->poll_buckets[j] * 100.0 /
     685                 :          0 :                                         p->total_polls;
     686                 :          0 :                                 fprintf(f, "%u-%u:%.02f%% ",
     687                 :          0 :                                         ((j << SW_DEQ_STAT_BUCKET_SHIFT) + 1),
     688                 :          0 :                                         ((j+1) << SW_DEQ_STAT_BUCKET_SHIFT),
     689                 :            :                                         poll_pc);
     690                 :            :                         }
     691                 :            :                 }
     692                 :            :                 fprintf(f, "\n");
     693                 :            : 
     694         [ #  # ]:          0 :                 if (p->rx_worker_ring) {
     695         [ #  # ]:          0 :                         uint64_t used = rte_event_ring_count(p->rx_worker_ring);
     696                 :          0 :                         uint64_t space = rte_event_ring_free_count(
     697                 :            :                                         p->rx_worker_ring);
     698         [ #  # ]:          0 :                         const char *col = (space == 0) ? COL_RED : COL_RESET;
     699                 :            :                         fprintf(f, "\t%srx ring used: %4"PRIu64"\tfree: %4"
     700                 :            :                                         PRIu64 COL_RESET"\n", col, used, space);
     701                 :            :                 } else
     702                 :            :                         fprintf(f, "\trx ring not initialized.\n");
     703                 :            : 
     704         [ #  # ]:          0 :                 if (p->cq_worker_ring) {
     705         [ #  # ]:          0 :                         uint64_t used = rte_event_ring_count(p->cq_worker_ring);
     706                 :          0 :                         uint64_t space = rte_event_ring_free_count(
     707                 :            :                                         p->cq_worker_ring);
     708         [ #  # ]:          0 :                         const char *col = (space == 0) ? COL_RED : COL_RESET;
     709                 :            :                         fprintf(f, "\t%scq ring used: %4"PRIu64"\tfree: %4"
     710                 :            :                                         PRIu64 COL_RESET"\n", col, used, space);
     711                 :            :                 } else
     712                 :            :                         fprintf(f, "\tcq ring not initialized.\n");
     713                 :            :         }
     714                 :            : 
     715         [ #  # ]:          0 :         for (i = 0; i < sw->qid_count; i++) {
     716                 :            :                 const struct sw_qid *qid = &sw->qids[i];
     717         [ #  # ]:          0 :                 if (!qid->initialized) {
     718                 :            :                         fprintf(f, "  %sQueue %d not initialized.%s\n",
     719                 :            :                                 COL_RED, i, COL_RESET);
     720                 :          0 :                         continue;
     721                 :            :                 }
     722                 :          0 :                 int affinities_per_port[SW_PORTS_MAX] = {0};
     723                 :            : 
     724                 :          0 :                 fprintf(f, "  Queue %d (%s)\n", i, q_type_strings[qid->type]);
     725                 :            :                 fprintf(f, "\trx   %"PRIu64"\tdrop %"PRIu64"\ttx   %"PRIu64"\n",
     726                 :          0 :                         qid->stats.rx_pkts, qid->stats.rx_dropped,
     727                 :          0 :                         qid->stats.tx_pkts);
     728         [ #  # ]:          0 :                 if (qid->type == RTE_SCHED_TYPE_ORDERED) {
     729                 :          0 :                         struct rob_ring *rob_buf_free =
     730                 :            :                                 qid->reorder_buffer_freelist;
     731         [ #  # ]:          0 :                         if (rob_buf_free)
     732                 :            :                                 fprintf(f, "\tReorder entries in use: %u\n",
     733                 :            :                                         rob_ring_free_count(rob_buf_free));
     734                 :            :                         else
     735                 :            :                                 fprintf(f,
     736                 :            :                                         "\tReorder buffer not initialized\n");
     737                 :            :                 }
     738                 :            : 
     739                 :            :                 uint32_t flow;
     740         [ #  # ]:          0 :                 for (flow = 0; flow < RTE_DIM(qid->fids); flow++)
     741         [ #  # ]:          0 :                         if (qid->fids[flow].cq != -1) {
     742                 :          0 :                                 affinities_per_port[qid->fids[flow].cq]++;
     743                 :            :                         }
     744                 :            : 
     745                 :            :                 uint32_t port;
     746                 :            :                 fprintf(f, "\tPer Port Stats:\n");
     747         [ #  # ]:          0 :                 for (port = 0; port < sw->port_count; port++) {
     748                 :            :                         fprintf(f, "\t  Port %d: Pkts: %"PRIu64, port,
     749                 :          0 :                                         qid->to_port[port]);
     750                 :          0 :                         fprintf(f, "\tFlows: %d\n", affinities_per_port[port]);
     751                 :            :                 }
     752                 :            : 
     753                 :            :                 uint32_t iq;
     754                 :            :                 uint32_t iq_printed = 0;
     755         [ #  # ]:          0 :                 for (iq = 0; iq < SW_IQS_MAX; iq++) {
     756         [ #  # ]:          0 :                         if (!qid->iq[iq].head) {
     757                 :            :                                 fprintf(f, "\tiq %d is not initialized.\n", iq);
     758                 :            :                                 iq_printed = 1;
     759                 :          0 :                                 continue;
     760                 :            :                         }
     761                 :          0 :                         uint32_t used = iq_count(&qid->iq[iq]);
     762                 :            :                         const char *col = COL_RESET;
     763         [ #  # ]:          0 :                         if (used > 0) {
     764                 :            :                                 fprintf(f, "\t%siq %d: Used %d"
     765                 :            :                                         COL_RESET"\n", col, iq, used);
     766                 :            :                                 iq_printed = 1;
     767                 :            :                         }
     768                 :            :                 }
     769         [ #  # ]:          0 :                 if (iq_printed == 0)
     770                 :            :                         fprintf(f, "\t-- iqs empty --\n");
     771                 :            :         }
     772                 :          0 : }
     773                 :            : 
     774                 :            : static int
     775                 :         59 : sw_start(struct rte_eventdev *dev)
     776                 :            : {
     777                 :            :         unsigned int i, j;
     778                 :            :         struct sw_evdev *sw = sw_pmd_priv(dev);
     779                 :            : 
     780                 :         59 :         rte_service_component_runstate_set(sw->service_id, 1);
     781                 :            : 
     782                 :            :         /* check a service core is mapped to this service */
     783         [ -  + ]:         59 :         if (!rte_service_runstate_get(sw->service_id)) {
     784                 :          0 :                 SW_LOG_ERR("Warning: No Service core enabled on service %s",
     785                 :            :                                 sw->service_name);
     786                 :          0 :                 return -ENOENT;
     787                 :            :         }
     788                 :            : 
     789                 :            :         /* check all ports are set up */
     790         [ +  + ]:        162 :         for (i = 0; i < sw->port_count; i++)
     791         [ -  + ]:        103 :                 if (sw->ports[i].rx_worker_ring == NULL) {
     792                 :          0 :                         SW_LOG_ERR("Port %d not configured", i);
     793                 :          0 :                         return -ESTALE;
     794                 :            :                 }
     795                 :            : 
     796                 :            :         /* check all queues are configured and mapped to ports*/
     797         [ +  + ]:        131 :         for (i = 0; i < sw->qid_count; i++)
     798         [ +  - ]:         72 :                 if (!sw->qids[i].initialized ||
     799         [ -  + ]:         72 :                     sw->qids[i].cq_num_mapped_cqs == 0) {
     800                 :          0 :                         SW_LOG_ERR("Queue %d not configured", i);
     801                 :          0 :                         return -ENOLINK;
     802                 :            :                 }
     803                 :            : 
     804                 :            :         /* build up our prioritized array of qids */
     805                 :            :         /* We don't use qsort here, as if all/multiple entries have the same
     806                 :            :          * priority, the result is non-deterministic. From "man 3 qsort":
     807                 :            :          * "If two members compare as equal, their order in the sorted
     808                 :            :          * array is undefined."
     809                 :            :          */
     810                 :            :         uint32_t qidx = 0;
     811         [ +  + ]:      15163 :         for (j = 0; j <= RTE_EVENT_DEV_PRIORITY_LOWEST; j++) {
     812         [ +  + ]:      33536 :                 for (i = 0; i < sw->qid_count; i++) {
     813         [ +  + ]:      18432 :                         if (sw->qids[i].priority == j) {
     814                 :         72 :                                 sw->qids_prioritized[qidx] = &sw->qids[i];
     815                 :         72 :                                 qidx++;
     816                 :            :                         }
     817                 :            :                 }
     818                 :            :         }
     819                 :            : 
     820                 :         59 :         sw_init_qid_iqs(sw);
     821                 :            : 
     822         [ +  - ]:         59 :         if (sw_xstats_init(sw) < 0)
     823                 :            :                 return -EINVAL;
     824                 :            : 
     825                 :            :         /* Release publishes device state before the started flag */
     826                 :         59 :         rte_atomic_store_explicit((uint8_t __rte_atomic *)&sw->started, 1,
     827                 :            :                 rte_memory_order_release);
     828                 :            : 
     829                 :         59 :         return 0;
     830                 :            : }
     831                 :            : 
     832                 :            : static void
     833                 :         59 : sw_stop(struct rte_eventdev *dev)
     834                 :            : {
     835                 :            :         struct sw_evdev *sw = sw_pmd_priv(dev);
     836                 :            :         int32_t runstate;
     837                 :            : 
     838                 :            :         /* Stop the scheduler if it's running */
     839                 :         59 :         runstate = rte_service_runstate_get(sw->service_id);
     840         [ +  - ]:         59 :         if (runstate == 1)
     841                 :         59 :                 rte_service_runstate_set(sw->service_id, 0);
     842                 :            : 
     843         [ -  + ]:         59 :         while (rte_service_may_be_active(sw->service_id))
     844                 :            :                 rte_pause();
     845                 :            : 
     846                 :            :         /* Flush all events out of the device */
     847   [ +  +  +  + ]:         80 :         while (!(sw_qids_empty(sw) && sw_ports_empty(sw))) {
     848                 :         21 :                 sw_event_schedule(dev);
     849                 :         21 :                 sw_drain_ports(dev);
     850                 :         21 :                 sw_drain_queues(dev);
     851                 :            :         }
     852                 :            : 
     853                 :         59 :         sw_clean_qid_iqs(dev);
     854                 :         59 :         sw_xstats_uninit(sw);
     855         [ +  - ]:         59 :         sw->started = 0;
     856                 :            :         /* Order the started store before re-enabling the service */
     857                 :            :         rte_atomic_thread_fence(rte_memory_order_release);
     858                 :            : 
     859         [ +  - ]:         59 :         if (runstate == 1)
     860                 :         59 :                 rte_service_runstate_set(sw->service_id, 1);
     861                 :         59 : }
     862                 :            : 
     863                 :            : static int
     864                 :         29 : sw_close(struct rte_eventdev *dev)
     865                 :            : {
     866                 :            :         struct sw_evdev *sw = sw_pmd_priv(dev);
     867                 :            :         uint32_t i;
     868                 :            : 
     869         [ +  + ]:         69 :         for (i = 0; i < sw->qid_count; i++)
     870                 :         40 :                 sw_queue_release(dev, i);
     871                 :         29 :         sw->qid_count = 0;
     872                 :            : 
     873         [ +  + ]:        101 :         for (i = 0; i < sw->port_count; i++)
     874                 :         72 :                 sw_port_release(&sw->ports[i]);
     875                 :         29 :         sw->port_count = 0;
     876                 :            : 
     877                 :         29 :         memset(&sw->stats, 0, sizeof(sw->stats));
     878                 :         29 :         sw->sched_called = 0;
     879                 :         29 :         sw->sched_no_iq_enqueues = 0;
     880                 :         29 :         sw->sched_no_cq_enqueues = 0;
     881                 :         29 :         sw->sched_cq_qid_called = 0;
     882                 :            : 
     883                 :         29 :         return 0;
     884                 :            : }
     885                 :            : 
     886                 :            : static int
     887                 :          0 : assign_numa_node(const char *key __rte_unused, const char *value, void *opaque)
     888                 :            : {
     889                 :            :         int *socket_id = opaque;
     890                 :          0 :         *socket_id = atoi(value);
     891         [ #  # ]:          0 :         if (*socket_id >= RTE_MAX_NUMA_NODES)
     892                 :          0 :                 return -1;
     893                 :            :         return 0;
     894                 :            : }
     895                 :            : 
     896                 :            : static int
     897                 :          0 : set_sched_quanta(const char *key __rte_unused, const char *value, void *opaque)
     898                 :            : {
     899                 :            :         int *quanta = opaque;
     900                 :          0 :         *quanta = atoi(value);
     901         [ #  # ]:          0 :         if (*quanta < 0 || *quanta >= 4096)
     902                 :          0 :                 return -1;
     903                 :            :         return 0;
     904                 :            : }
     905                 :            : 
     906                 :            : static int
     907                 :          0 : set_credit_quanta(const char *key __rte_unused, const char *value, void *opaque)
     908                 :            : {
     909                 :            :         int *credit = opaque;
     910                 :          0 :         *credit = atoi(value);
     911         [ #  # ]:          0 :         if (*credit < 0 || *credit >= 128)
     912                 :          0 :                 return -1;
     913                 :            :         return 0;
     914                 :            : }
     915                 :            : 
     916                 :            : static int
     917                 :          0 : set_deq_burst_sz(const char *key __rte_unused, const char *value, void *opaque)
     918                 :            : {
     919                 :            :         int *deq_burst_sz = opaque;
     920                 :          0 :         *deq_burst_sz = atoi(value);
     921         [ #  # ]:          0 :         if (*deq_burst_sz < 0 || *deq_burst_sz > SCHED_DEQUEUE_MAX_BURST_SIZE)
     922                 :          0 :                 return -1;
     923                 :            :         return 0;
     924                 :            : }
     925                 :            : 
     926                 :            : static int
     927                 :          0 : set_min_burst_sz(const char *key __rte_unused, const char *value, void *opaque)
     928                 :            : {
     929                 :            :         int *min_burst_sz = opaque;
     930                 :          0 :         *min_burst_sz = atoi(value);
     931         [ #  # ]:          0 :         if (*min_burst_sz < 0 || *min_burst_sz > SCHED_DEQUEUE_MAX_BURST_SIZE)
     932                 :          0 :                 return -1;
     933                 :            :         return 0;
     934                 :            : }
     935                 :            : 
     936                 :            : static int
     937                 :          0 : set_refill_once(const char *key __rte_unused, const char *value, void *opaque)
     938                 :            : {
     939                 :            :         int *refill_once_per_call = opaque;
     940                 :          0 :         *refill_once_per_call = atoi(value);
     941         [ #  # ]:          0 :         if (*refill_once_per_call < 0 || *refill_once_per_call > 1)
     942                 :          0 :                 return -1;
     943                 :            :         return 0;
     944                 :            : }
     945                 :            : 
     946                 :    4203595 : static int32_t sw_sched_service_func(void *args)
     947                 :            : {
     948                 :            :         struct rte_eventdev *dev = args;
     949                 :    4203595 :         return sw_event_schedule(dev);
     950                 :            : }
     951                 :            : 
     952                 :            : static int
     953                 :          2 : sw_probe(struct rte_vdev_device *vdev)
     954                 :            : {
     955                 :            :         static struct eventdev_ops evdev_sw_ops = {
     956                 :            :                         .dev_configure = sw_dev_configure,
     957                 :            :                         .dev_infos_get = sw_info_get,
     958                 :            :                         .dev_close = sw_close,
     959                 :            :                         .dev_start = sw_start,
     960                 :            :                         .dev_stop = sw_stop,
     961                 :            :                         .dump = sw_dump,
     962                 :            : 
     963                 :            :                         .queue_def_conf = sw_queue_def_conf,
     964                 :            :                         .queue_setup = sw_queue_setup,
     965                 :            :                         .queue_release = sw_queue_release,
     966                 :            :                         .port_def_conf = sw_port_def_conf,
     967                 :            :                         .port_setup = sw_port_setup,
     968                 :            :                         .port_release = sw_port_release,
     969                 :            :                         .port_link = sw_port_link,
     970                 :            :                         .port_unlink = sw_port_unlink,
     971                 :            :                         .port_unlinks_in_progress = sw_port_unlinks_in_progress,
     972                 :            : 
     973                 :            :                         .eth_rx_adapter_caps_get = sw_eth_rx_adapter_caps_get,
     974                 :            : 
     975                 :            :                         .timer_adapter_caps_get = sw_timer_adapter_caps_get,
     976                 :            : 
     977                 :            :                         .crypto_adapter_caps_get = sw_crypto_adapter_caps_get,
     978                 :            : 
     979                 :            :                         .xstats_get = sw_xstats_get,
     980                 :            :                         .xstats_get_names = sw_xstats_get_names,
     981                 :            :                         .xstats_get_by_name = sw_xstats_get_by_name,
     982                 :            :                         .xstats_reset = sw_xstats_reset,
     983                 :            : 
     984                 :            :                         .dev_selftest = test_sw_eventdev,
     985                 :            :         };
     986                 :            : 
     987                 :            :         static const char *const args[] = {
     988                 :            :                 NUMA_NODE_ARG,
     989                 :            :                 SCHED_QUANTA_ARG,
     990                 :            :                 CREDIT_QUANTA_ARG,
     991                 :            :                 MIN_BURST_SIZE_ARG,
     992                 :            :                 DEQ_BURST_SIZE_ARG,
     993                 :            :                 REFIL_ONCE_ARG,
     994                 :            :                 NULL
     995                 :            :         };
     996                 :            :         const char *name;
     997                 :            :         const char *params;
     998                 :            :         struct rte_eventdev *dev;
     999                 :            :         struct sw_evdev *sw;
    1000                 :          2 :         int socket_id = rte_socket_id();
    1001                 :          2 :         int sched_quanta  = SW_DEFAULT_SCHED_QUANTA;
    1002                 :          2 :         int credit_quanta = SW_DEFAULT_CREDIT_QUANTA;
    1003                 :          2 :         int min_burst_size = 1;
    1004                 :          2 :         int deq_burst_size = SCHED_DEQUEUE_DEFAULT_BURST_SIZE;
    1005         [ +  - ]:          2 :         int refill_once = 0;
    1006                 :            : 
    1007                 :            :         name = rte_vdev_device_name(vdev);
    1008                 :            :         params = rte_vdev_device_args(vdev);
    1009   [ +  -  -  + ]:          2 :         if (params != NULL && params[0] != '\0') {
    1010                 :          0 :                 struct rte_kvargs *kvlist = rte_kvargs_parse(params, args);
    1011                 :            : 
    1012         [ #  # ]:          0 :                 if (!kvlist) {
    1013                 :          0 :                         SW_LOG_INFO(
    1014                 :            :                                 "Ignoring unsupported parameters when creating device '%s'",
    1015                 :            :                                 name);
    1016                 :            :                 } else {
    1017                 :          0 :                         int ret = rte_kvargs_process(kvlist, NUMA_NODE_ARG,
    1018                 :            :                                         assign_numa_node, &socket_id);
    1019         [ #  # ]:          0 :                         if (ret != 0) {
    1020                 :          0 :                                 SW_LOG_ERR(
    1021                 :            :                                         "%s: Error parsing numa node parameter",
    1022                 :            :                                         name);
    1023                 :          0 :                                 rte_kvargs_free(kvlist);
    1024                 :          0 :                                 return ret;
    1025                 :            :                         }
    1026                 :            : 
    1027                 :          0 :                         ret = rte_kvargs_process(kvlist, SCHED_QUANTA_ARG,
    1028                 :            :                                         set_sched_quanta, &sched_quanta);
    1029         [ #  # ]:          0 :                         if (ret != 0) {
    1030                 :          0 :                                 SW_LOG_ERR(
    1031                 :            :                                         "%s: Error parsing sched quanta parameter",
    1032                 :            :                                         name);
    1033                 :          0 :                                 rte_kvargs_free(kvlist);
    1034                 :          0 :                                 return ret;
    1035                 :            :                         }
    1036                 :            : 
    1037                 :          0 :                         ret = rte_kvargs_process(kvlist, CREDIT_QUANTA_ARG,
    1038                 :            :                                         set_credit_quanta, &credit_quanta);
    1039         [ #  # ]:          0 :                         if (ret != 0) {
    1040                 :          0 :                                 SW_LOG_ERR(
    1041                 :            :                                         "%s: Error parsing credit quanta parameter",
    1042                 :            :                                         name);
    1043                 :          0 :                                 rte_kvargs_free(kvlist);
    1044                 :          0 :                                 return ret;
    1045                 :            :                         }
    1046                 :            : 
    1047                 :          0 :                         ret = rte_kvargs_process(kvlist, MIN_BURST_SIZE_ARG,
    1048                 :            :                                         set_min_burst_sz, &min_burst_size);
    1049         [ #  # ]:          0 :                         if (ret != 0) {
    1050                 :          0 :                                 SW_LOG_ERR(
    1051                 :            :                                         "%s: Error parsing minimum burst size parameter",
    1052                 :            :                                         name);
    1053                 :          0 :                                 rte_kvargs_free(kvlist);
    1054                 :          0 :                                 return ret;
    1055                 :            :                         }
    1056                 :            : 
    1057                 :          0 :                         ret = rte_kvargs_process(kvlist, DEQ_BURST_SIZE_ARG,
    1058                 :            :                                         set_deq_burst_sz, &deq_burst_size);
    1059         [ #  # ]:          0 :                         if (ret != 0) {
    1060                 :          0 :                                 SW_LOG_ERR(
    1061                 :            :                                         "%s: Error parsing dequeue burst size parameter",
    1062                 :            :                                         name);
    1063                 :          0 :                                 rte_kvargs_free(kvlist);
    1064                 :          0 :                                 return ret;
    1065                 :            :                         }
    1066                 :            : 
    1067                 :          0 :                         ret = rte_kvargs_process(kvlist, REFIL_ONCE_ARG,
    1068                 :            :                                         set_refill_once, &refill_once);
    1069         [ #  # ]:          0 :                         if (ret != 0) {
    1070                 :          0 :                                 SW_LOG_ERR(
    1071                 :            :                                         "%s: Error parsing refill once per call switch",
    1072                 :            :                                         name);
    1073                 :          0 :                                 rte_kvargs_free(kvlist);
    1074                 :          0 :                                 return ret;
    1075                 :            :                         }
    1076                 :            : 
    1077                 :          0 :                         rte_kvargs_free(kvlist);
    1078                 :            :                 }
    1079                 :            :         }
    1080                 :            : 
    1081                 :          2 :         SW_LOG_INFO(
    1082                 :            :                         "Creating eventdev sw device %s, numa_node=%d, "
    1083                 :            :                         "sched_quanta=%d, credit_quanta=%d "
    1084                 :            :                         "min_burst=%d, deq_burst=%d, refill_once=%d",
    1085                 :            :                         name, socket_id, sched_quanta, credit_quanta,
    1086                 :            :                         min_burst_size, deq_burst_size, refill_once);
    1087                 :            : 
    1088                 :          2 :         dev = rte_event_pmd_vdev_init(name,
    1089                 :            :                         sizeof(struct sw_evdev), socket_id, vdev);
    1090         [ -  + ]:          2 :         if (dev == NULL) {
    1091                 :          0 :                 SW_LOG_ERR("eventdev vdev init() failed");
    1092                 :          0 :                 return -EFAULT;
    1093                 :            :         }
    1094                 :          2 :         dev->dev_ops = &evdev_sw_ops;
    1095                 :          2 :         dev->enqueue_burst = sw_event_enqueue_burst;
    1096                 :          2 :         dev->enqueue_new_burst = sw_event_enqueue_burst;
    1097                 :          2 :         dev->enqueue_forward_burst = sw_event_enqueue_burst;
    1098                 :          2 :         dev->dequeue_burst = sw_event_dequeue_burst;
    1099                 :            : 
    1100         [ +  - ]:          2 :         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
    1101                 :            :                 return 0;
    1102                 :            : 
    1103                 :          2 :         sw = dev->data->dev_private;
    1104                 :          2 :         sw->data = dev->data;
    1105                 :            : 
    1106                 :            :         /* copy values passed from vdev command line to instance */
    1107                 :          2 :         sw->credit_update_quanta = credit_quanta;
    1108                 :          2 :         sw->sched_quanta = sched_quanta;
    1109                 :          2 :         sw->sched_min_burst_size = min_burst_size;
    1110                 :          2 :         sw->sched_deq_burst_size = deq_burst_size;
    1111                 :          2 :         sw->refill_once_per_iter = refill_once;
    1112                 :            : 
    1113                 :            :         /* register service with EAL */
    1114                 :            :         struct rte_service_spec service;
    1115                 :            :         memset(&service, 0, sizeof(struct rte_service_spec));
    1116                 :            :         snprintf(service.name, sizeof(service.name), "%s_service", name);
    1117                 :          2 :         snprintf(sw->service_name, sizeof(sw->service_name), "%s_service",
    1118                 :            :                         name);
    1119                 :          2 :         service.socket_id = socket_id;
    1120                 :          2 :         service.callback = sw_sched_service_func;
    1121                 :          2 :         service.callback_userdata = (void *)dev;
    1122                 :            : 
    1123                 :          2 :         int32_t ret = rte_service_component_register(&service, &sw->service_id);
    1124         [ -  + ]:          2 :         if (ret) {
    1125                 :          0 :                 SW_LOG_ERR("service register() failed");
    1126                 :          0 :                 return -ENOEXEC;
    1127                 :            :         }
    1128                 :            : 
    1129                 :          2 :         dev->data->service_inited = 1;
    1130                 :          2 :         dev->data->service_id = sw->service_id;
    1131                 :            : 
    1132                 :          2 :         event_dev_probing_finish(dev);
    1133                 :            : 
    1134                 :          2 :         return 0;
    1135                 :            : }
    1136                 :            : 
    1137                 :            : static int
    1138         [ +  - ]:          2 : sw_remove(struct rte_vdev_device *vdev)
    1139                 :            : {
    1140                 :            :         const char *name;
    1141                 :            : 
    1142                 :            :         name = rte_vdev_device_name(vdev);
    1143                 :            :         if (name == NULL)
    1144                 :            :                 return -EINVAL;
    1145                 :            : 
    1146                 :          2 :         SW_LOG_INFO("Closing eventdev sw device %s", name);
    1147                 :            : 
    1148                 :          2 :         return rte_event_pmd_vdev_uninit(name);
    1149                 :            : }
    1150                 :            : 
    1151                 :            : static struct rte_vdev_driver evdev_sw_pmd_drv = {
    1152                 :            :         .probe = sw_probe,
    1153                 :            :         .remove = sw_remove
    1154                 :            : };
    1155                 :            : 
    1156                 :        305 : RTE_PMD_REGISTER_VDEV(EVENTDEV_NAME_SW_PMD, evdev_sw_pmd_drv);
    1157                 :            : RTE_PMD_REGISTER_PARAM_STRING(event_sw, NUMA_NODE_ARG "=<int> "
    1158                 :            :                 SCHED_QUANTA_ARG "=<int>" CREDIT_QUANTA_ARG "=<int>"
    1159                 :            :                 MIN_BURST_SIZE_ARG "=<int>" DEQ_BURST_SIZE_ARG "=<int>"
    1160                 :            :                 REFIL_ONCE_ARG "=<int>");
    1161         [ -  + ]:        305 : RTE_LOG_REGISTER_DEFAULT(eventdev_sw_log_level, NOTICE);

Generated by: LCOV version 1.14