bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrii Nakryiko <andrii@kernel.org>
To: <bpf@vger.kernel.org>, <ast@kernel.org>, <daniel@iogearbox.net>
Cc: <andrii@kernel.org>, <kernel-team@fb.com>
Subject: [PATCH v2 bpf-next 4/4] docs/bpf: update BPF map definition example
Date: Wed, 19 Jan 2022 22:05:29 -0800	[thread overview]
Message-ID: <20220120060529.1890907-5-andrii@kernel.org> (raw)
In-Reply-To: <20220120060529.1890907-1-andrii@kernel.org>

Use BTF-defined map definition in the documentation example.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
---
 Documentation/bpf/btf.rst | 32 ++++++++++++++------------------
 1 file changed, 14 insertions(+), 18 deletions(-)

diff --git a/Documentation/bpf/btf.rst b/Documentation/bpf/btf.rst
index 1ebf4c5c7ddc..ab08852e53ae 100644
--- a/Documentation/bpf/btf.rst
+++ b/Documentation/bpf/btf.rst
@@ -565,18 +565,15 @@ A map can be created with ``btf_fd`` and specified key/value type id.::
 In libbpf, the map can be defined with extra annotation like below:
 ::
 
-    struct bpf_map_def SEC("maps") btf_map = {
-        .type = BPF_MAP_TYPE_ARRAY,
-        .key_size = sizeof(int),
-        .value_size = sizeof(struct ipv_counts),
-        .max_entries = 4,
-    };
-    BPF_ANNOTATE_KV_PAIR(btf_map, int, struct ipv_counts);
+    struct {
+        __uint(type, BPF_MAP_TYPE_ARRAY);
+        __type(key, int);
+        __type(value, struct ipv_counts);
+        __uint(max_entries, 4);
+    } btf_map SEC(".maps");
 
-Here, the parameters for macro BPF_ANNOTATE_KV_PAIR are map name, key and
-value types for the map. During ELF parsing, libbpf is able to extract
-key/value type_id's and assign them to BPF_MAP_CREATE attributes
-automatically.
+During ELF parsing, libbpf is able to extract key/value type_id's and assign
+them to BPF_MAP_CREATE attributes automatically.
 
 .. _BPF_Prog_Load:
 
@@ -824,13 +821,12 @@ structure has bitfields. For example, for the following map,::
            ___A b1:4;
            enum A b2:4;
       };
-      struct bpf_map_def SEC("maps") tmpmap = {
-           .type = BPF_MAP_TYPE_ARRAY,
-           .key_size = sizeof(__u32),
-           .value_size = sizeof(struct tmp_t),
-           .max_entries = 1,
-      };
-      BPF_ANNOTATE_KV_PAIR(tmpmap, int, struct tmp_t);
+      struct {
+           __uint(type, BPF_MAP_TYPE_ARRAY);
+           __type(key, int);
+           __type(value, struct tmp_t);
+           __uint(max_entries, 1);
+      } tmpmap SEC(".maps");
 
 bpftool is able to pretty print like below:
 ::
-- 
2.30.2


  parent reply	other threads:[~2022-01-20  6:06 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-20  6:05 [PATCH v2 bpf-next 0/4] libbpf: deprecate legacy BPF map definitions Andrii Nakryiko
2022-01-20  6:05 ` [PATCH v2 bpf-next 1/4] selftests/bpf: fail build on compilation warning Andrii Nakryiko
2022-01-20  6:05 ` [PATCH v2 bpf-next 2/4] selftests/bpf: convert remaining legacy map definitions Andrii Nakryiko
2022-01-20  6:05 ` [PATCH v2 bpf-next 3/4] libbpf: deprecate legacy BPF " Andrii Nakryiko
2022-01-20 11:44   ` Toke Høiland-Jørgensen
2022-01-20 19:13     ` Andrii Nakryiko
2022-01-21 20:43       ` Toke Høiland-Jørgensen
2022-01-21 22:04         ` David Ahern
2022-01-24 16:21           ` Andrii Nakryiko
2022-01-24 16:15         ` Andrii Nakryiko
2022-01-25  0:27           ` David Ahern
2022-01-25  5:41             ` Andrii Nakryiko
2022-01-25 12:10           ` Toke Høiland-Jørgensen
2022-01-25 20:52             ` John Fastabend
2022-01-25 21:52               ` Toke Høiland-Jørgensen
2022-01-25 22:35                 ` John Fastabend
2022-01-26  0:01                   ` Andrii Nakryiko
2022-01-26  2:02                     ` David Ahern
2022-01-25 23:46             ` Andrii Nakryiko
2022-01-20  6:05 ` Andrii Nakryiko [this message]
2022-01-25 20:52 ` [PATCH v2 bpf-next 0/4] " John Fastabend

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=20220120060529.1890907-5-andrii@kernel.org \
    --to=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kernel-team@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).