aboutsummaryrefslogtreecommitdiffstats
path: root/samples/bpf
diff options
context:
space:
mode:
authorMartin KaFai Lau <kafai@fb.com>2017-09-27 17:37:54 -0400
committerDavid S. Miller <davem@davemloft.net>2017-09-29 01:17:05 -0400
commit88cda1c9da02c8aa31e1d5dcf22e8a35cc8c19f2 (patch)
tree5096ddd73981e33a2164606461a45b56a189889c /samples/bpf
parentad5b177bd73f5107d97c36f56395c4281fb6f089 (diff)
bpf: libbpf: Provide basic API support to specify BPF obj name
This patch extends the libbpf to provide API support to allow specifying BPF object name. In tools/lib/bpf/libbpf, the C symbol of the function and the map is used. Regarding section name, all maps are under the same section named "maps". Hence, section name is not a good choice for map's name. To be consistent with map, bpf_prog also follows and uses its function symbol as the prog's name. This patch adds logic to collect function's symbols in libbpf. There is existing codes to collect the map's symbols and no change is needed. The bpf_load_program_name() and bpf_map_create_name() are added to take the name argument. For the other bpf_map_create_xxx() variants, a name argument is directly added to them. In samples/bpf, bpf_load.c in particular, the symbol is also used as the map's name and the map symbols has already been collected in the existing code. For bpf_prog, bpf_load.c does not collect the function symbol name. We can consider to collect them later if there is a need to continue supporting the bpf_load.c. Signed-off-by: Martin KaFai Lau <kafai@fb.com> Acked-by: Alexei Starovoitov <ast@fb.com> Acked-by: Daniel Borkmann <daniel@iogearbox.net> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'samples/bpf')
-rw-r--r--samples/bpf/bpf_load.c2
-rw-r--r--samples/bpf/map_perf_test_user.c1
2 files changed, 3 insertions, 0 deletions
diff --git a/samples/bpf/bpf_load.c b/samples/bpf/bpf_load.c
index 6aa50098dfb8..18b1c8dd0391 100644
--- a/samples/bpf/bpf_load.c
+++ b/samples/bpf/bpf_load.c
@@ -221,6 +221,7 @@ static int load_maps(struct bpf_map_data *maps, int nr_maps,
221 int inner_map_fd = map_fd[maps[i].def.inner_map_idx]; 221 int inner_map_fd = map_fd[maps[i].def.inner_map_idx];
222 222
223 map_fd[i] = bpf_create_map_in_map_node(maps[i].def.type, 223 map_fd[i] = bpf_create_map_in_map_node(maps[i].def.type,
224 maps[i].name,
224 maps[i].def.key_size, 225 maps[i].def.key_size,
225 inner_map_fd, 226 inner_map_fd,
226 maps[i].def.max_entries, 227 maps[i].def.max_entries,
@@ -228,6 +229,7 @@ static int load_maps(struct bpf_map_data *maps, int nr_maps,
228 numa_node); 229 numa_node);
229 } else { 230 } else {
230 map_fd[i] = bpf_create_map_node(maps[i].def.type, 231 map_fd[i] = bpf_create_map_node(maps[i].def.type,
232 maps[i].name,
231 maps[i].def.key_size, 233 maps[i].def.key_size,
232 maps[i].def.value_size, 234 maps[i].def.value_size,
233 maps[i].def.max_entries, 235 maps[i].def.max_entries,
diff --git a/samples/bpf/map_perf_test_user.c b/samples/bpf/map_perf_test_user.c
index a0310fc70057..519d9af4b04a 100644
--- a/samples/bpf/map_perf_test_user.c
+++ b/samples/bpf/map_perf_test_user.c
@@ -137,6 +137,7 @@ static void do_test_lru(enum test_type test, int cpu)
137 137
138 inner_lru_map_fds[cpu] = 138 inner_lru_map_fds[cpu] =
139 bpf_create_map_node(BPF_MAP_TYPE_LRU_HASH, 139 bpf_create_map_node(BPF_MAP_TYPE_LRU_HASH,
140 test_map_names[INNER_LRU_HASH_PREALLOC],
140 sizeof(uint32_t), 141 sizeof(uint32_t),
141 sizeof(long), 142 sizeof(long),
142 inner_lru_hash_size, 0, 143 inner_lru_hash_size, 0,