Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for map_in_map performance #14

Merged
merged 2 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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