Skip to contentSkip to conversation

add lock-free stack support discovery

PATCH In review Stanislaw Kardach 3 participants 14 messages Apr 12, 2021 – May 4, 2021

lore
Share & tools
lore
#0 lore raw

cover add lock-free stack support discovery

The lock-free stack implementation (RTE_STACK_F_LF) is supported only on a subset of platforms, namely x86_64 and arm64. Platforms supporting 128b atomics have to opt-in to a generic or C11 implementations. All other platforms use a stubbed implementation for push/pop operations which are basically NOPs. However rte_stack_create() will not fail and application can proceed assuming it has a working lock-free stack.

This means that among other things the stack_lf fast and perf tests will fail as if implementation is wrong (which one can argue is). Therefore this patchset tries to give user a way to check whether a lock_free is supported or not both at compile time (build flag) and at runtime (ENOTSUP errno in rte_stack_create).

I have added cc to [email protected] because check-git-log.sh suggested it. I'm not sure if adding a binary compatible change to API is worth [email protected].

Stanislaw Kardach (3):
stack: update lock-free supported archs
stack: add compile flag for lock-free support
test: run lock-free stack tests when supported

 app/test/test_stack.c                  | 4 ++++
 app/test/test_stack_perf.c             | 4 ++++
 doc/guides/rel_notes/release_21_05.rst | 4 ++++
 lib/librte_stack/rte_stack.c           | 4 +++-
 lib/librte_stack/rte_stack.h           | 3 ++-
 lib/librte_stack/rte_stack_lf.h        | 5 +++++
 6 files changed, 22 insertions(+), 2 deletions(-)
Signature · 1 line
2.27.0
#1 lore raw

PATCH 1/3 stack: update lock-free supported archs

Since 7911ba047 lock-free stack is supported on arm64 but this description was missing from the doxygen for the flag.

Fixes 7911ba0473e0 ("stack: enable lock-free implementation for aarch64")
---
 lib/librte_stack/rte_stack.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/librte_stack/rte_stack.h +1 -1
index 395b9ef83..b82c74e72 100644
@@ -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
 
Signature · 1 line
2.27.0
#3 lore raw

PATCH 2/3 stack: add lock-free support indication

In reply to Stanislaw Kardach

Currently it is impossible to detect programatically 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.

Fixes 7911ba0473e0 ("stack: enable lock-free implementation for aarch64")
---
 doc/guides/rel_notes/release_21_05.rst | 4 ++++
 lib/librte_stack/rte_stack.c           | 4 +++-
 lib/librte_stack/rte_stack.h           | 1 +
 lib/librte_stack/rte_stack_lf.h        | 5 +++++
 4 files changed, 13 insertions(+), 1 deletion(-)
doc/guides/rel_notes/release_21_05.rst +4 -0
index 6f5858c8f..42ed60da8 100644
@@ -166,6 +166,10 @@ API Changes
 * pci: The value ``PCI_ANY_ID`` is marked as deprecated
   and can be replaced with ``RTE_PCI_ANY_ID``.
 
+* Lock-free ``rte_stack`` no longer silently ignores push and pop when it's not
+  supported on the current platform. Instead ``rte_stack_create()`` fails and
+  ``rte_errno`` is set to ``ENOTSUP``.
+
 
 ABI Changes
 -----------
lib/librte_stack/rte_stack.c +3 -1
index 8a51fba17..10d3b2eeb 100644
@@ -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
lib/librte_stack/rte_stack.h +1 -0
index b82c74e72..27640f87b 100644
@@ -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,
lib/librte_stack/rte_stack_lf.h +5 -0
index eb106e64e..f2b012cd0 100644
@@ -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
 
 /**
Signature · 1 line
2.27.0
Acked-by on v1 2/3
#4 lore raw

Re: [dpdk-dev] [PATCH 2/3] stack: add lock-free support indication

Quoted 17 lines · Stanislaw Kardach

Currently it is impossible to detect programatically 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.

Quoted 4 lines
Fixes 7911ba0473e0 ("stack: enable lock-free implementation for aarch64")
#5 lore raw

PATCH 3/3 test: run lock-free stack tests when supported

In reply to Stanislaw Kardach

Use the recently 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.

---
 app/test/test_stack.c      | 4 ++++
 app/test/test_stack_perf.c | 4 ++++
 2 files changed, 8 insertions(+)
app/test/test_stack.c +4 -0
index 02422a32d..00efb38e2 100644
@@ -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);
app/test/test_stack_perf.c +4 -0
index 3590625c4..4ee40d5d1 100644
@@ -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);
Signature · 1 line
2.27.0
Acked-by on v1 3/3
#6 lore raw

Re: [dpdk-dev] [PATCH 3/3] test: run lock-free stack tests when supported

Quoted 8 lines · Stanislaw Kardach

Use the recently 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.

#7 lore raw
In reply to Stanislaw Kardach
Quoted 7 lines · Stanislaw Kardach

The lock-free stack implementation (RTE_STACK_F_LF) is supported only on a subset of platforms, namely x86_64 and arm64. Platforms supporting 128b atomics have to opt-in to a generic or C11 implementations. All other platforms use a stubbed implementation for push/pop operations which are basically NOPs. However rte_stack_create() will not fail and application can proceed assuming it has a working lock-free stack.

Did you actually hit this issue or is this only theoretical? I can only think of ppc64 displaying such behavior.

Signature · 1 line
David Marchand
#8 lore raw
Quoted 9 lines · David Marchand
Quoted 7 lines · Stanislaw Kardach

The lock-free stack implementation (RTE_STACK_F_LF) is supported only on a subset of platforms, namely x86_64 and arm64. Platforms supporting 128b atomics have to opt-in to a generic or C11 implementations. All other platforms use a stubbed implementation for push/pop operations which are basically NOPs. However rte_stack_create() will not fail and application can proceed assuming it has a working lock-free stack.

Quoted 3 lines

Did you actually hit this issue or is this only theoretical? I can only think of ppc64 displaying such behavior.

I actually hit this issue while working on a RISC-V port.
My reasoning here is that sooner or later someone else will stumble upon this, either on ppc64 or while trying to port to some new platform. It is also a really nasty limitation do debug given the silent nature of the failure.

Quoted 4 lines

--
David Marchand

--
Best Regards,
Stanislaw Kardach

#9 lore raw
In reply to Stanislaw Kardach
Quoted 13 lines · Stanislaw Kardach

The lock-free stack implementation (RTE_STACK_F_LF) is supported only on a subset of platforms, namely x86_64 and arm64. Platforms supporting 128b atomics have to opt-in to a generic or C11 implementations. All other platforms use a stubbed implementation for push/pop operations which are basically NOPs. However rte_stack_create() will not fail and application can proceed assuming it has a working lock-free stack.

This means that among other things the stack_lf fast and perf tests will fail as if implementation is wrong (which one can argue is). Therefore this patchset tries to give user a way to check whether a lock_free is supported or not both at compile time (build flag) and at runtime (ENOTSUP errno in rte_stack_create).

Quoted 4 lines

I have added cc to [email protected] because check-git-log.sh suggested it. I'm not sure if adding a binary compatible change to API is worth [email protected].

The issue was hit while porting to a new architecture. The feature is broken in existing stable releases and it won't get fixed by this change.

I'd rather not backport it.

Opinions?

Signature · 1 line
David Marchand
#10 lore raw
Quoted 19 lines · David Marchand
Quoted 13 lines · Stanislaw Kardach

The lock-free stack implementation (RTE_STACK_F_LF) is supported only on a subset of platforms, namely x86_64 and arm64. Platforms supporting 128b atomics have to opt-in to a generic or C11 implementations. All other platforms use a stubbed implementation for push/pop operations which are basically NOPs. However rte_stack_create() will not fail and application can proceed assuming it has a working lock-free stack.

This means that among other things the stack_lf fast and perf tests will fail as if implementation is wrong (which one can argue is). Therefore this patchset tries to give user a way to check whether a lock_free is supported or not both at compile time (build flag) and at runtime (ENOTSUP errno in rte_stack_create).

Quoted 4 lines

I have added cc to [email protected] because check-git-log.sh suggested it. I'm not sure if adding a binary compatible change to API is worth [email protected].

Quoted 7 lines

The issue was hit while porting to a new architecture. The feature is broken in existing stable releases and it won't get fixed by this change.

I'd rather not backport it.

Opinions?

Agreed.

#11 lore raw
Quoted 36 lines · On Mon, 3 May 2021, 16:28 Olivier Matz, <[email protected]> wrote:
Quoted 1 line · David Marchand

On Mon, Apr 12, 2021 at 10:29 AM Stanislaw Kardach <[email protected]>

Quoted 2 lines · wrote:
Quoted 2 lines

The lock-free stack implementation (RTE_STACK_F_LF) is supported only

on a

Quoted 1 line
Quoted 1 line

subset of platforms, namely x86_64 and arm64. Platforms supporting

128b atomics

Quoted 1 line
Quoted 1 line

have to opt-in to a generic or C11 implementations. All other

platforms use a

Quoted 1 line
Quoted 1 line

stubbed implementation for push/pop operations which are basically

NOPs.

Quoted 1 line
Quoted 1 line

However rte_stack_create() will not fail and application can proceed

assuming

Quoted 3 lines
Quoted 3 lines

it has a working lock-free stack.

This means that among other things the stack_lf fast and perf tests

will fail

Quoted 1 line
Quoted 1 line

as if implementation is wrong (which one can argue is). Therefore this

patchset

Quoted 1 line
Quoted 1 line

tries to give user a way to check whether a lock_free is supported or

not both

Quoted 1 line
Quoted 1 line

at compile time (build flag) and at runtime (ENOTSUP errno in

rte_stack_create).

Quoted 2 lines
Quoted 2 lines

I have added cc to [email protected] because check-git-log.sh suggested

it. I'm

Quoted 1 line
Quoted 1 line

not sure if adding a binary compatible change to API is worth

[email protected].

Quoted 7 lines
Quoted 2 lines

The issue was hit while porting to a new architecture. The feature is broken in existing stable releases and it won't get fixed by this change.

Quoted 6 lines
Quoted 3 lines

I'd rather not backport it.

Opinions?

Agreed.

Agreed.

Quoted 1 line
#12 lore raw
Quoted 13 lines · Stanisław Kardach
Quoted 12 lines · On Mon, 3 May 2021, 16:28 Olivier Matz, <[email protected]> wrote:
Quoted 11 lines · David Marchand
Quoted 5 lines · Stanislaw Kardach

I have added cc to [email protected] because check-git-log.sh suggested it. I'm not sure if adding a binary compatible change to API is worth [email protected].

The issue was hit while porting to a new architecture. The feature is broken in existing stable releases and it won't get fixed by this change.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

I'd rather not backport it.

Opinions?

Agreed.

Agreed.

Ok, thanks.
I'll take this series dropping Cc: stable.

Signature · 1 line
David Marchand
#13 lore raw
In reply to Stanislaw Kardach
Quoted 8 lines · Stanislaw Kardach

The lock-free stack implementation (RTE_STACK_F_LF) is supported only on a subset of platforms, namely x86_64 and arm64. Platforms supporting 128b atomics have to opt-in to a generic or C11 implementations. All other platforms use a stubbed implementation for push/pop operations which are basically NOPs. However rte_stack_create() will not fail and application can proceed assuming it has a working lock-free stack.

Quoted 4 lines

This means that among other things the stack_lf fast and perf tests will fail as if implementation is wrong (which one can argue is). Therefore this patchset tries to give user a way to check whether a lock_free is supported or not both at compile time (build flag) and at runtime (ENOTSUP errno in rte_stack_create).

Series applied.
Thanks Stanislaw!

Signature · 1 line
David Marchand