[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAEf4Bza6Bsee1i_ypbDogG5MsVFGW9pnatxHCn9PycW9eP2Gkw@mail.gmail.com>
Date: Wed, 22 Sep 2021 14:38:17 -0700
From: Andrii Nakryiko <andrii.nakryiko@...il.com>
To: Daniel Borkmann <daniel@...earbox.net>
Cc: Muhammad Falak R Wani <falakreyaz@...il.com>,
Alexei Starovoitov <ast@...nel.org>,
Andrii Nakryiko <andrii@...nel.org>,
Martin KaFai Lau <kafai@...com>,
Song Liu <songliubraving@...com>, Yonghong Song <yhs@...com>,
John Fastabend <john.fastabend@...il.com>,
KP Singh <kpsingh@...nel.org>,
Networking <netdev@...r.kernel.org>, bpf <bpf@...r.kernel.org>,
open list <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v2 bpf-next] libbpf: Use sysconf to simplify libbpf_num_possible_cpus
On Wed, Sep 22, 2021 at 2:22 PM Daniel Borkmann <daniel@...earbox.net> wrote:
>
> On 9/22/21 9:07 AM, Muhammad Falak R Wani wrote:
> > Simplify libbpf_num_possible_cpus by using sysconf(_SC_NPROCESSORS_CONF)
> > instead of parsing a file.
> > This patch is a part ([0]) of libbpf-1.0 milestone.
> >
> > [0] Closes: https://github.com/libbpf/libbpf/issues/383
> >
> > Signed-off-by: Muhammad Falak R Wani <falakreyaz@...il.com>
> > ---
> > tools/lib/bpf/libbpf.c | 17 ++++-------------
> > 1 file changed, 4 insertions(+), 13 deletions(-)
> >
> > diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> > index ef5db34bf913..f1c0abe5b58d 100644
> > --- a/tools/lib/bpf/libbpf.c
> > +++ b/tools/lib/bpf/libbpf.c
> > @@ -10898,25 +10898,16 @@ int parse_cpu_mask_file(const char *fcpu, bool **mask, int *mask_sz)
> >
> > int libbpf_num_possible_cpus(void)
> > {
> > - static const char *fcpu = "/sys/devices/system/cpu/possible";
> > static int cpus;
> > - int err, n, i, tmp_cpus;
> > - bool *mask;
> > + int tmp_cpus;
> >
> > tmp_cpus = READ_ONCE(cpus);
> > if (tmp_cpus > 0)
> > return tmp_cpus;
> >
> > - err = parse_cpu_mask_file(fcpu, &mask, &n);
> > - if (err)
> > - return libbpf_err(err);
> > -
> > - tmp_cpus = 0;
> > - for (i = 0; i < n; i++) {
> > - if (mask[i])
> > - tmp_cpus++;
> > - }
> > - free(mask);
> > + tmp_cpus = sysconf(_SC_NPROCESSORS_CONF);
> > + if (tmp_cpus < 1)
> > + return libbpf_err(-EINVAL);
>
> This approach is unfortunately broken, see also commit e00c7b216f34 ("bpf: fix
> multiple issues in selftest suite and samples") for more details:
Oh, that predates me. Thanks, Daniel!
Sorry, Muhammad, seems like current implementation is there for a
reason and will have to stay. Thanks a lot for working on this,
though. Hopefully you can help with other issues, though.
[...]
>
> Thanks,
> Daniel
>
> > WRITE_ONCE(cpus, tmp_cpus);
> > return tmp_cpus;
> >
>
Powered by blists - more mailing lists