Skip to contentSkip to conversation

tools/perf/builtin-lock: Fix return code for functions in __cmd_contention

PATCH Applied Athira Rajeev 2 participants 4 messages Jan 10, 2025 – Jan 18, 2025 perf events

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 tools/perf/builtin-lock: Fix return code for functions in __cmd_contention

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. Similarly set the return code properly for two other functions in builtin-lock, namely setup_output_field() and select_key().

---
Changelog:
v1 -> v2
Fixed return code in functions: setup_output_field() and select_key() as pointed out by Namhyung.

 tools/perf/builtin-lock.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
tools/perf/builtin-lock.c +8 -3
index 208c482daa56..94a2bc15a2fa 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;
 		}
@@ -2070,10 +2071,14 @@ static int __cmd_contention(int argc, const char **argv)
 		}
 	}
 
-	if (setup_output_field(true, output_fields))
+	err = setup_output_field(true, output_fields);
+	if (err) {
+		pr_err("Failed to setup output field\n");
 		goto out_delete;
+	}
 
-	if (select_key(true))
+	err = select_key(true);
+	if (err)
 		goto out_delete;
 
 	if (symbol_conf.field_sep) {
Signature · 1 line
2.43.5
maintainer Reviewed-by on v2 1/1
#1 lore raw
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 6 lines

Fix this by saving the return code for lock_contention_prepare so that command exits with proper return code. Similarly set the return code properly for two other functions in builtin-lock, namely setup_output_field() and select_key().

Thanks,
Namhyung

Quoted 43 lines

---
Changelog:
v1 -> v2
Fixed return code in functions: setup_output_field() and select_key() as pointed out by Namhyung.

 tools/perf/builtin-lock.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
tools/perf/builtin-lock.c +8 -3
index 208c482daa56..94a2bc15a2fa 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;
 		}
@@ -2070,10 +2071,14 @@ static int __cmd_contention(int argc, const char **argv)
 		}
 	}
 
-	if (setup_output_field(true, output_fields))
+	err = setup_output_field(true, output_fields);
+	if (err) {
+		pr_err("Failed to setup output field\n");
 		goto out_delete;
+	}
 
-	if (select_key(true))
+	err = select_key(true);
+	if (err)
 		goto out_delete;
 
 	if (symbol_conf.field_sep) {
Signature · 1 line
2.43.5
#2 lore raw
Quoted 28 lines · Namhyung Kim
Quoted 23 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. Similarly set the return code properly for two other functions in builtin-lock, namely setup_output_field() and select_key().

Quoted 6 lines
Quoted 1 line

Thanks,
Namhyung

Hi Namhyung,

Thanks for the reviewed-by

Athira

Quoted 43 lines
Quoted 43 lines

---
Changelog:
v1 -> v2
Fixed return code in functions: setup_output_field() and select_key() as pointed out by Namhyung.

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

1 file changed, 8 insertions(+), 3 deletions(-)
tools/perf/builtin-lock.c +8 -3
index 208c482daa56..94a2bc15a2fa 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;
 }
@@ -2070,10 +2071,14 @@ static int __cmd_contention(int argc, const char **argv)
 }
 }
 
- if (setup_output_field(true, output_fields))
+ err = setup_output_field(true, output_fields);
+ if (err) {
+ pr_err("Failed to setup output field\n");
 goto out_delete;
+ }
 
- if (select_key(true))
+ err = select_key(true);
+ if (err)
 goto out_delete;
 
 if (symbol_conf.field_sep) {
Signature · 1 line
2.43.5
maintainer Applied
#3 lore raw
In reply to Athira Rajeev
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 1 line

[...]

Applied to perf-tools-next, thanks!

Best regards,
Namhyung