public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Wang Nan <wangnan0@huawei.com>
Cc: namhyung@kernel.org, lizefan@huawei.com, pi3orama@163.com,
	linux-kernel@vger.kernel.org, Alexei Starovoitov <ast@kernel.org>
Subject: Re: [PATCH 2/4] perf tools: Pass LINUX_VERSION_CODE to BPF program when compiling
Date: Wed, 4 Nov 2015 19:23:19 -0300	[thread overview]
Message-ID: <20151104222319.GM13236@kernel.org> (raw)
In-Reply-To: <1446636007-239722-3-git-send-email-wangnan0@huawei.com>

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

  reply	other threads:[~2015-11-04 22:23 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:perf/urgent] perf llvm: Pass number of configured CPUs " tip-bot for Wang Nan
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 [this message]
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=20151104222319.GM13236@kernel.org \
    --to=acme@kernel.org \
    --cc=ast@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lizefan@huawei.com \
    --cc=namhyung@kernel.org \
    --cc=pi3orama@163.com \
    --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