[PATCH v3 1/2] stack: introduce pile

Morten Brørup mb at smartsharesystems.com
Mon Aug 31 18:37:03 CEST 2026


> From: Stephen Hemminger [mailto:stephen at networkplumber.org]
> Sent: Monday, 31 August 2026 18.06
> 
> On Thu, 27 Aug 2026 13:55:55 +0000
> Morten Brørup <mb at smartsharesystems.com> wrote:
> 
> > +__rte_stack_pile_pop(struct rte_stack *s,
> > +		void **obj_table,
> 
> NAK to using always_inline on a function this big
> It generates worse code in a lot of cases because of register spill.

OK, I will change it to "inline", and let the compiler decide.
Then we don't have to discuss which is better. :-)

I'll change the pull function too.

BTW, it's not quite as big as it looks.
Here's the function without comments, assertions and empty lines:

static __rte_always_inline unsigned int
__rte_stack_pile_pop(struct rte_stack *s,
		void **obj_table,
		unsigned int n)
{
	struct rte_stack_pile *pile = &s->stack_pile;
	struct rte_stack_pile_bulk_elem *bulk_first = NULL, *bulk_last = NULL;
	struct rte_stack_lf_elem *solo_first = NULL, *solo_last = NULL;
	unsigned int n_bulk = n / RTE_STACK_PILE_BULK_SIZE;
	unsigned int n_solo = n & (RTE_STACK_PILE_BULK_SIZE - 1);
	if (unlikely(n_bulk == 0)) {
		if (unlikely(n_solo == 0))
			return 0;
		goto solo;
	}
bulk:
	bulk_first = __rte_stack_pile_bulk_pop_elems(&pile->bulk, n_bulk, obj_table, &bulk_last);
	if (unlikely(bulk_first == NULL)) {
		unsigned int delta_bulk = n_bulk - __rte_stack_lf_elems_count(&pile->bulk);
		if (unlikely((int)delta_bulk <= 0))
			delta_bulk = 1;
		n_bulk -= delta_bulk;
		n_solo += RTE_STACK_PILE_BULK_SIZE * delta_bulk;
		if (n_bulk == 0)
			goto solo;
		goto bulk;
	}
	obj_table += n_bulk * RTE_STACK_PILE_BULK_SIZE;
	if (likely(n_solo == 0))
		goto done;
solo:
	solo_first = __rte_stack_lf_pop_elems(&pile->solo, n_solo,
			obj_table, &solo_last);
	if (solo_first != NULL)
		goto done;
	if (unlikely(n_solo >= RTE_STACK_PILE_BULK_SIZE))
		goto fail;
	if (unlikely(__rte_stack_pile_pop_frag(pile, obj_table, n_solo) == 0))
		goto fail;
done:
	if (bulk_first != NULL)
		__rte_stack_pile_bulk_push_elems(&pile->free_bulk, bulk_first, bulk_last, n_bulk);
	if (solo_first != NULL)
		__rte_stack_lf_push_elems(&pile->free_solo, solo_first, solo_last, n_solo);
	return n;
fail:
	if (bulk_first != NULL)
		__rte_stack_pile_bulk_push_elems(&pile->bulk, bulk_first, bulk_last, n_bulk);
	return 0;
}



More information about the dev mailing list