Skip to contentSkip to conversation

perf lock contention: Fix builtin detection

PATCH Applied Ian Rogers 3 participants 3 messages Mar 8, 2023 – Mar 13, 2023

Subsystems (2)
lore
Share & tools
lore

Ian Rogers

author reviewer
#0 lore raw

PATCH v2 1/1 perf lock contention: Fix builtin detection

__has_builtin was passed the macro rather than the actual builtin feature. The builtin test isn't sufficient and a clang version test also needs to be performed.

Fixes 1bece1351c65 ("perf lock contention: Support old rw_semaphore type")
---
 tools/perf/util/bpf_skel/lock_contention.bpf.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
tools/perf/util/bpf_skel/lock_contention.bpf.c +7 -1
index e6007eaeda1a..141b36d13b19 100644
@@ -182,7 +182,13 @@ static inline struct task_struct *get_lock_owner(__u64 lock, __u32 flags)
 		struct mutex *mutex = (void *)lock;
 		owner = BPF_CORE_READ(mutex, owner.counter);
 	} else if (flags == LCB_F_READ || flags == LCB_F_WRITE) {
-#if __has_builtin(bpf_core_type_matches)
+	/*
+	 * Support for the BPF_TYPE_MATCHES argument to the
+	 * __builtin_preserve_type_info builtin was added at some point during
+	 * development of clang 15 and it's what is needed for
+	 * bpf_core_type_matches.
+	 */
+#if __has_builtin(__builtin_preserve_type_info) && __clang_major__ >= 15
 		if (bpf_core_type_matches(struct rw_semaphore___old)) {
 			struct rw_semaphore___old *rwsem = (void *)lock;
 			owner = (unsigned long)BPF_CORE_READ(rwsem, owner);
Signature · 1 line
2.40.0.rc0.216.gc4246ad0f0-goog
maintainer Reviewed-by on v2 1/1
#1 lore raw
Quoted 7 lines · Ian Rogers

__has_builtin was passed the macro rather than the actual builtin feature. The builtin test isn't sufficient and a clang version test also needs to be performed.

Fixes 1bece1351c65 ("perf lock contention: Support old rw_semaphore type")

Thanks,
Namhyung

Quoted 26 lines
---
 tools/perf/util/bpf_skel/lock_contention.bpf.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
tools/perf/util/bpf_skel/lock_contention.bpf.c +7 -2
index e6007eaeda1a..141b36d13b19 100644
@@ -182,7 +182,13 @@ static inline struct task_struct *get_lock_owner(__u64 lock, __u32 flags)
                struct mutex *mutex = (void *)lock;
                owner = BPF_CORE_READ(mutex, owner.counter);
        } else if (flags == LCB_F_READ || flags == LCB_F_WRITE) {
-#if __has_builtin(bpf_core_type_matches)
+       /*
+        * Support for the BPF_TYPE_MATCHES argument to the
+        * __builtin_preserve_type_info builtin was added at some point during
+        * development of clang 15 and it's what is needed for
+        * bpf_core_type_matches.
+        */
+#if __has_builtin(__builtin_preserve_type_info) && __clang_major__ >= 15
                if (bpf_core_type_matches(struct rw_semaphore___old)) {
                        struct rw_semaphore___old *rwsem = (void *)lock;
                        owner = (unsigned long)BPF_CORE_READ(rwsem, owner);
--

2.40.0.rc0.216.gc4246ad0f0-goog

maintainer Applied
#2 lore raw

Em Tue, Mar 07, 2023 at 05:41:19PM -0800, Namhyung Kim escreveu:

Quoted 10 lines · Ian Rogers
Quoted 7 lines

__has_builtin was passed the macro rather than the actual builtin feature. The builtin test isn't sufficient and a clang version test also needs to be performed.

Fixes 1bece1351c65 ("perf lock contention: Support old rw_semaphore type")

Thanks, applied.

- Arnaldo

Quoted 30 lines

Thanks,
Namhyung

Quoted 26 lines
---
 tools/perf/util/bpf_skel/lock_contention.bpf.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
tools/perf/util/bpf_skel/lock_contention.bpf.c +7 -2
index e6007eaeda1a..141b36d13b19 100644
@@ -182,7 +182,13 @@ static inline struct task_struct *get_lock_owner(__u64 lock, __u32 flags)
                struct mutex *mutex = (void *)lock;
                owner = BPF_CORE_READ(mutex, owner.counter);
        } else if (flags == LCB_F_READ || flags == LCB_F_WRITE) {
-#if __has_builtin(bpf_core_type_matches)
+       /*
+        * Support for the BPF_TYPE_MATCHES argument to the
+        * __builtin_preserve_type_info builtin was added at some point during
+        * development of clang 15 and it's what is needed for
+        * bpf_core_type_matches.
+        */
+#if __has_builtin(__builtin_preserve_type_info) && __clang_major__ >= 15
                if (bpf_core_type_matches(struct rw_semaphore___old)) {
                        struct rw_semaphore___old *rwsem = (void *)lock;
                        owner = (unsigned long)BPF_CORE_READ(rwsem, owner);
--

2.40.0.rc0.216.gc4246ad0f0-goog

Signature · 1 line
- Arnaldo