public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Namhyung Kim <namhyung@kernel.org>
To: Wang Nan <wangnan0@huawei.com>
Cc: ast@plumgrid.com, davem@davemloft.net, acme@kernel.org,
	mingo@redhat.com, a.p.zijlstra@chello.nl,
	masami.hiramatsu.pt@hitachi.com, jolsa@kernel.org,
	lizefan@kernel.org, linux-kernel@vger.kernel.org,
	pi3orama@163.com, hekuang@huawei.com
Subject: Re: [RFC PATCH 09/22] perf bpf: collect map definitions.
Date: Mon, 11 May 2015 15:32:10 +0900	[thread overview]
Message-ID: <20150511063210.GC1630@sejong> (raw)
In-Reply-To: <1430391165-30267-10-git-send-email-wangnan0@huawei.com>

On Thu, Apr 30, 2015 at 10:52:32AM +0000, Wang Nan wrote:
> If maps are used by eBPF programs, corresponding object file(s) should
> contain a section named 'map'. Which contains map definitions, one for
> each map to describe its format. 'struct perf_bpf_map_def' is
> introduced as part of protocol between perf and eBPF programs. All map
> definitions are copied to obj->maps.
> 
> bpf.h is introduced for common bpf operations.
> 
> Signed-off-by: Wang Nan <wangnan0@huawei.com>
> ---
>  tools/perf/util/bpf-loader.c | 31 +++++++++++++++++++++++++++++++
>  tools/perf/util/bpf-loader.h |  3 +++
>  2 files changed, 34 insertions(+)
> 
> diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c
> index 296fb06..bf3b793 100644
> --- a/tools/perf/util/bpf-loader.c
> +++ b/tools/perf/util/bpf-loader.c
> @@ -65,6 +65,8 @@ static void bpf_obj_close(struct bpf_obj *obj)
>  
>  	if (obj->path)
>  		free(obj->path);
> +	if (obj->maps)
> +		free(obj->maps);
>  	free(obj);
>  }
>  
> @@ -183,6 +185,32 @@ static int bpf_obj_kver_init(struct bpf_obj *obj,
>  	return 0;
>  }
>  
> +static int bpf_obj_maps_init(struct bpf_obj *obj, void *data,
> +			     size_t size)
> +{
> +	size_t map_def_sz = sizeof(struct bpf_map_def);
> +	int nr_maps = size / map_def_sz;
> +
> +	if (nr_maps == 0) {
> +		pr_debug("bpf: %s doesn't need map definition\n",
> +			 obj->path);
> +		return 0;
> +	}
> +
> +	obj->maps = malloc(nr_maps * map_def_sz);
> +	if (!obj->maps) {
> +		pr_err("bpf: malloc maps failed: %s\n", obj->path);
> +		return -ENOMEM;
> +	}
> +
> +	obj->nr_maps = nr_maps;
> +	memcpy(obj->maps, data, nr_maps * map_def_sz);

Doesn't it need to swap the data as it's binary?

Thanks,
Namhyung


> +	pr_debug("bpf: %d map%s in %s\n", nr_maps,
> +			nr_maps > 1 ? "s" : "",
> +			obj->path);
> +	return 0;
> +}
> +
>  static int bpf_obj_elf_collect(struct bpf_obj *obj)
>  {
>  	Elf *elf = obj->elf.elf;
> @@ -237,6 +265,9 @@ static int bpf_obj_elf_collect(struct bpf_obj *obj)
>  		else if (strcmp(name, "version") == 0)
>  			err = bpf_obj_kver_init(obj, data->d_buf,
>  						data->d_size);
> +		else if (strcmp(name, "maps") == 0)
> +			err = bpf_obj_maps_init(obj, data->d_buf,
> +						data->d_size);
>  		if (err)
>  			goto out;
>  	}
> diff --git a/tools/perf/util/bpf-loader.h b/tools/perf/util/bpf-loader.h
> index e1d5c42..6c5c8d6 100644
> --- a/tools/perf/util/bpf-loader.h
> +++ b/tools/perf/util/bpf-loader.h
> @@ -14,6 +14,7 @@
>  #include "perf.h"
>  #include "symbol.h"
>  #include "probe-event.h"
> +#include "bpf.h"
>  
>  int bpf__load(const char *path);
>  int bpf__run(void);
> @@ -25,6 +26,8 @@ struct bpf_obj {
>  	bool needs_swap;
>  	char license[64];
>  	u32 kern_version;
> +	struct bpf_map_def *maps;
> +	size_t nr_maps;
>  
>  	/*
>  	 * Information when doing elf related work. Only valid if fd
> -- 
> 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/

  reply	other threads:[~2015-05-11  6:42 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-30 10:52 [RFC PATCH 00/22] perf tools: introduce 'perf bpf' command to load eBPF programs Wang Nan
2015-04-30 10:52 ` [RFC PATCH 01/22] perf: probe: avoid segfault if passed with '' Wang Nan
2015-05-05 14:09   ` Masami Hiramatsu
2015-05-05 15:26     ` Arnaldo Carvalho de Melo
2015-05-05 16:33       ` Masami Hiramatsu
2015-04-30 10:52 ` [RFC PATCH 02/22] perf: bpf: prepare: add __aligned_u64 to types.h Wang Nan
2015-04-30 10:52 ` [RFC PATCH 03/22] perf: add bpf common operations Wang Nan
2015-04-30 10:52 ` [RFC PATCH 04/22] perf tools: Add new 'perf bpf' command Wang Nan
2015-05-11  6:28   ` Namhyung Kim
2015-04-30 10:52 ` [RFC PATCH 05/22] perf bpf: open eBPF object file and do basic validation Wang Nan
2015-04-30 10:52 ` [RFC PATCH 06/22] perf bpf: check swap according to EHDR Wang Nan
2015-04-30 10:52 ` [RFC PATCH 07/22] perf bpf: iterater over elf sections to collect information Wang Nan
2015-04-30 10:52 ` [RFC PATCH 08/22] perf bpf: collect version and license from ELF Wang Nan
2015-04-30 10:52 ` [RFC PATCH 09/22] perf bpf: collect map definitions Wang Nan
2015-05-11  6:32   ` Namhyung Kim [this message]
2015-04-30 10:52 ` [RFC PATCH 10/22] perf bpf: collect config section in object Wang Nan
2015-04-30 10:52 ` [RFC PATCH 11/22] perf bpf: collect symbol table in object files Wang Nan
2015-04-30 10:52 ` [RFC PATCH 12/22] perf bpf: collect bpf programs from " Wang Nan
2015-04-30 10:52 ` [RFC PATCH 13/22] perf bpf: collects relocation sections from object file Wang Nan
2015-04-30 10:52 ` [RFC PATCH 14/22] perf bpf: config eBPF programs based on their names Wang Nan
2015-04-30 10:52 ` [RFC PATCH 15/22] perf bpf: config eBPF programs using config section Wang Nan
2015-04-30 10:52 ` [RFC PATCH 16/22] perf bpf: create maps needed by object file Wang Nan
2015-04-30 10:52 ` [RFC PATCH 17/22] perf bpf: relocation programs Wang Nan
2015-04-30 10:52 ` [RFC PATCH 18/22] perf bpf: load eBPF programs into kernel Wang Nan
2015-04-30 10:52 ` [RFC PATCH 19/22] perf bpf: dump eBPF program before loading Wang Nan
2015-04-30 10:52 ` [RFC PATCH 20/22] perf bpf: clean elf memory after loading Wang Nan
2015-04-30 10:52 ` [RFC PATCH 21/22] perf bpf: probe at kprobe points Wang Nan
2015-05-05 16:34   ` Masami Hiramatsu
2015-05-06  2:36     ` Wang Nan
2015-04-30 10:52 ` [RFC PATCH 22/22] perf bpf: attaches eBPF program to perf fd Wang Nan
2015-05-01  4:37 ` [RFC PATCH 00/22] perf tools: introduce 'perf bpf' command to load eBPF programs Alexei Starovoitov
2015-05-01 11:06   ` Peter Zijlstra
2015-05-01 11:49     ` Ingo Molnar
2015-05-01 16:56       ` Alexei Starovoitov
2015-05-01 17:06         ` Ingo Molnar
2015-05-05 15:39         ` Arnaldo Carvalho de Melo
2015-05-02  7:19   ` Wang Nan
2015-05-05  3:02     ` Alexei Starovoitov
2015-05-05  4:41       ` Wang Nan
2015-05-05  5:49         ` Alexei Starovoitov
2015-05-05  6:14           ` Wang Nan
2015-05-06  4:46             ` Wang Nan
2015-05-06  4:56               ` Alexei Starovoitov
2015-05-06  5:00                 ` Wang Nan
2015-05-01  7:16 ` Ingo Molnar
2015-05-05 21:52 ` Brendan Gregg

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=20150511063210.GC1630@sejong \
    --to=namhyung@kernel.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@kernel.org \
    --cc=ast@plumgrid.com \
    --cc=davem@davemloft.net \
    --cc=hekuang@huawei.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lizefan@kernel.org \
    --cc=masami.hiramatsu.pt@hitachi.com \
    --cc=mingo@redhat.com \
    --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