diff options
Diffstat (limited to 'benchmarks')
| -rw-r--r-- | benchmarks/Makefile | 16 | ||||
| -rw-r--r-- | benchmarks/benchmarks.mk | 52 | ||||
| l--------- | benchmarks/common | 1 | ||||
| -rw-r--r-- | benchmarks/create/init.c | 27 | ||||
| -rw-r--r-- | benchmarks/create/source.mk | 1 | ||||
| -rw-r--r-- | benchmarks/fork/init.c | 27 | ||||
| -rw-r--r-- | benchmarks/fork/source.mk | 1 | ||||
| -rw-r--r-- | benchmarks/ipc-req/init.c | 24 | ||||
| -rw-r--r-- | benchmarks/ipc-req/source.mk | 1 | ||||
| -rw-r--r-- | benchmarks/malloc/init.c | 22 | ||||
| -rw-r--r-- | benchmarks/malloc/source.mk | 1 | ||||
| -rwxr-xr-x | benchmarks/scripts/gen-benchmark | 32 | ||||
| -rw-r--r-- | benchmarks/scripts/makefile | 47 |
13 files changed, 252 insertions, 0 deletions
diff --git a/benchmarks/Makefile b/benchmarks/Makefile new file mode 100644 index 0000000..79e1afd --- /dev/null +++ b/benchmarks/Makefile @@ -0,0 +1,16 @@ +.PHONY: benchmark +benchmark: + $(MAKE) -f scripts/makefile benchmark + +.DEFAULT: + $(MAKE) -f scripts/makefile $< + +SOURCES != echo */source.mk +DO != echo -n > benchmarks.mk +include $(SOURCES) + +RM ?= rm + +.PHONY: clean +clean: + $(RM) -rf build diff --git a/benchmarks/benchmarks.mk b/benchmarks/benchmarks.mk new file mode 100644 index 0000000..6b29504 --- /dev/null +++ b/benchmarks/benchmarks.mk @@ -0,0 +1,52 @@ +build/create/init.o.d: +-include build/create/init.o.d +build/create/init.o: create/ + mkdir -p build/create + $(COMPILE_BENCHMARK) -c create/init.c -o build/create/init.o +build/create/initrd: build/create/init.o $(COMMON) + $(COMPILE_BENCHMARK) build/create/init.o $(COMMON) -o build/create/init + echo build/create/init | $(GEN_INITRD) build/create/initrd +BENCHMARKS += create +.PHONY: create +create: build/create/initrd + mkdir -p reports/create + timeout --foreground 30s $(QEMU) build/create/initrd > reports/create/log +build/fork/init.o.d: +-include build/fork/init.o.d +build/fork/init.o: fork/ + mkdir -p build/fork + $(COMPILE_BENCHMARK) -c fork/init.c -o build/fork/init.o +build/fork/initrd: build/fork/init.o $(COMMON) + $(COMPILE_BENCHMARK) build/fork/init.o $(COMMON) -o build/fork/init + echo build/fork/init | $(GEN_INITRD) build/fork/initrd +BENCHMARKS += fork +.PHONY: fork +fork: build/fork/initrd + mkdir -p reports/fork + timeout --foreground 30s $(QEMU) build/fork/initrd > reports/fork/log +build/ipc-req/init.o.d: +-include build/ipc-req/init.o.d +build/ipc-req/init.o: ipc-req/ + mkdir -p build/ipc-req + $(COMPILE_BENCHMARK) -c ipc-req/init.c -o build/ipc-req/init.o +build/ipc-req/initrd: build/ipc-req/init.o $(COMMON) + $(COMPILE_BENCHMARK) build/ipc-req/init.o $(COMMON) -o build/ipc-req/init + echo build/ipc-req/init | $(GEN_INITRD) build/ipc-req/initrd +BENCHMARKS += ipc-req +.PHONY: ipc-req +ipc-req: build/ipc-req/initrd + mkdir -p reports/ipc-req + timeout --foreground 30s $(QEMU) build/ipc-req/initrd > reports/ipc-req/log +build/malloc/init.o.d: +-include build/malloc/init.o.d +build/malloc/init.o: malloc/ + mkdir -p build/malloc + $(COMPILE_BENCHMARK) -c malloc/init.c -o build/malloc/init.o +build/malloc/initrd: build/malloc/init.o $(COMMON) + $(COMPILE_BENCHMARK) build/malloc/init.o $(COMMON) -o build/malloc/init + echo build/malloc/init | $(GEN_INITRD) build/malloc/initrd +BENCHMARKS += malloc +.PHONY: malloc +malloc: build/malloc/initrd + mkdir -p reports/malloc + timeout --foreground 30s $(QEMU) build/malloc/initrd > reports/malloc/log diff --git a/benchmarks/common b/benchmarks/common new file mode 120000 index 0000000..7d2aca5 --- /dev/null +++ b/benchmarks/common @@ -0,0 +1 @@ +../tests/common
\ No newline at end of file diff --git a/benchmarks/create/init.c b/benchmarks/create/init.c new file mode 100644 index 0000000..7254296 --- /dev/null +++ b/benchmarks/create/init.c @@ -0,0 +1,27 @@ +#include <common/benchmark.h> + +void callback() +{ + sys_exit(1); +} + +START(pid, tid, d0, d1, d2, d3) +{ + UNUSED(pid); + UNUSED(tid); + UNUSED(d0); + UNUSED(d1); + UNUSED(d2); + UNUSED(d3); + + uint64_t timebase = sys_timebase(); + uint64_t start = sys_ticks(); + + for (size_t i = 0; i < 1000; ++i) { + id_t new_id = sys_create((uintptr_t)callback, 0, 0, 0, 0); + sys_swap(new_id); + } + + uint64_t end = sys_ticks(); + report(start, end, timebase); +} diff --git a/benchmarks/create/source.mk b/benchmarks/create/source.mk new file mode 100644 index 0000000..0377337 --- /dev/null +++ b/benchmarks/create/source.mk @@ -0,0 +1 @@ +DO != ./scripts/gen-benchmark -n create diff --git a/benchmarks/fork/init.c b/benchmarks/fork/init.c new file mode 100644 index 0000000..95f6466 --- /dev/null +++ b/benchmarks/fork/init.c @@ -0,0 +1,27 @@ +#include <common/benchmark.h> + +START(pid, tid, d0, d1, d2, d3) +{ + UNUSED(pid); + UNUSED(tid); + UNUSED(d0); + UNUSED(d1); + UNUSED(d2); + UNUSED(d3); + + uint64_t timebase = sys_timebase(); + uint64_t start = sys_ticks(); + + for (size_t i = 0; i < 1000; ++i) { + id_t our_tid = 0; + id_t new_id = sys_fork(&our_tid); + if (new_id == 0) { + /* child instantly dies */ + sys_exit(1); + } + sys_swap(new_id); + } + + uint64_t end = sys_ticks(); + report(start, end, timebase); +} diff --git a/benchmarks/fork/source.mk b/benchmarks/fork/source.mk new file mode 100644 index 0000000..46bde60 --- /dev/null +++ b/benchmarks/fork/source.mk @@ -0,0 +1 @@ +DO != ./scripts/gen-benchmark -n fork diff --git a/benchmarks/ipc-req/init.c b/benchmarks/ipc-req/init.c new file mode 100644 index 0000000..02064a6 --- /dev/null +++ b/benchmarks/ipc-req/init.c @@ -0,0 +1,24 @@ +#include <common/benchmark.h> + +START(pid, tid, d0, d1, d2, d3) +{ + UNUSED(tid); + UNUSED(d0); + UNUSED(d1); + UNUSED(d2); + UNUSED(d3); + + if (pid == 0) { + uint64_t timebase = sys_timebase(); + uint64_t start = sys_ticks(); + + for (size_t i = 0; i < 1000; ++i) + sys_ipc_req0(1); + + uint64_t end = sys_ticks(); + report(start, end, timebase); + } + else if (pid == 1) { + sys_ipc_resp0(); + } +} diff --git a/benchmarks/ipc-req/source.mk b/benchmarks/ipc-req/source.mk new file mode 100644 index 0000000..21dc0e0 --- /dev/null +++ b/benchmarks/ipc-req/source.mk @@ -0,0 +1 @@ +DO != ./scripts/gen-benchmark -n ipc-req diff --git a/benchmarks/malloc/init.c b/benchmarks/malloc/init.c new file mode 100644 index 0000000..d58eeb2 --- /dev/null +++ b/benchmarks/malloc/init.c @@ -0,0 +1,22 @@ +#include <common/benchmark.h> + +START(pid, tid, d0, d1, d2, d3) +{ + UNUSED(pid); + UNUSED(tid); + UNUSED(d0); + UNUSED(d1); + UNUSED(d2); + UNUSED(d3); + + uint64_t timebase = sys_timebase(); + uint64_t start = sys_ticks(); + + for (size_t i = 0; i < 1000; ++i) { + void *p = sys_req_mem(1, VM_R | VM_W); + sys_free_mem((uintptr_t)p); + } + + uint64_t end = sys_ticks(); + report(start, end, timebase); +} diff --git a/benchmarks/malloc/source.mk b/benchmarks/malloc/source.mk new file mode 100644 index 0000000..3367314 --- /dev/null +++ b/benchmarks/malloc/source.mk @@ -0,0 +1 @@ +DO != ./scripts/gen-benchmark -n malloc diff --git a/benchmarks/scripts/gen-benchmark b/benchmarks/scripts/gen-benchmark new file mode 100755 index 0000000..459040d --- /dev/null +++ b/benchmarks/scripts/gen-benchmark @@ -0,0 +1,32 @@ +#!/bin/sh + +NAME= +while getopts "n:p:" opt; do + case "$opt" in + n) NAME="$OPTARG";; + *) echo "unrecognised options -$OPTARG" >&2; exit 1; + esac +done + +obj="build/${NAME}/init.o" +dep="${obj}.d" + +echo "${dep}:" >> benchmarks.mk +echo "-include ${dep}" >> benchmarks.mk +echo "${obj}: $NAME/${s}" >> benchmarks.mk +echo " mkdir -p build/$NAME" >> benchmarks.mk +echo " \$(COMPILE_BENCHMARK) -c $NAME/init.c -o ${obj}" >> benchmarks.mk + +echo "build/${NAME}/initrd: ${obj} \$(COMMON)" >> benchmarks.mk +echo " \$(COMPILE_BENCHMARK) ${obj} \ + \$(COMMON) -o build/${NAME}/init" >> benchmarks.mk + +echo " echo build/${NAME}/init | \ + \$(GEN_INITRD) build/${NAME}/initrd" >> benchmarks.mk + +echo "BENCHMARKS += ${NAME}" >> benchmarks.mk +echo ".PHONY: ${NAME}" >> benchmarks.mk +echo "${NAME}: build/${NAME}/initrd" >> benchmarks.mk +echo " mkdir -p reports/${NAME}" >> benchmarks.mk +echo " timeout --foreground 30s \ + \$(QEMU) build/${NAME}/initrd > reports/${NAME}/log" >> benchmarks.mk diff --git a/benchmarks/scripts/makefile b/benchmarks/scripts/makefile new file mode 100644 index 0000000..7140c05 --- /dev/null +++ b/benchmarks/scripts/makefile @@ -0,0 +1,47 @@ +.PHONY: all +all: benchmark + +ARCH ?= riscv64 +CROSS_COMPILE ?= $(ARCH)-unknown-elf- + +LLVM ?= 0 +COMPILER != [ "$(LLVM)" != "0" ] \ + && echo clang --target="$(CROSS_COMPILE)" \ + || echo $(CROSS_COMPILE)gcc + +include common/arch/$(ARCH)/source.mk + +OBFLAGS := -ffreestanding -nostdlib -std=c17 -g -O2 +INCLUDEFLAGS := -I ../include -I. +WARNFLAGS := -Wall -Wextra +DEPFLAGS = -MT $@ -MMD -MP -MF $@.d +COMPILE_BENCHMARK = $(COMPILER) $(WARNFLAGS) $(INCLUDEFLAGS) \ + $(DEPFLAGS) $(OBFLAGS) $(ARCH_FLAGS) + +GEN_INITRD := cpio -H newc -o > + +# icount gives a rough approximation of how many instructions are executed, but +# *actual* performance would still have to be measured on real systems +QEMU := qemu-system-$(ARCH) -machine virt -kernel ../kmi.bin \ + -serial stdio \ + -monitor none \ + -nographic \ + -no-reboot \ + -m 128M \ + -icount 0 \ + -initrd + +KMI := ../kmi.bin +COMMON := build/printf.o + +build/printf.o: common/printf.c $(KMI) + $(COMPILE_BENCHMARK) -c common/printf.c -o build/printf.o + +BENCHMARKS := +include benchmarks.mk + +.PHONY: benchmark +benchmark: $(BENCHMARKS) + @cd reports; for d in * ; do \ + printf "%8s: " "$$d"; tail -n 1 $$d/log | tr -d '\r' | bc -l; \ + done |
