bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrii Nakryiko <andrii.nakryiko@gmail.com>
To: Yonghong Song <yhs@fb.com>
Cc: Paul Chaignon <paul.chaignon@orange.com>,
	"bpf@vger.kernel.org" <bpf@vger.kernel.org>,
	"paul.chaignon@gmail.com" <paul.chaignon@gmail.com>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>, Martin Lau <kafai@fb.com>,
	Song Liu <songliubraving@fb.com>,
	Andrii Nakryiko <andriin@fb.com>
Subject: Re: [PATCH bpf-next 1/3] bpf: Single-cpu updates for per-cpu maps
Date: Wed, 18 Dec 2019 16:49:27 -0800	[thread overview]
Message-ID: <CAEf4BzZe7hoq1CsCf8am=w2pHr6j+S5dKE08K38PP8RL6At2Zg@mail.gmail.com> (raw)
In-Reply-To: <377d5ad0-cf4f-4c8b-c23d-ed37dce4ad9f@fb.com>

On Wed, Dec 18, 2019 at 11:11 AM Yonghong Song <yhs@fb.com> wrote:
>
>
>
> On 12/18/19 6:23 AM, Paul Chaignon wrote:
> > Currently, userspace programs have to update the values of all CPUs at
> > once when updating per-cpu maps.  This limitation prevents the update of
> > a single CPU's value without the risk of missing concurrent updates on
> > other CPU's values.
> >
> > This patch allows userspace to update the value of a specific CPU in
> > per-cpu maps.  The CPU whose value should be updated is encoded in the
> > 32 upper-bits of the flags argument, as follows.  The new BPF_CPU flag
> > can be combined with existing flags.
> >
> >    bpf_map_update_elem(..., cpuid << 32 | BPF_CPU)
>
> Some additional comments beyond Alexei's one.
>
> >
> > Signed-off-by: Paul Chaignon <paul.chaignon@orange.com>
> > ---
> >   include/uapi/linux/bpf.h       |  4 +++
> >   kernel/bpf/arraymap.c          | 19 ++++++++-----
> >   kernel/bpf/hashtab.c           | 49 ++++++++++++++++++++--------------
> >   kernel/bpf/local_storage.c     | 16 +++++++----
> >   kernel/bpf/syscall.c           | 17 +++++++++---
> >   tools/include/uapi/linux/bpf.h |  4 +++
> >   6 files changed, 74 insertions(+), 35 deletions(-)
> >
> > diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
> > index dbbcf0b02970..2efb17d2c77a 100644
> > --- a/include/uapi/linux/bpf.h
> > +++ b/include/uapi/linux/bpf.h
> > @@ -316,6 +316,10 @@ enum bpf_attach_type {
> >   #define BPF_NOEXIST 1 /* create new element if it didn't exist */
> >   #define BPF_EXIST   2 /* update existing element */
> >   #define BPF_F_LOCK  4 /* spin_lock-ed map_lookup/map_update */
> > +#define BPF_CPU              8 /* single-cpu update for per-cpu maps */
> > +
> > +/* CPU mask for single-cpu updates */
> > +#define BPF_CPU_MASK 0xFFFFFFFF00000000ULL
> BPF_F_CPU_MASK?

Maybe even define this as a function-like macro:

#define BPF_F_CPU_NR(cpu) ((cpu) << 32)

so that it can be easily combined with other flags in code like so:

bpf_map_update_element(...., BPF_F_LOCK | BPF_F_CPU_NR(10))

BPF_F_CPU_NR can automatically set BPF_F_CPU flag as well, btw.

[...]

  reply	other threads:[~2019-12-19  0:49 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-18 14:22 [PATCH bpf-next 0/3] Single-cpu updates for per-cpu maps Paul Chaignon
2019-12-18 14:23 ` [PATCH bpf-next 1/3] bpf: " Paul Chaignon
2019-12-18 18:00   ` Alexei Starovoitov
2019-12-19  9:14     ` Paul Chaignon
2019-12-18 19:10   ` Yonghong Song
2019-12-19  0:49     ` Andrii Nakryiko [this message]
2019-12-18 14:23 ` [PATCH bpf-next 2/3] selftests/bpf: Tests for single-cpu updates of " Paul Chaignon
2019-12-18 14:23 ` [PATCH bpf-next 3/3] bpftool: Support single-cpu updates for " Paul Chaignon

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='CAEf4BzZe7hoq1CsCf8am=w2pHr6j+S5dKE08K38PP8RL6At2Zg@mail.gmail.com' \
    --to=andrii.nakryiko@gmail.com \
    --cc=andriin@fb.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kafai@fb.com \
    --cc=netdev@vger.kernel.org \
    --cc=paul.chaignon@gmail.com \
    --cc=paul.chaignon@orange.com \
    --cc=songliubraving@fb.com \
    --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).