Add ComputeBudget tuner (#12476)
This commit is contained in:
27
programs/bpf/c/src/sanity++/sanity++.cc
Normal file
27
programs/bpf/c/src/sanity++/sanity++.cc
Normal file
@ -0,0 +1,27 @@
|
||||
/**
|
||||
* @brief Example C++-based BPF program that prints out the parameters
|
||||
* passed to it
|
||||
*/
|
||||
#include <solana_sdk.h>
|
||||
|
||||
/**
|
||||
* Custom error for when input serialization fails
|
||||
*/
|
||||
#define INVALID_INPUT 1
|
||||
|
||||
extern uint64_t entrypoint(const uint8_t *input) {
|
||||
SolAccountInfo ka[1];
|
||||
SolParameters params = (SolParameters) { .ka = ka };
|
||||
|
||||
sol_log(__FILE__);
|
||||
|
||||
if (!sol_deserialize(input, ¶ms, SOL_ARRAY_SIZE(ka))) {
|
||||
return ERROR_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
// Log the provided input parameters. In the case of the no-op
|
||||
// program, no account keys or input data are expected but real
|
||||
// programs will have specific requirements so they can do their work.
|
||||
sol_log_params(¶ms);
|
||||
return SUCCESS;
|
||||
}
|
23
programs/bpf/c/src/tuner/tuner.c
Normal file
23
programs/bpf/c/src/tuner/tuner.c
Normal file
@ -0,0 +1,23 @@
|
||||
/**
|
||||
* @brief Compute budget tuner program. Spins in a loop consuming the entire
|
||||
* budget, used by the tuner bench test to tune the compute budget costs.
|
||||
*
|
||||
* Care should be taken because the compiler might optimize out the mechanism
|
||||
* you are trying to tune.
|
||||
*/
|
||||
|
||||
#include <solana_sdk.h>
|
||||
|
||||
extern uint64_t entrypoint(const uint8_t *input) {
|
||||
uint8_t *val = (uint8_t *)input;
|
||||
for (uint64_t i = 0; i < UINT64_MAX; i++) {
|
||||
|
||||
// Uncomment for raw compute
|
||||
{
|
||||
if (*val != 0) {
|
||||
*val = *val + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return *val;
|
||||
}
|
Reference in New Issue
Block a user