[RFC,1/3] eal: add enhanced lock annotations

Message ID 20241202125316.3732529-2-david.marchand@redhat.com (mailing list archive)
State Superseded
Delegated to: Thomas Monjalon
Headers
Series Improve lock annotations |

Commit Message

David Marchand Dec. 2, 2024, 12:53 p.m. UTC
Clang 3.6+ offers enhanced lock annotations when it comes to shared vs
exclusive capability/lock release.
Introduce macros for those new function attributes.

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 doc/api/doxy-api.conf.in               | 12 +++++++
 lib/eal/include/rte_lock_annotations.h | 48 ++++++++++++++++++++++++++
 2 files changed, 60 insertions(+)
  

Comments

Stephen Hemminger Dec. 2, 2024, 4:13 p.m. UTC | #1
On Mon,  2 Dec 2024 13:53:14 +0100
David Marchand <david.marchand@redhat.com> wrote:

> diff --git a/doc/api/doxy-api.conf.in b/doc/api/doxy-api.conf.in
> index d23352d300..ac490e7631 100644
> --- a/doc/api/doxy-api.conf.in
> +++ b/doc/api/doxy-api.conf.in
> @@ -103,6 +103,18 @@ PREDEFINED              = __DOXYGEN__ \
>                            __rte_shared_trylock_function(x)= \
>                            __rte_assert_shared_lock(x)= \
>                            __rte_unlock_function(x)= \
> +                          __rte_capability(x)= \
> +                          __rte_requires_capability(x)= \
> +                          __rte_acquire_capability(x)= \
> +                          __rte_try_acquire_capability(x)= \
> +                          __rte_release_capability(x)= \
> +                          __rte_assert_capability(x)= \
> +                          __rte_requires_shared_capability(x)= \
> +                          __rte_acquire_shared_capability(x)= \
> +                          __rte_try_acquire_shared_capability(x)= \
> +                          __rte_release_shared_capability(x)= \
> +                          __rte_assert_shared_capability(x)= \
> +                          __rte_exclude_capability(x)= \
>                            __attribute__(x)=

I would suggest shortened names:
	__rte_acquires(x)
	__rte_releases(x)
	__rte_must_hold(x)

Based on the original source of all these lock annotations which is sparse.
  

Patch

diff --git a/doc/api/doxy-api.conf.in b/doc/api/doxy-api.conf.in
index d23352d300..ac490e7631 100644
--- a/doc/api/doxy-api.conf.in
+++ b/doc/api/doxy-api.conf.in
@@ -103,6 +103,18 @@  PREDEFINED              = __DOXYGEN__ \
                           __rte_shared_trylock_function(x)= \
                           __rte_assert_shared_lock(x)= \
                           __rte_unlock_function(x)= \
+                          __rte_capability(x)= \
+                          __rte_requires_capability(x)= \
+                          __rte_acquire_capability(x)= \
+                          __rte_try_acquire_capability(x)= \
+                          __rte_release_capability(x)= \
+                          __rte_assert_capability(x)= \
+                          __rte_requires_shared_capability(x)= \
+                          __rte_acquire_shared_capability(x)= \
+                          __rte_try_acquire_shared_capability(x)= \
+                          __rte_release_shared_capability(x)= \
+                          __rte_assert_shared_capability(x)= \
+                          __rte_exclude_capability(x)= \
                           __attribute__(x)=
 
 OPTIMIZE_OUTPUT_FOR_C   = YES
diff --git a/lib/eal/include/rte_lock_annotations.h b/lib/eal/include/rte_lock_annotations.h
index 2456a69352..4240458c53 100644
--- a/lib/eal/include/rte_lock_annotations.h
+++ b/lib/eal/include/rte_lock_annotations.h
@@ -43,6 +43,36 @@  extern "C" {
 #define __rte_locks_excluded(...) \
 	__attribute__((locks_excluded(__VA_ARGS__)))
 
+
+#define __rte_capability(...) \
+	__attribute__((capability(__VA_ARGS__)))
+
+#define __rte_requires_capability(...) \
+	__attribute__((requires_capability(__VA_ARGS__)))
+#define __rte_acquire_capability(...) \
+	__attribute__((acquire_capability(__VA_ARGS__)))
+#define __rte_try_acquire_capability(ret, ...) \
+	__attribute__((try_acquire_capability(ret, __VA_ARGS__)))
+#define __rte_release_capability(...) \
+	__attribute__((release_capability(__VA_ARGS__)))
+#define __rte_assert_capability(...) \
+	__attribute__((assert_capability(__VA_ARGS__)))
+
+#define __rte_requires_shared_capability(...) \
+	__attribute__((requires_shared_capability(__VA_ARGS__)))
+#define __rte_acquire_shared_capability(...) \
+	__attribute__((acquire_shared_capability(__VA_ARGS__)))
+#define __rte_try_acquire_shared_capability(ret, ...) \
+	__attribute__((try_acquire_shared_capability(ret, __VA_ARGS__)))
+#define __rte_release_shared_capability(...) \
+	__attribute__((release_shared_capability(__VA_ARGS__)))
+#define __rte_assert_shared_capability(...) \
+	__attribute__((assert_shared_capability(__VA_ARGS__)))
+
+#define __rte_exclude_capability(...) \
+	__attribute__((exclude_capability(__VA_ARGS__)))
+
+
 #define __rte_no_thread_safety_analysis \
 	__attribute__((no_thread_safety_analysis))
 
@@ -67,6 +97,24 @@  extern "C" {
 
 #define __rte_locks_excluded(...)
 
+
+#define __rte_capability(...)
+
+#define __rte_requires_capability(...)
+#define __rte_acquire_capability(...)
+#define __rte_try_acquire_capability(...)
+#define __rte_release_capability(...)
+#define __rte_assert_capability(...)
+
+#define __rte_requires_shared_capability(...)
+#define __rte_acquire_shared_capability(...)
+#define __rte_try_acquire_shared_capability(...)
+#define __rte_release_shared_capability(...)
+#define __rte_assert_shared_capability(...)
+
+#define __rte_exclude_capability(...)
+
+
 #define __rte_no_thread_safety_analysis
 
 #endif /* RTE_ANNOTATE_LOCKS */