diff --git a/CMakeLists.txt b/CMakeLists.txt index 3a6d588..6fa3d9b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,7 +35,7 @@ FILE(GLOB TGC_VM_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/vm/interp/vm_*.cpp) set(LIB_SOURCES src/vm/fp_functions.cpp src/plugin/instruction_count.cpp - src/plugin/cov.cpp + src/plugin/pctrace.cpp ${TGC_SOURCES} ${TGC_VM_SOURCES} diff --git a/incl/iss/plugin/cov.h b/incl/iss/plugin/pctrace.h similarity index 83% rename from incl/iss/plugin/cov.h rename to incl/iss/plugin/pctrace.h index 1f0c9bd..0cad8b0 100644 --- a/incl/iss/plugin/cov.h +++ b/incl/iss/plugin/pctrace.h @@ -52,6 +52,18 @@ class cov : public iss::vm_plugin { size_t not_taken_delay; size_t taken_delay; }; + BEGIN_BF_DECL(instr_desc, uint32_t) + BF_FIELD(taken, 24, 8) + BF_FIELD(not_taken, 16, 8) + BF_FIELD(is_branch, 8, 8) + BF_FIELD(size, 0, 8) + instr_desc(uint32_t size, uint32_t taken, uint32_t not_taken, bool branch): instr_desc() { + this->size=size; + this->taken=taken; + this->not_taken=not_taken; + this->is_branch=branch; + } + END_BF_DECL(); public: @@ -59,7 +71,7 @@ public: cov(const cov &&) = delete; - cov(); + cov(std::string const &); virtual ~cov(); @@ -75,8 +87,10 @@ public: private: iss::instrumentation_if *instr_if {nullptr}; - int counter {0}; std::ofstream output; + std::string filename; + std::vector delays; + }; } } diff --git a/src/plugin/cov.cpp b/src/plugin/cov.cpp deleted file mode 100644 index 46b1d32..0000000 --- a/src/plugin/cov.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#include -#include -#include - - -iss::plugin::cov::cov() { - std::cout << "Entering Constructor"<get_instrumentation_if(); - return true; -} -void iss::plugin::cov::callback(instr_info_t iinfo, const exec_info&) { -// if((instr_if->get_next_pc() - instr_if->get_pc() != 4) ||( instr_if->get_next_pc() - instr_if->get_pc() != 2)){ -// std::cout << "jump from " << std::hex << instr_if->get_pc() << " to " << instr_if->get_next_pc()<< " after " << std::dec << counter <<" linear instructions" <get_pc() << std::endl; -} diff --git a/src/plugin/cycle_estimate.cpp b/src/plugin/cycle_estimate.cpp index 88e275a..f68d241 100644 --- a/src/plugin/cycle_estimate.cpp +++ b/src/plugin/cycle_estimate.cpp @@ -85,7 +85,7 @@ bool iss::plugin::cycle_estimate::registration(const char* const version, vm_if& delays.push_back(instr_desc{size.Get(), d, d, branch.Get()}); } else throw runtime_error("JSON parse error"); - } + } } else { LOG(ERR)<<"plugin cycle_estimate: could not find an entry for "< 1) + if (exc_info.branch_taken && (entry.taken > 1)) arch_instr->set_curr_instr_cycles(entry.taken); else if (entry.not_taken > 1) arch_instr->set_curr_instr_cycles(entry.not_taken); diff --git a/src/plugin/pctrace.cpp b/src/plugin/pctrace.cpp new file mode 100644 index 0000000..1a92dd4 --- /dev/null +++ b/src/plugin/pctrace.cpp @@ -0,0 +1,97 @@ +#include +#include +#include +#include +#include +#include "rapidjson/writer.h" +#include "rapidjson/stringbuffer.h" +#include +#include +#include + +#include + + +using namespace rapidjson; +using namespace std; + +iss::plugin::cov::cov(std::string const &filename) + : instr_if(nullptr) + , filename(filename) +{ + output.open("output.trc"); +} + +iss::plugin::cov::~cov() { + output.close(); +} + +bool iss::plugin::cov::registration(const char *const version, vm_if& vm) { + instr_if = vm.get_arch()->get_instrumentation_if(); + if(!instr_if) return false; + const string core_name = instr_if->core_type_name(); + if (filename.length() > 0) { + ifstream is(filename); + if (is.is_open()) { + try { + IStreamWrapper isw(is); + Document d; + ParseResult ok = d.ParseStream(isw); + if(ok) { + Value& val = d[core_name.c_str()]; + if(val.IsArray()){ + delays.reserve(val.Size()); + for (auto it = val.Begin(); it != val.End(); ++it) { + auto& name = (*it)["name"]; + auto& size = (*it)["size"]; + auto& delay = (*it)["delay"]; + auto& branch = (*it)["branch"]; + if(delay.IsArray()) { + auto dt = delay[0].Get(); + auto dnt = delay[1].Get(); + delays.push_back(instr_desc{size.Get(), dt, dnt, branch.Get()}); + } else if(delay.Is()) { + auto d = delay.Get(); + delays.push_back(instr_desc{size.Get(), d, d, branch.Get()}); + } else + throw runtime_error("JSON parse error"); + + } + } else { + LOG(ERR)<<"plugin cycle_estimate: could not find an entry for "<get_next_pc() - instr_if->get_pc() != 4) ||( instr_if->get_next_pc() - instr_if->get_pc() != 2)){ +// std::cout << "jump from " << std::hex << instr_if->get_pc() << " to " << instr_if->get_next_pc()<< " after " << std::dec << counter <<" linear instructions" <get_pc() <<"," << delay << "\n"; +} diff --git a/src/sysc/core_complex.cpp b/src/sysc/core_complex.cpp index 8ec288d..23ab3e5 100644 --- a/src/sysc/core_complex.cpp +++ b/src/sysc/core_complex.cpp @@ -69,7 +69,7 @@ using tgc_d_xrb_nn_plat_type = iss::arch::riscv_hart_mu_p #include #include -#include +#include // clang-format on @@ -426,8 +426,8 @@ void core_complex::before_end_of_elaboration() { auto *plugin = new iss::plugin::cycle_estimate(filename); cpu->vm->register_plugin(*plugin); plugin_list.push_back(plugin); - } else if (plugin_name == "cov") { - auto *plugin = new iss::plugin::cov(); + } else if (plugin_name == "pctrace") { + auto *plugin = new iss::plugin::cov(filename); cpu->vm->register_plugin(*plugin); plugin_list.push_back(plugin); } else {