xref: /dpdk/lib/stack/rte_stack_lf.c (revision 99a2dd955fba6e4cc23b77d590a033650ced9c45)
1*99a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
2*99a2dd95SBruce Richardson  * Copyright(c) 2019 Intel Corporation
3*99a2dd95SBruce Richardson  */
4*99a2dd95SBruce Richardson 
5*99a2dd95SBruce Richardson #include "rte_stack.h"
6*99a2dd95SBruce Richardson 
7*99a2dd95SBruce Richardson void
rte_stack_lf_init(struct rte_stack * s,unsigned int count)8*99a2dd95SBruce Richardson rte_stack_lf_init(struct rte_stack *s, unsigned int count)
9*99a2dd95SBruce Richardson {
10*99a2dd95SBruce Richardson 	struct rte_stack_lf_elem *elems = s->stack_lf.elems;
11*99a2dd95SBruce Richardson 	unsigned int i;
12*99a2dd95SBruce Richardson 
13*99a2dd95SBruce Richardson 	for (i = 0; i < count; i++)
14*99a2dd95SBruce Richardson 		__rte_stack_lf_push_elems(&s->stack_lf.free,
15*99a2dd95SBruce Richardson 					  &elems[i], &elems[i], 1);
16*99a2dd95SBruce Richardson }
17*99a2dd95SBruce Richardson 
18*99a2dd95SBruce Richardson ssize_t
rte_stack_lf_get_memsize(unsigned int count)19*99a2dd95SBruce Richardson rte_stack_lf_get_memsize(unsigned int count)
20*99a2dd95SBruce Richardson {
21*99a2dd95SBruce Richardson 	ssize_t sz = sizeof(struct rte_stack);
22*99a2dd95SBruce Richardson 
23*99a2dd95SBruce Richardson 	sz += RTE_CACHE_LINE_ROUNDUP(count * sizeof(struct rte_stack_lf_elem));
24*99a2dd95SBruce Richardson 
25*99a2dd95SBruce Richardson 	/* Add padding to avoid false sharing conflicts caused by
26*99a2dd95SBruce Richardson 	 * next-line hardware prefetchers.
27*99a2dd95SBruce Richardson 	 */
28*99a2dd95SBruce Richardson 	sz += 2 * RTE_CACHE_LINE_SIZE;
29*99a2dd95SBruce Richardson 
30*99a2dd95SBruce Richardson 	return sz;
31*99a2dd95SBruce Richardson }
32