netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Borkmann <daniel@iogearbox.net>
To: Andrii Nakryiko <andriin@fb.com>
Cc: bpf@vger.kernel.org, netdev@vger.kernel.org, ast@fb.com,
	andrii.nakryiko@gmail.com, kernel-team@fb.com
Subject: Re: [PATCH bpf-next] libbpf: generate more efficient BPF_CORE_READ code
Date: Fri, 11 Oct 2019 23:26:31 +0200	[thread overview]
Message-ID: <20191011212631.GE21131@pc-63.home> (raw)
In-Reply-To: <20191011023847.275936-1-andriin@fb.com>

On Thu, Oct 10, 2019 at 07:38:47PM -0700, Andrii Nakryiko wrote:
> 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>

Applied, thanks!

      reply	other threads:[~2019-10-11 21:26 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-11  2:38 [PATCH bpf-next] libbpf: generate more efficient BPF_CORE_READ code Andrii Nakryiko
2019-10-11 21:26 ` Daniel Borkmann [this message]

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=20191011212631.GE21131@pc-63.home \
    --to=daniel@iogearbox.net \
    --cc=andrii.nakryiko@gmail.com \
    --cc=andriin@fb.com \
    --cc=ast@fb.com \
    --cc=bpf@vger.kernel.org \
    --cc=kernel-team@fb.com \
    --cc=netdev@vger.kernel.org \
    /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).