netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Song Liu <songliubraving@fb.com>
To: Andrii Nakryiko <andriin@fb.com>
Cc: Andrii Nakryiko <andrii.nakryiko@gmail.com>,
	Alexei Starovoitov <ast@fb.com>,
	"daniel@iogearbox.net" <daniel@iogearbox.net>,
	"bpf@vger.kernel.org" <bpf@vger.kernel.org>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	Kernel Team <Kernel-team@fb.com>
Subject: Re: [PATCH v2 bpf-next 2/3] libbpf: auto-set PERF_EVENT_ARRAY size to number of CPUs
Date: Wed, 26 Jun 2019 18:57:49 +0000	[thread overview]
Message-ID: <3E535E64-3FD8-4B3D-BBBB-033057084319@fb.com> (raw)
In-Reply-To: <20190626061235.602633-3-andriin@fb.com>



> On Jun 25, 2019, at 11:12 PM, Andrii Nakryiko <andriin@fb.com> wrote:
> 
> For BPF_MAP_TYPE_PERF_EVENT_ARRAY typically correct size is number of
> possible CPUs. This is impossible to specify at compilation time. This
> change adds automatic setting of PERF_EVENT_ARRAY size to number of
> system CPUs, unless non-zero size is specified explicitly. This allows
> to adjust size for advanced specific cases, while providing convenient
> and logical defaults.
> 
> Signed-off-by: Andrii Nakryiko <andriin@fb.com>
> ---
> tools/lib/bpf/libbpf.c | 17 ++++++++++++++++-
> 1 file changed, 16 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index c74cc535902a..8f2b8a081ba7 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -2114,6 +2114,7 @@ static int
> bpf_object__create_maps(struct bpf_object *obj)
> {
> 	struct bpf_create_map_attr create_attr = {};
> +	int nr_cpus = 0;
> 	unsigned int i;
> 	int err;
> 
> @@ -2136,7 +2137,21 @@ bpf_object__create_maps(struct bpf_object *obj)
> 		create_attr.map_flags = def->map_flags;
> 		create_attr.key_size = def->key_size;
> 		create_attr.value_size = def->value_size;
> -		create_attr.max_entries = def->max_entries;
> +		if (def->type == BPF_MAP_TYPE_PERF_EVENT_ARRAY &&
> +		    !def->max_entries) {
> +			if (!nr_cpus)
> +				nr_cpus = libbpf_num_possible_cpus();
> +			if (nr_cpus < 0) {
> +				pr_warning("failed to determine number of system CPUs: %d\n",
> +					   nr_cpus);
> +				return nr_cpus;

I think we need to goto err_out here. 

Thanks,
Song


  reply	other threads:[~2019-06-26 18:58 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-26  6:12 [PATCH v2 bpf-next 0/3] libbpf: add perf buffer abstraction and API Andrii Nakryiko
2019-06-26  6:12 ` [PATCH v2 bpf-next 1/3] libbpf: add perf buffer API Andrii Nakryiko
2019-06-26 19:02   ` Song Liu
2019-06-27 21:04   ` Daniel Borkmann
2019-06-27 21:45     ` Andrii Nakryiko
2019-06-29  5:56       ` Andrii Nakryiko
2019-06-26  6:12 ` [PATCH v2 bpf-next 2/3] libbpf: auto-set PERF_EVENT_ARRAY size to number of CPUs Andrii Nakryiko
2019-06-26 18:57   ` Song Liu [this message]
2019-06-26 22:31     ` Andrii Nakryiko
2019-06-26  6:12 ` [PATCH v2 bpf-next 3/3] selftests/bpf: test perf buffer API Andrii Nakryiko
2019-06-26 11:55 ` [PATCH v2 bpf-next 0/3] libbpf: add perf buffer abstraction and API Toke Høiland-Jørgensen
2019-06-26 18:41   ` Andrii Nakryiko
2019-06-26 20:50     ` Toke Høiland-Jørgensen

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=3E535E64-3FD8-4B3D-BBBB-033057084319@fb.com \
    --to=songliubraving@fb.com \
    --cc=Kernel-team@fb.com \
    --cc=andrii.nakryiko@gmail.com \
    --cc=andriin@fb.com \
    --cc=ast@fb.com \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --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).