Skip to content

Commit

Permalink
Make shared default, use monotonic on other systems for time
Browse files Browse the repository at this point in the history
  • Loading branch information
fwsGonzo committed Jun 7, 2020
1 parent c37d3e3 commit 1895007
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
16 changes: 10 additions & 6 deletions engine/src/script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ Script::Script(const riscv::Machine<riscv::RISCV32>& 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<riscv::RISCV32> options {
Expand All @@ -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;
}
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions engine/src/script.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<riscv::RISCV32>&);
void setup_syscall_interface(riscv::Machine<riscv::RISCV32>&);
static std::array<riscv::Page, 2> g_shared_area; // shared memory area
Expand Down

0 comments on commit 1895007

Please sign in to comment.