From: Lorenzo Bianconi <lorenzo@kernel.org>
To: Yonghong Song <yhs@fb.com>
Cc: bpf@vger.kernel.org, netdev@vger.kernel.org, ast@kernel.org,
davem@davemloft.net, brouer@redhat.com, daniel@iogearbox.net,
lorenzo.bianconi@redhat.com
Subject: Re: [PATCH bpf-next] samples/bpf: xdp_redirect_cpu: set MAX_CPUS according to NR_CPUS
Date: Tue, 12 May 2020 12:51:09 +0200 [thread overview]
Message-ID: <20200512105109.GA79080@localhost.localdomain> (raw)
In-Reply-To: <c3fa2001-ef77-46c4-c0de-3335e7934db9@fb.com>
[-- Attachment #1: Type: text/plain, Size: 2480 bytes --]
>
>
> On 5/11/20 1:24 PM, Lorenzo Bianconi wrote:
> > xdp_redirect_cpu is currently failing in bpf_prog_load_xattr()
> > allocating cpu_map map if CONFIG_NR_CPUS is less than 64 since
> > cpu_map_alloc() requires max_entries to be less than NR_CPUS.
> > Set cpu_map max_entries according to NR_CPUS in xdp_redirect_cpu_kern.c
> > and get currently running cpus in xdp_redirect_cpu_user.c
> >
> > Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
> > ---
> > samples/bpf/xdp_redirect_cpu_kern.c | 2 +-
> > samples/bpf/xdp_redirect_cpu_user.c | 29 ++++++++++++++++-------------
> > 2 files changed, 17 insertions(+), 14 deletions(-)
> >
[...]
> > static void mark_cpus_unavailable(void)
> > {
> > - __u32 invalid_cpu = MAX_CPUS;
> > + __u32 invalid_cpu = n_cpus;
> > int ret, i;
> > - for (i = 0; i < MAX_CPUS; i++) {
> > + for (i = 0; i < n_cpus; i++) {
> > ret = bpf_map_update_elem(cpus_available_map_fd, &i,
> > &invalid_cpu, 0);
> > if (ret) {
> > @@ -688,6 +689,8 @@ int main(int argc, char **argv)
> > int prog_fd;
> > __u32 qsize;
> > + n_cpus = get_nprocs();
>
> get_nprocs() gets the number of available cpus, not including offline cpus.
> But gaps may exist in cpus, e.g., get_nprocs() returns 4, and cpus are
> 0-1,4-5. map updates will miss cpus 4-5. And in this situation,
> map_update will fail on offline cpus.
>
> This sample test does not need to deal with complication of
> cpu offlining, I think. Maybe we can get
> n_cpus = get_nprocs();
> n_cpus_conf = get_nprocs_conf();
> if (n_cpus != n_cpus_conf) {
> /* message that some cpus are offline and not supported. */
> return error
> }
>
Hi Yonghong,
thanks for pointing this out. Why not just use:
n_cpus = get_nprocs_conf()
and let the user pick the right cpu id with 'c' option (since it is mandatory)?
Regards,
Lorenzo
> > +
> > /* Notice: choosing he queue size is very important with the
> > * ixgbe driver, because it's driver page recycling trick is
> > * dependend on pages being returned quickly. The number of
> > @@ -757,7 +760,7 @@ int main(int argc, char **argv)
> > case 'c':
> > /* Add multiple CPUs */
> > add_cpu = strtoul(optarg, NULL, 0);
> > - if (add_cpu >= MAX_CPUS) {
> > + if (add_cpu >= n_cpus) {
> > fprintf(stderr,
> > "--cpu nr too large for cpumap err(%d):%s\n",
> > errno, strerror(errno));
> >
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
next prev parent reply other threads:[~2020-05-12 10:51 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-11 20:24 [PATCH bpf-next] samples/bpf: xdp_redirect_cpu: set MAX_CPUS according to NR_CPUS Lorenzo Bianconi
2020-05-12 0:35 ` Yonghong Song
2020-05-12 10:51 ` Lorenzo Bianconi [this message]
2020-05-12 14:22 ` Yonghong Song
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=20200512105109.GA79080@localhost.localdomain \
--to=lorenzo@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=brouer@redhat.com \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=lorenzo.bianconi@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=yhs@fb.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).