diff options
author | Wang Nan <wangnan0@huawei.com> | 2015-07-21 07:13:34 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2015-08-07 09:16:59 -0400 |
commit | aa61fd05ca79666c973d5b15e0f91ecdc7dcfa21 (patch) | |
tree | c707784bf05f1345fa6bb9228149d29432442059 | |
parent | 9a208effd1832e50e1f7ea002f400f8b9ca8b1ed (diff) |
perf tools: Introduce llvm config options
This patch introduces [llvm] config section with 5 options. Following
patches will use then to config llvm dynamica compiling.
'llvm-utils.[ch]' is introduced in this patch for holding all
llvm/clang related stuffs.
Example:
[llvm]
# Path to clang. If omit, search it from $PATH.
clang-path = "/path/to/clang"
# Cmdline template. Following line shows its default value.
# Environment variable is used to passing options.
#
# *NOTE*: -D__KERNEL__ MUST appears before $CLANG_OPTIONS,
# so user have a chance to use -U__KERNEL__ in $CLANG_OPTIONS
# to cancel it.
clang-bpf-cmd-template = "$CLANG_EXEC -D__KERNEL__ $CLANG_OPTIONS \
$KERNEL_INC_OPTIONS -Wno-unused-value \
-Wno-pointer-sign -working-directory \
$WORKING_DIR -c $CLANG_SOURCE -target \
bpf -O2 -o -"
# Options passed to clang, will be passed to cmdline by
# $CLANG_OPTIONS.
clang-opt = "-Wno-unused-value -Wno-pointer-sign"
# kbuild directory. If not set, use /lib/modules/`uname -r`/build.
# If set to "" deliberately, skip kernel header auto-detector.
kbuild-dir = "/path/to/kernel/build"
# Options passed to 'make' when detecting kernel header options.
kbuild-opts = "ARCH=x86_64"
Signed-off-by: Wang Nan <wangnan0@huawei.com>
Acked-by: Alexei Starovoitov <ast@plumgrid.com>
Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: David Ahern <dsahern@gmail.com>
Cc: He Kuang <hekuang@huawei.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kaixu Xia <xiakaixu@huawei.com>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
Link: http://lkml.kernel.org/r/1437477214-149684-1-git-send-email-wangnan0@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | tools/perf/util/Build | 1 | ||||
-rw-r--r-- | tools/perf/util/config.c | 4 | ||||
-rw-r--r-- | tools/perf/util/llvm-utils.c | 45 | ||||
-rw-r--r-- | tools/perf/util/llvm-utils.h | 36 |
4 files changed, 86 insertions, 0 deletions
diff --git a/tools/perf/util/Build b/tools/perf/util/Build index a1e5168dc1fb..2ee81d74cf45 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build | |||
@@ -14,6 +14,7 @@ libperf-y += find_next_bit.o | |||
14 | libperf-y += help.o | 14 | libperf-y += help.o |
15 | libperf-y += kallsyms.o | 15 | libperf-y += kallsyms.o |
16 | libperf-y += levenshtein.o | 16 | libperf-y += levenshtein.o |
17 | libperf-y += llvm-utils.o | ||
17 | libperf-y += parse-options.o | 18 | libperf-y += parse-options.o |
18 | libperf-y += parse-events.o | 19 | libperf-y += parse-events.o |
19 | libperf-y += path.o | 20 | libperf-y += path.o |
diff --git a/tools/perf/util/config.c b/tools/perf/util/config.c index e18f653cd7db..2e452ac1353d 100644 --- a/tools/perf/util/config.c +++ b/tools/perf/util/config.c | |||
@@ -12,6 +12,7 @@ | |||
12 | #include "cache.h" | 12 | #include "cache.h" |
13 | #include "exec_cmd.h" | 13 | #include "exec_cmd.h" |
14 | #include "util/hist.h" /* perf_hist_config */ | 14 | #include "util/hist.h" /* perf_hist_config */ |
15 | #include "util/llvm-utils.h" /* perf_llvm_config */ | ||
15 | 16 | ||
16 | #define MAXNAME (256) | 17 | #define MAXNAME (256) |
17 | 18 | ||
@@ -408,6 +409,9 @@ int perf_default_config(const char *var, const char *value, | |||
408 | if (!prefixcmp(var, "call-graph.")) | 409 | if (!prefixcmp(var, "call-graph.")) |
409 | return perf_callchain_config(var, value); | 410 | return perf_callchain_config(var, value); |
410 | 411 | ||
412 | if (!prefixcmp(var, "llvm.")) | ||
413 | return perf_llvm_config(var, value); | ||
414 | |||
411 | /* Add other config variables here. */ | 415 | /* Add other config variables here. */ |
412 | return 0; | 416 | return 0; |
413 | } | 417 | } |
diff --git a/tools/perf/util/llvm-utils.c b/tools/perf/util/llvm-utils.c new file mode 100644 index 000000000000..472e8cd69361 --- /dev/null +++ b/tools/perf/util/llvm-utils.c | |||
@@ -0,0 +1,45 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2015, Wang Nan <wangnan0@huawei.com> | ||
3 | * Copyright (C) 2015, Huawei Inc. | ||
4 | */ | ||
5 | |||
6 | #include <stdio.h> | ||
7 | #include "util.h" | ||
8 | #include "debug.h" | ||
9 | #include "llvm-utils.h" | ||
10 | #include "cache.h" | ||
11 | |||
12 | #define CLANG_BPF_CMD_DEFAULT_TEMPLATE \ | ||
13 | "$CLANG_EXEC -D__KERNEL__ $CLANG_OPTIONS " \ | ||
14 | "$KERNEL_INC_OPTIONS -Wno-unused-value " \ | ||
15 | "-Wno-pointer-sign -working-directory " \ | ||
16 | "$WORKING_DIR -c \"$CLANG_SOURCE\" -target bpf -O2 -o -" | ||
17 | |||
18 | struct llvm_param llvm_param = { | ||
19 | .clang_path = "clang", | ||
20 | .clang_bpf_cmd_template = CLANG_BPF_CMD_DEFAULT_TEMPLATE, | ||
21 | .clang_opt = NULL, | ||
22 | .kbuild_dir = NULL, | ||
23 | .kbuild_opts = NULL, | ||
24 | }; | ||
25 | |||
26 | int perf_llvm_config(const char *var, const char *value) | ||
27 | { | ||
28 | if (prefixcmp(var, "llvm.")) | ||
29 | return 0; | ||
30 | var += sizeof("llvm.") - 1; | ||
31 | |||
32 | if (!strcmp(var, "clang-path")) | ||
33 | llvm_param.clang_path = strdup(value); | ||
34 | else if (!strcmp(var, "clang-bpf-cmd-template")) | ||
35 | llvm_param.clang_bpf_cmd_template = strdup(value); | ||
36 | else if (!strcmp(var, "clang-opt")) | ||
37 | llvm_param.clang_opt = strdup(value); | ||
38 | else if (!strcmp(var, "kbuild-dir")) | ||
39 | llvm_param.kbuild_dir = strdup(value); | ||
40 | else if (!strcmp(var, "kbuild-opts")) | ||
41 | llvm_param.kbuild_opts = strdup(value); | ||
42 | else | ||
43 | return -1; | ||
44 | return 0; | ||
45 | } | ||
diff --git a/tools/perf/util/llvm-utils.h b/tools/perf/util/llvm-utils.h new file mode 100644 index 000000000000..504b799687fb --- /dev/null +++ b/tools/perf/util/llvm-utils.h | |||
@@ -0,0 +1,36 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2015, Wang Nan <wangnan0@huawei.com> | ||
3 | * Copyright (C) 2015, Huawei Inc. | ||
4 | */ | ||
5 | #ifndef __LLVM_UTILS_H | ||
6 | #define __LLVM_UTILS_H | ||
7 | |||
8 | #include "debug.h" | ||
9 | |||
10 | struct llvm_param { | ||
11 | /* Path of clang executable */ | ||
12 | const char *clang_path; | ||
13 | /* | ||
14 | * Template of clang bpf compiling. 5 env variables | ||
15 | * can be used: | ||
16 | * $CLANG_EXEC: Path to clang. | ||
17 | * $CLANG_OPTIONS: Extra options to clang. | ||
18 | * $KERNEL_INC_OPTIONS: Kernel include directories. | ||
19 | * $WORKING_DIR: Kernel source directory. | ||
20 | * $CLANG_SOURCE: Source file to be compiled. | ||
21 | */ | ||
22 | const char *clang_bpf_cmd_template; | ||
23 | /* Will be filled in $CLANG_OPTIONS */ | ||
24 | const char *clang_opt; | ||
25 | /* Where to find kbuild system */ | ||
26 | const char *kbuild_dir; | ||
27 | /* | ||
28 | * Arguments passed to make, like 'ARCH=arm' if doing cross | ||
29 | * compiling. Should not be used for dynamic compiling. | ||
30 | */ | ||
31 | const char *kbuild_opts; | ||
32 | }; | ||
33 | |||
34 | extern struct llvm_param llvm_param; | ||
35 | extern int perf_llvm_config(const char *var, const char *value); | ||
36 | #endif | ||