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>
This commit is contained in:
committed by
Arnaldo Carvalho de Melo
parent
474b3f2882
commit
a8a2d5c0b3
@@ -38,6 +38,8 @@ struct llvm_param llvm_param = {
|
|||||||
.user_set_param = false,
|
.user_set_param = false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static void version_notice(void);
|
||||||
|
|
||||||
int perf_llvm_config(const char *var, const char *value)
|
int perf_llvm_config(const char *var, const char *value)
|
||||||
{
|
{
|
||||||
if (!strstarts(var, "llvm."))
|
if (!strstarts(var, "llvm."))
|
||||||
@@ -108,6 +110,21 @@ search_program(const char *def, const char *name,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int search_program_and_warn(const char *def, const char *name,
|
||||||
|
char *output)
|
||||||
|
{
|
||||||
|
int ret = search_program(def, name, output);
|
||||||
|
|
||||||
|
if (ret) {
|
||||||
|
pr_err("ERROR:\tunable to find %s.\n"
|
||||||
|
"Hint:\tTry to install latest clang/llvm to support BPF. Check your $PATH\n"
|
||||||
|
" \tand '%s-path' option in [llvm] section of ~/.perfconfig.\n",
|
||||||
|
name, name);
|
||||||
|
version_notice();
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
#define READ_SIZE 4096
|
#define READ_SIZE 4096
|
||||||
static int
|
static int
|
||||||
read_from_pipe(const char *cmd, void **p_buf, size_t *p_read_sz)
|
read_from_pipe(const char *cmd, void **p_buf, size_t *p_read_sz)
|
||||||
@@ -458,16 +475,10 @@ int llvm__compile_bpf(const char *path, void **p_obj_buf,
|
|||||||
if (!template)
|
if (!template)
|
||||||
template = CLANG_BPF_CMD_DEFAULT_TEMPLATE;
|
template = CLANG_BPF_CMD_DEFAULT_TEMPLATE;
|
||||||
|
|
||||||
err = search_program(llvm_param.clang_path,
|
err = search_program_and_warn(llvm_param.clang_path,
|
||||||
"clang", clang_path);
|
"clang", clang_path);
|
||||||
if (err) {
|
if (err)
|
||||||
pr_err(
|
|
||||||
"ERROR:\tunable to find clang.\n"
|
|
||||||
"Hint:\tTry to install latest clang/llvm to support BPF. Check your $PATH\n"
|
|
||||||
" \tand 'clang-path' option in [llvm] section of ~/.perfconfig.\n");
|
|
||||||
version_notice();
|
|
||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This is an optional work. Even it fail we can continue our
|
* This is an optional work. Even it fail we can continue our
|
||||||
@@ -495,14 +506,9 @@ int llvm__compile_bpf(const char *path, void **p_obj_buf,
|
|||||||
force_set_env("WORKING_DIR", kbuild_dir ? : ".");
|
force_set_env("WORKING_DIR", kbuild_dir ? : ".");
|
||||||
|
|
||||||
if (opts) {
|
if (opts) {
|
||||||
err = search_program(llvm_param.llc_path, "llc", llc_path);
|
err = search_program_and_warn(llvm_param.llc_path, "llc", llc_path);
|
||||||
if (err) {
|
if (err)
|
||||||
pr_err("ERROR:\tunable to find llc.\n"
|
|
||||||
"Hint:\tTry to install latest clang/llvm to support BPF. Check your $PATH\n"
|
|
||||||
" \tand 'llc-path' option in [llvm] section of ~/.perfconfig.\n");
|
|
||||||
version_notice();
|
|
||||||
goto errout;
|
goto errout;
|
||||||
}
|
|
||||||
|
|
||||||
err = -ENOMEM;
|
err = -ENOMEM;
|
||||||
if (asprintf(&pipe_template, "%s -emit-llvm | %s -march=bpf %s -filetype=obj -o -",
|
if (asprintf(&pipe_template, "%s -emit-llvm | %s -march=bpf %s -filetype=obj -o -",
|
||||||
|
|||||||
Reference in New Issue
Block a user