Commit 96c85308 authored by Andrii Nakryiko's avatar Andrii Nakryiko Committed by Alexei Starovoitov

docs/bpf: update BPF map definition example

Use BTF-defined map definition in the documentation example.
Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/r/20220120060529.1890907-5-andrii@kernel.orgSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parent 93b8952d
...@@ -565,18 +565,15 @@ A map can be created with ``btf_fd`` and specified key/value type id.:: ...@@ -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: In libbpf, the map can be defined with extra annotation like below:
:: ::
struct bpf_map_def SEC("maps") btf_map = { struct {
.type = BPF_MAP_TYPE_ARRAY, __uint(type, BPF_MAP_TYPE_ARRAY);
.key_size = sizeof(int), __type(key, int);
.value_size = sizeof(struct ipv_counts), __type(value, struct ipv_counts);
.max_entries = 4, __uint(max_entries, 4);
}; } btf_map SEC(".maps");
BPF_ANNOTATE_KV_PAIR(btf_map, int, struct ipv_counts);
Here, the parameters for macro BPF_ANNOTATE_KV_PAIR are map name, key and During ELF parsing, libbpf is able to extract key/value type_id's and assign
value types for the map. During ELF parsing, libbpf is able to extract them to BPF_MAP_CREATE attributes automatically.
key/value type_id's and assign them to BPF_MAP_CREATE attributes
automatically.
.. _BPF_Prog_Load: .. _BPF_Prog_Load:
...@@ -824,13 +821,12 @@ structure has bitfields. For example, for the following map,:: ...@@ -824,13 +821,12 @@ structure has bitfields. For example, for the following map,::
___A b1:4; ___A b1:4;
enum A b2:4; enum A b2:4;
}; };
struct bpf_map_def SEC("maps") tmpmap = { struct {
.type = BPF_MAP_TYPE_ARRAY, __uint(type, BPF_MAP_TYPE_ARRAY);
.key_size = sizeof(__u32), __type(key, int);
.value_size = sizeof(struct tmp_t), __type(value, struct tmp_t);
.max_entries = 1, __uint(max_entries, 1);
}; } tmpmap SEC(".maps");
BPF_ANNOTATE_KV_PAIR(tmpmap, int, struct tmp_t);
bpftool is able to pretty print like below: bpftool is able to pretty print like below:
:: ::
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment