Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf tools: Refactor LLVM test warning for missing binary

The same warning is duplicated in two places so refactor it into a
single function "search_program_and_warn". This will be used a third
time in a later commit.

Signed-off-by: James Clark <james.clark@arm.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: clang-built-linux@googlegroups.com
Link: http://lore.kernel.org/lkml/20210831145501.2135754-1-james.clark@arm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

James Clark and committed by
Arnaldo Carvalho de Melo
a8a2d5c0 474b3f28

+21 -15
+21 -15
tools/perf/util/llvm-utils.c
··· 38 38 .user_set_param = false, 39 39 }; 40 40 41 + static void version_notice(void); 42 + 41 43 int perf_llvm_config(const char *var, const char *value) 42 44 { 43 45 if (!strstarts(var, "llvm.")) ··· 107 105 } 108 106 109 107 free(env); 108 + return ret; 109 + } 110 + 111 + static int search_program_and_warn(const char *def, const char *name, 112 + char *output) 113 + { 114 + int ret = search_program(def, name, output); 115 + 116 + if (ret) { 117 + pr_err("ERROR:\tunable to find %s.\n" 118 + "Hint:\tTry to install latest clang/llvm to support BPF. Check your $PATH\n" 119 + " \tand '%s-path' option in [llvm] section of ~/.perfconfig.\n", 120 + name, name); 121 + version_notice(); 122 + } 110 123 return ret; 111 124 } 112 125 ··· 475 458 if (!template) 476 459 template = CLANG_BPF_CMD_DEFAULT_TEMPLATE; 477 460 478 - err = search_program(llvm_param.clang_path, 461 + err = search_program_and_warn(llvm_param.clang_path, 479 462 "clang", clang_path); 480 - if (err) { 481 - pr_err( 482 - "ERROR:\tunable to find clang.\n" 483 - "Hint:\tTry to install latest clang/llvm to support BPF. Check your $PATH\n" 484 - " \tand 'clang-path' option in [llvm] section of ~/.perfconfig.\n"); 485 - version_notice(); 463 + if (err) 486 464 return -ENOENT; 487 - } 488 465 489 466 /* 490 467 * This is an optional work. Even it fail we can continue our ··· 506 495 force_set_env("WORKING_DIR", kbuild_dir ? : "."); 507 496 508 497 if (opts) { 509 - err = search_program(llvm_param.llc_path, "llc", llc_path); 510 - if (err) { 511 - pr_err("ERROR:\tunable to find llc.\n" 512 - "Hint:\tTry to install latest clang/llvm to support BPF. Check your $PATH\n" 513 - " \tand 'llc-path' option in [llvm] section of ~/.perfconfig.\n"); 514 - version_notice(); 498 + err = search_program_and_warn(llvm_param.llc_path, "llc", llc_path); 499 + if (err) 515 500 goto errout; 516 - } 517 501 518 502 err = -ENOMEM; 519 503 if (asprintf(&pipe_template, "%s -emit-llvm | %s -march=bpf %s -filetype=obj -o -",