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

Generated by: LCOV version 1.14