From 1a2e1fff7ce4b8fd8db46549d81e71e76b842da3 Mon Sep 17 00:00:00 2001 From: Kimplul Date: Fri, 30 Aug 2024 18:56:49 +0300 Subject: add some basic benchmarks --- benchmarks/scripts/gen-benchmark | 32 +++++++++++++++++++++++++++ benchmarks/scripts/makefile | 47 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100755 benchmarks/scripts/gen-benchmark create mode 100644 benchmarks/scripts/makefile (limited to 'benchmarks/scripts') 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 -- cgit v1.3