Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
saxena-anurag committed Sep 6, 2024
1 parent 8fb250b commit 6cb9a81
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 21 deletions.
40 changes: 20 additions & 20 deletions libs/execution_context/ebpf_maps.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ typedef struct _ebpf_core_object_map
// Fewer partitions will result in more contention on the lock, but more partitions will consume more memory.
#define EBPF_LRU_MAXIMUM_PARTITIONS 8

#define ZERO_LENGTH_KEY(type) ((type) == BPF_MAP_TYPE_QUEUE || (type) == BPF_MAP_TYPE_STACK)

#define PER_CPU_MAP(type) \
((type) == BPF_MAP_TYPE_PERCPU_HASH || (type) == BPF_MAP_TYPE_PERCPU_ARRAY || \
(type) == BPF_MAP_TYPE_LRU_PERCPU_HASH)

#define MAP_UPDATE_SUPPORTED(type) ((type) != BPF_MAP_TYPE_RINGBUF)

/**
* @brief The BPF_MAP_TYPE_LRU_HASH is a hash table that stores a limited number of entries. When the map is full, the
* least recently used entry is removed to make room for a new entry. The map is implemented as a hash table with a pair
Expand Down Expand Up @@ -452,8 +460,7 @@ _delete_array_map(_In_ _Post_invalid_ ebpf_core_map_t* map)
ebpf_epoch_free(map);
}

EBPF_INLINE_HINT
ebpf_result_t
static ebpf_result_t
_find_array_map_entry(
_Inout_ ebpf_core_map_t* map, _In_opt_ const uint8_t* key, bool delete_on_success, _Outptr_ uint8_t** data)
{
Expand All @@ -473,8 +480,7 @@ _find_array_map_entry(
return EBPF_SUCCESS;
}

EBPF_INLINE_HINT
ebpf_result_t
static ebpf_result_t
_update_array_map_entry(
_Inout_ ebpf_core_map_t* map, _In_opt_ const uint8_t* key, _In_opt_ const uint8_t* data, ebpf_map_option_t option)
{
Expand Down Expand Up @@ -916,7 +922,7 @@ _delete_map_array_map_entry(_Inout_ ebpf_core_map_t* map, _In_ const uint8_t* ke
* @param[in] key Pointer to the key to search for.
* @returns Object pointer, or NULL if none.
*/
EBPF_INLINE_HINT _Ret_maybenull_ ebpf_core_object_t*
static _Ret_maybenull_ ebpf_core_object_t*
_get_object_from_array_map_entry(_Inout_ ebpf_core_map_t* map, _In_ const uint8_t* key)
{
uint32_t index = *(uint32_t*)key;
Expand Down Expand Up @@ -1493,8 +1499,7 @@ _reap_oldest_map_entry(_Inout_ ebpf_core_map_t* map)
}
}

EBPF_INLINE_HINT
ebpf_result_t
static ebpf_result_t
_find_hash_map_entry(
_Inout_ ebpf_core_map_t* map, _In_opt_ const uint8_t* key, bool delete_on_success, _Outptr_ uint8_t** data)
{
Expand Down Expand Up @@ -1528,7 +1533,7 @@ _find_hash_map_entry(
* @param[in] key Pointer to the key to search for.
* @returns Object pointer, or NULL if none.
*/
EBPF_INLINE_HINT _Ret_maybenull_ ebpf_core_object_t*
static _Ret_maybenull_ ebpf_core_object_t*
_get_object_from_hash_map_entry(_In_ ebpf_core_map_t* map, _In_ const uint8_t* key)
{
ebpf_core_object_t* object = NULL;
Expand All @@ -1545,8 +1550,7 @@ _get_object_from_hash_map_entry(_In_ ebpf_core_map_t* map, _In_ const uint8_t* k

volatile int32_t reap_attempt_counts[64] = {0};

EBPF_INLINE_HINT
ebpf_result_t
static ebpf_result_t
_update_hash_map_entry(
_Inout_ ebpf_core_map_t* map, _In_opt_ const uint8_t* key, _In_opt_ const uint8_t* data, ebpf_map_option_t option)
{
Expand Down Expand Up @@ -1747,7 +1751,7 @@ _ebpf_adjust_value_pointer(_In_ const ebpf_map_t* map, _Inout_ uint8_t** value)
{
uint32_t current_cpu;

if (!(ebpf_map_metadata_tables[map->ebpf_map_definition.type].per_cpu)) {
if (!PER_CPU_MAP(map->ebpf_map_definition.type)) {
return EBPF_SUCCESS;
}

Expand All @@ -1772,7 +1776,6 @@ _ebpf_adjust_value_pointer(_In_ const ebpf_map_t* map, _Inout_ uint8_t** value)
* @retval EBPF_INVALID_ARGUMENT Unable to perform this operation due to
* current CPU > allocated value buffer size.
*/
EBPF_INLINE_HINT
_Must_inspect_result_ ebpf_result_t
_update_entry_per_cpu(
_Inout_ ebpf_core_map_t* map, _In_ const uint8_t* key, _In_ const uint8_t* value, ebpf_map_option_t option)
Expand Down Expand Up @@ -1887,8 +1890,7 @@ _delete_lpm_map_entry(_In_ ebpf_core_map_t* map, _Inout_ const uint8_t* key)
return _delete_hash_map_entry(map, key);
}

EBPF_INLINE_HINT
ebpf_result_t
static ebpf_result_t
_update_lpm_map_entry(
_Inout_ ebpf_core_map_t* map, _In_opt_ const uint8_t* key, _In_opt_ const uint8_t* data, ebpf_map_option_t option)
{
Expand Down Expand Up @@ -1981,8 +1983,7 @@ _find_circular_map_entry(
return *data == NULL ? EBPF_OBJECT_NOT_FOUND : EBPF_SUCCESS;
}

EBPF_INLINE_HINT
ebpf_result_t
static ebpf_result_t
_update_circular_map_entry(
_Inout_ ebpf_core_map_t* map, _In_opt_ const uint8_t* key, _In_opt_ const uint8_t* data, ebpf_map_option_t option)
{
Expand Down Expand Up @@ -2669,7 +2670,7 @@ ebpf_map_update_entry(
// High volume call - Skip entry/exit logging.
ebpf_result_t result;

if (ebpf_map_metadata_tables[map->ebpf_map_definition.type].zero_length_key) {
if (ZERO_LENGTH_KEY(map->ebpf_map_definition.type)) {
if (key_size != 0) {
EBPF_LOG_MESSAGE_UINT64(
EBPF_TRACELOG_LEVEL_ERROR,
Expand Down Expand Up @@ -2700,7 +2701,7 @@ ebpf_map_update_entry(
return EBPF_INVALID_ARGUMENT;
}

if (ebpf_map_metadata_tables[map->ebpf_map_definition.type].update_entry == NULL) {
if (!MAP_UPDATE_SUPPORTED(map->ebpf_map_definition.type)) {
EBPF_LOG_MESSAGE_UINT64(
EBPF_TRACELOG_LEVEL_ERROR,
EBPF_TRACELOG_KEYWORD_MAP,
Expand All @@ -2710,8 +2711,7 @@ ebpf_map_update_entry(
return EBPF_OPERATION_NOT_SUPPORTED;
}

if ((flags & EBPF_MAP_FLAG_HELPER) &&
ebpf_map_metadata_tables[map->ebpf_map_definition.type].update_entry_per_cpu) {
if ((flags & EBPF_MAP_FLAG_HELPER) && PER_CPU_MAP(map->ebpf_map_definition.type)) {
UPDATE_ENTRY_PER_CPU(map->ebpf_map_definition.type, map, key, value, option, result);
} else {
UPDATE_ENTRY(map->ebpf_map_definition.type, map, key, value, option, result);
Expand Down
1 change: 0 additions & 1 deletion libs/runtime/ebpf_ring_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ ebpf_ring_buffer_destroy(_Frees_ptr_opt_ ebpf_ring_buffer_t* ring_buffer);
* @retval EBPF_SUCCESS Successfully wrote record ring buffer.
* @retval EBPF_OUT_OF_SPACE Unable to output to ring buffer due to inadequate space.
*/
EBPF_INLINE_HINT
_Must_inspect_result_ ebpf_result_t
ebpf_ring_buffer_output(_Inout_ ebpf_ring_buffer_t* ring_buffer, _In_reads_bytes_(length) uint8_t* data, size_t length);

Expand Down
Binary file modified spd/EbpfCore.spd
Binary file not shown.

0 comments on commit 6cb9a81

Please sign in to comment.