Skip to content

Commit

Permalink
Cleanup batch APIs and remove unused parameter (#3580)
Browse files Browse the repository at this point in the history
Signed-off-by: Alan Jowett <[email protected]>
Co-authored-by: Alan Jowett <[email protected]>
Co-authored-by: Sharmi <[email protected]>
  • Loading branch information
3 people authored May 29, 2024
1 parent b2f2acf commit a5ebdba
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 42 deletions.
6 changes: 2 additions & 4 deletions docs/eBpfExtensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,6 @@ typedef ebpf_result_t (*ebpf_program_invoke_function_t)(
/**
* @brief Prepare the eBPF program for batch invocation.
*
* @param[in] extension_client_binding_context The context provided by the extension client when the binding was created.
* @param[in] state_size The size of the state to be allocated, which should be greater than or equal to
* sizeof(ebpf_execution_context_state_t).
* @param[out] state The state to be used for batch invocation.
Expand All @@ -360,7 +359,7 @@ typedef ebpf_result_t (*ebpf_program_invoke_function_t)(
* @retval EBPF_EXTENSION_FAILED_TO_LOAD if required extension is not loaded.
*/
typedef ebpf_result_t (*ebpf_program_batch_begin_invoke_function_t)(
_In_ const void* extension_client_binding_context, size_t state_size, _Out_writes_(state_size) void* state);
size_t state_size, _Out_writes_(state_size) void* state);

/**
* @brief Invoke the eBPF program in batch mode.
Expand All @@ -381,13 +380,12 @@ typedef ebpf_result_t (*ebpf_program_batch_invoke_function_t)(
/**
* @brief Clean up the eBPF program after batch invocation.
*
* @param[in] extension_client_binding_context The context provided by the extension client when the binding was created.
* @param[in,out] state The state to be used for batch invocation.
*
* @retval EBPF_SUCCESS.
*/
typedef ebpf_result_t (*ebpf_program_batch_end_invoke_function_t)(
_In_ const void* extension_client_binding_context, _Inout_ void* state);
_Inout_ void* state);
```
The function pointer can be obtained from the client dispatch table as follows:
Expand Down
9 changes: 2 additions & 7 deletions include/ebpf_extension.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ typedef ebpf_result_t (*ebpf_program_invoke_function_t)(
/**
* @brief Prepare the eBPF program for batch invocation.
*
* @param[in] extension_client_binding_context The context provided by the extension client when the binding was
* created.
* @param[in] state_size The size of the state to be allocated, which should be greater than or equal to
* sizeof(ebpf_execution_context_state_t).
* @param[out] state The state to be used for batch invocation.
Expand All @@ -44,7 +42,7 @@ typedef ebpf_result_t (*ebpf_program_invoke_function_t)(
* @retval EBPF_EXTENSION_FAILED_TO_LOAD The required extension is not loaded.
*/
typedef ebpf_result_t (*ebpf_program_batch_begin_invoke_function_t)(
_In_ const void* extension_client_binding_context, size_t state_size, _Out_writes_(state_size) void* state);
size_t state_size, _Out_writes_(state_size) void* state);

/**
* @brief Invoke the eBPF program in batch mode.
Expand All @@ -66,14 +64,11 @@ typedef ebpf_result_t (*ebpf_program_batch_invoke_function_t)(
/**
* @brief Clean up the eBPF program after batch invocation.
*
* @param[in] extension_client_binding_context The context provided by the extension client when the binding was
* created.
* @param[in,out] state The state to be used for batch invocation.
*
* @retval EBPF_SUCCESS The operation was successful.
*/
typedef ebpf_result_t (*ebpf_program_batch_end_invoke_function_t)(
_In_ const void* extension_client_binding_context, _Inout_ void* state);
typedef ebpf_result_t (*ebpf_program_batch_end_invoke_function_t)(_Inout_ void* state);

typedef struct _ebpf_extension_program_dispatch_table
{
Expand Down
17 changes: 6 additions & 11 deletions libs/execution_context/ebpf_link.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ _ebpf_link_instance_invoke(
_In_ const void* extension_client_binding_context, _Inout_ void* program_context, _Out_ uint32_t* result);

static ebpf_result_t
_ebpf_link_instance_invoke_batch_begin(
_In_ const void* extension_client_binding_context, size_t state_size, _Out_writes_(state_size) void* state);
_ebpf_link_instance_invoke_batch_begin(size_t state_size, _Out_writes_(state_size) void* state);

static ebpf_result_t
_ebpf_link_instance_invoke_batch(
Expand All @@ -87,7 +86,7 @@ _ebpf_link_instance_invoke_batch(
_In_ const void* state);

static ebpf_result_t
_ebpf_link_instance_invoke_batch_end(_In_ const void* extension_client_binding_context, _Inout_ void* state);
_ebpf_link_instance_invoke_batch_end(_Inout_ void* state);

typedef enum _ebpf_link_dispatch_table_version
{
Expand Down Expand Up @@ -467,25 +466,22 @@ _ebpf_link_instance_invoke(
{
ebpf_execution_context_state_t state = {0};
ebpf_result_t return_value;
return_value = _ebpf_link_instance_invoke_batch_begin(
extension_client_binding_context, sizeof(ebpf_execution_context_state_t), &state);
return_value = _ebpf_link_instance_invoke_batch_begin(sizeof(ebpf_execution_context_state_t), &state);

if (return_value != EBPF_SUCCESS) {
goto Done;
}

return_value = _ebpf_link_instance_invoke_batch(extension_client_binding_context, program_context, result, &state);
(void)_ebpf_link_instance_invoke_batch_end(extension_client_binding_context, &state);
(void)_ebpf_link_instance_invoke_batch_end(&state);

Done:
return return_value;
}

static ebpf_result_t
_ebpf_link_instance_invoke_batch_begin(
_In_ const void* client_binding_context, size_t state_size, _Out_writes_(state_size) void* state)
_ebpf_link_instance_invoke_batch_begin(size_t state_size, _Out_writes_(state_size) void* state)
{
UNREFERENCED_PARAMETER(client_binding_context);
ebpf_execution_context_state_t* execution_context_state = (ebpf_execution_context_state_t*)state;
bool epoch_entered = false;
ebpf_result_t return_value;
Expand Down Expand Up @@ -514,9 +510,8 @@ _ebpf_link_instance_invoke_batch_begin(
}

static ebpf_result_t
_ebpf_link_instance_invoke_batch_end(_In_ const void* extension_client_binding_context, _Inout_ void* state)
_ebpf_link_instance_invoke_batch_end(_Inout_ void* state)
{
UNREFERENCED_PARAMETER(extension_client_binding_context);
ebpf_execution_context_state_t* execution_context_state = (ebpf_execution_context_state_t*)state;
ebpf_assert_success(ebpf_state_store(ebpf_program_get_state_index(), 0, execution_context_state));
ebpf_epoch_exit((ebpf_epoch_state_t*)(execution_context_state->epoch_state));
Expand Down
20 changes: 6 additions & 14 deletions tests/end_to_end/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,10 @@ typedef class _single_instance_hook : public _hook_helper
return EBPF_EXTENSION_FAILED_TO_LOAD;
}

ebpf_result (*batch_begin_function)(
_In_ const void* extension_client_binding_context,
size_t state_size,
_In_reads_bytes_(state_size) void* state);

ebpf_program_batch_begin_invoke_function_t batch_begin_function;
batch_begin_function = reinterpret_cast<decltype(batch_begin_function)>(client_dispatch_table->function[1]);

return batch_begin_function(client_binding_context, state_size, state);
return batch_begin_function(state_size, state);
}

_Must_inspect_result_ ebpf_result_t
Expand All @@ -246,25 +242,21 @@ typedef class _single_instance_hook : public _hook_helper
return EBPF_EXTENSION_FAILED_TO_LOAD;
}

ebpf_result_t (*batch_invoke_function)(
_In_ const void* extension_client_binding_context,
_Inout_ void* program_context,
_Out_ uint32_t* result,
_In_ const void* state);
ebpf_program_batch_invoke_function_t batch_invoke_function;
batch_invoke_function = reinterpret_cast<decltype(batch_invoke_function)>(client_dispatch_table->function[2]);
return batch_invoke_function(client_binding_context, program_context, result, state);
}

_Must_inspect_result_ ebpf_result_t
batch_end(_In_ const void* state)
batch_end(_In_ void* state)
{
if (client_binding_context == nullptr) {
return EBPF_EXTENSION_FAILED_TO_LOAD;
}

ebpf_result_t (*batch_end_function)(_In_ const void* extension_client_binding_context, _In_ const void* state);
ebpf_program_batch_end_invoke_function_t batch_end_function;
batch_end_function = reinterpret_cast<decltype(batch_end_function)>(client_dispatch_table->function[3]);
return batch_end_function(client_binding_context, state);
return batch_end_function(state);
}

private:
Expand Down
8 changes: 2 additions & 6 deletions undocked/tests/sample/ext/drv/sample_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -529,9 +529,7 @@ sample_ebpf_extension_invoke_batch_begin_program(_Inout_ ebpf_execution_context_
goto Exit;
}
ebpf_program_batch_begin_invoke_function_t batch_begin_function = hook_client->begin_batch_program_invoke;
const void* client_binding_context = hook_client->client_binding_context;

return_value = batch_begin_function(client_binding_context, sizeof(ebpf_execution_context_state_t), state);
return_value = batch_begin_function(sizeof(ebpf_execution_context_state_t), state);

Exit:
return return_value;
Expand Down Expand Up @@ -574,9 +572,7 @@ sample_ebpf_extension_invoke_batch_end_program(_Inout_ ebpf_execution_context_st
goto Exit;
}
ebpf_program_batch_end_invoke_function_t batch_end_function = hook_client->end_batch_program_invoke;
const void* client_binding_context = hook_client->client_binding_context;

return_value = batch_end_function(client_binding_context, state);
return_value = batch_end_function(state);

Exit:
return return_value;
Expand Down

0 comments on commit a5ebdba

Please sign in to comment.