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

Run machines directly from backing storage #281

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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: 1 addition & 0 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ LIBCARTESI_OBJS:= \
virtio-net-carrier-slirp.o \
dtb.o \
os.o \
os-mmap.o \
htif.o \
htif-factory.o \
shadow-state.o \
Expand Down
6 changes: 6 additions & 0 deletions src/compiler-defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@

#define NO_INLINE __attribute__((noinline))

#if defined(__GNUC__)
#define FORCE_OPTIMIZE_O3 __attribute__((optimize("-O3")))
#else
#define FORCE_OPTIMIZE_O3
#endif

#define NO_RETURN [[noreturn]]

// These macros are used only in very hot code paths (such as TLB hit checks).
Expand Down
37 changes: 37 additions & 0 deletions src/is-pristine.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright Cartesi and individual authors (see AUTHORS)
// SPDX-License-Identifier: LGPL-3.0-or-later
//
// This program is free software: you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License as published by the Free
// Software Foundation, either version 3 of the License, or (at your option) any
// later version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
// PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License along
// with this program (see COPYING). If not, see <https://www.gnu.org/licenses/>.
//

#ifndef IS_PRISTINE_H
#define IS_PRISTINE_H

#include "compiler-defines.h"
#include <stddef.h>
#include <stdint.h>

namespace cartesi {

// NOLINTNEXTLINE(clang-diagnostic-unknown-attributes)
static inline bool FORCE_OPTIMIZE_O3 is_pristine(const unsigned char *data, size_t length) {
unsigned char bits = 0;
for (size_t i = 0; i < length; ++i) {
bits |= data[i];
}
return bits == 0;
}

} // namespace cartesi

#endif
4 changes: 4 additions & 0 deletions src/json-util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,8 @@ void ju_get_opt_field(const nlohmann::json &j, const K &key, machine_runtime_con
ju_get_opt_field(j[key], "skip_root_hash_store"s, value.skip_root_hash_store, path + to_string(key) + "/");
ju_get_opt_field(j[key], "skip_version_check"s, value.skip_version_check, path + to_string(key) + "/");
ju_get_opt_field(j[key], "soft_yield"s, value.soft_yield, path + to_string(key) + "/");
ju_get_opt_field(j[key], "copy_reflink"s, value.copy_reflink, path + to_string(key) + "/");
ju_get_opt_field(j[key], "backing_storage"s, value.backing_storage, path + to_string(key) + "/");
}

template void ju_get_opt_field<uint64_t>(const nlohmann::json &j, const uint64_t &key, machine_runtime_config &value,
Expand Down Expand Up @@ -1971,6 +1973,8 @@ void to_json(nlohmann::json &j, const machine_runtime_config &runtime) {
{"skip_root_hash_store", runtime.skip_root_hash_store},
{"skip_version_check", runtime.skip_version_check},
{"soft_yield", runtime.soft_yield},
{"copy_reflink", runtime.copy_reflink},
{"backing_storage", runtime.backing_storage},
};
}

Expand Down
1 change: 1 addition & 0 deletions src/machine-config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ machine_config machine_config::load(const std::string &dir) {
}
ju_get_field(j, std::string("config"), c, "");
adjust_image_filenames(c, dir);
c.load_dir = dir;
} catch (std::exception &e) {
throw std::runtime_error{e.what()};
}
Expand Down
2 changes: 2 additions & 0 deletions src/machine-config.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ struct machine_config final {
/// \brief Stores the machine config to a directory
/// \param dir Directory where "config" will be stored
void store(const std::string &dir) const;

std::string load_dir{}; ///< Directory this machine config was loaded from
};

} // namespace cartesi
Expand Down
3 changes: 3 additions & 0 deletions src/machine-runtime-config.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#define MACHINE_RUNTIME_CONFIG_H

#include <cstdint>
#include <string>

/// \file
/// \brief Runtime configuration for machines.
Expand All @@ -42,6 +43,8 @@ struct machine_runtime_config {
bool skip_root_hash_store{};
bool skip_version_check{};
bool soft_yield{};
bool copy_reflink{};
std::string backing_storage{};
};

/// \brief CONCURRENCY constants
Expand Down
Loading
Loading