Skip to content

Commit 8619295

Browse files
committed
feat: add backing storage runtime option for running machines from disk
1 parent 4a3040d commit 8619295

20 files changed

+923
-470
lines changed

src/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ LIBCARTESI_OBJS:= \
337337
virtio-net-carrier-slirp.o \
338338
dtb.o \
339339
os.o \
340+
os-mmap.o \
340341
htif.o \
341342
htif-factory.o \
342343
shadow-state.o \

src/compiler-defines.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@
2727

2828
#define NO_INLINE __attribute__((noinline))
2929

30+
#if defined(__GNUC__)
31+
#define FORCE_OPTIMIZE_O3 __attribute__((optimize("-O3")))
32+
#else
33+
#define FORCE_OPTIMIZE_O3
34+
#endif
35+
3036
#define NO_RETURN [[noreturn]]
3137

3238
// These macros are used only in very hot code paths (such as TLB hit checks).

src/is-pristine.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright Cartesi and individual authors (see AUTHORS)
2+
// SPDX-License-Identifier: LGPL-3.0-or-later
3+
//
4+
// This program is free software: you can redistribute it and/or modify it under
5+
// the terms of the GNU Lesser General Public License as published by the Free
6+
// Software Foundation, either version 3 of the License, or (at your option) any
7+
// later version.
8+
//
9+
// This program is distributed in the hope that it will be useful, but WITHOUT ANY
10+
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
11+
// PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
12+
//
13+
// You should have received a copy of the GNU Lesser General Public License along
14+
// with this program (see COPYING). If not, see <https://www.gnu.org/licenses/>.
15+
//
16+
17+
#ifndef IS_PRISTINE_H
18+
#define IS_PRISTINE_H
19+
20+
#include "compiler-defines.h"
21+
#include <stddef.h>
22+
#include <stdint.h>
23+
24+
namespace cartesi {
25+
26+
// NOLINTNEXTLINE(clang-diagnostic-unknown-attributes)
27+
static inline bool FORCE_OPTIMIZE_O3 is_pristine(const unsigned char *data, size_t length) {
28+
unsigned char bits = 0;
29+
for (size_t i = 0; i < length; ++i) {
30+
bits |= data[i];
31+
}
32+
return bits == 0;
33+
}
34+
35+
} // namespace cartesi
36+
37+
#endif

src/json-util.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,8 @@ void ju_get_opt_field(const nlohmann::json &j, const K &key, machine_runtime_con
789789
ju_get_opt_field(j[key], "skip_root_hash_store"s, value.skip_root_hash_store, path + to_string(key) + "/");
790790
ju_get_opt_field(j[key], "skip_version_check"s, value.skip_version_check, path + to_string(key) + "/");
791791
ju_get_opt_field(j[key], "soft_yield"s, value.soft_yield, path + to_string(key) + "/");
792+
ju_get_opt_field(j[key], "copy_reflink"s, value.copy_reflink, path + to_string(key) + "/");
793+
ju_get_opt_field(j[key], "backing_storage"s, value.backing_storage, path + to_string(key) + "/");
792794
}
793795

794796
template void ju_get_opt_field<uint64_t>(const nlohmann::json &j, const uint64_t &key, machine_runtime_config &value,
@@ -1971,6 +1973,8 @@ void to_json(nlohmann::json &j, const machine_runtime_config &runtime) {
19711973
{"skip_root_hash_store", runtime.skip_root_hash_store},
19721974
{"skip_version_check", runtime.skip_version_check},
19731975
{"soft_yield", runtime.soft_yield},
1976+
{"copy_reflink", runtime.copy_reflink},
1977+
{"backing_storage", runtime.backing_storage},
19741978
};
19751979
}
19761980

src/machine-config.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ machine_config machine_config::load(const std::string &dir) {
7777
}
7878
ju_get_field(j, std::string("config"), c, "");
7979
adjust_image_filenames(c, dir);
80+
c.load_dir = dir;
8081
} catch (std::exception &e) {
8182
throw std::runtime_error{e.what()};
8283
}

src/machine-config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,8 @@ struct machine_config final {
211211
/// \brief Stores the machine config to a directory
212212
/// \param dir Directory where "config" will be stored
213213
void store(const std::string &dir) const;
214+
215+
std::string load_dir{}; ///< Directory this machine config was loaded from
214216
};
215217

216218
} // namespace cartesi

src/machine-runtime-config.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#define MACHINE_RUNTIME_CONFIG_H
1919

2020
#include <cstdint>
21+
#include <string>
2122

2223
/// \file
2324
/// \brief Runtime configuration for machines.
@@ -42,6 +43,8 @@ struct machine_runtime_config {
4243
bool skip_root_hash_store{};
4344
bool skip_version_check{};
4445
bool soft_yield{};
46+
bool copy_reflink{};
47+
std::string backing_storage{};
4548
};
4649

4750
/// \brief CONCURRENCY constants

0 commit comments

Comments
 (0)