LCOV - code coverage report
Current view: top level - drivers/mempool/ring - rte_mempool_ring.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 35 54 64.8 %
Date: 2024-12-01 18:57:19 Functions: 14 20 70.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 10 22 45.5 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2010-2016 Intel Corporation
       3                 :            :  */
       4                 :            : 
       5                 :            : #include <stdio.h>
       6                 :            : #include <string.h>
       7                 :            : 
       8                 :            : #include <rte_errno.h>
       9                 :            : #include <rte_ring.h>
      10                 :            : #include <rte_mempool.h>
      11                 :            : 
      12                 :            : static int
      13                 :   44720773 : common_ring_mp_enqueue(struct rte_mempool *mp, void * const *obj_table,
      14                 :            :                 unsigned n)
      15                 :            : {
      16                 :   44720773 :         return rte_ring_mp_enqueue_bulk(mp->pool_data,
      17         [ +  - ]:   44720773 :                         obj_table, n, NULL) == 0 ? -ENOBUFS : 0;
      18                 :            : }
      19                 :            : 
      20                 :            : static int
      21                 :     256469 : common_ring_sp_enqueue(struct rte_mempool *mp, void * const *obj_table,
      22                 :            :                 unsigned n)
      23                 :            : {
      24                 :     256469 :         return rte_ring_sp_enqueue_bulk(mp->pool_data,
      25                 :     256469 :                         obj_table, n, NULL) == 0 ? -ENOBUFS : 0;
      26                 :            : }
      27                 :            : 
      28                 :            : static int
      29                 :          0 : rts_ring_mp_enqueue(struct rte_mempool *mp, void * const *obj_table,
      30                 :            :         unsigned int n)
      31                 :            : {
      32                 :          0 :         return rte_ring_mp_rts_enqueue_bulk(mp->pool_data,
      33         [ #  # ]:          0 :                         obj_table, n, NULL) == 0 ? -ENOBUFS : 0;
      34                 :            : }
      35                 :            : 
      36                 :            : static int
      37                 :          0 : hts_ring_mp_enqueue(struct rte_mempool *mp, void * const *obj_table,
      38                 :            :         unsigned int n)
      39                 :            : {
      40                 :          0 :         return rte_ring_mp_hts_enqueue_bulk(mp->pool_data,
      41         [ #  # ]:          0 :                         obj_table, n, NULL) == 0 ? -ENOBUFS : 0;
      42                 :            : }
      43                 :            : 
      44                 :            : static int
      45                 :   44701482 : common_ring_mc_dequeue(struct rte_mempool *mp, void **obj_table, unsigned n)
      46                 :            : {
      47                 :   44701482 :         return rte_ring_mc_dequeue_bulk(mp->pool_data,
      48         [ +  + ]:   44701482 :                         obj_table, n, NULL) == 0 ? -ENOBUFS : 0;
      49                 :            : }
      50                 :            : 
      51                 :            : static int
      52                 :     266709 : common_ring_sc_dequeue(struct rte_mempool *mp, void **obj_table, unsigned n)
      53                 :            : {
      54                 :     266709 :         return rte_ring_sc_dequeue_bulk(mp->pool_data,
      55                 :     266709 :                         obj_table, n, NULL) == 0 ? -ENOBUFS : 0;
      56                 :            : }
      57                 :            : 
      58                 :            : static int
      59                 :          0 : rts_ring_mc_dequeue(struct rte_mempool *mp, void **obj_table, unsigned int n)
      60                 :            : {
      61                 :          0 :         return rte_ring_mc_rts_dequeue_bulk(mp->pool_data,
      62         [ #  # ]:          0 :                         obj_table, n, NULL) == 0 ? -ENOBUFS : 0;
      63                 :            : }
      64                 :            : 
      65                 :            : static int
      66                 :          0 : hts_ring_mc_dequeue(struct rte_mempool *mp, void **obj_table, unsigned int n)
      67                 :            : {
      68                 :          0 :         return rte_ring_mc_hts_dequeue_bulk(mp->pool_data,
      69         [ #  # ]:          0 :                         obj_table, n, NULL) == 0 ? -ENOBUFS : 0;
      70                 :            : }
      71                 :            : 
      72                 :            : static unsigned
      73                 :        642 : common_ring_get_count(const struct rte_mempool *mp)
      74                 :            : {
      75                 :        642 :         return rte_ring_count(mp->pool_data);
      76                 :            : }
      77                 :            : 
      78                 :            : static int
      79                 :        109 : ring_alloc(struct rte_mempool *mp, uint32_t rg_flags)
      80                 :            : {
      81                 :            :         int ret;
      82                 :            :         char rg_name[RTE_RING_NAMESIZE];
      83                 :            :         struct rte_ring *r;
      84                 :            : 
      85                 :            :         ret = snprintf(rg_name, sizeof(rg_name),
      86         [ -  + ]:        109 :                 RTE_MEMPOOL_MZ_FORMAT, mp->name);
      87         [ -  + ]:        109 :         if (ret < 0 || ret >= (int)sizeof(rg_name)) {
      88                 :          0 :                 rte_errno = ENAMETOOLONG;
      89                 :          0 :                 return -rte_errno;
      90                 :            :         }
      91                 :            : 
      92                 :            :         /*
      93                 :            :          * Allocate the ring that will be used to store objects.
      94                 :            :          * Ring functions will return appropriate errors if we are
      95                 :            :          * running as a secondary process etc., so no checks made
      96                 :            :          * in this function for that condition.
      97                 :            :          */
      98                 :        109 :         r = rte_ring_create(rg_name, rte_align32pow2(mp->size + 1),
      99                 :            :                 mp->socket_id, rg_flags);
     100         [ -  + ]:        109 :         if (r == NULL)
     101                 :          0 :                 return -rte_errno;
     102                 :            : 
     103                 :        109 :         mp->pool_data = r;
     104                 :            : 
     105                 :        109 :         return 0;
     106                 :            : }
     107                 :            : 
     108                 :            : static int
     109                 :        109 : common_ring_alloc(struct rte_mempool *mp)
     110                 :            : {
     111                 :            :         uint32_t rg_flags = 0;
     112                 :            : 
     113         [ +  + ]:        109 :         if (mp->flags & RTE_MEMPOOL_F_SP_PUT)
     114                 :            :                 rg_flags |= RING_F_SP_ENQ;
     115         [ +  + ]:        109 :         if (mp->flags & RTE_MEMPOOL_F_SC_GET)
     116                 :          1 :                 rg_flags |= RING_F_SC_DEQ;
     117                 :            : 
     118                 :        109 :         return ring_alloc(mp, rg_flags);
     119                 :            : }
     120                 :            : 
     121                 :            : static int
     122                 :          0 : rts_ring_alloc(struct rte_mempool *mp)
     123                 :            : {
     124                 :          0 :         return ring_alloc(mp, RING_F_MP_RTS_ENQ | RING_F_MC_RTS_DEQ);
     125                 :            : }
     126                 :            : 
     127                 :            : static int
     128                 :          0 : hts_ring_alloc(struct rte_mempool *mp)
     129                 :            : {
     130                 :          0 :         return ring_alloc(mp, RING_F_MP_HTS_ENQ | RING_F_MC_HTS_DEQ);
     131                 :            : }
     132                 :            : 
     133                 :            : static void
     134                 :        104 : common_ring_free(struct rte_mempool *mp)
     135                 :            : {
     136                 :        104 :         rte_ring_free(mp->pool_data);
     137                 :        104 : }
     138                 :            : 
     139                 :            : /*
     140                 :            :  * The following 4 declarations of mempool ops structs address
     141                 :            :  * the need for the backward compatible mempool handlers for
     142                 :            :  * single/multi producers and single/multi consumers as dictated by the
     143                 :            :  * flags provided to the rte_mempool_create function
     144                 :            :  */
     145                 :            : static const struct rte_mempool_ops ops_mp_mc = {
     146                 :            :         .name = "ring_mp_mc",
     147                 :            :         .alloc = common_ring_alloc,
     148                 :            :         .free = common_ring_free,
     149                 :            :         .enqueue = common_ring_mp_enqueue,
     150                 :            :         .dequeue = common_ring_mc_dequeue,
     151                 :            :         .get_count = common_ring_get_count,
     152                 :            : };
     153                 :            : 
     154                 :            : static const struct rte_mempool_ops ops_sp_sc = {
     155                 :            :         .name = "ring_sp_sc",
     156                 :            :         .alloc = common_ring_alloc,
     157                 :            :         .free = common_ring_free,
     158                 :            :         .enqueue = common_ring_sp_enqueue,
     159                 :            :         .dequeue = common_ring_sc_dequeue,
     160                 :            :         .get_count = common_ring_get_count,
     161                 :            : };
     162                 :            : 
     163                 :            : static const struct rte_mempool_ops ops_mp_sc = {
     164                 :            :         .name = "ring_mp_sc",
     165                 :            :         .alloc = common_ring_alloc,
     166                 :            :         .free = common_ring_free,
     167                 :            :         .enqueue = common_ring_mp_enqueue,
     168                 :            :         .dequeue = common_ring_sc_dequeue,
     169                 :            :         .get_count = common_ring_get_count,
     170                 :            : };
     171                 :            : 
     172                 :            : static const struct rte_mempool_ops ops_sp_mc = {
     173                 :            :         .name = "ring_sp_mc",
     174                 :            :         .alloc = common_ring_alloc,
     175                 :            :         .free = common_ring_free,
     176                 :            :         .enqueue = common_ring_sp_enqueue,
     177                 :            :         .dequeue = common_ring_mc_dequeue,
     178                 :            :         .get_count = common_ring_get_count,
     179                 :            : };
     180                 :            : 
     181                 :            : /* ops for mempool with ring in MT_RTS sync mode */
     182                 :            : static const struct rte_mempool_ops ops_mt_rts = {
     183                 :            :         .name = "ring_mt_rts",
     184                 :            :         .alloc = rts_ring_alloc,
     185                 :            :         .free = common_ring_free,
     186                 :            :         .enqueue = rts_ring_mp_enqueue,
     187                 :            :         .dequeue = rts_ring_mc_dequeue,
     188                 :            :         .get_count = common_ring_get_count,
     189                 :            : };
     190                 :            : 
     191                 :            : /* ops for mempool with ring in MT_HTS sync mode */
     192                 :            : static const struct rte_mempool_ops ops_mt_hts = {
     193                 :            :         .name = "ring_mt_hts",
     194                 :            :         .alloc = hts_ring_alloc,
     195                 :            :         .free = common_ring_free,
     196                 :            :         .enqueue = hts_ring_mp_enqueue,
     197                 :            :         .dequeue = hts_ring_mc_dequeue,
     198                 :            :         .get_count = common_ring_get_count,
     199                 :            : };
     200                 :            : 
     201                 :        251 : RTE_MEMPOOL_REGISTER_OPS(ops_mp_mc);
     202                 :        251 : RTE_MEMPOOL_REGISTER_OPS(ops_sp_sc);
     203                 :        251 : RTE_MEMPOOL_REGISTER_OPS(ops_mp_sc);
     204                 :        251 : RTE_MEMPOOL_REGISTER_OPS(ops_sp_mc);
     205                 :        251 : RTE_MEMPOOL_REGISTER_OPS(ops_mt_rts);
     206                 :        251 : RTE_MEMPOOL_REGISTER_OPS(ops_mt_hts);

Generated by: LCOV version 1.14