From: "Wangnan (F)" <wangnan0@huawei.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: <paulus@samba.org>, <a.p.zijlstra@chello.nl>, <mingo@redhat.com>,
<acme@kernel.org>, <namhyung@kernel.org>, <jolsa@kernel.org>,
<dsahern@gmail.com>, <daniel@iogearbox.net>,
<brendan.d.gregg@gmail.com>, <masami.hiramatsu.pt@hitachi.com>,
<lizefan@huawei.com>, <linux-kernel@vger.kernel.org>,
<pi3orama@163.com>, xiakaixu 00238161 <xiakaixu@huawei.com>
Subject: Re: [RFC PATCH v4 10/29] bpf tools: Collect map definitions from 'maps' section
Date: Thu, 28 May 2015 11:09:50 +0800 [thread overview]
Message-ID: <556686FE.105@huawei.com> (raw)
In-Reply-To: <20150528022833.GI20764@Alexeis-MacBook-Pro.local>
On 2015/5/28 10:28, Alexei Starovoitov wrote:
> On Thu, May 28, 2015 at 10:03:04AM +0800, Wangnan (F) wrote:
>>
>> On 2015/5/28 9:53, Alexei Starovoitov wrote:
>>> On Wed, May 27, 2015 at 05:19:45AM +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. This
>>>> patch copies the data of the whole section. Map data parsing should be
>>>> acted just before map loading.
>>>>
>>>> Signed-off-by: Wang Nan <wangnan0@huawei.com>
>>>> ---
>>> ...
>>>> +static int
>>>> +bpf_object__init_maps(struct bpf_object *obj, void *data,
>>>> + size_t size)
>>>> +{
>>>> + if (size == 0) {
>>>> + pr_debug("%s doesn't need map definition\n",
>>>> + obj->path);
>>>> + return 0;
>>>> + }
>>>> +
>>>> + obj->maps_buf = malloc(size);
>>>> + if (!obj->maps_buf) {
>>>> + pr_warning("malloc maps failed: %s\n", obj->path);
>>>> + return -ENOMEM;
>>>> + }
>>>> +
>>>> + obj->maps_buf_sz = size;
>>>> + memcpy(obj->maps_buf, data, size);
>>> why copy it? To create maps and apply fixups to instructions
>>> relo sections are needed anyway, so elf has to be open while
>>> this section is being processed. So why copy?
>>>
>> When creating maps, ELF file has been closed.
>>
>> I divide libelf info two phases: opening and loading. ELF file is closed
>> at the end of opening phase. I think some caller need 'opening' phase only.
>> For example, checking metadata in an eBPF object file. In this case, we
>> don't
>> need create map file descriptors.
> loading elf into memory, parsing it, copying map, prog, relo sections
> just to check metadata? That doesn't sound like real use case.
> imo it's cleaner to remember where maps and relocations are in a loaded elf,
> then create maps, patch copied progs and release all elf.
> This elfs are all very small, so we're not talking about large memory savings,
> but still.
>
So do you suggest me to create maps in opening phase?
In bpf_object__open:
struct bpf_object *bpf_object__open(const char *path)
{
....
if (bpf_object__elf_init(obj))
goto out;
/* Real useful things put here */
....
/* Here we collect map information */
if (bpf_object__elf_collect(obj))
goto out;
....
/* And ELF file is closed here */
bpf_object__elf_finish(obj);
....
}
You can see that, after bpf_object__open() return we won't have chance
to access map data. Therefore we must create maps in bpf_object__open().
However this breaks a law in current design that opening phase doesn't
talk to kernel with sys_bpf() at all. All related staff is done in loading
phase. This principle ensures that in every systems, no matter it support
sys_bpf() or not, can read eBPF object without failure.
In fact I didn't separate opening and loading when I start working on
libbpf.
However I soon found inconvenience that:
1. The uniform design doesn't allow users to adjust things before
doing real work;
2. In my development environment I write code on a server without
sys_bpf() support,
the uniform design prevent me to test my opening phase code. I
have to test it
in QEMU.
In addition, this copying gives libbpf an ability that it can open once and
load - unload - load - unload many times without reopening and reparsing the
ELF file.
Moreover, we are planning to introduce hardware PMU to eBPF in the way
like maps,
to give eBPF programs the ability to access hardware PMU counter. I
haven't think
it thoroughly so I didn't discuss it with you and others. I think it
should be
something like:
struct bpf_pmu {
/* attr of the hardware PMU which will be passed to perf_event_open
to create an FD */
};
SEC("hw_pmu")
struct bpf_pmu cache_misses = {
...
};
SEC("lock_page=lock_page")
int lock_page_hook(struct pt_regs *ctx)
{
...
counter = bpf_read_pmu_counter(&cache_misses);
...
}
(My colleague Xia Kaixu is working on it. I append him to the CC list).
Creating that PMU FDs may require perf to adjust more things than
programs and maps.
I believe that we shouldn't let libbpf to do its own without help from
caller. Therefore
the separation of opening and loading should be required.
What do you think?
Thank you.
next prev parent reply other threads:[~2015-05-28 3:10 UTC|newest]
Thread overview: 62+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-27 5:19 [RFC PATCH v4 00/29] perf tools: filtering events using eBPF programs Wang Nan
2015-05-27 5:19 ` [RFC PATCH v4 01/29] tools: Add __aligned_u64 to types.h Wang Nan
2015-05-27 13:00 ` Arnaldo Carvalho de Melo
2015-05-28 0:28 ` Wangnan (F)
2015-05-28 0:31 ` Arnaldo Carvalho de Melo
2015-05-27 5:19 ` [RFC PATCH v4 02/29] perf tools: Move linux/kernel.h to tools/include Wang Nan
2015-05-27 13:03 ` Arnaldo Carvalho de Melo
2015-05-27 5:19 ` [RFC PATCH v4 03/29] perf tools: Move linux/{list.h,poison.h} " Wang Nan
2015-05-27 13:15 ` Arnaldo Carvalho de Melo
2015-05-27 13:21 ` Arnaldo Carvalho de Melo
2015-05-27 15:30 ` Arnaldo Carvalho de Melo
2015-05-27 5:19 ` [RFC PATCH v4 04/29] bpf tools: Introduce 'bpf' library to tools Wang Nan
2015-05-27 5:19 ` [RFC PATCH v4 05/29] bpf tools: Allow caller to set printing function Wang Nan
2015-05-29 13:35 ` Namhyung Kim
2015-05-27 5:19 ` [RFC PATCH v4 06/29] bpf tools: Open eBPF object file and do basic validation Wang Nan
2015-05-28 1:44 ` Alexei Starovoitov
2015-05-27 5:19 ` [RFC PATCH v4 07/29] bpf tools: Check endianess and make libbpf fail early Wang Nan
2015-05-28 1:45 ` Alexei Starovoitov
2015-05-27 5:19 ` [RFC PATCH v4 08/29] bpf tools: Iterate over ELF sections to collect information Wang Nan
2015-05-28 1:46 ` Alexei Starovoitov
2015-05-27 5:19 ` [RFC PATCH v4 09/29] bpf tools: Collect version and license from ELF sections Wang Nan
2015-05-28 1:48 ` Alexei Starovoitov
2015-05-28 3:34 ` Wangnan (F)
2015-05-28 5:51 ` Alexei Starovoitov
2015-05-27 5:19 ` [RFC PATCH v4 10/29] bpf tools: Collect map definitions from 'maps' section Wang Nan
2015-05-28 1:53 ` Alexei Starovoitov
2015-05-28 2:03 ` Wangnan (F)
2015-05-28 2:28 ` Alexei Starovoitov
2015-05-28 3:09 ` Wangnan (F) [this message]
2015-05-28 6:09 ` Alexei Starovoitov
2015-05-28 7:14 ` Wangnan (F)
2015-05-29 3:35 ` Alexei Starovoitov
2015-05-29 3:59 ` Wangnan (F)
2015-06-01 2:12 ` Namhyung Kim
2015-06-01 5:19 ` Wangnan (F)
2015-06-01 6:03 ` Namhyung Kim
2015-06-01 13:01 ` Arnaldo Carvalho de Melo
2015-05-27 5:19 ` [RFC PATCH v4 11/29] bpf tools: Collect symbol table from SHT_SYMTAB section Wang Nan
2015-05-27 5:19 ` [RFC PATCH v4 12/29] bpf tools: Collect eBPF programs from their own sections Wang Nan
2015-05-27 5:19 ` [RFC PATCH v4 13/29] bpf tools: Collect relocation sections from SHT_REL sections Wang Nan
2015-05-27 5:19 ` [RFC PATCH v4 14/29] bpf tools: Record map accessing instructions for each program Wang Nan
2015-05-27 5:19 ` [RFC PATCH v4 15/29] bpf tools: Add bpf.c/h for common bpf operations Wang Nan
2015-05-28 1:55 ` Alexei Starovoitov
2015-05-29 14:44 ` Namhyung Kim
2015-05-27 5:19 ` [RFC PATCH v4 16/29] bpf tools: Create eBPF maps defined in an object file Wang Nan
2015-05-28 1:57 ` Alexei Starovoitov
2015-05-27 5:19 ` [RFC PATCH v4 17/29] bpf tools: Relocate eBPF programs Wang Nan
2015-06-01 5:32 ` Namhyung Kim
2015-06-01 6:36 ` Wangnan (F)
2015-05-27 5:19 ` [RFC PATCH v4 18/29] bpf tools: Introduce bpf_load_program() to bpf.c Wang Nan
2015-05-28 2:14 ` Alexei Starovoitov
2015-05-27 5:19 ` [RFC PATCH v4 19/29] bpf tools: Load eBPF programs in object files into kernel Wang Nan
2015-05-27 5:19 ` [RFC PATCH v4 20/29] bpf tools: Introduce accessors for struct bpf_program Wang Nan
2015-05-27 5:19 ` [RFC PATCH v4 21/29] bpf tools: Introduce accessors for struct bpf_object Wang Nan
2015-05-27 5:19 ` [RFC PATCH v4 22/29] bpf tools: Link all bpf objects onto a list Wang Nan
2015-05-27 5:19 ` [RFC PATCH v4 23/29] perf tools: Make perf depend on libbpf Wang Nan
2015-05-27 5:19 ` [RFC PATCH v4 24/29] perf record: Enable passing bpf object file to --event Wang Nan
2015-05-27 5:20 ` [RFC PATCH v4 25/29] perf tools: Parse probe points of eBPF programs during preparation Wang Nan
2015-05-27 5:20 ` [RFC PATCH v4 26/29] perf record: Probe at kprobe points Wang Nan
2015-05-27 5:20 ` [RFC PATCH v4 27/29] perf record: Load all eBPF object into kernel Wang Nan
2015-05-27 5:20 ` [RFC PATCH v4 28/29] perf tools: Add bpf_fd field to evsel and config it Wang Nan
2015-05-27 5:20 ` [RFC PATCH v4 29/29] perf tools: Attach eBPF program to perf event 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=556686FE.105@huawei.com \
--to=wangnan0@huawei.com \
--cc=a.p.zijlstra@chello.nl \
--cc=acme@kernel.org \
--cc=alexei.starovoitov@gmail.com \
--cc=brendan.d.gregg@gmail.com \
--cc=daniel@iogearbox.net \
--cc=dsahern@gmail.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lizefan@huawei.com \
--cc=masami.hiramatsu.pt@hitachi.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=paulus@samba.org \
--cc=pi3orama@163.com \
--cc=xiakaixu@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;
as well as URLs for NNTP newsgroup(s).