f-stack/dpdk/drivers/mempool/stack/rte_mempool_stack.c

98 lines
1.8 KiB
C
Raw Normal View History

2019-06-25 11:12:58 +00:00
/* SPDX-License-Identifier: BSD-3-Clause
2020-06-18 16:55:50 +00:00
* Copyright(c) 2016-2019 Intel Corporation
2017-04-21 10:43:26 +00:00
*/
#include <stdio.h>
#include <rte_mempool.h>
2020-06-18 16:55:50 +00:00
#include <rte_stack.h>
2017-04-21 10:43:26 +00:00
static int
2020-06-18 16:55:50 +00:00
__stack_alloc(struct rte_mempool *mp, uint32_t flags)
2017-04-21 10:43:26 +00:00
{
2020-06-18 16:55:50 +00:00
char name[RTE_STACK_NAMESIZE];
struct rte_stack *s;
int ret;
ret = snprintf(name, sizeof(name),
RTE_MEMPOOL_MZ_FORMAT, mp->name);
if (ret < 0 || ret >= (int)sizeof(name)) {
rte_errno = ENAMETOOLONG;
return -rte_errno;
2017-04-21 10:43:26 +00:00
}
2020-06-18 16:55:50 +00:00
s = rte_stack_create(name, mp->size, mp->socket_id, flags);
if (s == NULL)
return -rte_errno;
2017-04-21 10:43:26 +00:00
mp->pool_data = s;
return 0;
}
static int
2020-06-18 16:55:50 +00:00
stack_alloc(struct rte_mempool *mp)
2017-04-21 10:43:26 +00:00
{
2020-06-18 16:55:50 +00:00
return __stack_alloc(mp, 0);
}
2017-04-21 10:43:26 +00:00
2020-06-18 16:55:50 +00:00
static int
lf_stack_alloc(struct rte_mempool *mp)
{
return __stack_alloc(mp, RTE_STACK_F_LF);
}
2017-04-21 10:43:26 +00:00
2020-06-18 16:55:50 +00:00
static int
stack_enqueue(struct rte_mempool *mp, void * const *obj_table,
unsigned int n)
{
struct rte_stack *s = mp->pool_data;
2017-04-21 10:43:26 +00:00
2020-06-18 16:55:50 +00:00
return rte_stack_push(s, obj_table, n) == 0 ? -ENOBUFS : 0;
2017-04-21 10:43:26 +00:00
}
static int
stack_dequeue(struct rte_mempool *mp, void **obj_table,
2020-06-18 16:55:50 +00:00
unsigned int n)
2017-04-21 10:43:26 +00:00
{
2020-06-18 16:55:50 +00:00
struct rte_stack *s = mp->pool_data;
2017-04-21 10:43:26 +00:00
2020-06-18 16:55:50 +00:00
return rte_stack_pop(s, obj_table, n) == 0 ? -ENOBUFS : 0;
2017-04-21 10:43:26 +00:00
}
static unsigned
stack_get_count(const struct rte_mempool *mp)
{
2020-06-18 16:55:50 +00:00
struct rte_stack *s = mp->pool_data;
2017-04-21 10:43:26 +00:00
2020-06-18 16:55:50 +00:00
return rte_stack_count(s);
2017-04-21 10:43:26 +00:00
}
static void
stack_free(struct rte_mempool *mp)
{
2020-06-18 16:55:50 +00:00
struct rte_stack *s = mp->pool_data;
rte_stack_free(s);
2017-04-21 10:43:26 +00:00
}
static struct rte_mempool_ops ops_stack = {
.name = "stack",
.alloc = stack_alloc,
.free = stack_free,
.enqueue = stack_enqueue,
.dequeue = stack_dequeue,
.get_count = stack_get_count
};
2020-06-18 16:55:50 +00:00
static struct rte_mempool_ops ops_lf_stack = {
.name = "lf_stack",
.alloc = lf_stack_alloc,
.free = stack_free,
.enqueue = stack_enqueue,
.dequeue = stack_dequeue,
.get_count = stack_get_count
};
2017-04-21 10:43:26 +00:00
MEMPOOL_REGISTER_OPS(ops_stack);
2020-06-18 16:55:50 +00:00
MEMPOOL_REGISTER_OPS(ops_lf_stack);