LCOV - code coverage report
Current view: top level - drivers/mempool/stack - rte_mempool_stack.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 24 29 82.8 %
Date: 2025-02-01 18:54:23 Functions: 8 9 88.9 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 8 16 50.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2016-2019 Intel Corporation
       3                 :            :  */
       4                 :            : 
       5                 :            : #include <stdio.h>
       6                 :            : #include <rte_mempool.h>
       7                 :            : #include <rte_stack.h>
       8                 :            : 
       9                 :            : static int
      10                 :          1 : __stack_alloc(struct rte_mempool *mp, uint32_t flags)
      11                 :            : {
      12                 :            :         char name[RTE_STACK_NAMESIZE];
      13                 :            :         struct rte_stack *s;
      14                 :            :         int ret;
      15                 :            : 
      16                 :            :         ret = snprintf(name, sizeof(name),
      17         [ -  + ]:          1 :                        RTE_MEMPOOL_MZ_FORMAT, mp->name);
      18         [ -  + ]:          1 :         if (ret < 0 || ret >= (int)sizeof(name)) {
      19                 :          0 :                 rte_errno = ENAMETOOLONG;
      20                 :          0 :                 return -rte_errno;
      21                 :            :         }
      22                 :            : 
      23                 :          1 :         s = rte_stack_create(name, mp->size, mp->socket_id, flags);
      24         [ -  + ]:          1 :         if (s == NULL)
      25                 :          0 :                 return -rte_errno;
      26                 :            : 
      27                 :          1 :         mp->pool_data = s;
      28                 :            : 
      29                 :          1 :         return 0;
      30                 :            : }
      31                 :            : 
      32                 :            : static int
      33                 :          1 : stack_alloc(struct rte_mempool *mp)
      34                 :            : {
      35                 :          1 :         return __stack_alloc(mp, 0);
      36                 :            : }
      37                 :            : 
      38                 :            : static int
      39                 :          0 : lf_stack_alloc(struct rte_mempool *mp)
      40                 :            : {
      41                 :          0 :         return __stack_alloc(mp, RTE_STACK_F_LF);
      42                 :            : }
      43                 :            : 
      44                 :            : static int
      45                 :       1057 : stack_enqueue(struct rte_mempool *mp, void * const *obj_table,
      46                 :            :               unsigned int n)
      47                 :            : {
      48         [ -  + ]:       1057 :         struct rte_stack *s = mp->pool_data;
      49                 :            : 
      50         [ +  - ]:       1057 :         return rte_stack_push(s, obj_table, n) == 0 ? -ENOBUFS : 0;
      51                 :            : }
      52                 :            : 
      53                 :            : static int
      54                 :       1115 : stack_dequeue(struct rte_mempool *mp, void **obj_table,
      55                 :            :               unsigned int n)
      56                 :            : {
      57         [ -  + ]:       1115 :         struct rte_stack *s = mp->pool_data;
      58                 :            : 
      59         [ +  - ]:       1086 :         return rte_stack_pop(s, obj_table, n) == 0 ? -ENOBUFS : 0;
      60                 :            : }
      61                 :            : 
      62                 :            : static unsigned
      63                 :          8 : stack_get_count(const struct rte_mempool *mp)
      64                 :            : {
      65         [ -  + ]:          8 :         struct rte_stack *s = mp->pool_data;
      66                 :            : 
      67                 :          8 :         return rte_stack_count(s);
      68                 :            : }
      69                 :            : 
      70                 :            : static void
      71                 :          1 : stack_free(struct rte_mempool *mp)
      72                 :            : {
      73                 :          1 :         struct rte_stack *s = mp->pool_data;
      74                 :            : 
      75                 :          1 :         rte_stack_free(s);
      76                 :          1 : }
      77                 :            : 
      78                 :            : static struct rte_mempool_ops ops_stack = {
      79                 :            :         .name = "stack",
      80                 :            :         .alloc = stack_alloc,
      81                 :            :         .free = stack_free,
      82                 :            :         .enqueue = stack_enqueue,
      83                 :            :         .dequeue = stack_dequeue,
      84                 :            :         .get_count = stack_get_count
      85                 :            : };
      86                 :            : 
      87                 :            : static struct rte_mempool_ops ops_lf_stack = {
      88                 :            :         .name = "lf_stack",
      89                 :            :         .alloc = lf_stack_alloc,
      90                 :            :         .free = stack_free,
      91                 :            :         .enqueue = stack_enqueue,
      92                 :            :         .dequeue = stack_dequeue,
      93                 :            :         .get_count = stack_get_count
      94                 :            : };
      95                 :            : 
      96                 :        252 : RTE_MEMPOOL_REGISTER_OPS(ops_stack);
      97                 :        252 : RTE_MEMPOOL_REGISTER_OPS(ops_lf_stack);

Generated by: LCOV version 1.14