diff options
author | Andrii Nakryiko <andriin@fb.com> | 2019-10-11 04:38:47 +0200 |
---|---|---|
committer | Daniel Borkmann <daniel@iogearbox.net> | 2019-10-11 22:35:46 +0200 |
commit | 409017847d2014db8ab1da49dd48182af88344b7 (patch) | |
tree | cd6f2070bf31969ce71d5f88a4b41dc66d67a9f3 /tools/lib/bpf/btf_dump.c | |
parent | xdp: Trivial, fix spelling in function description (diff) | |
download | linux-409017847d2014db8ab1da49dd48182af88344b7.tar.xz linux-409017847d2014db8ab1da49dd48182af88344b7.zip |
libbpf: Generate more efficient BPF_CORE_READ code
Existing BPF_CORE_READ() macro generates slightly suboptimal code. If
there are intermediate pointers to be read, initial source pointer is
going to be assigned into a temporary variable and then temporary
variable is going to be uniformly used as a "source" pointer for all
intermediate pointer reads. Schematically (ignoring all the type casts),
BPF_CORE_READ(s, a, b, c) is expanded into:
({
const void *__t = src;
bpf_probe_read(&__t, sizeof(*__t), &__t->a);
bpf_probe_read(&__t, sizeof(*__t), &__t->b);
typeof(s->a->b->c) __r;
bpf_probe_read(&__r, sizeof(*__r), &__t->c);
})
This initial `__t = src` makes calls more uniform, but causes slightly
less optimal register usage sometimes when compiled with Clang. This can
cascase into, e.g., more register spills.
This patch fixes this issue by generating more optimal sequence:
({
const void *__t;
bpf_probe_read(&__t, sizeof(*__t), &src->a); /* <-- src here */
bpf_probe_read(&__t, sizeof(*__t), &__t->b);
typeof(s->a->b->c) __r;
bpf_probe_read(&__r, sizeof(*__r), &__t->c);
})
Fixes: 7db3822ab991 ("libbpf: Add BPF_CORE_READ/BPF_CORE_READ_INTO helpers")
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20191011023847.275936-1-andriin@fb.com
Diffstat (limited to 'tools/lib/bpf/btf_dump.c')
0 files changed, 0 insertions, 0 deletions