Add performance test for LRU map (#607)

* Add performance test for LRU map

Signed-off-by: Alan Jowett <alanjo@microsoft.com>

* Add additional test for BPF_MAP_TYPE_LRU_HASH

Signed-off-by: Alan Jowett <alanjo@microsoft.com>

* More bug fixes

Signed-off-by: Alan Jowett <alanjo@microsoft.com>

* Fix build break

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
This commit is contained in:
Alan Jowett 2021-10-01 18:07:19 -06:00 коммит произвёл GitHub
Родитель 1bbbc41233
Коммит 244325d8cd
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 48 добавлений и 5 удалений

Просмотреть файл

@ -730,7 +730,7 @@ _update_hash_map_entry(
entry_count = ebpf_hash_table_key_count((ebpf_hash_table_t*)map->data);
if ((entry_count == map->ebpf_map_definition.max_entries) &&
if ((entry_count >= map->ebpf_map_definition.max_entries) &&
(ebpf_hash_table_find((ebpf_hash_table_t*)map->data, key, &value) != EBPF_SUCCESS) &&
!_reap_oldest_map_entry(map))
result = EBPF_INVALID_ARGUMENT;

Просмотреть файл

@ -235,7 +235,6 @@ _ebpf_hash_table_replace_bucket(
{
ebpf_result_t result;
size_t index;
size_t old_data_index = MAXSIZE_T;
size_t entry_size = EBPF_OFFSET_OF(ebpf_hash_bucket_entry_t, key) + hash_table->key_size;
uint8_t* old_data = NULL;
uint8_t* new_data = NULL;
@ -265,6 +264,7 @@ _ebpf_hash_table_replace_bucket(
}
for (;;) {
size_t old_data_index = MAXSIZE_T;
size_t old_bucket_count = 0;
size_t new_bucket_count = 0;

Просмотреть файл

@ -4,6 +4,7 @@
#define TEST_AREA "ExecutionContext"
#include <numeric>
#include <optional>
#include "performance.h"
@ -82,11 +83,15 @@ typedef class _ebpf_program_test_state
typedef class _ebpf_map_test_state
{
public:
_ebpf_map_test_state(ebpf_map_type_t type)
_ebpf_map_test_state(ebpf_map_type_t type, std::optional<uint32_t> map_size = {})
{
ebpf_utf8_string_t name{(uint8_t*)"test", 4};
ebpf_map_definition_in_memory_t definition{
sizeof(ebpf_map_definition_in_memory_t), type, sizeof(uint32_t), sizeof(uint64_t), ebpf_get_cpu_count()};
sizeof(ebpf_map_definition_in_memory_t),
type,
sizeof(uint32_t),
sizeof(uint64_t),
map_size.has_value() ? map_size.value() : ebpf_get_cpu_count()};
REQUIRE(ebpf_core_initiate() == EBPF_SUCCESS);
REQUIRE(ebpf_map_create(&name, &definition, ebpf_handle_invalid, &map) == EBPF_SUCCESS);
@ -136,6 +141,16 @@ typedef class _ebpf_map_test_state
ebpf_epoch_exit();
}
void
test_update_lru()
{
uint32_t key = ebpf_random_uint32();
uint64_t value = 0;
ebpf_epoch_enter();
ebpf_map_update_entry(map, 0, (uint8_t*)&key, 0, (uint8_t*)&value, EBPF_ANY, EBPF_MAP_FLAG_HELPER);
ebpf_epoch_exit();
}
private:
ebpf_map_t* map;
} ebpf_map_test_state_t;
@ -248,6 +263,12 @@ _map_update_test(uint32_t cpu_id)
_ebpf_map_test_state_instance->test_update(cpu_id);
}
static void
_map_update_lru_test()
{
_ebpf_map_test_state_instance->test_update_lru();
}
static void
_lpm_trie_ipv4_find()
{
@ -274,6 +295,8 @@ _ebpf_map_type_t_to_string(ebpf_map_type_t type)
return "BPF_MAP_TYPE_HASH_OF_MAPS";
case BPF_MAP_TYPE_ARRAY_OF_MAPS:
return "BPF_MAP_TYPE_ARRAY_OF_MAPS";
case BPF_MAP_TYPE_LRU_HASH:
return "BPF_MAP_TYPE_LRU_HASH";
default:
return "Error";
}
@ -324,6 +347,21 @@ test_bpf_map_update_elem(bool preemptible)
measure.run_test();
}
template <ebpf_map_type_t map_type>
void
test_bpf_map_update_lru_elem(bool preemptible)
{
size_t iterations = 1000;
ebpf_map_test_state_t map_test_state(map_type, {100});
_ebpf_map_test_state_instance = &map_test_state;
std::string name = __FUNCTION__;
name += "<";
name += _ebpf_map_type_t_to_string(map_type);
name += ">";
_performance_measure measure(name.c_str(), preemptible, _map_update_lru_test, iterations);
measure.run_test();
}
void
test_program_invoke_jit(bool preemptible)
{
@ -375,18 +413,23 @@ PERF_TEST(test_bpf_map_lookup_elem_read<BPF_MAP_TYPE_HASH>);
PERF_TEST(test_bpf_map_lookup_elem_read<BPF_MAP_TYPE_ARRAY>);
PERF_TEST(test_bpf_map_lookup_elem_read<BPF_MAP_TYPE_PERCPU_HASH>);
PERF_TEST(test_bpf_map_lookup_elem_read<BPF_MAP_TYPE_PERCPU_ARRAY>);
PERF_TEST(test_bpf_map_lookup_elem_read<BPF_MAP_TYPE_LRU_HASH>);
PERF_TEST(test_bpf_map_lookup_elem_write<BPF_MAP_TYPE_HASH>);
PERF_TEST(test_bpf_map_lookup_elem_write<BPF_MAP_TYPE_ARRAY>);
PERF_TEST(test_bpf_map_lookup_elem_write<BPF_MAP_TYPE_PERCPU_HASH>);
PERF_TEST(test_bpf_map_lookup_elem_write<BPF_MAP_TYPE_PERCPU_ARRAY>);
PERF_TEST(test_bpf_map_lookup_elem_write<BPF_MAP_TYPE_LRU_HASH>);
PERF_TEST(test_bpf_map_update_elem<BPF_MAP_TYPE_HASH>);
PERF_TEST(test_bpf_map_update_elem<BPF_MAP_TYPE_ARRAY>);
PERF_TEST(test_bpf_map_update_elem<BPF_MAP_TYPE_PERCPU_HASH>);
PERF_TEST(test_bpf_map_update_elem<BPF_MAP_TYPE_PERCPU_ARRAY>);
PERF_TEST(test_bpf_map_update_elem<BPF_MAP_TYPE_LRU_HASH>);
PERF_TEST(test_bpf_map_update_lru_elem<BPF_MAP_TYPE_LRU_HASH>);
PERF_TEST(test_lpm_trie_ipv4<1024>);
PERF_TEST(test_lpm_trie_ipv4<1024 * 16>);
PERF_TEST(test_lpm_trie_ipv4<1024 * 256>);
PERF_TEST(test_lpm_trie_ipv4<1024 * 1024>);
PERF_TEST(test_lpm_trie_ipv4<1024 * 1024>);