rv32emu icon indicating copy to clipboard operation
rv32emu copied to clipboard

Implement performance counter

Open TheCloudlet opened this issue 3 years ago • 6 comments

On-going tasks:

  • [x] 1. Add new register in structure riscv_t
  • [x] 2. Create an API for getting performance counter
  • [ ] 3. Implementing the incrementation of CSR_CYCLEH, CSR_TIME and CSR_INSTRT in rv_step()

TheCloudlet avatar Oct 16 '22 02:10 TheCloudlet

Don't frequently close/reopen a pull request. Instead, you can force push the commits if you found something wrong.

jserv avatar Oct 16 '22 02:10 jserv

  • [ ] 3. Implementing the incrementation of CSR_CYCLEH, CSR_TIME and CSR_INSTRT in rv_step()

You shall provide some test programs which utilize performance counter. Either C with inline assembly or assembly programs are pretty well.

jserv avatar Oct 16 '22 02:10 jserv

You shall provide a minimal RISC-V assembly program which examines CSR functionalities.

jserv avatar Oct 18 '22 15:10 jserv

You shall provide a minimal RISC-V assembly program which examines CSR functionalities.

Will do. Thanks.

TheCloudlet avatar Oct 19 '22 14:10 TheCloudlet

Hi @jserv,

Do you think it is okay for me to write a test program "test_csr.c" with Makefile to test performance? Or do you think I shall try to use unit testing instead?

TheCloudlet avatar Oct 19 '22 14:10 TheCloudlet

Do you think it is okay for me to write a test program "test_csr.c" with Makefile to test performance? Or do you think I shall try to use unit testing instead?

You can create a test program named tests/csr-tests.c or tests/csr-tests.S. Furthermore, add it into the list of CHECK_ELF_FILES, so that make check can verify CSR implementations.

jserv avatar Oct 19 '22 14:10 jserv

What should I do to use syscall_gettimeofday() in emulate.c without using #include "syscall.c"?

TheCloudlet avatar Oct 23 '22 04:10 TheCloudlet

What should I do to use syscall_gettimeofday() in emulate.c without using #include "syscall.c"?

You can decouple the common part into a dedicated utility source file. Let's say, utils.[ch], and then you can invoke the utility function(s) in syscall and CSR specific handling.

jserv avatar Oct 23 '22 04:10 jserv

I cannot #include "utils.h" in both emulate.c and syscall.c it will show the following error message

Undefined symbols for architecture arm64:
  "_rv_gettimeofday", referenced from:
      _csr_get_ptr in emulate.o
      _syscall_handler in syscall.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [build/rv32emu] Error 1

TheCloudlet avatar Oct 23 '22 06:10 TheCloudlet

I cannot #include "utils.h" in both emulate.c and syscall.c it will show the following error message

You have to tweak Makefile accordingly.

jserv avatar Oct 23 '22 06:10 jserv

Apply the following change:

diff --git a/Makefile b/Makefile
index 37c8c38..cce99d0 100644
--- a/Makefile
+++ b/Makefile
@@ -95,6 +95,7 @@ all: $(BIN)
 
 OBJS := \
        map.o \
+       utils.o \
        emulate.o \
        io.o \
        elf.o \
diff --git a/src/emulate.c b/src/emulate.c
index 7193c69..936d375 100644
--- a/src/emulate.c
+++ b/src/emulate.c
@@ -30,7 +30,7 @@ extern struct target_ops gdbstub_ops;
 
 #include "riscv.h"
 #include "riscv_private.h"
-#include "utils.c"
+#include "utils.h"
 
 /* RISC-V exception code list */
 #define RV_EXCEPTION_LIST                                       \             

jserv avatar Oct 23 '22 17:10 jserv

Hi @jserv,

How should I test program counters? I should try to implement something in assembly to check the usage of csr_csrrs(*rv, CSR_TIME, 0 right?

TheCloudlet avatar Oct 29 '22 01:10 TheCloudlet

How should I test program counters? I should try to implement something in assembly to check the usage of csr_csrrs(*rv, CSR_TIME, 0 right?

You can simply write RISC-V assembly programs to validate CSR.

jserv avatar Oct 29 '22 02:10 jserv

Notes:

  • Assembly not fully working.
  • Successfully create main and loop.
  • Working on csr instructions and print

TheCloudlet avatar Nov 01 '22 12:11 TheCloudlet

Notes:

  • Assembly not fully working.
  • Successfully create main and loop.
  • Working on csr instructions and print

You don't have to print out the values of CSR. Instead, you can compare the difference between previous cycles and the present while running the loop. That is, you check if the changes of cycle counts is expected.

jserv avatar Nov 01 '22 23:11 jserv

Notes:

  • Assembly not fully working.
  • Successfully create main and loop.
  • Working on csr instructions and print

You don't have to print out the values of CSR. Instead, you can compare the difference between previous cycles and the present while running the loop. That is, check if the changes of cycle counts is expected since you know the instruction latency in advance. (CPI = 1 in rv32emu for no pipeline)

jserv avatar Nov 02 '22 00:11 jserv

Start working on assembly itself.

TheCloudlet avatar Nov 02 '22 14:11 TheCloudlet

Close in favor of commit 53a6f9463c4b344746cb1154cbfb995e44f30300

jserv avatar Nov 05 '22 17:11 jserv