Skip to content

Commit

Permalink
stack: allow lock-free only on relevant architectures
Browse files Browse the repository at this point in the history
[ upstream commit 1abb185 ]

Since commit 7911ba0 ("stack: enable lock-free implementation for
aarch64"), lock-free stack is supported on arm64 but this description was
missing from the doxygen for the flag.

Currently it is impossible to detect programmatically whether lock-free
implementation of rte_stack is supported. One could check whether the
header guard for lock-free stubs is defined (_RTE_STACK_LF_STUBS_H_) but
that's an unstable implementation detail. Because of that currently all
lock-free ring creations silently succeed (as long as the stack header
is 16B long) which later leads to push and pop operations being NOPs.
The observable effect is that stack_lf_autotest fails on platforms not
supporting the lock-free. Instead it should just skip the lock-free test
altogether.

This commit adds a new errno value (ENOTSUP) that may be returned by
rte_stack_create() to indicate that a given combination of flags is not
supported on a current platform.
This is detected by checking a compile-time flag in the include logic in
rte_stack_lf.h which may be used by applications to check the lock-free
support at compile time.

Use the added RTE_STACK_LF_SUPPORTED flag to disable the lock-free stack
tests at the compile time.
Perf test doesn't fail because rte_ring_create() succeeds, however
marking this test as skipped gives a better indication of what actually
was tested.

Fixes: 7911ba0 ("stack: enable lock-free implementation for aarch64")

Signed-off-by: Stanislaw Kardach <kda@semihalf.com>
Acked-by: Olivier Matz <olivier.matz@6wind.com>
  • Loading branch information
semihalf-kardach-stanislaw authored and steevenlee committed Jun 8, 2021
1 parent ad11991 commit cf948fe
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 2 deletions.
4 changes: 4 additions & 0 deletions app/test/test_stack.c
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,11 @@ test_stack(void)
static int
test_lf_stack(void)
{
#if defined(RTE_STACK_LF_SUPPORTED)
return __test_stack(RTE_STACK_F_LF);
#else
return TEST_SKIPPED;
#endif
}

REGISTER_TEST_COMMAND(stack_autotest, test_stack);
Expand Down
4 changes: 4 additions & 0 deletions app/test/test_stack_perf.c
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,11 @@ test_stack_perf(void)
static int
test_lf_stack_perf(void)
{
#if defined(RTE_STACK_LF_SUPPORTED)
return __test_stack_perf(RTE_STACK_F_LF);
#else
return TEST_SKIPPED;
#endif
}

REGISTER_TEST_COMMAND(stack_perf_autotest, test_stack_perf);
Expand Down
4 changes: 3 additions & 1 deletion lib/librte_stack/rte_stack.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,11 @@ rte_stack_create(const char *name, unsigned int count, int socket_id,

#ifdef RTE_ARCH_64
RTE_BUILD_BUG_ON(sizeof(struct rte_stack_lf_head) != 16);
#else
#endif
#if !defined(RTE_STACK_LF_SUPPORTED)
if (flags & RTE_STACK_F_LF) {
STACK_LOG_ERR("Lock-free stack is not supported on your platform\n");
rte_errno = ENOTSUP;
return NULL;
}
#endif
Expand Down
3 changes: 2 additions & 1 deletion lib/librte_stack/rte_stack.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ struct rte_stack {

/**
* The stack uses lock-free push and pop functions. This flag is only
* supported on x86_64 platforms, currently.
* supported on x86_64 or arm64 platforms, currently.
*/
#define RTE_STACK_F_LF 0x0001

Expand Down Expand Up @@ -205,6 +205,7 @@ rte_stack_free_count(struct rte_stack *s)
* - EEXIST - a stack with the same name already exists
* - ENOMEM - insufficient memory to create the stack
* - ENAMETOOLONG - name size exceeds RTE_STACK_NAMESIZE
* - ENOTSUP - platform does not support given flags combination.
*/
struct rte_stack *
rte_stack_create(const char *name, unsigned int count, int socket_id,
Expand Down
5 changes: 5 additions & 0 deletions lib/librte_stack/rte_stack_lf.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
#else
#include "rte_stack_lf_generic.h"
#endif

/**
* Indicates that RTE_STACK_F_LF is supported.
*/
#define RTE_STACK_LF_SUPPORTED
#endif

/**
Expand Down

0 comments on commit cf948fe

Please sign in to comment.