Skip to contentSkip to conversation

perf lock contention: Fix builtin detection

PATCH Superseded Ian Rogers 2 participants 4 messages Mar 7, 2023

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Ian Rogers

author reviewer
#0 lore raw

PATCH 1/1 perf lock contention: Fix builtin detection

__has_builtin was passed the macro rather than the actual builtin feature.

Fixes 1bece1351c65 ("perf lock contention: Support old rw_semaphore type")
---
 tools/perf/util/bpf_skel/lock_contention.bpf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/bpf_skel/lock_contention.bpf.c +1 -1
index e6007eaeda1a..e422eee0f942 100644
@@ -182,7 +182,7 @@ 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)
+#if __has_builtin(__builtin_preserve_type_info)
 		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
#1 lore raw

Hi Ian,

Quoted 3 lines · Ian Rogers

__has_builtin was passed the macro rather than the actual builtin feature.

Oh, I missed it's a macro define in tools/lib/bpf/bpf_core_read.h file.

Looking at some BPF test codes, it seems you also need to check the clang compiler version. Please take a look at the file below:

tools/testing/selftests/bpf/progs/test_core_reloc_type_base.c

Thanks,
Namhyung

Quoted 23 lines
Fixes 1bece1351c65 ("perf lock contention: Support old rw_semaphore type")
---
 tools/perf/util/bpf_skel/lock_contention.bpf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/bpf_skel/lock_contention.bpf.c +1 -2
index e6007eaeda1a..e422eee0f942 100644
@@ -182,7 +182,7 @@ 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)
+#if __has_builtin(__builtin_preserve_type_info)
                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

author reviewer
#2 lore raw
Quoted 10 lines · Namhyung Kim

Hi Ian,

Quoted 3 lines · Ian Rogers

__has_builtin was passed the macro rather than the actual builtin feature.

Oh, I missed it's a macro define in tools/lib/bpf/bpf_core_read.h file.

Quoted 7 lines

Looking at some BPF test codes, it seems you also need to check the clang compiler version. Please take a look at the file below:

tools/testing/selftests/bpf/progs/test_core_reloc_type_base.c

Thanks,
Namhyung

Hmm..

tools/testing/selftests/bpf/progs/test_core_reloc_kernel.c:
...
/* 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 we require for this test. */
#if __has_builtin(__builtin_preserve_type_info) && __clang_major__ >= 15
...

I'm not sure we need to worry about development clang builds and just the __has_builtin is cleaner. Perhaps the BPF folks can chime in.

Thanks,
Ian

Quoted 23 lines
Quoted 23 lines
Fixes 1bece1351c65 ("perf lock contention: Support old rw_semaphore type")
---
 tools/perf/util/bpf_skel/lock_contention.bpf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/bpf_skel/lock_contention.bpf.c +1 -2
index e6007eaeda1a..e422eee0f942 100644
@@ -182,7 +182,7 @@ 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)
+#if __has_builtin(__builtin_preserve_type_info)
                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
#3 lore raw
Quoted 31 lines · Ian Rogers
Quoted 10 lines · Namhyung Kim

Hi Ian,

Quoted 3 lines · Ian Rogers

__has_builtin was passed the macro rather than the actual builtin feature.

Oh, I missed it's a macro define in tools/lib/bpf/bpf_core_read.h file.

Quoted 7 lines

Looking at some BPF test codes, it seems you also need to check the clang compiler version. Please take a look at the file below:

tools/testing/selftests/bpf/progs/test_core_reloc_type_base.c

Thanks,
Namhyung

Hmm..

tools/testing/selftests/bpf/progs/test_core_reloc_kernel.c:
...
/* 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 we require for this test. */
#if __has_builtin(__builtin_preserve_type_info) && __clang_major__ >= 15
...

Quoted 2 lines

I'm not sure we need to worry about development clang builds and just the __has_builtin is cleaner. Perhaps the BPF folks can chime in.

My understanding is that __builtin_preserve_type_info is supported before. But clang 15 added BPF_TYPE_MATCHES which is used for bpf_core_type_matches(). So just checking the builtin would not work.

Thanks,
Namhyung