Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1262218 > unrolled thread

[PATCH 1/4] perf tools: Pass available CPU number to clang compiler

Started byWang Nan <wangnan0@huawei.com>
First post2015-11-04 12:30 +0100
Last post2015-11-08 08:40 +0100
Articles 4 — 4 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH 1/4] perf tools: Pass available CPU number to clang compiler Wang Nan <wangnan0@huawei.com> - 2015-11-04 12:30 +0100
    Re: [PATCH 1/4] perf tools: Pass available CPU number to clang  compiler Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-11-04 23:20 +0100
      Re: [PATCH 1/4] perf tools: Pass available CPU number to clang compiler "Wangnan (F)" <wangnan0@huawei.com> - 2015-11-05 02:50 +0100
    [tip:perf/urgent] perf llvm:   Pass number of configured CPUs to clang compiler tip-bot for Wang Nan <tipbot@zytor.com> - 2015-11-08 08:40 +0100

#1262218 — [PATCH 1/4] perf tools: Pass available CPU number to clang compiler

FromWang Nan <wangnan0@huawei.com>
Date2015-11-04 12:30 +0100
Subject[PATCH 1/4] perf tools: Pass available CPU number to clang compiler
Message-ID<qr4ql-8db-7@gated-at.bofh.it>
This patch introduces a new macro "__NR_CPUS__" to perf's embedded
clang compiler, which represent the available CPU counters in this
system. BPF program can use this macro to create a map with same
number of system CPUs. For exmaple:

 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: 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 | 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);
-- 
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]


#1262657 — Re: [PATCH 1/4] perf tools: Pass available CPU number to clang compiler

FromArnaldo Carvalho de Melo <acme@kernel.org>
Date2015-11-04 23:20 +0100
SubjectRe: [PATCH 1/4] perf tools: Pass available CPU number to clang compiler
Message-ID<qrezq-6oW-59@gated-at.bofh.it>
In reply to#1262218
Em Wed, Nov 04, 2015 at 11:20:04AM +0000, Wang Nan escreveu:
> This patch introduces a new macro "__NR_CPUS__" to perf's embedded
> clang compiler, which represent the available CPU counters in this

available "CPU counters"? ENOPARSE :-)

> system. BPF program can use this macro to create a map with same
> number of system CPUs. For exmaple:
                             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__,
>  };

I wonder if we shouldn't use the getconf() parameter here, i.e. define
_SC_NPROCESSORS_CONF and also provide _SC_NPROCESSORS_ONLN.

The kernel uses NR_CPUS, for accessing CONFIG_NR_CPUS, Alexei, what do
you think?

- 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 | 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);
> -- 
> 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]


#1262806

From"Wangnan (F)" <wangnan0@huawei.com>
Date2015-11-05 02:50 +0100
Message-ID<qrhQC-8ni-17@gated-at.bofh.it>
In reply to#1262657

On 2015/11/5 6:09, Arnaldo Carvalho de Melo wrote:
> Em Wed, Nov 04, 2015 at 11:20:04AM +0000, Wang Nan escreveu:
>> This patch introduces a new macro "__NR_CPUS__" to perf's embedded
>> clang compiler, which represent the available CPU counters in this
> available "CPU counters"? ENOPARSE :-)

Your changing is better.

This patch is for support Alexei's BPF output and Xia Kaixu's BPF
pmu reading. In these cases we need to create an array with
same number of slots with system CPUs.

Thank you.

--
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]


#1265015 — [tip:perf/urgent] perf llvm: Pass number of configured CPUs to clang compiler

Fromtip-bot for Wang Nan <tipbot@zytor.com>
Date2015-11-08 08:40 +0100
Subject[tip:perf/urgent] perf llvm: Pass number of configured CPUs to clang compiler
Message-ID<qssJX-5As-5@gated-at.bofh.it>
In reply to#1262218
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);
--
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