Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1262221 > unrolled thread
| Started by | Wang Nan <wangnan0@huawei.com> |
|---|---|
| First post | 2015-11-04 12:30 +0100 |
| Last post | 2015-11-08 08:40 +0100 |
| Articles | 5 — 3 participants |
Back to article view | Back to linux.kernel
[PATCH 0/4] perf tools: Improve llvm compiling and test Wang Nan <wangnan0@huawei.com> - 2015-11-04 12:30 +0100
[PATCH 4/4] perf test: Enforce LLVM test: add kbuild test Wang Nan <wangnan0@huawei.com> - 2015-11-04 12:30 +0100
[PATCH 2/4] perf tools: Pass LINUX_VERSION_CODE to BPF program when compiling Wang Nan <wangnan0@huawei.com> - 2015-11-04 12:30 +0100
Re: [PATCH 2/4] perf tools: Pass LINUX_VERSION_CODE to BPF program when compiling Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-11-04 23:30 +0100
[tip:perf/urgent] perf llvm: Pass LINUX_VERSION_CODE to BPF program when compiling tip-bot for Wang Nan <tipbot@zytor.com> - 2015-11-08 08:40 +0100
| From | Wang Nan <wangnan0@huawei.com> |
|---|---|
| Date | 2015-11-04 12:30 +0100 |
| Subject | [PATCH 0/4] perf tools: Improve llvm compiling and test |
| Message-ID | <qr4ql-8db-5@gated-at.bofh.it> |
This patchset is based on perf/core in Arnaldo's repository. The first 2 patches addes some macro which helps writing BPF programs easier. The last 2 patches enforce 'perf test LLVM', improves coding. Wang Nan (4): perf tools: Pass available CPU number to clang compiler perf tools: Pass LINUX_VERSION_CODE to BPF program when compiling perf test: Enforce LLVM test: update basic BPF test program perf test: Enforce LLVM test: add kbuild test tools/perf/tests/Build | 16 +++- tools/perf/tests/bpf-script-example.c | 4 + tools/perf/tests/bpf-script-test-kbuild.c | 21 +++++ tools/perf/tests/llvm.c | 135 +++++++++++++++++++++++------- tools/perf/tests/llvm.h | 18 ++++ tools/perf/util/llvm-utils.c | 51 +++++++++-- 6 files changed, 208 insertions(+), 37 deletions(-) create mode 100644 tools/perf/tests/bpf-script-test-kbuild.c create mode 100644 tools/perf/tests/llvm.h -- 1.8.3.4 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [next] | [standalone]
| From | Wang Nan <wangnan0@huawei.com> |
|---|---|
| Date | 2015-11-04 12:30 +0100 |
| Subject | [PATCH 4/4] perf test: Enforce LLVM test: add kbuild test |
| Message-ID | <qr4ql-8db-3@gated-at.bofh.it> |
| In reply to | #1262221 |
This patch adds a kbuild testcase to check whether kernel headers
can be correctly found.
For example:
# mv /lib/modules/4.3.0-rc5{,.bak}
# perf test LLVM
38: Test LLVM searching and compiling : Skip
# perf test -v LLVM
...
<stdin>:11:10: fatal error: 'uapi/linux/fs.h' file not found
#include <uapi/linux/fs.h>
^
1 error generated.
ERROR: unable to compile -
Hint: Check error message shown above.
Hint: You can also pre-compile it into .o using:
clang -target bpf -O2 -c -
with proper -I and -D options.
Failed to compile test case: 'Test kbuild searching'
test child finished with -2
Signed-off-by: Wang Nan <wangnan0@huawei.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
---
tools/perf/tests/Build | 9 ++++++++-
tools/perf/tests/bpf-script-test-kbuild.c | 21 +++++++++++++++++++++
tools/perf/tests/llvm.c | 4 ++++
tools/perf/tests/llvm.h | 2 ++
4 files changed, 35 insertions(+), 1 deletion(-)
create mode 100644 tools/perf/tests/bpf-script-test-kbuild.c
diff --git a/tools/perf/tests/Build b/tools/perf/tests/Build
index 6c095b3..a47b211 100644
--- a/tools/perf/tests/Build
+++ b/tools/perf/tests/Build
@@ -31,7 +31,7 @@ perf-y += sample-parsing.o
perf-y += parse-no-sample-id-all.o
perf-y += kmod-path.o
perf-y += thread-map.o
-perf-y += llvm.o llvm-src-base.o
+perf-y += llvm.o llvm-src-base.o llvm-src-kbuild.o
perf-y += topology.o
$(OUTPUT)tests/llvm-src-base.c: tests/bpf-script-example.c
@@ -41,6 +41,13 @@ $(OUTPUT)tests/llvm-src-base.c: tests/bpf-script-example.c
$(Q)sed -e 's/"/\\"/g' -e 's/\(.*\)/"\1\\n"/g' $< >> $@
$(Q)echo ';' >> $@
+$(OUTPUT)tests/llvm-src-kbuild.c: tests/bpf-script-test-kbuild.c
+ $(call rule_mkdir)
+ $(Q)echo '#include <tests/llvm.h>' > $@
+ $(Q)echo 'const char test_llvm__bpf_test_kbuild_prog[] =' >> $@
+ $(Q)sed -e 's/"/\\"/g' -e 's/\(.*\)/"\1\\n"/g' $< >> $@
+ $(Q)echo ';' >> $@
+
ifeq ($(ARCH),$(filter $(ARCH),x86 arm arm64))
perf-$(CONFIG_DWARF_UNWIND) += dwarf-unwind.o
endif
diff --git a/tools/perf/tests/bpf-script-test-kbuild.c b/tools/perf/tests/bpf-script-test-kbuild.c
new file mode 100644
index 0000000..3626924
--- /dev/null
+++ b/tools/perf/tests/bpf-script-test-kbuild.c
@@ -0,0 +1,21 @@
+/*
+ * bpf-script-test-kbuild.c
+ * Test include from kernel header
+ */
+#ifndef LINUX_VERSION_CODE
+# error Need LINUX_VERSION_CODE
+# error Example: for 4.2 kernel, put 'clang-opt="-DLINUX_VERSION_CODE=0x40200" into llvm section of ~/.perfconfig'
+#endif
+#define SEC(NAME) __attribute__((section(NAME), used))
+
+#include <uapi/linux/fs.h>
+#include <uapi/asm/ptrace.h>
+
+SEC("func=vfs_llseek")
+int bpf_func__vfs_llseek(void *ctx)
+{
+ return 0;
+}
+
+char _license[] SEC("license") = "GPL";
+int _version SEC("version") = LINUX_VERSION_CODE;
diff --git a/tools/perf/tests/llvm.c b/tools/perf/tests/llvm.c
index f4f1437..6941e66 100644
--- a/tools/perf/tests/llvm.c
+++ b/tools/perf/tests/llvm.c
@@ -40,6 +40,10 @@ static struct {
.source = test_llvm__bpf_base_prog,
.desc = "Basic BPF llvm compiling test",
},
+ [LLVM_TESTCASE_KBUILD] = {
+ .source = test_llvm__bpf_test_kbuild_prog,
+ .desc = "Test kbuild searching",
+ },
};
diff --git a/tools/perf/tests/llvm.h b/tools/perf/tests/llvm.h
index bd63cee..d91d8f4 100644
--- a/tools/perf/tests/llvm.h
+++ b/tools/perf/tests/llvm.h
@@ -5,9 +5,11 @@
#include <stdbool.h> /* for bool */
extern const char test_llvm__bpf_base_prog[];
+extern const char test_llvm__bpf_test_kbuild_prog[];
enum test_llvm__testcase {
LLVM_TESTCASE_BASE,
+ LLVM_TESTCASE_KBUILD,
__LLVM_TESTCASE_MAX,
};
--
1.8.3.4
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Wang Nan <wangnan0@huawei.com> |
|---|---|
| Date | 2015-11-04 12:30 +0100 |
| Subject | [PATCH 2/4] perf tools: Pass LINUX_VERSION_CODE to BPF program when compiling |
| Message-ID | <qr4qm-8db-21@gated-at.bofh.it> |
| In reply to | #1262221 |
Arnaldo suggests to make LINUX_VERSION_CODE works like __func__ and
__FILE__ so user don't need to care setting right linux version
too much. In this patch, perf llvm transfers LINUX_VERSION_CODE macro
through clang cmdline.
[1] http://lkml.kernel.org/r/20151029223744.GK2923@kernel.org
Signed-off-by: Wang Nan <wangnan0@huawei.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
---
tools/perf/util/llvm-utils.c | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/tools/perf/util/llvm-utils.c b/tools/perf/util/llvm-utils.c
index 80eecef..8ee25be 100644
--- a/tools/perf/util/llvm-utils.c
+++ b/tools/perf/util/llvm-utils.c
@@ -12,6 +12,7 @@
#define CLANG_BPF_CMD_DEFAULT_TEMPLATE \
"$CLANG_EXEC -D__KERNEL__ -D__NR_CPUS__=$NR_CPUS "\
+ "-DLINUX_VERSION_CODE=$LINUX_VERSION_CODE " \
"$CLANG_OPTIONS $KERNEL_INC_OPTIONS " \
"-Wno-unused-value -Wno-pointer-sign " \
"-working-directory $WORKING_DIR " \
@@ -324,11 +325,33 @@ get_kbuild_opts(char **kbuild_dir, char **kbuild_include_opts)
pr_debug("include option is set to %s\n", *kbuild_include_opts);
}
+static unsigned long
+fetch_kernel_version(void)
+{
+ struct utsname utsname;
+ int version, patchlevel, sublevel, err;
+
+ if (uname(&utsname))
+ return 0;
+
+ err = sscanf(utsname.release, "%d.%d.%d",
+ &version, &patchlevel, &sublevel);
+
+ if (err != 3) {
+ pr_debug("Unablt to get kernel version from uname '%s'\n",
+ utsname.release);
+ return 0;
+ }
+
+ return (version << 16) + (patchlevel << 8) + sublevel;
+}
+
int llvm__compile_bpf(const char *path, void **p_obj_buf,
size_t *p_obj_buf_sz)
{
int err, nr_cpus_avail;
char clang_path[PATH_MAX], nr_cpus_avail_str[64];
+ char linux_version_code_str[64];
const char *clang_opt = llvm_param.clang_opt;
const char *template = llvm_param.clang_bpf_cmd_template;
char *kbuild_dir = NULL, *kbuild_include_opts = NULL;
@@ -365,7 +388,11 @@ int llvm__compile_bpf(const char *path, void **p_obj_buf,
snprintf(nr_cpus_avail_str, sizeof(nr_cpus_avail_str), "%d",
nr_cpus_avail);
+ snprintf(linux_version_code_str, sizeof(linux_version_code_str),
+ "0x%lx", fetch_kernel_version());
+
force_set_env("NR_CPUS", nr_cpus_avail_str);
+ force_set_env("LINUX_VERSION_CODE", linux_version_code_str);
force_set_env("CLANG_EXEC", clang_path);
force_set_env("CLANG_OPTIONS", clang_opt);
force_set_env("KERNEL_INC_OPTIONS", kbuild_include_opts);
--
1.8.3.4
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Arnaldo Carvalho de Melo <acme@kernel.org> |
|---|---|
| Date | 2015-11-04 23:30 +0100 |
| Subject | Re: [PATCH 2/4] perf tools: Pass LINUX_VERSION_CODE to BPF program when compiling |
| Message-ID | <qreJ6-6sC-51@gated-at.bofh.it> |
| In reply to | #1262224 |
Em Wed, Nov 04, 2015 at 11:20:05AM +0000, Wang Nan escreveu:
> Arnaldo suggests to make LINUX_VERSION_CODE works like __func__ and
> __FILE__ so user don't need to care setting right linux version
> too much. In this patch, perf llvm transfers LINUX_VERSION_CODE macro
> through clang cmdline.
>
> [1] http://lkml.kernel.org/r/20151029223744.GK2923@kernel.org
Tested, updated the comment, applied and pushed to my perf/core branch,
please continue from there, I'll try to push it tomorrow.
- Arnaldo
> Signed-off-by: Wang Nan <wangnan0@huawei.com>
> Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
> Cc: Alexei Starovoitov <ast@kernel.org>
> Cc: Namhyung Kim <namhyung@kernel.org>
> Cc: Zefan Li <lizefan@huawei.com>
> Cc: pi3orama@163.com
> ---
> tools/perf/util/llvm-utils.c | 27 +++++++++++++++++++++++++++
> 1 file changed, 27 insertions(+)
>
> diff --git a/tools/perf/util/llvm-utils.c b/tools/perf/util/llvm-utils.c
> index 80eecef..8ee25be 100644
> --- a/tools/perf/util/llvm-utils.c
> +++ b/tools/perf/util/llvm-utils.c
> @@ -12,6 +12,7 @@
>
> #define CLANG_BPF_CMD_DEFAULT_TEMPLATE \
> "$CLANG_EXEC -D__KERNEL__ -D__NR_CPUS__=$NR_CPUS "\
> + "-DLINUX_VERSION_CODE=$LINUX_VERSION_CODE " \
> "$CLANG_OPTIONS $KERNEL_INC_OPTIONS " \
> "-Wno-unused-value -Wno-pointer-sign " \
> "-working-directory $WORKING_DIR " \
> @@ -324,11 +325,33 @@ get_kbuild_opts(char **kbuild_dir, char **kbuild_include_opts)
> pr_debug("include option is set to %s\n", *kbuild_include_opts);
> }
>
> +static unsigned long
> +fetch_kernel_version(void)
> +{
> + struct utsname utsname;
> + int version, patchlevel, sublevel, err;
> +
> + if (uname(&utsname))
> + return 0;
> +
> + err = sscanf(utsname.release, "%d.%d.%d",
> + &version, &patchlevel, &sublevel);
> +
> + if (err != 3) {
> + pr_debug("Unablt to get kernel version from uname '%s'\n",
> + utsname.release);
> + return 0;
> + }
> +
> + return (version << 16) + (patchlevel << 8) + sublevel;
> +}
> +
> int llvm__compile_bpf(const char *path, void **p_obj_buf,
> size_t *p_obj_buf_sz)
> {
> int err, nr_cpus_avail;
> char clang_path[PATH_MAX], nr_cpus_avail_str[64];
> + char linux_version_code_str[64];
> const char *clang_opt = llvm_param.clang_opt;
> const char *template = llvm_param.clang_bpf_cmd_template;
> char *kbuild_dir = NULL, *kbuild_include_opts = NULL;
> @@ -365,7 +388,11 @@ int llvm__compile_bpf(const char *path, void **p_obj_buf,
> snprintf(nr_cpus_avail_str, sizeof(nr_cpus_avail_str), "%d",
> nr_cpus_avail);
>
> + snprintf(linux_version_code_str, sizeof(linux_version_code_str),
> + "0x%lx", fetch_kernel_version());
> +
> force_set_env("NR_CPUS", nr_cpus_avail_str);
> + force_set_env("LINUX_VERSION_CODE", linux_version_code_str);
> force_set_env("CLANG_EXEC", clang_path);
> force_set_env("CLANG_OPTIONS", clang_opt);
> force_set_env("KERNEL_INC_OPTIONS", kbuild_include_opts);
> --
> 1.8.3.4
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | tip-bot for Wang Nan <tipbot@zytor.com> |
|---|---|
| Date | 2015-11-08 08:40 +0100 |
| Subject | [tip:perf/urgent] perf llvm: Pass LINUX_VERSION_CODE to BPF program when compiling |
| Message-ID | <qssJY-5As-29@gated-at.bofh.it> |
| In reply to | #1262224 |
Commit-ID: 4a4f66a1a7031675745812729ade94ad1caf1db6
Gitweb: http://git.kernel.org/tip/4a4f66a1a7031675745812729ade94ad1caf1db6
Author: Wang Nan <wangnan0@huawei.com>
AuthorDate: Wed, 4 Nov 2015 11:20:05 +0000
Committer: Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Thu, 5 Nov 2015 12:47:50 -0300
perf llvm: Pass LINUX_VERSION_CODE to BPF program when compiling
Arnaldo suggests to make LINUX_VERSION_CODE works like __func__ and
__FILE__ so user don't need to care setting right linux version too
much. In this patch, perf llvm transfers LINUX_VERSION_CODE macro
through clang cmdline.
[1] http://lkml.kernel.org/r/20151029223744.GK2923@kernel.org
Committer notes:
Before, forgetting to update the version:
# uname -r
4.3.0-rc1+
# cat bpf.c
__attribute__((section("fork=_do_fork"), used))
int fork(void *ctx)
{
return 1;
}
char _license[] __attribute__((section("license"), used)) = "GPL";
int _version __attribute__((section("version"), used)) = 0x40200;
#
# perf record -e bpf.c sleep 1
event syntax error: 'bpf.c'
\___ Invalid argument: Are you root and runing a CONFIG_BPF_SYSCALL kernel?
(add -v to see detail)
Run 'perf list' for a list of valid events
Usage: perf record [<options>] [<command>]
or: perf record [<options>] -- <command> [<options>]
-e, --event <event> event selector. use 'perf list' to list available events
#
After:
# grep version bpf.c
int _version __attribute__((section("version"), used)) = LINUX_VERSION_CODE;
# perf record -e bpf.c sleep 1
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.017 MB perf.data ]
# perf evlist -v
perf_bpf_probe:fork: type: 2, size: 112, config: 0x5ee, { sample_period,
sample_freq }: 1, sample_type: IP|TID|TIME|CPU|PERIOD|RAW, disabled: 1,
inherit: 1, mmap: 1, comm: 1, enable_on_exec: 1, task: 1, sample_id_all:
1, exclude_guest: 1, mmap2: 1, comm_exec: 1
#
Suggested-and-Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Wang Nan <wangnan0@huawei.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
Link: http://lkml.kernel.org/r/1446636007-239722-3-git-send-email-wangnan0@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/util/llvm-utils.c | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/tools/perf/util/llvm-utils.c b/tools/perf/util/llvm-utils.c
index 80eecef..8ee25be 100644
--- a/tools/perf/util/llvm-utils.c
+++ b/tools/perf/util/llvm-utils.c
@@ -12,6 +12,7 @@
#define CLANG_BPF_CMD_DEFAULT_TEMPLATE \
"$CLANG_EXEC -D__KERNEL__ -D__NR_CPUS__=$NR_CPUS "\
+ "-DLINUX_VERSION_CODE=$LINUX_VERSION_CODE " \
"$CLANG_OPTIONS $KERNEL_INC_OPTIONS " \
"-Wno-unused-value -Wno-pointer-sign " \
"-working-directory $WORKING_DIR " \
@@ -324,11 +325,33 @@ get_kbuild_opts(char **kbuild_dir, char **kbuild_include_opts)
pr_debug("include option is set to %s\n", *kbuild_include_opts);
}
+static unsigned long
+fetch_kernel_version(void)
+{
+ struct utsname utsname;
+ int version, patchlevel, sublevel, err;
+
+ if (uname(&utsname))
+ return 0;
+
+ err = sscanf(utsname.release, "%d.%d.%d",
+ &version, &patchlevel, &sublevel);
+
+ if (err != 3) {
+ pr_debug("Unablt to get kernel version from uname '%s'\n",
+ utsname.release);
+ return 0;
+ }
+
+ return (version << 16) + (patchlevel << 8) + sublevel;
+}
+
int llvm__compile_bpf(const char *path, void **p_obj_buf,
size_t *p_obj_buf_sz)
{
int err, nr_cpus_avail;
char clang_path[PATH_MAX], nr_cpus_avail_str[64];
+ char linux_version_code_str[64];
const char *clang_opt = llvm_param.clang_opt;
const char *template = llvm_param.clang_bpf_cmd_template;
char *kbuild_dir = NULL, *kbuild_include_opts = NULL;
@@ -365,7 +388,11 @@ int llvm__compile_bpf(const char *path, void **p_obj_buf,
snprintf(nr_cpus_avail_str, sizeof(nr_cpus_avail_str), "%d",
nr_cpus_avail);
+ snprintf(linux_version_code_str, sizeof(linux_version_code_str),
+ "0x%lx", fetch_kernel_version());
+
force_set_env("NR_CPUS", nr_cpus_avail_str);
+ force_set_env("LINUX_VERSION_CODE", linux_version_code_str);
force_set_env("CLANG_EXEC", clang_path);
force_set_env("CLANG_OPTIONS", clang_opt);
force_set_env("KERNEL_INC_OPTIONS", kbuild_include_opts);
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web