Skip to content

Commit

Permalink
cleanup dromajo emul
Browse files Browse the repository at this point in the history
  • Loading branch information
renau committed Dec 15, 2022
1 parent 3b31f9f commit f44fc46
Show file tree
Hide file tree
Showing 31 changed files with 228 additions and 2,399 deletions.
6 changes: 3 additions & 3 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ http_archive(
name = "dromajo",
build_file = "dromajo.BUILD",
patches = ["//external:dromajo.patch"],
sha256 = "b974f7b27d612a814612c776a9c2f0a5174a1fd174e01a186ea31eccf9c60c09",
strip_prefix = "dromajo-e912df28ee330332cc1e12b26855cc935485d0b8",
sha256 = "93dfc8f4c7d872cc370da70fe831225df959b184ff50bd06f24dbd0936917d2e",
strip_prefix = "dromajo-c6a1057a23e6a7d8f627938042bc56577a9082ff",
urls = [
"https://github.com/masc-ucsc/dromajo/archive/e912df28ee330332cc1e12b26855cc935485d0b8.zip",
"https://github.com/masc-ucsc/dromajo/archive/c6a1057a23e6a7d8f627938042bc56577a9082ff.zip",
],
)

Expand Down
2 changes: 2 additions & 0 deletions core/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class Config {

protected:
public:
Config() = delete; // No object instance. All methods are static

static void init(const std::string f = "desesc.conf");

static std::string get_string(const std::string &block, const std::string &name,
Expand Down
21 changes: 4 additions & 17 deletions emul/emul_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,9 @@

// #include "config.hpp"

Emul_base::Emul_base(Config conf)
: config(conf)
/* Base class Emul_base constructor */
{
num = 0;
type = "INVALID";
// if (Config::get_string("soc", "emul") == "drom_emul") {
num = Config::get_integer("drom_emu", "num");
type = Config::get_string("drom_emu", "type", {"dromajo", "trace"});
rabbit = Config::get_integer("drom_emu", "rabbit");
detail = Config::get_integer("drom_emu", "detail");
time = Config::get_integer("drom_emu", "time");
//}
fmt::print("emul.num={} emul.type={}\n", num, type);
Emul_base::Emul_base() {
}

Emul_base::~Emul_base()
/* Emul_base destructor */
{}
Emul_base::~Emul_base() {

}
7 changes: 1 addition & 6 deletions emul/emul_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,11 @@

class Emul_base {
protected:
Config config;
std::string section;
std::string type; // dromajo, trace,...
int num;
int rabbit;
int detail;
int time;

public:
Emul_base(Config conf);
Emul_base();
virtual ~Emul_base();

virtual Dinst *peek(Hartid_t fid) = 0;
Expand Down
75 changes: 71 additions & 4 deletions emul/emul_dromajo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,34 @@
#include <assert.h>
#include <stdio.h>

Emul_dromajo::Emul_dromajo(Config conf) : Emul_base(conf) {}
Emul_dromajo::Emul_dromajo() : Emul_base() {
num = 0;

Emul_dromajo::~Emul_dromajo()
/* Emul_dromajo destructor */
{}
auto nemuls = Config::get_array_size("soc", "emul");
for (auto i=0u;i<nemuls;++i) {
auto tp = Config::get_string("soc","emul",i,"type");
if (tp != "dromajo")
continue;

if (num==0) {
section = Config::get_string("soc","emul", i);

rabbit = Config::get_integer("soc","emul", i, "rabbit");
detail = Config::get_integer("soc","emul", i, "detail");
time = Config::get_integer("soc","emul", i, "time");
bench = Config::get_integer("soc","emul", i, "bench");
}
++num;
}
type = "dromajo";
if (num) {
init_dromajo_machine();
}
}

Emul_dromajo::~Emul_dromajo() {

}

void Emul_dromajo::destroy_machine() {
if (machine != NULL) {
Expand Down Expand Up @@ -197,5 +220,49 @@ bool Emul_dromajo::is_sleeping(Hartid_t fid) const {
return true;
}

void Emul_dromajo::init_dromajo_machine() {
assert(type == "dromajo");

std::vector<const char *> dromajo_args;
dromajo_args.push_back("desesc_drom");
dromajo_args.push_back(bench.c_str());

std::vector<std::string> list_args = {"cmdline",
"ncpus",
"load",
"simpoint",
"save",
"maxinsns",
"terminate-event",
"trace",
"ignore_sbi_shutdown",
"dump_memories",
"memory_size",
"memory_addr",
"bootrom",
"dtb, compact_bootrom",
"reset_vector",
"plic",
"clint",
"custom_extension",
"gdbinit",
"clear_ids"};

dromajo_args.reserve(list_args.size());

for (auto &&item : list_args) {
if (Config::has_entry(section, item)) {
std::string arg = "--" + item + "=" + Config::get_string(section, item);
dromajo_args.push_back(arg.c_str());
}
}
char *argv[dromajo_args.size()];
for (auto i=0u;i<dromajo_args.size();++i) {
argv[i] = const_cast<char *>(dromajo_args[i]);
}

machine = virt_machine_main(dromajo_args.size(), argv);
}

// TO-DO: Config::init(dromajo.cfg) ... as started below:
// auto bootroom = Config::get_string("emul", "bootroom");
52 changes: 10 additions & 42 deletions emul/emul_dromajo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,53 +7,21 @@

class Emul_dromajo : public Emul_base {
protected:
RISCVMachine *machine = NULL;
RISCVMachine *machine = nullptr;

uint64_t num;
uint64_t rabbit;
uint64_t detail;
uint64_t time;

std::string bench;

void init_dromajo_machine();
public:
Emul_dromajo(Config conf);
Emul_dromajo();
virtual ~Emul_dromajo();

void destroy_machine();
bool init_dromajo_machine(char *dromajo_cfg) {
assert(type == "dromajo");
assert(dromajo_cfg);

std::vector<char *> dromajo_args;
char dummy_arg[] = "arg0";
dromajo_args.push_back(dummy_arg);
dromajo_args.push_back(dromajo_cfg);

std::vector<std::string> list_args = {"cmdline",
"ncpus",
"load",
"simpoint",
"save",
"maxinsns",
"terminate-event",
"trace",
"ignore_sbi_shutdown",
"dump_memories",
"memory_size",
"memory_addr",
"bootrom",
"dtb, compact_bootrom",
"reset_vector",
"plic",
"clint",
"custom_extension",
"gdbinit",
"clear_ids"};
dromajo_args.reserve(list_args.size());
for (auto &&item : list_args) {
if (Config::has_entry("drom_emu", item)) {
std::string arg = "--" + item + "=" + Config::get_string("drom_emu", item);
dromajo_args.push_back(const_cast<char *>(arg.c_str()));
}
}

machine = virt_machine_main(dromajo_args.size(), &dromajo_args[0]);
return machine;
}

virtual Dinst *peek(Hartid_t fid) final;
virtual void execute(Hartid_t fid) final;
Expand Down
12 changes: 4 additions & 8 deletions emul/emul_dromajo_bench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "benchmark/benchmark.h"
#include "emul_dromajo.hpp"

Emul_dromajo* dromajo_ptr;
std::shared_ptr<Emul_dromajo> dromajo_ptr;

static void BM_InstructionExecuteAndDecode(benchmark::State& state) {
for (auto _ : state) {
Expand Down Expand Up @@ -31,15 +31,11 @@ int main(int argc, char* argv[]) {
file << "\n[drom_emu]\n";
file << "num = \"1\"\n";
file << "type = \"dromajo\"\n";
file << "bench =\"dhrystone.riscv\"\n";
file.close();

Config configuration;
configuration.init("emul_dromajo_test.toml");
Config::init("emul_dromajo_test.toml");

char benchmark_name[] = "dhrystone.riscv";

Emul_dromajo dromajo_emul(configuration);
dromajo_emul.init_dromajo_machine(benchmark_name);
dromajo_ptr = &dromajo_emul;
dromajo_ptr = std::make_shared<Emul_dromajo>();
benchmark::RunSpecifiedBenchmarks();
}
37 changes: 16 additions & 21 deletions emul/emul_dromajo_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

class Emul_Dromajo_test : public ::testing::Test {
protected:
std::shared_ptr<Emul_dromajo> dromajo_ptr;

void SetUp() override {
std::ofstream file;
file.open("emul_dromajo_test.toml");
Expand All @@ -43,38 +45,31 @@ class Emul_Dromajo_test : public ::testing::Test {
file << "rabbit = 1e6\n";
file << "detail = 1e6\n";
file << "time = 2e6\n";
file << "bench=\"dhrystone.riscv\"\n";
file.close();

Config configuration;
configuration.init("emul_dromajo_test.toml");

char benchmark_name[] = "dhrystone.riscv";
Config::init("emul_dromajo_test.toml");

Emul_dromajo dromajo_emul(configuration);
dromajo_emul.init_dromajo_machine(benchmark_name);
dromajo_ptr = &dromajo_emul;
dromajo_ptr = std::make_shared<Emul_dromajo>();
}

Emul_dromajo *dromajo_ptr;

void TearDown() override {
// Graph_library::sync_all();
}
};

TEST_F(Emul_Dromajo_test, dhrystone_test) {
Emul_dromajo dromajo_emul = *dromajo_ptr;
EXPECT_FALSE(dromajo_ptr == NULL);
EXPECT_NE(dromajo_ptr,nullptr);

dromajo_emul.skip_rabbit(0, 664);
Dinst *dinst = dromajo_emul.peek(0); // csrr
dromajo_ptr->skip_rabbit(0, 664);
Dinst *dinst = dromajo_ptr->peek(0); // csrr
EXPECT_EQ(0x0000000080002aaa, dinst->getPC());
const Instruction *inst = dinst->getInst();
EXPECT_EQ(15, inst->getDst1());
dinst->recycle();

dromajo_emul.skip_rabbit(0, 197);
dinst = dromajo_emul.peek(0); // bge
dromajo_ptr->skip_rabbit(0, 197);
dinst = dromajo_ptr->peek(0); // bge
EXPECT_EQ(0x0000000080002094, dinst->getPC());
EXPECT_EQ(0x00000000800020a4, dinst->getAddr());
inst = dinst->getInst();
Expand All @@ -84,24 +79,24 @@ TEST_F(Emul_Dromajo_test, dhrystone_test) {
EXPECT_TRUE(inst->isBranch());
dinst->recycle();

dromajo_emul.skip_rabbit(0, 6); // ret
dinst = dromajo_emul.peek(0);
dromajo_ptr->skip_rabbit(0, 6); // ret
dinst = dromajo_ptr->peek(0);
EXPECT_EQ(0x00000000800020ae, dinst->getPC());
inst = dinst->getInst();
EXPECT_TRUE(inst->isFuncRet());
dinst->recycle();

dromajo_emul.skip_rabbit(0, 2); // addi
dinst = dromajo_emul.peek(0);
dromajo_ptr->skip_rabbit(0, 2); // addi
dinst = dromajo_ptr->peek(0);
EXPECT_EQ(0x0000000080002b38, dinst->getPC());
inst = dinst->getInst();
EXPECT_EQ(8, inst->getSrc1());
EXPECT_EQ(12, inst->getDst1());
EXPECT_TRUE(inst->isALU());
dinst->recycle();

dromajo_emul.skip_rabbit(0, 5); // sw
dinst = dromajo_emul.peek(0);
dromajo_ptr->skip_rabbit(0, 5); // sw
dinst = dromajo_ptr->peek(0);
EXPECT_EQ(0x0000000080002b46, dinst->getPC());
EXPECT_EQ(0x0000000080025658, dinst->getAddr());
inst = dinst->getInst();
Expand Down
Loading

0 comments on commit f44fc46

Please sign in to comment.