Skip to contentSkip to conversation

tools/perf: Fix return code for lock_contention_prepare

PATCH In review Athira Rajeev 2 participants 4 messages Dec 23, 2024 – Jan 10, 2025 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools/perf: Fix return code for lock_contention_prepare

perf lock contention returns zero exit value even if the lock contention BPF setup failed.

   # ./perf lock con -b true
   libbpf: kernel BTF is missing at '/sys/kernel/btf/vmlinux', was CONFIG_DEBUG_INFO_BTF enabled?
   libbpf: failed to find '.BTF' ELF section in /lib/modules/6.13.0-rc3+/build/vmlinux
   libbpf: failed to find valid kernel BTF
   libbpf: kernel BTF is missing at '/sys/kernel/btf/vmlinux', was CONFIG_DEBUG_INFO_BTF enabled?
   libbpf: failed to find '.BTF' ELF section in /lib/modules/6.13.0-rc3+/build/vmlinux
   libbpf: failed to find valid kernel BTF
   libbpf: Error loading vmlinux BTF: -ESRCH
   libbpf: failed to load object 'lock_contention_bpf'
   libbpf: failed to load BPF skeleton 'lock_contention_bpf': -ESRCH
   Failed to load lock-contention BPF skeleton
   lock contention BPF setup failed
   # echo $?
    0

Fix this by saving the return code for lock_contention_prepare so that command exits with proper return code

---
 tools/perf/builtin-lock.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/builtin-lock.c +2 -1
index 208c482daa56..2226c7dd4ae6 100644
@@ -2049,7 +2049,8 @@ static int __cmd_contention(int argc, const char **argv)
 				goto out_delete;
 		}
 
-		if (lock_contention_prepare(&con) < 0) {
+		err = lock_contention_prepare(&con);
+		if (err < 0) {
 			pr_err("lock contention BPF setup failed\n");
 			goto out_delete;
 		}
Signature · 1 line
2.43.5
#1 lore raw
Quoted 22 lines · Athira Rajeev

perf lock contention returns zero exit value even if the lock contention BPF setup failed.

  # ./perf lock con -b true
  libbpf: kernel BTF is missing at '/sys/kernel/btf/vmlinux', was CONFIG_DEBUG_INFO_BTF enabled?
  libbpf: failed to find '.BTF' ELF section in /lib/modules/6.13.0-rc3+/build/vmlinux
  libbpf: failed to find valid kernel BTF
  libbpf: kernel BTF is missing at '/sys/kernel/btf/vmlinux', was CONFIG_DEBUG_INFO_BTF enabled?
  libbpf: failed to find '.BTF' ELF section in /lib/modules/6.13.0-rc3+/build/vmlinux
  libbpf: failed to find valid kernel BTF
  libbpf: Error loading vmlinux BTF: -ESRCH
  libbpf: failed to load object 'lock_contention_bpf'
  libbpf: failed to load BPF skeleton 'lock_contention_bpf': -ESRCH
  Failed to load lock-contention BPF skeleton
  lock contention BPF setup failed
  # echo $?
   0
Quoted 4 lines

Fix this by saving the return code for lock_contention_prepare so that command exits with proper return code

Hi,

Looking for review comments on this

Athira

Quoted 21 lines

---
tools/perf/builtin-lock.c | 3 ++-

1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/builtin-lock.c +2 -1
index 208c482daa56..2226c7dd4ae6 100644
@@ -2049,7 +2049,8 @@ static int __cmd_contention(int argc, const char **argv)
 goto out_delete;
 }
 
- if (lock_contention_prepare(&con) < 0) {
+ err = lock_contention_prepare(&con);
+ if (err < 0) {
 pr_err("lock contention BPF setup failed\n");
 goto out_delete;
 }
Signature · 1 line
2.43.5
maintainer
#2 lore raw
In reply to Athira Rajeev

Hello,

Quoted 18 lines · Athira Rajeev

perf lock contention returns zero exit value even if the lock contention BPF setup failed.

   # ./perf lock con -b true
   libbpf: kernel BTF is missing at '/sys/kernel/btf/vmlinux', was CONFIG_DEBUG_INFO_BTF enabled?
   libbpf: failed to find '.BTF' ELF section in /lib/modules/6.13.0-rc3+/build/vmlinux
   libbpf: failed to find valid kernel BTF
   libbpf: kernel BTF is missing at '/sys/kernel/btf/vmlinux', was CONFIG_DEBUG_INFO_BTF enabled?
   libbpf: failed to find '.BTF' ELF section in /lib/modules/6.13.0-rc3+/build/vmlinux
   libbpf: failed to find valid kernel BTF
   libbpf: Error loading vmlinux BTF: -ESRCH
   libbpf: failed to load object 'lock_contention_bpf'
   libbpf: failed to load BPF skeleton 'lock_contention_bpf': -ESRCH
   Failed to load lock-contention BPF skeleton
   lock contention BPF setup failed
   # echo $?
    0
Quoted 4 lines

Fix this by saving the return code for lock_contention_prepare so that command exits with proper return code

Thanks for the fix, the change itself looks good but I think we need the same for setup_output_field() and select_key() as well.

Thanks,
Namhyung

Quoted 21 lines
---
 tools/perf/builtin-lock.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/builtin-lock.c +2 -1
index 208c482daa56..2226c7dd4ae6 100644
@@ -2049,7 +2049,8 @@ static int __cmd_contention(int argc, const char **argv)
 				goto out_delete;
 		}
 
-		if (lock_contention_prepare(&con) < 0) {
+		err = lock_contention_prepare(&con);
+		if (err < 0) {
 			pr_err("lock contention BPF setup failed\n");
 			goto out_delete;
 		}
Signature · 1 line
2.43.5
#3 lore raw
Quoted 28 lines · Namhyung Kim

Hello,

Quoted 21 lines · Athira Rajeev

perf lock contention returns zero exit value even if the lock contention BPF setup failed.

  # ./perf lock con -b true
  libbpf: kernel BTF is missing at '/sys/kernel/btf/vmlinux', was CONFIG_DEBUG_INFO_BTF enabled?
  libbpf: failed to find '.BTF' ELF section in /lib/modules/6.13.0-rc3+/build/vmlinux
  libbpf: failed to find valid kernel BTF
  libbpf: kernel BTF is missing at '/sys/kernel/btf/vmlinux', was CONFIG_DEBUG_INFO_BTF enabled?
  libbpf: failed to find '.BTF' ELF section in /lib/modules/6.13.0-rc3+/build/vmlinux
  libbpf: failed to find valid kernel BTF
  libbpf: Error loading vmlinux BTF: -ESRCH
  libbpf: failed to load object 'lock_contention_bpf'
  libbpf: failed to load BPF skeleton 'lock_contention_bpf': -ESRCH
  Failed to load lock-contention BPF skeleton
  lock contention BPF setup failed
  # echo $?
   0

Fix this by saving the return code for lock_contention_prepare so that command exits with proper return code

Quoted 7 lines
Quoted 1 line

Thanks for the fix, the change itself looks good but I think we need the same for setup_output_field() and select_key() as well.

Thanks,
Namhyung

Hi Namhyung

Thanks for reviewing and pointing out setup_output_field() and select_key() I will send a V2 with handling return code for these two functions as well

Thanks
Athira

Quoted 22 lines
Quoted 22 lines

---
tools/perf/builtin-lock.c | 3 ++-

1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/builtin-lock.c +2 -1
index 208c482daa56..2226c7dd4ae6 100644
@@ -2049,7 +2049,8 @@ static int 	(int argc, const char **argv)
 goto out_delete;
 }
 
- if (lock_contention_prepare(&con) < 0) {
+ err = lock_contention_prepare(&con);
+ if (err < 0) {
 pr_err("lock contention BPF setup failed\n");
 goto out_delete;
 }
Signature · 1 line
2.43.5