Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
sysio::chain::eosvmoc::code_cache_async Class Reference

#include <code_cache.hpp>

Inheritance diagram for sysio::chain::eosvmoc::code_cache_async:
Collaboration diagram for sysio::chain::eosvmoc::code_cache_async:

Public Member Functions

 code_cache_async (const bfs::path data_dir, const eosvmoc::config &eosvmoc_config, const chainbase::database &db)
 
 ~code_cache_async ()
 
const code_descriptor *const get_descriptor_for_code (const digest_type &code_id, const uint8_t &vm_version)
 
- Public Member Functions inherited from sysio::chain::eosvmoc::code_cache_base
 code_cache_base (const bfs::path data_dir, const eosvmoc::config &eosvmoc_config, const chainbase::database &db)
 
 ~code_cache_base ()
 
const int & fd () const
 
void free_code (const digest_type &code_id, const uint8_t &vm_version)
 

Additional Inherited Members

- Protected Types inherited from sysio::chain::eosvmoc::code_cache_base
typedef boost::multi_index_container< code_descriptor, indexed_by< sequenced<>, hashed_unique< tag< by_hash >, composite_key< code_descriptor, member< code_descriptor, digest_type, &code_descriptor::code_hash >, member< code_descriptor, uint8_t, &code_descriptor::vm_version > > > > > code_cache_index
 
- Protected Member Functions inherited from sysio::chain::eosvmoc::code_cache_base
void check_eviction_threshold (size_t free_bytes)
 
void run_eviction_round ()
 
void set_on_disk_region_dirty (bool)
 
template<typename T >
void serialize_cache_index (fc::datastream< T > &ds)
 
- Protected Attributes inherited from sysio::chain::eosvmoc::code_cache_base
code_cache_index _cache_index
 
const chainbase::database_db
 
bfs::path _cache_file_path
 
int _cache_fd
 
io_context _ctx
 
local::datagram_protocol::socket _compile_monitor_write_socket {_ctx}
 
local::datagram_protocol::socket _compile_monitor_read_socket {_ctx}
 
std::unordered_set< code_tuple_queued_compiles
 
std::unordered_map< code_tuple, bool > _outstanding_compiles_and_poison
 
size_t _free_bytes_eviction_threshold
 

Detailed Description

Definition at line 89 of file code_cache.hpp.

Constructor & Destructor Documentation

◆ code_cache_async()

sysio::chain::eosvmoc::code_cache_async::code_cache_async ( const bfs::path data_dir,
const eosvmoc::config & eosvmoc_config,
const chainbase::database & db )

Definition at line 42 of file code_cache.cpp.

42 :
43 code_cache_base(data_dir, eosvmoc_config, db),
44 _result_queue(eosvmoc_config.threads * 2),
45 _threads(eosvmoc_config.threads)
46{
47 FC_ASSERT(_threads, "SYS VM OC requires at least 1 compile thread");
48
49 wait_on_compile_monitor_message();
50
51 _monitor_reply_thread = std::thread([this]() {
52 fc::set_os_thread_name("oc-monitor");
53 _ctx.run();
54 });
55}
code_cache_base(const bfs::path data_dir, const eosvmoc::config &eosvmoc_config, const chainbase::database &db)
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.
void set_os_thread_name(const string &name)
Here is the call graph for this function:

◆ ~code_cache_async()

sysio::chain::eosvmoc::code_cache_async::~code_cache_async ( )

Definition at line 57 of file code_cache.cpp.

57 {
58 _compile_monitor_write_socket.shutdown(local::datagram_protocol::socket::shutdown_send);
59 _monitor_reply_thread.join();
60 consume_compile_thread_queue();
61}
local::datagram_protocol::socket _compile_monitor_write_socket

Member Function Documentation

◆ get_descriptor_for_code()

const code_descriptor *const sysio::chain::eosvmoc::code_cache_async::get_descriptor_for_code ( const digest_type & code_id,
const uint8_t & vm_version )

Definition at line 109 of file code_cache.cpp.

109 {
110 //if there are any outstanding compiles, process the result queue now
112 auto [count_processed, bytes_remaining] = consume_compile_thread_queue();
113
114 if(count_processed)
115 check_eviction_threshold(bytes_remaining);
116
117 while(count_processed && _queued_compiles.size()) {
118 auto nextup = _queued_compiles.begin();
119
120 //it's not clear this check is required: if apply() was called for code then it existed in the code_index; and then
121 // if we got notification of it no longer existing we would have removed it from queued_compiles
122 const code_object* const codeobject = _db.find<code_object,by_code_hash>(boost::make_tuple(nextup->code_id, 0, nextup->vm_version));
123 if(codeobject) {
124 _outstanding_compiles_and_poison.emplace(*nextup, false);
125 std::vector<wrapped_fd> fds_to_pass;
126 fds_to_pass.emplace_back(memfd_for_bytearray(codeobject->code));
127 FC_ASSERT(write_message_with_fds(_compile_monitor_write_socket, compile_wasm_message{ *nextup }, fds_to_pass), "SYS VM failed to communicate to OOP manager");
128 --count_processed;
129 }
130 _queued_compiles.erase(nextup);
131 }
132 }
133
134 //check for entry in cache
135 code_cache_index::index<by_hash>::type::iterator it = _cache_index.get<by_hash>().find(boost::make_tuple(code_id, vm_version));
136 if(it != _cache_index.get<by_hash>().end()) {
137 _cache_index.relocate(_cache_index.begin(), _cache_index.project<0>(it));
138 return &*it;
139 }
140
141 const code_tuple ct = code_tuple{code_id, vm_version};
142
143 if(_blacklist.find(ct) != _blacklist.end())
144 return nullptr;
145 if(auto it = _outstanding_compiles_and_poison.find(ct); it != _outstanding_compiles_and_poison.end()) {
146 it->second = false;
147 return nullptr;
148 }
149 if(_queued_compiles.find(ct) != _queued_compiles.end())
150 return nullptr;
151
152 if(_outstanding_compiles_and_poison.size() >= _threads) {
153 _queued_compiles.emplace(ct);
154 return nullptr;
155 }
156
157 const code_object* const codeobject = _db.find<code_object,by_code_hash>(boost::make_tuple(code_id, 0, vm_version));
158 if(!codeobject) //should be impossible right?
159 return nullptr;
160
161 _outstanding_compiles_and_poison.emplace(ct, false);
162 std::vector<wrapped_fd> fds_to_pass;
163 fds_to_pass.emplace_back(memfd_for_bytearray(codeobject->code));
164 write_message_with_fds(_compile_monitor_write_socket, compile_wasm_message{ ct }, fds_to_pass);
165 return nullptr;
166}
const ObjectType * find(CompatibleKey &&key) const
void check_eviction_threshold(size_t free_bytes)
std::unordered_set< code_tuple > _queued_compiles
std::unordered_map< code_tuple, bool > _outstanding_compiles_and_poison
const chainbase::database & _db
RUNTIME_API Runtime::ObjectInstance * find(const std::string &name, const IR::ObjectType &type)
bool write_message_with_fds(boost::asio::local::datagram_protocol::socket &s, const eosvmoc_message &message, const std::vector< wrapped_fd > &fds=std::vector< wrapped_fd >())
wrapped_fd memfd_for_bytearray(const T &bytes)
Here is the call graph for this function:

The documentation for this class was generated from the following files: