Skip to content

Commit 698b2b3

Browse files
committed
Add cache test and tetris binary to rootfs
1 parent 9a90a54 commit 698b2b3

File tree

3 files changed

+68
-3
lines changed

3 files changed

+68
-3
lines changed

Makefile

+9-3
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,11 @@ pk: install-dir $(RISCV)/bin/riscv64-unknown-elf-gcc
9696
all: gnu-toolchain-newlib gnu-toolchain-libc fesvr isa-sim tests pk
9797

9898

99-
vmlinux: $(buildroot_defconfig) $(linux_defconfig) $(busybox_defconfig) $(RISCV)/bin/riscv64-unknown-elf-gcc $(RISCV)/bin/riscv64-unknown-linux-gnu-gcc
99+
cachetest:
100+
cd ./cachetest/ && $(RISCV)/bin/riscv64-unknown-elf-gcc cachetest.c -o cachetest.elf
101+
cp ./cachetest/cachetest.elf rootfs/
102+
103+
vmlinux: $(buildroot_defconfig) $(linux_defconfig) $(busybox_defconfig) $(RISCV)/bin/riscv64-unknown-elf-gcc $(RISCV)/bin/riscv64-unknown-linux-gnu-gcc cachetest
100104
mkdir -p build
101105
make -C buildroot clean
102106
make -C buildroot defconfig BR2_DEFCONFIG=../configs/buildroot_defconfig
@@ -113,14 +117,16 @@ bbl_binary: bbl
113117
riscv64-unknown-elf-objcopy -O binary bbl bbl_binary
114118

115119
clean:
116-
rm -rf vmlinux bbl riscv-pk/build/vmlinux riscv-pk/build/bbl
120+
rm -rf vmlinux bbl riscv-pk/build/vmlinux riscv-pk/build/bbl cachetest/*.elf
117121
make -C buildroot distclean
118122

119123
bbl.bin: bbl
120124
riscv64-unknown-elf-objcopy -S -O binary --change-addresses -0x80000000 $< $@
121125

122126
clean-all: clean
123-
rm -rf riscv-fesvr/build riscv-isa-sim/build riscv-gnu-toolchain/build riscv-tests/build riscv-pk/build
127+
rm -rf riscv-fesvr/build riscv-isa-sim/build riscv-gnu-toolchain/build riscv-tests/build riscv-pk/build cachetest/*.elf
128+
129+
.PHONY: cachetest
124130

125131
help:
126132
@echo "usage: $(MAKE) [RISCV='<install/here>'] [tool/img] ..."

cachetest/cachetest.c

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Copyright 2019 ETH Zurich and University of Bologna.
2+
// Copyright and related rights are licensed under the Solderpad Hardware
3+
// License, Version 0.51 (the "License"); you may not use this file except in
4+
// compliance with the License. You may obtain a copy of the License at
5+
// http://solderpad.org/licenses/SHL-0.51. Unless required by applicable law
6+
// or agreed to in writing, software, hardware and materials distributed under
7+
// this License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
8+
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
9+
// specific language governing permissions and limitations under the License.
10+
11+
extern int printf(const char *format, ...);
12+
13+
#define read_csr(reg) ({ unsigned long __tmp; \
14+
asm volatile ("csrr %0, " #reg : "=r"(__tmp)); \
15+
__tmp; })
16+
17+
char buffer[1024 * 1024];
18+
19+
void sweep(int stride)
20+
{
21+
long instret_start, cycle_start;
22+
int max_j = 4 * 1024;
23+
int working_set = max_j * stride;
24+
25+
for(int i = 0; i < 10; i++)
26+
{
27+
if(i == 1)
28+
{
29+
instret_start = read_csr(instret);
30+
cycle_start = read_csr(cycle);
31+
}
32+
33+
for(int j = 0; j < max_j; j += 4)
34+
{
35+
buffer[(j + 0) * stride] = 0;
36+
buffer[(j + 1) * stride] = 0;
37+
buffer[(j + 2) * stride] = 0;
38+
buffer[(j + 3) * stride] = 0;
39+
}
40+
}
41+
42+
long instrets = read_csr(instret) - instret_start;
43+
long cycles = read_csr(cycle) - cycle_start;
44+
45+
printf("working_set = %2dKB, %ld instructions, %ld cycles, CPI = %f\n",
46+
working_set / 1024, instrets, cycles, (float) cycles / instrets);
47+
}
48+
49+
int main()
50+
{
51+
sweep(0);
52+
sweep(1);
53+
sweep(2);
54+
sweep(4);
55+
sweep(8);
56+
sweep(16);
57+
58+
return 0;
59+
}

rootfs/tetris

98.6 KB
Binary file not shown.

0 commit comments

Comments
 (0)