From: tip-bot for Wang Nan <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, mingo@kernel.org,
tglx@linutronix.de, hpa@zytor.com, acme@redhat.com,
ast@kernel.org, namhyung@kernel.org, lizefan@huawei.com,
wangnan0@huawei.com
Subject: [tip:perf/urgent] perf llvm: Pass number of configured CPUs to clang compiler
Date: Sat, 7 Nov 2015 23:29:48 -0800 [thread overview]
Message-ID: <tip-59f41af980f95cbd556a6dc2e064b412abc439cf@git.kernel.org> (raw)
In-Reply-To: <1446636007-239722-2-git-send-email-wangnan0@huawei.com>
Commit-ID: 59f41af980f95cbd556a6dc2e064b412abc439cf
Gitweb: http://git.kernel.org/tip/59f41af980f95cbd556a6dc2e064b412abc439cf
Author: Wang Nan <wangnan0@huawei.com>
AuthorDate: Wed, 4 Nov 2015 11:20:04 +0000
Committer: Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Thu, 5 Nov 2015 12:47:02 -0300
perf llvm: Pass number of configured CPUs to clang compiler
This patch introduces a new macro "__NR_CPUS__" to perf's embedded clang
compiler, which represent the number of configured CPUs in this system.
BPF programs can use this macro to create a map with the same number of
system CPUs. For example:
struct bpf_map_def SEC("maps") pmu_map = {
.type = BPF_MAP_TYPE_PERF_EVENT_ARRAY,
.key_size = sizeof(int),
.value_size = sizeof(u32),
.max_entries = __NR_CPUS__,
};
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-2-git-send-email-wangnan0@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/util/llvm-utils.c | 24 ++++++++++++++++++------
1 file changed, 18 insertions(+), 6 deletions(-)
diff --git a/tools/perf/util/llvm-utils.c b/tools/perf/util/llvm-utils.c
index 4f6a478..80eecef 100644
--- a/tools/perf/util/llvm-utils.c
+++ b/tools/perf/util/llvm-utils.c
@@ -11,10 +11,11 @@
#include "cache.h"
#define CLANG_BPF_CMD_DEFAULT_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 -"
+ "$CLANG_EXEC -D__KERNEL__ -D__NR_CPUS__=$NR_CPUS "\
+ "$CLANG_OPTIONS $KERNEL_INC_OPTIONS " \
+ "-Wno-unused-value -Wno-pointer-sign " \
+ "-working-directory $WORKING_DIR " \
+ "-c \"$CLANG_SOURCE\" -target bpf -O2 -o -"
struct llvm_param llvm_param = {
.clang_path = "clang",
@@ -326,8 +327,8 @@ get_kbuild_opts(char **kbuild_dir, char **kbuild_include_opts)
int llvm__compile_bpf(const char *path, void **p_obj_buf,
size_t *p_obj_buf_sz)
{
- int err;
- char clang_path[PATH_MAX];
+ int err, nr_cpus_avail;
+ char clang_path[PATH_MAX], nr_cpus_avail_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;
@@ -354,6 +355,17 @@ int llvm__compile_bpf(const char *path, void **p_obj_buf,
*/
get_kbuild_opts(&kbuild_dir, &kbuild_include_opts);
+ nr_cpus_avail = sysconf(_SC_NPROCESSORS_CONF);
+ if (nr_cpus_avail <= 0) {
+ pr_err(
+"WARNING:\tunable to get available CPUs in this system: %s\n"
+" \tUse 128 instead.\n", strerror(errno));
+ nr_cpus_avail = 128;
+ }
+ snprintf(nr_cpus_avail_str, sizeof(nr_cpus_avail_str), "%d",
+ nr_cpus_avail);
+
+ force_set_env("NR_CPUS", nr_cpus_avail_str);
force_set_env("CLANG_EXEC", clang_path);
force_set_env("CLANG_OPTIONS", clang_opt);
force_set_env("KERNEL_INC_OPTIONS", kbuild_include_opts);
next prev parent reply other threads:[~2015-11-08 7:30 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-04 11:20 [PATCH 0/4] perf tools: Improve llvm compiling and test Wang Nan
2015-11-04 11:20 ` [PATCH 1/4] perf tools: Pass available CPU number to clang compiler Wang Nan
2015-11-04 22:09 ` Arnaldo Carvalho de Melo
2015-11-05 1:41 ` Wangnan (F)
2015-11-08 7:29 ` tip-bot for Wang Nan [this message]
2015-11-04 11:20 ` [PATCH 2/4] perf tools: Pass LINUX_VERSION_CODE to BPF program when compiling Wang Nan
2015-11-04 22:23 ` Arnaldo Carvalho de Melo
2015-11-08 7:30 ` [tip:perf/urgent] perf llvm: " tip-bot for Wang Nan
2015-11-04 11:20 ` [PATCH 3/4] perf test: Enforce LLVM test: update basic BPF test program Wang Nan
2015-11-04 22:23 ` Arnaldo Carvalho de Melo
2015-11-04 11:20 ` [PATCH 4/4] perf test: Enforce LLVM test: add kbuild test Wang Nan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=tip-59f41af980f95cbd556a6dc2e064b412abc439cf@git.kernel.org \
--to=tipbot@zytor.com \
--cc=acme@redhat.com \
--cc=ast@kernel.org \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=lizefan@huawei.com \
--cc=mingo@kernel.org \
--cc=namhyung@kernel.org \
--cc=tglx@linutronix.de \
--cc=wangnan0@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox