From 189500733583cc2b9f601d6053a57e944279fcf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alf-Andr=C3=A9=20Walla?= Date: Sun, 7 Jun 2020 15:52:53 +0200 Subject: [PATCH] Make shared default, use monotonic on other systems for time --- engine/src/script.cpp | 16 ++++++++++------ engine/src/script.hpp | 4 ++-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/engine/src/script.cpp b/engine/src/script.cpp index 1dced6d..ed6b82b 100644 --- a/engine/src/script.cpp +++ b/engine/src/script.cpp @@ -22,12 +22,12 @@ Script::Script(const riscv::Machine& smach, const std::string& name) : m_source_machine(smach), m_name(name), m_hash(crc32(name.c_str())) { - this->reset(true); + this->reset(); } Script::~Script() {} -bool Script::reset(bool shared) +bool Script::reset() { try { riscv::MachineOptions options { @@ -42,7 +42,7 @@ bool Script::reset(bool shared) // TODO: shutdown engine? exit(1); } - if (this->machine_initialize(shared)) { + if (this->machine_initialize()) { this->m_crashed = false; return true; } @@ -69,12 +69,12 @@ void Script::add_shared_memory() mem.install_shared_page(HIDDEN_AREA >> riscv::Page::SHIFT, g_hidden_stack); } -bool Script::machine_initialize(bool shared) +bool Script::machine_initialize() { // setup system calls and traps this->machine_setup(machine()); // install the shared memory area - if (shared) this->add_shared_memory(); + this->add_shared_memory(); // clear some state belonging to previous initialization this->m_tick_event = 0; // run through the initialization @@ -288,7 +288,11 @@ long Script::measure(uint32_t address) timespec time_now() { timespec t; - clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &t); +#ifdef __linux__ + clock_gettime(CLOCK_THREAD_CPUTIME_ID, &t); +#else + clock_gettime(CLOCK_MONOTONIC, &t); +#endif return t; } long nanodiff(timespec start_time, timespec end_time) diff --git a/engine/src/script.hpp b/engine/src/script.hpp index 9d75479..156c290 100644 --- a/engine/src/script.hpp +++ b/engine/src/script.hpp @@ -36,7 +36,7 @@ class Script { bool crashed() const noexcept { return m_crashed; } void add_shared_memory(); - bool reset(bool shared); // true if the reset was successful + bool reset(); // true if the reset was successful void hash_public_api_symbols(const std::string& file); std::string symbol_name(uint32_t address) const; @@ -59,7 +59,7 @@ class Script { void handle_exception(uint32_t); void handle_timeout(uint32_t); bool install_binary(const std::string& file, bool shared = true); - bool machine_initialize(bool shared); + bool machine_initialize(); void machine_setup(riscv::Machine&); void setup_syscall_interface(riscv::Machine&); static std::array g_shared_area; // shared memory area