All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] perf tools: Refactor LLVM test warning for missing binary
@ 2021-08-31 14:54 James Clark
  2021-08-31 14:55 ` [PATCH 2/3] perf tools: Fix LLVM test failure when running in verbose mode James Clark
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: James Clark @ 2021-08-31 14:54 UTC (permalink / raw)
  To: acme, linux-perf-users
  Cc: James Clark, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Namhyung Kim, linux-kernel, clang-built-linux

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>
---
 tools/perf/util/llvm-utils.c | 36 +++++++++++++++++++++---------------
 1 file changed, 21 insertions(+), 15 deletions(-)

diff --git a/tools/perf/util/llvm-utils.c b/tools/perf/util/llvm-utils.c
index cbd9b268f168..cec9c16efb17 100644
--- a/tools/perf/util/llvm-utils.c
+++ b/tools/perf/util/llvm-utils.c
@@ -38,6 +38,8 @@ struct llvm_param llvm_param = {
 	.user_set_param = false,
 };
 
+static void version_notice(void);
+
 int perf_llvm_config(const char *var, const char *value)
 {
 	if (!strstarts(var, "llvm."))
@@ -108,6 +110,21 @@ search_program(const char *def, const char *name,
 	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
 static int
 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)
 		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);
-	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();
+	if (err)
 		return -ENOENT;
-	}
 
 	/*
 	 * 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 ? : ".");
 
 	if (opts) {
-		err = search_program(llvm_param.llc_path, "llc", llc_path);
-		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();
+		err = search_program_and_warn(llvm_param.llc_path, "llc", llc_path);
+		if (err)
 			goto errout;
-		}
 
 		err = -ENOMEM;
 		if (asprintf(&pipe_template, "%s -emit-llvm | %s -march=bpf %s -filetype=obj -o -",
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/3] perf tools: Fix LLVM test failure when running in verbose mode
  2021-08-31 14:54 [PATCH 1/3] perf tools: Refactor LLVM test warning for missing binary James Clark
@ 2021-08-31 14:55 ` James Clark
  2021-08-31 14:55 ` [PATCH 3/3] perf tools: Fix LLVM download hint link James Clark
  2021-08-31 18:18 ` [PATCH 1/3] perf tools: Refactor LLVM test warning for missing binary Arnaldo Carvalho de Melo
  2 siblings, 0 replies; 4+ messages in thread
From: James Clark @ 2021-08-31 14:55 UTC (permalink / raw)
  To: acme, linux-perf-users
  Cc: James Clark, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Namhyung Kim, linux-kernel, clang-built-linux

A CI system might want to run all tests in verbose mode so that there is
enough information to diagnose issues. This LLVM test is the only test
that uses "-v" to signify to not skip the test if the preconditions
aren't met (LLVM isn't installed). This means that running the test in
verbose mode without LLVM installed causes a test failure.

For consistency with the other tests, remove this verbose/skip check. An
alternate solution would be to make _all_ tests not skip when run in
verbose mode, but I don't think that would be intuitive.

Also change the search_program() call to search_program_and_warn().
Previously the hint about installing LLVM was only printed by the actual
test because this check was skipped in verbose mode. To maintain the old
behaviour, the precondition check must also print the full warning.

Previous output:

  $ ./perf test llvm
  40: LLVM search and compile                                     :
  40.1: Basic BPF llvm compile                                    : Skip

  $ ./perf test -v llvm
  40: LLVM search and compile                                     :
  40.1: Basic BPF llvm compile                                    :
  --- start ---
  test child forked, pid 2085835
  ERROR:	unable to find clang.
  Hint:	Try to install latest clang/llvm to support BPF. Check your $PATH
  ...
  test child finished with -1
  ---- end ----
  LLVM search and compile subtest 1: FAILED!

New output (non verbose mode is identical, verbose changes from fail to
skip):

  $ ./perf test llvm
  40: LLVM search and compile                                     :
  40.1: Basic BPF llvm compile                                    : Skip

  $ ./perf test -v llvm
  40: LLVM search and compile                                     :
  40.1: Basic BPF llvm compile                                    :
  --- start ---
  test child forked, pid 2087680
  ERROR:	unable to find clang.
  Hint:	Try to install latest clang/llvm to support BPF. Check your $PATH
  ...
  No clang, skip this test
  test child finished with -2
  ---- end ----
  LLVM search and compile subtest 1: Skip

Signed-off-by: James Clark <james.clark@arm.com>
---
 tools/perf/tests/llvm.c      | 7 +++----
 tools/perf/util/llvm-utils.c | 2 +-
 2 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/tools/perf/tests/llvm.c b/tools/perf/tests/llvm.c
index 98da8a8757ab..33e43cce9064 100644
--- a/tools/perf/tests/llvm.c
+++ b/tools/perf/tests/llvm.c
@@ -67,12 +67,11 @@ test_llvm__fetch_bpf_obj(void **p_obj_buf,
 
 	/*
 	 * Skip this test if user's .perfconfig doesn't set [llvm] section
-	 * and clang is not found in $PATH, and this is not perf test -v
+	 * and clang is not found in $PATH
 	 */
-	if (!force && (verbose <= 0 &&
-		       !llvm_param.user_set_param &&
+	if (!force && (!llvm_param.user_set_param &&
 		       llvm__search_clang())) {
-		pr_debug("No clang and no verbosive, skip this test\n");
+		pr_debug("No clang, skip this test\n");
 		return TEST_SKIP;
 	}
 
diff --git a/tools/perf/util/llvm-utils.c b/tools/perf/util/llvm-utils.c
index cec9c16efb17..d95c56d175bc 100644
--- a/tools/perf/util/llvm-utils.c
+++ b/tools/perf/util/llvm-utils.c
@@ -585,5 +585,5 @@ int llvm__search_clang(void)
 {
 	char clang_path[PATH_MAX];
 
-	return search_program(llvm_param.clang_path, "clang", clang_path);
+	return search_program_and_warn(llvm_param.clang_path, "clang", clang_path);
 }
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 3/3] perf tools: Fix LLVM download hint link
  2021-08-31 14:54 [PATCH 1/3] perf tools: Refactor LLVM test warning for missing binary James Clark
  2021-08-31 14:55 ` [PATCH 2/3] perf tools: Fix LLVM test failure when running in verbose mode James Clark
@ 2021-08-31 14:55 ` James Clark
  2021-08-31 18:18 ` [PATCH 1/3] perf tools: Refactor LLVM test warning for missing binary Arnaldo Carvalho de Melo
  2 siblings, 0 replies; 4+ messages in thread
From: James Clark @ 2021-08-31 14:55 UTC (permalink / raw)
  To: acme, linux-perf-users
  Cc: James Clark, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Namhyung Kim, linux-kernel, clang-built-linux

http://llvm.org/apt returns 404, it has moved to https://apt.llvm.org/

Signed-off-by: James Clark <james.clark@arm.com>
---
 tools/perf/util/llvm-utils.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/util/llvm-utils.c b/tools/perf/util/llvm-utils.c
index d95c56d175bc..96c8ef60f4f8 100644
--- a/tools/perf/util/llvm-utils.c
+++ b/tools/perf/util/llvm-utils.c
@@ -234,7 +234,7 @@ version_notice(void)
 "     \t\tgit clone http://llvm.org/git/clang.git\n\n"
 "     \tOr fetch the latest clang/llvm 3.7 from pre-built llvm packages for\n"
 "     \tdebian/ubuntu:\n"
-"     \t\thttp://llvm.org/apt\n\n"
+"     \t\thttps://apt.llvm.org/\n\n"
 "     \tIf you are using old version of clang, change 'clang-bpf-cmd-template'\n"
 "     \toption in [llvm] section of ~/.perfconfig to:\n\n"
 "     \t  \"$CLANG_EXEC $CLANG_OPTIONS $KERNEL_INC_OPTIONS $PERF_BPF_INC_OPTIONS \\\n"
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/3] perf tools: Refactor LLVM test warning for missing binary
  2021-08-31 14:54 [PATCH 1/3] perf tools: Refactor LLVM test warning for missing binary James Clark
  2021-08-31 14:55 ` [PATCH 2/3] perf tools: Fix LLVM test failure when running in verbose mode James Clark
  2021-08-31 14:55 ` [PATCH 3/3] perf tools: Fix LLVM download hint link James Clark
@ 2021-08-31 18:18 ` Arnaldo Carvalho de Melo
  2 siblings, 0 replies; 4+ messages in thread
From: Arnaldo Carvalho de Melo @ 2021-08-31 18:18 UTC (permalink / raw)
  To: James Clark
  Cc: linux-perf-users, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Namhyung Kim, linux-kernel, clang-built-linux

Em Tue, Aug 31, 2021 at 03:54:59PM +0100, James Clark escreveu:
> 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.

Thanks, applied the three patches.

- Arnaldo

 
> Signed-off-by: James Clark <james.clark@arm.com>
> ---
>  tools/perf/util/llvm-utils.c | 36 +++++++++++++++++++++---------------
>  1 file changed, 21 insertions(+), 15 deletions(-)
> 
> diff --git a/tools/perf/util/llvm-utils.c b/tools/perf/util/llvm-utils.c
> index cbd9b268f168..cec9c16efb17 100644
> --- a/tools/perf/util/llvm-utils.c
> +++ b/tools/perf/util/llvm-utils.c
> @@ -38,6 +38,8 @@ struct llvm_param llvm_param = {
>  	.user_set_param = false,
>  };
>  
> +static void version_notice(void);
> +
>  int perf_llvm_config(const char *var, const char *value)
>  {
>  	if (!strstarts(var, "llvm."))
> @@ -108,6 +110,21 @@ search_program(const char *def, const char *name,
>  	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
>  static int
>  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)
>  		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);
> -	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();
> +	if (err)
>  		return -ENOENT;
> -	}
>  
>  	/*
>  	 * 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 ? : ".");
>  
>  	if (opts) {
> -		err = search_program(llvm_param.llc_path, "llc", llc_path);
> -		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();
> +		err = search_program_and_warn(llvm_param.llc_path, "llc", llc_path);
> +		if (err)
>  			goto errout;
> -		}
>  
>  		err = -ENOMEM;
>  		if (asprintf(&pipe_template, "%s -emit-llvm | %s -march=bpf %s -filetype=obj -o -",
> -- 
> 2.28.0

-- 

- Arnaldo

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-08-31 18:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-31 14:54 [PATCH 1/3] perf tools: Refactor LLVM test warning for missing binary James Clark
2021-08-31 14:55 ` [PATCH 2/3] perf tools: Fix LLVM test failure when running in verbose mode James Clark
2021-08-31 14:55 ` [PATCH 3/3] perf tools: Fix LLVM download hint link James Clark
2021-08-31 18:18 ` [PATCH 1/3] perf tools: Refactor LLVM test warning for missing binary Arnaldo Carvalho de Melo

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.