DPDK 22.11.4
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_debug.h>
23#include <rte_errno.h>
24#include <rte_memzone.h>
25#include <rte_spinlock.h>
26
27#define RTE_TAILQ_STACK_NAME "RTE_STACK"
28#define RTE_STACK_MZ_PREFIX "STK_"
30#define RTE_STACK_NAMESIZE (RTE_MEMZONE_NAMESIZE - \
31 sizeof(RTE_STACK_MZ_PREFIX) + 1)
32
33struct rte_stack_lf_elem {
34 void *data;
35 struct rte_stack_lf_elem *next;
36};
37
38struct rte_stack_lf_head {
39 struct rte_stack_lf_elem *top;
40 uint64_t cnt;
41};
42
43struct rte_stack_lf_list {
45 struct rte_stack_lf_head head __rte_aligned(16);
47 uint64_t len;
48};
49
50/* Structure containing two lock-free LIFO lists: the stack itself and a list
51 * of free linked-list elements.
52 */
53struct rte_stack_lf {
55 struct rte_stack_lf_list used __rte_cache_aligned;
57 struct rte_stack_lf_list free __rte_cache_aligned;
59 struct rte_stack_lf_elem elems[] __rte_cache_aligned;
60};
61
62/* Structure containing the LIFO, its current length, and a lock for mutual
63 * exclusion.
64 */
65struct rte_stack_std {
66 rte_spinlock_t lock;
67 uint32_t len;
68 void *objs[];
69};
70
71/* The RTE stack structure contains the LIFO structure itself, plus metadata
72 * such as its name and memzone pointer.
73 */
74struct rte_stack {
78 const struct rte_memzone *memzone;
79 uint32_t capacity;
80 uint32_t flags;
82 union {
83 struct rte_stack_lf stack_lf;
84 struct rte_stack_std stack_std;
85 };
87
92#define RTE_STACK_F_LF 0x0001
93
94#include "rte_stack_std.h"
95#include "rte_stack_lf.h"
96
109static __rte_always_inline unsigned int
110rte_stack_push(struct rte_stack *s, void * const *obj_table, unsigned int n)
111{
112 RTE_ASSERT(s != NULL);
113 RTE_ASSERT(obj_table != NULL);
114
115 if (s->flags & RTE_STACK_F_LF)
116 return __rte_stack_lf_push(s, obj_table, n);
117 else
118 return __rte_stack_std_push(s, obj_table, n);
119}
120
133static __rte_always_inline unsigned int
134rte_stack_pop(struct rte_stack *s, void **obj_table, unsigned int n)
135{
136 RTE_ASSERT(s != NULL);
137 RTE_ASSERT(obj_table != NULL);
138
139 if (s->flags & RTE_STACK_F_LF)
140 return __rte_stack_lf_pop(s, obj_table, n);
141 else
142 return __rte_stack_std_pop(s, obj_table, n);
143}
144
153static __rte_always_inline unsigned int
154rte_stack_count(struct rte_stack *s)
155{
156 RTE_ASSERT(s != NULL);
157
158 if (s->flags & RTE_STACK_F_LF)
159 return __rte_stack_lf_count(s);
160 else
161 return __rte_stack_std_count(s);
162}
163
172static __rte_always_inline unsigned int
173rte_stack_free_count(struct rte_stack *s)
174{
175 RTE_ASSERT(s != NULL);
176
177 return s->capacity - rte_stack_count(s);
178}
179
208struct rte_stack *
209rte_stack_create(const char *name, unsigned int count, int socket_id,
210 uint32_t flags);
211
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:440
#define RTE_STD_C11
Definition: rte_common.h:39
#define __rte_always_inline
Definition: rte_common.h:255
#define RTE_STACK_F_LF
Definition: rte_stack.h:92
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:30
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:154
static __rte_always_inline unsigned int rte_stack_push(struct rte_stack *s, void *const *obj_table, unsigned int n)
Definition: rte_stack.h:110
static __rte_always_inline unsigned int rte_stack_free_count(struct rte_stack *s)
Definition: rte_stack.h:173
static __rte_always_inline unsigned int rte_stack_pop(struct rte_stack *s, void **obj_table, unsigned int n)
Definition: rte_stack.h:134
struct rte_stack * rte_stack_lookup(const char *name)
uint32_t flags
Definition: rte_memzone.h:65