DPDK 21.11.9
rte_stack.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019 Intel Corporation
3 */
4
15#ifndef _RTE_STACK_H_
16#define _RTE_STACK_H_
17
18#ifdef __cplusplus
19extern "C" {
20#endif
21
22#include <rte_compat.h>
23#include <rte_debug.h>
24#include <rte_errno.h>
25#include <rte_memzone.h>
26#include <rte_spinlock.h>
27
28#define RTE_TAILQ_STACK_NAME "RTE_STACK"
29#define RTE_STACK_MZ_PREFIX "STK_"
31#define RTE_STACK_NAMESIZE (RTE_MEMZONE_NAMESIZE - \
32 sizeof(RTE_STACK_MZ_PREFIX) + 1)
33
34struct rte_stack_lf_elem {
35 void *data;
36 struct rte_stack_lf_elem *next;
37};
38
39struct rte_stack_lf_head {
40 struct rte_stack_lf_elem *top;
41 uint64_t cnt;
42};
43
44struct rte_stack_lf_list {
46 struct rte_stack_lf_head head __rte_aligned(16);
48 uint64_t len;
49};
50
51/* Structure containing two lock-free LIFO lists: the stack itself and a list
52 * of free linked-list elements.
53 */
54struct rte_stack_lf {
56 struct rte_stack_lf_list used __rte_cache_aligned;
58 struct rte_stack_lf_list free __rte_cache_aligned;
60 struct rte_stack_lf_elem elems[] __rte_cache_aligned;
61};
62
63/* Structure containing the LIFO, its current length, and a lock for mutual
64 * exclusion.
65 */
66struct rte_stack_std {
67 rte_spinlock_t lock;
68 uint32_t len;
69 void *objs[];
70};
71
72/* The RTE stack structure contains the LIFO structure itself, plus metadata
73 * such as its name and memzone pointer.
74 */
75struct rte_stack {
79 const struct rte_memzone *memzone;
80 uint32_t capacity;
81 uint32_t flags;
83 union {
84 struct rte_stack_lf stack_lf;
85 struct rte_stack_std stack_std;
86 };
88
93#define RTE_STACK_F_LF 0x0001
94
95#include "rte_stack_std.h"
96#include "rte_stack_lf.h"
97
110static __rte_always_inline unsigned int
111rte_stack_push(struct rte_stack *s, void * const *obj_table, unsigned int n)
112{
113 RTE_ASSERT(s != NULL);
114 RTE_ASSERT(obj_table != NULL);
115
116 if (s->flags & RTE_STACK_F_LF)
117 return __rte_stack_lf_push(s, obj_table, n);
118 else
119 return __rte_stack_std_push(s, obj_table, n);
120}
121
134static __rte_always_inline unsigned int
135rte_stack_pop(struct rte_stack *s, void **obj_table, unsigned int n)
136{
137 RTE_ASSERT(s != NULL);
138 RTE_ASSERT(obj_table != NULL);
139
140 if (s->flags & RTE_STACK_F_LF)
141 return __rte_stack_lf_pop(s, obj_table, n);
142 else
143 return __rte_stack_std_pop(s, obj_table, n);
144}
145
154static __rte_always_inline unsigned int
155rte_stack_count(struct rte_stack *s)
156{
157 RTE_ASSERT(s != NULL);
158
159 if (s->flags & RTE_STACK_F_LF)
160 return __rte_stack_lf_count(s);
161 else
162 return __rte_stack_std_count(s);
163}
164
173static __rte_always_inline unsigned int
174rte_stack_free_count(struct rte_stack *s)
175{
176 RTE_ASSERT(s != NULL);
177
178 return s->capacity - rte_stack_count(s);
179}
180
209struct rte_stack *
210rte_stack_create(const char *name, unsigned int count, int socket_id,
211 uint32_t flags);
212
219void
220rte_stack_free(struct rte_stack *s);
221
233struct rte_stack *
234rte_stack_lookup(const char *name);
235
236#ifdef __cplusplus
237}
238#endif
239
240#endif /* _RTE_STACK_H_ */
#define __rte_cache_aligned
Definition: rte_common.h:420
#define RTE_STD_C11
Definition: rte_common.h:42
#define __rte_always_inline
Definition: rte_common.h:233
#define RTE_STACK_F_LF
Definition: rte_stack.h:93
struct rte_stack * rte_stack_create(const char *name, unsigned int count, int socket_id, uint32_t flags)
#define RTE_STACK_NAMESIZE
Definition: rte_stack.h:31
void rte_stack_free(struct rte_stack *s)
static __rte_always_inline unsigned int rte_stack_count(struct rte_stack *s)
Definition: rte_stack.h:155
static __rte_always_inline unsigned int rte_stack_push(struct rte_stack *s, void *const *obj_table, unsigned int n)
Definition: rte_stack.h:111
static __rte_always_inline unsigned int rte_stack_free_count(struct rte_stack *s)
Definition: rte_stack.h:174
static __rte_always_inline unsigned int rte_stack_pop(struct rte_stack *s, void **obj_table, unsigned int n)
Definition: rte_stack.h:135
struct rte_stack * rte_stack_lookup(const char *name)
uint32_t flags
Definition: rte_memzone.h:66