LCOV - code coverage report
Current view: top level - lib/mbuf - rte_mbuf_pool_ops.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 12 40 30.0 %
Date: 2025-05-01 17:49:45 Functions: 3 5 60.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 4 26 15.4 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright 2018 NXP
       3                 :            :  */
       4                 :            : 
       5                 :            : #include <string.h>
       6                 :            : #include <eal_export.h>
       7                 :            : #include <rte_eal.h>
       8                 :            : #include <rte_mbuf.h>
       9                 :            : #include <rte_errno.h>
      10                 :            : #include <rte_mbuf_pool_ops.h>
      11                 :            : 
      12                 :            : #include "mbuf_log.h"
      13                 :            : 
      14                 :            : RTE_EXPORT_SYMBOL(rte_mbuf_set_platform_mempool_ops)
      15                 :            : int
      16                 :          0 : rte_mbuf_set_platform_mempool_ops(const char *ops_name)
      17                 :            : {
      18                 :            :         const struct rte_memzone *mz;
      19                 :            : 
      20                 :          0 :         size_t len = strnlen(ops_name, RTE_MEMPOOL_OPS_NAMESIZE);
      21         [ #  # ]:          0 :         if (len == 0)
      22                 :            :                 return -EINVAL;
      23         [ #  # ]:          0 :         if (len == RTE_MEMPOOL_OPS_NAMESIZE)
      24                 :            :                 return -ENAMETOOLONG;
      25                 :            : 
      26                 :          0 :         mz = rte_memzone_lookup("mbuf_platform_pool_ops");
      27         [ #  # ]:          0 :         if (mz == NULL) {
      28                 :          0 :                 mz = rte_memzone_reserve("mbuf_platform_pool_ops",
      29                 :            :                         RTE_MEMPOOL_OPS_NAMESIZE, SOCKET_ID_ANY, 0);
      30         [ #  # ]:          0 :                 if (mz == NULL)
      31                 :          0 :                         return -rte_errno;
      32                 :          0 :                 strcpy(mz->addr, ops_name);
      33                 :          0 :                 return 0;
      34         [ #  # ]:          0 :         } else if (strcmp(mz->addr, ops_name) == 0) {
      35                 :            :                 return 0;
      36                 :            :         }
      37                 :            : 
      38                 :          0 :         MBUF_LOG(ERR,
      39                 :            :                 "%s is already registered as platform mbuf pool ops",
      40                 :            :                 (char *)mz->addr);
      41                 :          0 :         return -EEXIST;
      42                 :            : }
      43                 :            : 
      44                 :            : RTE_EXPORT_SYMBOL(rte_mbuf_platform_mempool_ops)
      45                 :            : const char *
      46                 :         29 : rte_mbuf_platform_mempool_ops(void)
      47                 :            : {
      48                 :            :         const struct rte_memzone *mz;
      49                 :            : 
      50                 :         29 :         mz = rte_memzone_lookup("mbuf_platform_pool_ops");
      51         [ -  + ]:         29 :         if (mz == NULL)
      52                 :            :                 return NULL;
      53                 :          0 :         return mz->addr;
      54                 :            : }
      55                 :            : 
      56                 :            : RTE_EXPORT_SYMBOL(rte_mbuf_set_user_mempool_ops)
      57                 :            : int
      58                 :          0 : rte_mbuf_set_user_mempool_ops(const char *ops_name)
      59                 :            : {
      60                 :            :         const struct rte_memzone *mz;
      61                 :            : 
      62                 :          0 :         size_t len = strnlen(ops_name, RTE_MEMPOOL_OPS_NAMESIZE);
      63         [ #  # ]:          0 :         if (len == 0)
      64                 :            :                 return -EINVAL;
      65         [ #  # ]:          0 :         if (len == RTE_MEMPOOL_OPS_NAMESIZE)
      66                 :            :                 return -ENAMETOOLONG;
      67                 :            : 
      68                 :          0 :         mz = rte_memzone_lookup("mbuf_user_pool_ops");
      69         [ #  # ]:          0 :         if (mz == NULL) {
      70                 :          0 :                 mz = rte_memzone_reserve("mbuf_user_pool_ops",
      71                 :            :                         RTE_MEMPOOL_OPS_NAMESIZE, SOCKET_ID_ANY, 0);
      72         [ #  # ]:          0 :                 if (mz == NULL)
      73                 :          0 :                         return -rte_errno;
      74                 :            :         }
      75                 :            : 
      76                 :          0 :         strcpy(mz->addr, ops_name);
      77                 :          0 :         return 0;
      78                 :            : 
      79                 :            : }
      80                 :            : 
      81                 :            : RTE_EXPORT_SYMBOL(rte_mbuf_user_mempool_ops)
      82                 :            : const char *
      83                 :         29 : rte_mbuf_user_mempool_ops(void)
      84                 :            : {
      85                 :            :         const struct rte_memzone *mz;
      86                 :            : 
      87                 :         29 :         mz = rte_memzone_lookup("mbuf_user_pool_ops");
      88         [ +  - ]:         29 :         if (mz == NULL)
      89                 :         29 :                 return rte_eal_mbuf_user_pool_ops();
      90                 :          0 :         return mz->addr;
      91                 :            : }
      92                 :            : 
      93                 :            : /* Return mbuf pool ops name */
      94                 :            : RTE_EXPORT_SYMBOL(rte_mbuf_best_mempool_ops)
      95                 :            : const char *
      96                 :         29 : rte_mbuf_best_mempool_ops(void)
      97                 :            : {
      98                 :            :         /* User defined mempool ops takes the priority */
      99                 :         29 :         const char *best_ops = rte_mbuf_user_mempool_ops();
     100         [ +  - ]:         29 :         if (best_ops)
     101                 :            :                 return best_ops;
     102                 :            : 
     103                 :            :         /* Next choice is platform configured mempool ops */
     104                 :         29 :         best_ops = rte_mbuf_platform_mempool_ops();
     105         [ -  + ]:         29 :         if (best_ops)
     106                 :          0 :                 return best_ops;
     107                 :            : 
     108                 :            :         /* Last choice is to use the compile time config pool */
     109                 :            :         return RTE_MBUF_DEFAULT_MEMPOOL_OPS;
     110                 :            : }

Generated by: LCOV version 1.14