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

Use a single WASM interface per nodeos (instead of per thread) to save WASM compile time and cache #1549

Merged
merged 14 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from 12 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
1 change: 0 additions & 1 deletion libraries/chain/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ add_library( eosio_chain

wast_to_wasm.cpp
wasm_interface.cpp
wasm_interface_collection.cpp
wasm_eosio_validation.cpp
wasm_eosio_injection.cpp
wasm_config.cpp
Expand Down
1 change: 0 additions & 1 deletion libraries/chain/apply_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include <eosio/chain/controller.hpp>
#include <eosio/chain/transaction_context.hpp>
#include <eosio/chain/exceptions.hpp>
#include <eosio/chain/wasm_interface_collection.hpp>
#include <eosio/chain/generated_transaction_object.hpp>
#include <eosio/chain/authorization_manager.hpp>
#include <eosio/chain/resource_limits.hpp>
Expand Down
25 changes: 15 additions & 10 deletions libraries/chain/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include <eosio/chain/thread_utils.hpp>
#include <eosio/chain/platform_timer.hpp>
#include <eosio/chain/deep_mind.hpp>
#include <eosio/chain/wasm_interface_collection.hpp>

#include <chainbase/chainbase.hpp>
#include <eosio/vm/allocator.hpp>
Expand Down Expand Up @@ -256,7 +255,7 @@ struct controller_impl {
#if defined(EOSIO_EOS_VM_RUNTIME_ENABLED) || defined(EOSIO_EOS_VM_JIT_RUNTIME_ENABLED)
thread_local static vm::wasm_allocator wasm_alloc; // a copy for main thread and each read-only thread
#endif
wasm_interface_collection wasm_if_collect;
wasm_interface wasmif;
app_window_type app_window = app_window_type::write;

typedef pair<scope_name,action_name> handler_key;
Expand Down Expand Up @@ -315,7 +314,7 @@ struct controller_impl {
chain_id( chain_id ),
read_mode( cfg.read_mode ),
thread_pool(),
wasm_if_collect( conf.wasm_runtime, conf.eosvmoc_tierup, db, conf.state_dir, conf.eosvmoc_config, !conf.profile_accounts.empty() )
wasmif( conf.wasm_runtime, conf.eosvmoc_tierup, db, conf.state_dir, conf.eosvmoc_config, !conf.profile_accounts.empty() )
{
fork_db.open( [this]( block_timestamp_type timestamp,
const flat_set<digest_type>& cur_features,
Expand All @@ -342,7 +341,7 @@ struct controller_impl {
set_activation_handler<builtin_protocol_feature_t::bls_primitives>();

self.irreversible_block.connect([this](const block_state_ptr& bsp) {
wasm_if_collect.current_lib(bsp->block_num);
wasmif.current_lib(bsp->block_num);
});


Expand Down Expand Up @@ -2686,20 +2685,26 @@ struct controller_impl {

#ifdef EOSIO_EOS_VM_OC_RUNTIME_ENABLED
bool is_eos_vm_oc_enabled() const {
return wasm_if_collect.is_eos_vm_oc_enabled();
return wasmif.is_eos_vm_oc_enabled();
}
#endif

// Only called from read-only trx execution threads when producer_plugin
// starts them. Only OC requires initialize thread specific data.
void init_thread_local_data() {
wasm_if_collect.init_thread_local_data(db, conf.state_dir, conf.eosvmoc_config, !conf.profile_accounts.empty());
#ifdef EOSIO_EOS_VM_OC_RUNTIME_ENABLED
if ( is_eos_vm_oc_enabled() ) {
wasmif.init_thread_local_data();
}
#endif
}

wasm_interface_collection& get_wasm_interface() {
return wasm_if_collect;
wasm_interface& get_wasm_interface() {
return wasmif;
}

void code_block_num_last_used(const digest_type& code_hash, uint8_t vm_type, uint8_t vm_version, uint32_t block_num) {
wasm_if_collect.code_block_num_last_used(code_hash, vm_type, vm_version, block_num);
wasmif.code_block_num_last_used(code_hash, vm_type, vm_version, block_num);
}

block_state_ptr fork_db_head() const;
Expand Down Expand Up @@ -3400,7 +3405,7 @@ const apply_handler* controller::find_apply_handler( account_name receiver, acco
}
return nullptr;
}
wasm_interface_collection& controller::get_wasm_interface() {
wasm_interface& controller::get_wasm_interface() {
return my->get_wasm_interface();
}

Expand Down
3 changes: 1 addition & 2 deletions libraries/chain/include/eosio/chain/controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ namespace eosio { namespace chain {
class account_object;
class deep_mind_handler;
class subjective_billing;
class wasm_interface_collection;
using resource_limits::resource_limits_manager;
using apply_handler = std::function<void(apply_context&)>;
using forked_branch_callback = std::function<void(const branch_type&)>;
Expand Down Expand Up @@ -349,7 +348,7 @@ namespace eosio { namespace chain {
*/

const apply_handler* find_apply_handler( account_name contract, scope_name scope, action_name act )const;
wasm_interface_collection& get_wasm_interface();
wasm_interface& get_wasm_interface();

static chain_id_type extract_chain_id(snapshot_reader& snapshot);

Expand Down
19 changes: 16 additions & 3 deletions libraries/chain/include/eosio/chain/wasm_interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,19 @@ namespace eosio { namespace chain {
oc_none
};

wasm_interface(vm_type vm, const chainbase::database& d, const std::filesystem::path data_dir, const eosvmoc::config& eosvmoc_config, bool profile);
inline static bool test_disable_tierup = false; // set by unittests to test tierup failing

wasm_interface(vm_type vm, vm_oc_enable eosvmoc_tierup, const chainbase::database& d, const std::filesystem::path data_dir, const eosvmoc::config& eosvmoc_config, bool profile);
~wasm_interface();

#ifdef EOSIO_EOS_VM_OC_RUNTIME_ENABLED
// initialize exec per thread
void init_thread_local_data();

// returns true if EOS VM OC is enabled
bool is_eos_vm_oc_enabled() const;
#endif

//call before dtor to skip what can be minutes of dtor overhead with some runtimes; can cause leaks
void indicate_shutting_down();

Expand All @@ -61,15 +68,21 @@ namespace eosio { namespace chain {
//indicate that a particular code probably won't be used after given block_num
void code_block_num_last_used(const digest_type& code_hash, const uint8_t& vm_type, const uint8_t& vm_version, const uint32_t& block_num);

//indicate the current LIB. evicts old cache entries, each evicted entry is provided to callback
void current_lib(const uint32_t lib, const std::function<void(const digest_type&, uint8_t)>& callback);
//indicate the current LIB. evicts old cache entries
void current_lib(const uint32_t lib);

//Calls apply or error on a given code
void apply(const digest_type& code_hash, const uint8_t& vm_type, const uint8_t& vm_version, apply_context& context);

//Returns true if the code is cached
bool is_code_cached(const digest_type& code_hash, const uint8_t& vm_type, const uint8_t& vm_version) const;

// If substitute_apply is set, then apply calls it before doing anything else. If substitute_apply returns true,
// then apply returns immediately. Provided function must be multi-thread safe.
std::function<bool(const digest_type& code_hash, uint8_t vm_type, uint8_t vm_version, apply_context& context)> substitute_apply;

private:
vm_oc_enable eosvmoc_tierup;
unique_ptr<struct wasm_interface_impl> my;
};

Expand Down
65 changes: 0 additions & 65 deletions libraries/chain/include/eosio/chain/wasm_interface_collection.hpp

This file was deleted.

Loading