From 6ecdbe876951440d3bc4d0329a2ed3f15ac3e41e Mon Sep 17 00:00:00 2001 From: Shupei Fan Date: Wed, 8 Jan 2025 05:30:22 +0000 Subject: [PATCH 1/7] [difftest] generate mmio-event.jsonl --- .../src/interconnect/simctrl.rs | 40 ++++++++++++++++--- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/difftest/dpi_t1rocketemu/src/interconnect/simctrl.rs b/difftest/dpi_t1rocketemu/src/interconnect/simctrl.rs index b84efbaef..21f94ad71 100644 --- a/difftest/dpi_t1rocketemu/src/interconnect/simctrl.rs +++ b/difftest/dpi_t1rocketemu/src/interconnect/simctrl.rs @@ -1,10 +1,16 @@ -use std::sync::{ - atomic::{AtomicU32, Ordering}, - Arc, +use std::{ + fs::File, + io::Write as _, + sync::{ + atomic::{AtomicU32, Ordering}, + Arc, + }, }; use tracing::{info, warn}; +use crate::get_t; + use super::RegDevice; #[derive(Default, Debug, Clone)] @@ -28,20 +34,36 @@ pub const EXIT_CODE: u32 = 0xdead_beef; /// Reg map: /// - 0x0000 : WO, write EXIT_CODE to mark simulation finish +/// - 0x0010 : WO, uart write register +/// - 0x0014 : WO, profile write register +/// +/// Event file: +/// all writes to uart/profile write register are recorded blindly +/// to "mmio-event.jsonl" pub struct SimCtrl { exit_flag: ExitFlagRef, + event_file: File, } impl SimCtrl { pub fn new(exit_flag: ExitFlagRef) -> Self { - SimCtrl { exit_flag } + let event_file = File::create("mmio-event.jsonl").unwrap(); + SimCtrl { exit_flag, event_file } + } + + fn append_event(&mut self, event: &str, value: u32) { + let cycle = get_t(); + let buf = format!("{{\"cycle\": {cycle}, \"event\": \"{event}\", \"value\": {value}}}\n"); + + self.event_file.write_all(buf.as_bytes()).unwrap(); + self.event_file.flush().unwrap(); } } impl RegDevice for SimCtrl { fn reg_read(&mut self, offset: u32) -> u32 { let _ = offset; - unimplemented!() + unimplemented!("simctrl does not support mmio read") } fn reg_write(&mut self, reg_offset: u32, value: u32) { @@ -54,7 +76,13 @@ impl RegDevice for SimCtrl { warn!("simctrl: write EXIT_POS with value 0x{value:08x}, ignored"); } } - _ => panic!(), + 0x10 => { + self.append_event("uart-write", value); + } + 0x14 => { + self.append_event("profile", value); + } + _ => panic!("simctrl: invalid write addr: base + 0x{reg_offset:02x}"), } } } From 710b55aebb7f9942f68a30c8da12147056634e7e Mon Sep 17 00:00:00 2001 From: Shupei Fan Date: Wed, 8 Jan 2025 05:39:41 +0000 Subject: [PATCH 2/7] [nix] copy mmio-event.jsonl --- nix/t1/run/run-vcs-emu.nix | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/nix/t1/run/run-vcs-emu.nix b/nix/t1/run/run-vcs-emu.nix index 58617e28c..6e780e769 100644 --- a/nix/t1/run/run-vcs-emu.nix +++ b/nix/t1/run/run-vcs-emu.nix @@ -126,6 +126,10 @@ stdenvNoCC.mkDerivation (rec { mv perf.json $out/ fi + if [ -r mmio-event.jsonl ]; then + cp -v mmio-event.jsonl $out/ + fi + ${lib.optionalString emulator.enableCover '' ${snps-fhs-env}/bin/snps-fhs-env -c "urg -dir cm.vdb -format text -metric assert -show summary" # TODO: add a flag to specify 'vdb only generated in ci mode' From 698141e44d78396a20b06dff53138932f5d4607a Mon Sep 17 00:00:00 2001 From: Avimitin Date: Thu, 9 Jan 2025 01:47:55 +0800 Subject: [PATCH 3/7] [chore] format code Signed-off-by: Avimitin --- tests/emurt/emurt.c | 91 +++++++++++++++++++-------------------------- tests/emurt/emurt.h | 9 ++--- 2 files changed, 42 insertions(+), 58 deletions(-) diff --git a/tests/emurt/emurt.c b/tests/emurt/emurt.c index 04fd1b416..4a5ca10d5 100644 --- a/tests/emurt/emurt.c +++ b/tests/emurt/emurt.c @@ -6,46 +6,46 @@ struct uartlite_regs *const ttyUL0 = (struct uartlite_regs *)0x10000000; -#define SR_TX_FIFO_FULL (1<<3) /* transmit FIFO full */ -#define SR_TX_FIFO_EMPTY (1<<2) /* transmit FIFO empty */ -#define SR_RX_FIFO_VALID_DATA (1<<0) /* data in receive FIFO */ -#define SR_RX_FIFO_FULL (1<<1) /* receive FIFO full */ +#define SR_TX_FIFO_FULL (1 << 3) /* transmit FIFO full */ +#define SR_TX_FIFO_EMPTY (1 << 2) /* transmit FIFO empty */ +#define SR_RX_FIFO_VALID_DATA (1 << 0) /* data in receive FIFO */ +#define SR_RX_FIFO_FULL (1 << 1) /* receive FIFO full */ -#define ULITE_CONTROL_RST_TX 0x01 -#define ULITE_CONTROL_RST_RX 0x02 +#define ULITE_CONTROL_RST_TX 0x01 +#define ULITE_CONTROL_RST_RX 0x02 void uart_put_c(char c) { - while (ttyUL0->status & SR_TX_FIFO_FULL); - ttyUL0->tx_fifo = c; + while (ttyUL0->status & SR_TX_FIFO_FULL) + ; + ttyUL0->tx_fifo = c; } char uart_check_read() { // 1: data ready, 0: no data - return (ttyUL0->status & SR_RX_FIFO_VALID_DATA) != 0; + return (ttyUL0->status & SR_RX_FIFO_VALID_DATA) != 0; } -char uart_get_c() { - return ttyUL0->rx_fifo; -} +char uart_get_c() { return ttyUL0->rx_fifo; } void get(char *s, int n) { - char debug[20] = "Enter get()"; + char debug[20] = "Enter get()"; + print_s(debug); + int i = 0; + while (uart_check_read() != 1) + ; + while (uart_check_read() && i < n - 1) { print_s(debug); - int i = 0; - while (uart_check_read() != 1); - while (uart_check_read() && i < n - 1) { - print_s(debug); - char c = uart_get_c(); - uart_put_c(c); - if (c == '\r' || c == '\n') { - break; // Break if carriage return or newline is encountered - } - *(s + i) = c; - i++; + char c = uart_get_c(); + uart_put_c(c); + if (c == '\r' || c == '\n') { + break; // Break if carriage return or newline is encountered } - s[i] = '\0'; + *(s + i) = c; + i++; + } + s[i] = '\0'; } -int _write(int file, char* ptr, int len) { +int _write(int file, char *ptr, int len) { int i = 0; for (; i < len; i++) { uart_put_c(ptr[i]); @@ -62,17 +62,17 @@ void _exit(int code) { } void print_s(const char *c) { - while (*c) { - uart_put_c(*c); - c ++; - } + while (*c) { + uart_put_c(*c); + c++; + } } /////////////////////// // allocation /////////////////////// -extern char* __heapbegin; +extern char *__heapbegin; char *heap_top; char *_sbrk(int nbytes) { @@ -91,37 +91,22 @@ char *_sbrk(int nbytes) { /////////////////////// // We don't support FS -int _isatty(int file) { - return -1; -} +int _isatty(int file) { return -1; } // We don't support proc -int _kill(int pid, int sig) { - return -1; -} +int _kill(int pid, int sig) { return -1; } // We don't support proc -int _getpid() { - return -1; -} +int _getpid() { return -1; } // We don't support FS -int _fstat(int file, struct stat* st) { - return -1; -} +int _fstat(int file, struct stat *st) { return -1; } // We don't support close -int _close(int file) { - return -1; -} +int _close(int file) { return -1; } // We don't support lseek -int _lseek(int file, int ptr, int dir) { - return -1; -} +int _lseek(int file, int ptr, int dir) { return -1; } // TODO: We can support read -int _read(int file, char* ptr, int len) { - return -1; -} - +int _read(int file, char *ptr, int len) { return -1; } diff --git a/tests/emurt/emurt.h b/tests/emurt/emurt.h index b31c1b8f9..34638f1c0 100644 --- a/tests/emurt/emurt.h +++ b/tests/emurt/emurt.h @@ -3,12 +3,11 @@ #include struct uartlite_regs { - volatile unsigned int rx_fifo; - volatile unsigned int tx_fifo; - volatile unsigned int status; - volatile unsigned int control; + volatile unsigned int rx_fifo; + volatile unsigned int tx_fifo; + volatile unsigned int status; + volatile unsigned int control; }; void get(char *s, int n); void print_s(const char *c); - From fdc8915275e14bac5cb874339e61775583ead444 Mon Sep 17 00:00:00 2001 From: Avimitin Date: Thu, 9 Jan 2025 02:19:49 +0800 Subject: [PATCH 4/7] [emurt] update write design and add new program instrument function Signed-off-by: Avimitin --- tests/emurt/emurt.c | 53 ++++++++------------------------------------- tests/emurt/emurt.h | 9 +------- 2 files changed, 10 insertions(+), 52 deletions(-) diff --git a/tests/emurt/emurt.c b/tests/emurt/emurt.c index 4a5ca10d5..ce9539594 100644 --- a/tests/emurt/emurt.c +++ b/tests/emurt/emurt.c @@ -1,54 +1,19 @@ #include "emurt.h" +#define EXIT_REG 0x10000000 +#define UART_W_REG 0x10000010 +#define PERF_REG 0x10000014 + +void t1_put_char(char c) { *(uint32_t *)(UART_W_REG) = (uint32_t)c; } +void place_counter(int i) { *(int *)(PERF_REG) = i; } + /////////////////////// // uart /////////////////////// - -struct uartlite_regs *const ttyUL0 = (struct uartlite_regs *)0x10000000; - -#define SR_TX_FIFO_FULL (1 << 3) /* transmit FIFO full */ -#define SR_TX_FIFO_EMPTY (1 << 2) /* transmit FIFO empty */ -#define SR_RX_FIFO_VALID_DATA (1 << 0) /* data in receive FIFO */ -#define SR_RX_FIFO_FULL (1 << 1) /* receive FIFO full */ - -#define ULITE_CONTROL_RST_TX 0x01 -#define ULITE_CONTROL_RST_RX 0x02 - -void uart_put_c(char c) { - while (ttyUL0->status & SR_TX_FIFO_FULL) - ; - ttyUL0->tx_fifo = c; -} - -char uart_check_read() { // 1: data ready, 0: no data - return (ttyUL0->status & SR_RX_FIFO_VALID_DATA) != 0; -} - -char uart_get_c() { return ttyUL0->rx_fifo; } - -void get(char *s, int n) { - char debug[20] = "Enter get()"; - print_s(debug); - int i = 0; - while (uart_check_read() != 1) - ; - while (uart_check_read() && i < n - 1) { - print_s(debug); - char c = uart_get_c(); - uart_put_c(c); - if (c == '\r' || c == '\n') { - break; // Break if carriage return or newline is encountered - } - *(s + i) = c; - i++; - } - s[i] = '\0'; -} - int _write(int file, char *ptr, int len) { int i = 0; for (; i < len; i++) { - uart_put_c(ptr[i]); + t1_put_char(ptr[i]); } return i; } @@ -63,7 +28,7 @@ void _exit(int code) { void print_s(const char *c) { while (*c) { - uart_put_c(*c); + t1_put_char(*c); c++; } } diff --git a/tests/emurt/emurt.h b/tests/emurt/emurt.h index 34638f1c0..56c3dbb82 100644 --- a/tests/emurt/emurt.h +++ b/tests/emurt/emurt.h @@ -2,12 +2,5 @@ #include -struct uartlite_regs { - volatile unsigned int rx_fifo; - volatile unsigned int tx_fifo; - volatile unsigned int status; - volatile unsigned int control; -}; - -void get(char *s, int n); void print_s(const char *c); +void place_counter(int i); From 6243e3ddc7f88eadbfc4d75f0dfd7ab5def43e39 Mon Sep 17 00:00:00 2001 From: Avimitin Date: Thu, 9 Jan 2025 02:20:09 +0800 Subject: [PATCH 5/7] [emurt] add simple write char test Signed-off-by: Avimitin --- tests/default.nix | 3 ++- tests/emurt/tests/default.nix | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 tests/emurt/tests/default.nix diff --git a/tests/default.nix b/tests/default.nix index ceb5e6500..611a5a119 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -90,11 +90,12 @@ let rvv_bench = casesSelf.callPackage ./rvv_bench { }; pytorch = casesSelf.callPackage ./pytorch { }; disp = casesSelf.callPackage ./disp { }; + emurt-test = casesSelf.callPackage ./emurt/tests { }; })); # remove non-case attributes in scope scopeStripped = { - inherit (scope) mlir intrinsic asm perf codegen rvv_bench pytorch disp; + inherit (scope) mlir intrinsic asm perf codegen rvv_bench pytorch disp emurt-test; }; # This derivation is for internal CI use only. diff --git a/tests/emurt/tests/default.nix b/tests/emurt/tests/default.nix new file mode 100644 index 000000000..eb66ef1ab --- /dev/null +++ b/tests/emurt/tests/default.nix @@ -0,0 +1,31 @@ +{ linkerScript, t1main, makeBuilder, writeText }: +let + builder = makeBuilder { casePrefix = "emurt-test"; }; +in +{ + simple = builder { + caseName = "simple"; + + dontUnpack = true; + csrc = writeText "simple-emurt-test.c" '' + #include + + void test() { + place_counter(1); + print_s("Hello, World\n"); + place_counter(2); + } + ''; + + buildPhase = '' + runHook preBuild + + $CC -T${linkerScript} \ + $csrc \ + ${t1main} \ + -o $pname.elf + + runHook postBuild + ''; + }; +} From 2a06ca728c6a7959d478d8fa1da8533d852bfe80 Mon Sep 17 00:00:00 2001 From: Avimitin Date: Thu, 9 Jan 2025 13:24:13 +0800 Subject: [PATCH 6/7] [emurt] add volatile keyword to mmio register Signed-off-by: Avimitin --- tests/emurt/emurt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/emurt/emurt.c b/tests/emurt/emurt.c index ce9539594..9ae15de55 100644 --- a/tests/emurt/emurt.c +++ b/tests/emurt/emurt.c @@ -4,8 +4,8 @@ #define UART_W_REG 0x10000010 #define PERF_REG 0x10000014 -void t1_put_char(char c) { *(uint32_t *)(UART_W_REG) = (uint32_t)c; } -void place_counter(int i) { *(int *)(PERF_REG) = i; } +void t1_put_char(char c) { *(uint8_t volatile *)(UART_W_REG) = (uint8_t)c; } +void place_counter(int i) { *(int volatile *)(PERF_REG) = i; } /////////////////////// // uart From d60f4aea8d423306f1ab9e6e5cef02dad7e497d2 Mon Sep 17 00:00:00 2001 From: github-actions Date: Thu, 9 Jan 2025 10:31:44 +0000 Subject: [PATCH 7/7] [ci] update t1 test case cycle data --- .github/designs/blastoise/t1rocketemu.json | 26 +++++++++++----------- .github/designs/rookidee/t1rocketemu.json | 20 ++++++++--------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/.github/designs/blastoise/t1rocketemu.json b/.github/designs/blastoise/t1rocketemu.json index f071c4a8b..638164a5a 100644 --- a/.github/designs/blastoise/t1rocketemu.json +++ b/.github/designs/blastoise/t1rocketemu.json @@ -512,17 +512,17 @@ "mlir.rvv_vp_intrinsic_add_scalable": 1008, "mlir.stripmining": 9242, "mlir.vectoradd": 13344, - "pytorch.demo": 33242, - "pytorch.matmul": 73186, - "rvv_bench.ascii_to_utf16": 702304, - "rvv_bench.ascii_to_utf32": 235872, - "rvv_bench.byteswap": 407420, - "rvv_bench.chacha20": 40757, - "rvv_bench.mandelbrot": 557756, - "rvv_bench.memcpy": 709571, - "rvv_bench.memset": 295866, - "rvv_bench.mergelines": 577082, - "rvv_bench.poly1305": 40757, - "rvv_bench.strlen": 220022, - "rvv_bench.utf8_count": 2304110 + "pytorch.demo": 33202, + "pytorch.matmul": 73102, + "rvv_bench.ascii_to_utf16": 701692, + "rvv_bench.ascii_to_utf32": 235679, + "rvv_bench.byteswap": 407359, + "rvv_bench.chacha20": 40800, + "rvv_bench.mandelbrot": 557777, + "rvv_bench.memcpy": 709378, + "rvv_bench.memset": 295845, + "rvv_bench.mergelines": 577117, + "rvv_bench.poly1305": 40800, + "rvv_bench.strlen": 220857, + "rvv_bench.utf8_count": 2304128 } \ No newline at end of file diff --git a/.github/designs/rookidee/t1rocketemu.json b/.github/designs/rookidee/t1rocketemu.json index f4f20073d..3cbf3881c 100644 --- a/.github/designs/rookidee/t1rocketemu.json +++ b/.github/designs/rookidee/t1rocketemu.json @@ -435,14 +435,14 @@ "mlir.rvv_vp_intrinsic_add": 606, "mlir.rvv_vp_intrinsic_add_scalable": 896, "mlir.stripmining": 28954, - "rvv_bench.ascii_to_utf16": 704963, - "rvv_bench.ascii_to_utf32": 236223, - "rvv_bench.byteswap": 445945, - "rvv_bench.chacha20": 40757, - "rvv_bench.memcpy": 716867, - "rvv_bench.memset": 301885, - "rvv_bench.mergelines": 595373, - "rvv_bench.poly1305": 40757, - "rvv_bench.strlen": 239291, - "rvv_bench.utf8_count": 2377771 + "rvv_bench.ascii_to_utf16": 704310, + "rvv_bench.ascii_to_utf32": 235978, + "rvv_bench.byteswap": 445875, + "rvv_bench.chacha20": 40800, + "rvv_bench.memcpy": 716655, + "rvv_bench.memset": 301824, + "rvv_bench.mergelines": 595465, + "rvv_bench.poly1305": 40800, + "rvv_bench.strlen": 240136, + "rvv_bench.utf8_count": 2377786 } \ No newline at end of file