-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
wasm_engine.hh
59 lines (47 loc) · 1.5 KB
/
wasm_engine.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
* Copyright (C) 2021-present ScyllaDB
*/
/*
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
#pragma once
#include <seastar/core/future.hh>
#include <seastar/core/sharded.hh>
#ifdef SCYLLA_ENABLE_WASMTIME
#include "wasmtime.hh"
namespace wasm {
// Fuel defines more or less how many bytecode instructions
// can be performed at once. Empirically, 20k units
// allow for considerably less than 0.5ms of preemption-free execution time.
// TODO: investigate other configuration variables.
// We're particularly interested in limiting resource usage
// and yielding in the middle of execution - which is possible
// in the original wasmtime implementation for Rust and tightly
// bound with its native async support, but not yet possible
// in wasmtime.hh binding at the time of this writing.
// It's highly probable that a more generic support for yielding
// can be contributed to wasmtime.
constexpr uint64_t default_initial_fuel_amount = 20*1024;
class engine {
wasmtime::Engine _engine;
uint64_t _initial_fuel_amount;
public:
engine(uint64_t initial_fuel_amount = default_initial_fuel_amount)
: _engine(make_config())
, _initial_fuel_amount(initial_fuel_amount)
{}
wasmtime::Engine& get() { return _engine; }
uint64_t initial_fuel_amount() { return _initial_fuel_amount; };
private:
wasmtime::Config make_config() {
wasmtime::Config cfg;
cfg.consume_fuel(true);
return cfg;
}
};
}
#else
namespace wasm {
class engine {};
}
#endif