Skip to content

Commit

Permalink
Merge pull request #14 from Alan-Jowett/map_in_map
Browse files Browse the repository at this point in the history
Add tests for map_in_map performance
  • Loading branch information
Alan-Jowett authored Oct 27, 2023
2 parents fe55919 + 8bfbde5 commit d2c32f1
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 9 deletions.
3 changes: 2 additions & 1 deletion bpf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ set(test_cases
"lpm,lpm_16384,-DMAX_ENTRIES=16384"
"lpm,lpm_262144,-DMAX_ENTRIES=262144"
"lpm,lpm_1048576,-DMAX_ENTRIES=1048576"
"map_in_map"
"map_in_map,hash_of_array,-DTYPE=BPF_MAP_TYPE_HASH_OF_MAPS"
"map_in_map,array_of_array,-DTYPE=BPF_MAP_TYPE_ARRAY_OF_MAPS"
"rolling_lru"
"tail_call"
"xdp"
Expand Down
20 changes: 12 additions & 8 deletions bpf/map_in_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
#define MAX_ENTRIES 8192
#endif

#if !defined(TYPE)
#define TYPE BPF_MAP_TYPE_HASH_OF_MAPS
#endif

struct
{
__uint(type, BPF_MAP_TYPE_HASH);
Expand All @@ -17,7 +21,7 @@ struct

struct
{
__uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS);
__uint(type, TYPE);
__type(key, unsigned int);
__type(value, unsigned int);
__uint(max_entries, 1);
Expand Down Expand Up @@ -50,11 +54,11 @@ SEC("xdp/read") int read(void* ctx)
{
int outer_key = 0;
int key = bpf_get_prandom_u32() % MAX_ENTRIES;
void* inner_map = bpf_map_lookup_elem(&outer_map, &outer_key);
if (!inner_map) {
return 1;
void* map = bpf_map_lookup_elem(&outer_map, &outer_key);
if (!map) {
return 2;
}
int* value = bpf_map_lookup_elem(inner_map, &key);
int* value = bpf_map_lookup_elem(map, &key);
if (value) {
return 0;
}
Expand All @@ -66,9 +70,9 @@ SEC("xdp/update") int update(void* ctx)
{
int outer_key = 0;
int key = bpf_get_prandom_u32() % MAX_ENTRIES;
void* inner_map = bpf_map_lookup_elem(&outer_map, &outer_key);
if (!inner_map) {
void* map = bpf_map_lookup_elem(&outer_map, &outer_key);
if (!map) {
return 1;
}
return bpf_map_update_elem(inner_map, &key, &key, BPF_ANY);
return bpf_map_update_elem(map, &key, &key, BPF_ANY);
}
42 changes: 42 additions & 0 deletions bpf/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -426,4 +426,46 @@ tests:
program_cpu_assignment:
test_bpf_get_smp_processor_id: all

- name: BPF_MAP_TYPE_ARRAY_OF_MAPS read
description: Tests the BPF_MAP_TYPE_ARRAY_OF_MAPS map type.
elf_file: array_of_array.o
map_state_preparation:
program: prepare
iteration_count: 8192
iteration_count: 10000000
program_cpu_assignment:
read: all

- name: BPF_MAP_TYPE_ARRAY_OF_MAPS update
description: Tests the BPF_MAP_TYPE_ARRAY_OF_MAPS map type.
elf_file: array_of_array.o
map_state_preparation:
program: prepare
iteration_count: 8192
iteration_count: 10000000
program_cpu_assignment:
update: all

- name: BPF_MAP_TYPE_HASH_OF_MAPS read
description: Tests the BPF_MAP_TYPE_HASH_OF_MAPS map type.
elf_file: hash_of_array.o
platform: Linux
map_state_preparation:
program: prepare
iteration_count: 8192
iteration_count: 10000000
program_cpu_assignment:
read: all

- name: BPF_MAP_TYPE_HASH_OF_MAPS update
description: Tests the BPF_MAP_TYPE_HASH_OF_MAPS map type.
elf_file: hash_of_array.o
platform: Linux
map_state_preparation:
program: prepare
iteration_count: 8192
iteration_count: 10000000
program_cpu_assignment:
update: all

# Add more test cases as needed

0 comments on commit d2c32f1

Please sign in to comment.