All of lore.kernel.org
 help / color / mirror / Atom feed
From: Donald Hunter <donald.hunter@gmail.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: bpf <bpf@vger.kernel.org>,
	"open list:DOCUMENTATION" <linux-doc@vger.kernel.org>,
	dave@dtucker.co.uk
Subject: Re: [PATCH bpf-next v7 1/1] bpf, docs: document BPF_MAP_TYPE_ARRAY
Date: Fri, 21 Oct 2022 14:37:38 +0100	[thread overview]
Message-ID: <m2fsfhuwkd.fsf@gmail.com> (raw)
In-Reply-To: <CAADnVQLRyP2hgvmLubnCdZuPHofQ8CGRiGq_a2FQy_ZzRimiEw@mail.gmail.com> (Alexei Starovoitov's message of "Wed, 19 Oct 2022 17:05:32 -0700")

Alexei Starovoitov <alexei.starovoitov@gmail.com> writes:

> On Fri, Oct 7, 2022 at 9:39 AM Donald Hunter <donald.hunter@gmail.com> wrote:
>
> Actually all values are rounded up to 8.
> Maybe we should say that all array elements are aligned to 8
> instead of values are rounded?
> Because values_size=4 stays as 4 from bpf prog pov.
> The progs cannot access bytes 5,6,7,8 though that memory is consumed.

Agreed, I will reword to mention alignment instead of rounding.

>> +When using a ``BPF_MAP_TYPE_PERCPU_ARRAY`` the ``bpf_map_update_elem()`` and
>> +``bpf_map_lookup_elem()`` helpers automatically access the hash slot for the
>> +current CPU.
>
> hash slot?
> the copy paste went wrong? :)

Good catch.

>> +    int bpf_prog(struct __sk_buff *skb)
>> +    {
>> +            int index = load_byte(skb,
>> +                                  ETH_HLEN + offsetof(struct iphdr, protocol));
>> +            long *value;
>
> Please avoid using deprecated instructions like load_byte in examples.

Will rewrite to use bpf_skb_load_bytes.

>> +    int create_array() {
>> +            int fd;
>> +            LIBBPF_OPTS(bpf_map_create_opts, opts, .map_flags = BPF_F_MMAPABLE);
>
> Add empty line pls.

Ack.

>> +    int lookup(int fd) {
>> +            __u32 index = 42;
>> +            long value;
>> +            int ret = bpf_map_lookup_elem(fd, &index, &value);
>
> Empty line pls.
> Or better yet do 'int ret;'
> and ret = bpf_map... on a separate line.

Ack.

>> +    int lookup(int fd) {
>> +            int ncpus = libbpf_num_possible_cpus();
>> +            __u32 index = 42, j;
>> +            long values[ncpus];
>> +            int ret = bpf_map_lookup_elem(fd, &index, &values);
>
> same here.

Ack. Thansk for the review!

      reply	other threads:[~2022-10-21 13:38 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-07 16:27 [PATCH bpf-next v7 0/1] Document BPF_MAP_TYPE_ARRAY Donald Hunter
2022-10-07 16:27 ` [PATCH bpf-next v7 1/1] bpf, docs: document BPF_MAP_TYPE_ARRAY Donald Hunter
2022-10-20  0:05   ` Alexei Starovoitov
2022-10-21 13:37     ` Donald Hunter [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=m2fsfhuwkd.fsf@gmail.com \
    --to=donald.hunter@gmail.com \
    --cc=alexei.starovoitov@gmail.com \
    --cc=bpf@vger.kernel.org \
    --cc=dave@dtucker.co.uk \
    --cc=linux-doc@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.