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

Generated by: LCOV version 1.14