From 11797fbb6eb59c62504e35fec29d8e628952a362 Mon Sep 17 00:00:00 2001 From: Charles Papon Date: Tue, 14 Mar 2017 23:25:04 +0100 Subject: [PATCH] Add sim performance print --- src/test/cpp/testA/main.cpp | 24 +++++++++++++++++++++++- src/test/cpp/testA/makefile | 2 +- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/test/cpp/testA/main.cpp b/src/test/cpp/testA/main.cpp index f5eea13..f3a86e2 100644 --- a/src/test/cpp/testA/main.cpp +++ b/src/test/cpp/testA/main.cpp @@ -120,7 +120,7 @@ class success : public std::exception { }; class Workspace{ public: - + static uint32_t cycles; Memory mem; string name; VVexRiscv* top; @@ -215,6 +215,7 @@ public: top->eval(); } + cycles += 1; top->iRsp_inst = iRsp_inst_next; top->dRsp_data = dRsp_inst_next; @@ -238,6 +239,7 @@ public: return this; } }; +uint32_t Workspace::cycles = 0; class TestA : public Workspace{ public: @@ -341,10 +343,27 @@ string riscvTestMemory[] = { // "rv32ui-p-remu.hex"] +#include + +struct timespec timer_start(){ + struct timespec start_time; + clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start_time); + return start_time; +} + +long timer_end(struct timespec start_time){ + struct timespec end_time; + clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &end_time); + long diffInNanos = end_time.tv_nsec - start_time.tv_nsec; + return diffInNanos; +} + int main(int argc, char **argv, char **env) { Verilated::randReset(2); Verilated::commandArgs(argc, argv); printf("BOOT\n"); + timespec startedAt = timer_start(); + TestA().run(); for(const string &name : riscvTestMain){ @@ -353,6 +372,9 @@ int main(int argc, char **argv, char **env) { for(const string &name : riscvTestMemory){ RiscvTest(name).run(); } + + long duration = timer_end(startedAt); + cout << "Had simulate " << Workspace::cycles << " clock cycles in " << duration*1e-9 << " s (" << Workspace::cycles / (duration*1e-9) << " Khz)" << endl; printf("exit\n"); exit(0); } diff --git a/src/test/cpp/testA/makefile b/src/test/cpp/testA/makefile index 1a7f209..2d23295 100644 --- a/src/test/cpp/testA/makefile +++ b/src/test/cpp/testA/makefile @@ -2,7 +2,7 @@ run: compile ./obj_dir/VVexRiscv verilate: - verilator -cc ../../../../VexRiscv.v -CFLAGS -std=c++11 --gdbbt --trace -Wno-WIDTH --x-assign unique --exe main.cpp + verilator -cc ../../../../VexRiscv.v -O3 -CFLAGS -std=c++11 --gdbbt --trace -Wno-WIDTH --x-assign unique --exe main.cpp compile: verilate make -j -C obj_dir/ -f VVexRiscv.mk VVexRiscv