Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1490037
| From | Wang Nan <wangnan0@huawei.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH 11/14] perf tools: Extract kernel build option detector as utils |
| Date | 2016-09-23 15:00 +0200 |
| Message-ID | <skyf8-3M0-37@gated-at.bofh.it> (permalink) |
| References | <skyf7-3M0-9@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
Following commits will use builtin clang to compile BPF script.
llvm__get_kbuild_opts() is extracted to help it detect kbuild dir
and include options.
Signed-off-by: Wang Nan <wangnan0@huawei.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexei Starovoitov <ast@fb.com>
Cc: He Kuang <hekuang@huawei.com>
Cc: Jiri Olsa <jolsa@kernel.org>
---
tools/perf/util/llvm-utils.c | 44 ++++++++++++++++++++++++++++++++++++++------
tools/perf/util/llvm-utils.h | 3 +++
2 files changed, 41 insertions(+), 6 deletions(-)
diff --git a/tools/perf/util/llvm-utils.c b/tools/perf/util/llvm-utils.c
index bf7216b..d780a82 100644
--- a/tools/perf/util/llvm-utils.c
+++ b/tools/perf/util/llvm-utils.c
@@ -7,6 +7,7 @@
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
+#include <linux/err.h>
#include "debug.h"
#include "llvm-utils.h"
#include "config.h"
@@ -282,9 +283,10 @@ static const char *kinc_fetch_script =
"rm -rf $TMPDIR\n"
"exit $RET\n";
-static inline void
-get_kbuild_opts(char **kbuild_dir, char **kbuild_include_opts)
+void llvm__get_kbuild_opts(char **kbuild_dir, char **kbuild_include_opts)
{
+ static char *saved_kbuild_dir;
+ static char *saved_kbuild_include_opts;
int err;
if (!kbuild_dir || !kbuild_include_opts)
@@ -293,10 +295,28 @@ get_kbuild_opts(char **kbuild_dir, char **kbuild_include_opts)
*kbuild_dir = NULL;
*kbuild_include_opts = NULL;
+ if (saved_kbuild_dir && saved_kbuild_include_opts &&
+ !IS_ERR(saved_kbuild_dir) && !IS_ERR(saved_kbuild_include_opts)) {
+ *kbuild_dir = strdup(saved_kbuild_dir);
+ *kbuild_include_opts = strdup(saved_kbuild_include_opts);
+
+ if (*kbuild_dir && *kbuild_include_opts)
+ return;
+
+ zfree(kbuild_dir);
+ zfree(kbuild_include_opts);
+ /*
+ * Don't fall through: it may breaks saved_kbuild_dir and
+ * saved_kbuild_include_opts if detect them again when
+ * memory is low.
+ */
+ return;
+ }
+
if (llvm_param.kbuild_dir && !llvm_param.kbuild_dir[0]) {
pr_debug("[llvm.kbuild-dir] is set to \"\" deliberately.\n");
pr_debug("Skip kbuild options detection.\n");
- return;
+ goto errout;
}
err = detect_kbuild_dir(kbuild_dir);
@@ -306,7 +326,7 @@ get_kbuild_opts(char **kbuild_dir, char **kbuild_include_opts)
"Hint:\tSet correct kbuild directory using 'kbuild-dir' option in [llvm]\n"
" \tsection of ~/.perfconfig or set it to \"\" to suppress kbuild\n"
" \tdetection.\n\n");
- return;
+ goto errout;
}
pr_debug("Kernel build dir is set to %s\n", *kbuild_dir);
@@ -325,10 +345,22 @@ get_kbuild_opts(char **kbuild_dir, char **kbuild_include_opts)
free(*kbuild_dir);
*kbuild_dir = NULL;
- return;
+ goto errout;
}
pr_debug("include option is set to %s\n", *kbuild_include_opts);
+
+ saved_kbuild_dir = strdup(*kbuild_dir);
+ saved_kbuild_include_opts = strdup(*kbuild_include_opts);
+
+ if (!saved_kbuild_dir || !saved_kbuild_include_opts) {
+ zfree(&saved_kbuild_dir);
+ zfree(&saved_kbuild_include_opts);
+ }
+ return;
+errout:
+ saved_kbuild_dir = ERR_PTR(-EINVAL);
+ saved_kbuild_include_opts = ERR_PTR(-EINVAL);
}
static void
@@ -406,7 +438,7 @@ int llvm__compile_bpf(const char *path, void **p_obj_buf,
* This is an optional work. Even it fail we can continue our
* work. Needn't to check error return.
*/
- get_kbuild_opts(&kbuild_dir, &kbuild_include_opts);
+ llvm__get_kbuild_opts(&kbuild_dir, &kbuild_include_opts);
nr_cpus_avail = sysconf(_SC_NPROCESSORS_CONF);
if (nr_cpus_avail <= 0) {
diff --git a/tools/perf/util/llvm-utils.h b/tools/perf/util/llvm-utils.h
index 9f501ce..d3f410d 100644
--- a/tools/perf/util/llvm-utils.h
+++ b/tools/perf/util/llvm-utils.h
@@ -50,4 +50,7 @@ int llvm__compile_bpf(const char *path, void **p_obj_buf, size_t *p_obj_buf_sz);
/* This function is for test__llvm() use only */
int llvm__search_clang(void);
+
+/* This function is reused by builtin clang support */
+void llvm__get_kbuild_opts(char **kbuild_dir, char **kbuild_include_opts);
#endif
--
1.8.3.4
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH 00/14] perf clang: Support compiling BPF script use builtin clang Wang Nan <wangnan0@huawei.com> - 2016-09-23 15:00 +0200
[PATCH 03/14] perf tools: Add feature detection for LLVM Wang Nan <wangnan0@huawei.com> - 2016-09-23 15:00 +0200
[PATCH 01/14] tools build: Support compiling C++ source file Wang Nan <wangnan0@huawei.com> - 2016-09-23 15:00 +0200
Re: [PATCH 01/14] tools build: Support compiling C++ source file Jiri Olsa <jolsa@redhat.com> - 2016-09-28 16:40 +0200
[PATCH 04/14] perf tools: Add feature detection for clang Wang Nan <wangnan0@huawei.com> - 2016-09-23 15:00 +0200
[PATCH 09/14] perf clang: Update test case to use real BPF script Wang Nan <wangnan0@huawei.com> - 2016-09-23 15:00 +0200
[PATCH 08/14] perf clang: Allow passing CFLAGS to builtin clang Wang Nan <wangnan0@huawei.com> - 2016-09-23 15:00 +0200
[PATCH 13/14] perf clang: Pass fill path compiler Wang Nan <wangnan0@huawei.com> - 2016-09-23 15:00 +0200
[PATCH 12/14] perf bpf: Compile BPF script use builtin cflags support Wang Nan <wangnan0@huawei.com> - 2016-09-23 15:00 +0200
[PATCH 02/14] perf tools: Add feature detection for g++ Wang Nan <wangnan0@huawei.com> - 2016-09-23 15:00 +0200
[PATCH 11/14] perf tools: Extract kernel build option detector as utils Wang Nan <wangnan0@huawei.com> - 2016-09-23 15:00 +0200
[PATCH 06/14] perf clang: Add builtin clang support ant test case Wang Nan <wangnan0@huawei.com> - 2016-09-23 15:00 +0200
[PATCH 05/14] perf build: Add clang and llvm compile and linking support Wang Nan <wangnan0@huawei.com> - 2016-09-23 15:00 +0200
[PATCH 07/14] perf clang: Use real file system for #include Wang Nan <wangnan0@huawei.com> - 2016-09-23 15:00 +0200
[PATCH 14/14] perf clang: Pass correct CFLAGS to builtin clang Wang Nan <wangnan0@huawei.com> - 2016-09-23 15:00 +0200
[PATCH 10/14] perf clang: Support compile IR to BPF object and add testcase Wang Nan <wangnan0@huawei.com> - 2016-09-23 15:00 +0200
Re: [PATCH 00/14] perf clang: Support compiling BPF script use builtin clang Alexei Starovoitov <alexei.starovoitov@gmail.com> - 2016-09-24 17:20 +0200
Re: [PATCH 00/14] perf clang: Support compiling BPF script use builtin clang "Wangnan (F)" <wangnan0@huawei.com> - 2016-09-26 04:00 +0200
Re: [PATCH 00/14] perf clang: Support compiling BPF script use builtin clang Alexei Starovoitov <alexei.starovoitov@gmail.com> - 2016-09-27 01:50 +0200
Re: [PATCH 00/14] perf clang: Support compiling BPF script use builtin clang "Wangnan (F)" <wangnan0@huawei.com> - 2016-09-27 04:00 +0200
csiph-web