From 1cfb1af56ef623c3d6ffb5daedca75af625978ff Mon Sep 17 00:00:00 2001 From: Stefan Kalkowski Date: Fri, 19 Jun 2020 16:41:20 +0200 Subject: [PATCH] os: automate cpu_bench testsuite * Differentiate in between different architectures with assembler routines for correct measures * Automate first step measuring of 10G bogomips across different hardware Fix #3785 --- repos/os/run/cpu_bench.run | 85 +++++++++++-------- repos/os/src/test/cpu_bench/bogomips.h | 20 +++-- repos/os/src/test/cpu_bench/linux/Makefile | 7 -- .../os/src/test/cpu_bench/linux/Makefile.inc | 14 +++ repos/os/src/test/cpu_bench/linux/main.cc | 17 ++-- repos/os/src/test/cpu_bench/main.cc | 18 ++-- .../os/src/test/cpu_bench/spec/arm/bogomips.s | 28 ++++++ .../test/cpu_bench/spec/arm/linux/Makefile | 3 + .../os/src/test/cpu_bench/spec/arm/target.mk | 3 + .../src/test/cpu_bench/spec/arm_64/bogomips.s | 24 ++++++ .../test/cpu_bench/spec/arm_64/linux/Makefile | 3 + .../src/test/cpu_bench/spec/arm_64/target.mk | 3 + .../src/test/cpu_bench/spec/x86_32/bogomips.s | 26 ++++++ .../test/cpu_bench/spec/x86_32/linux/Makefile | 3 + .../src/test/cpu_bench/spec/x86_32/target.mk | 3 + .../src/test/cpu_bench/spec/x86_64/bogomips.s | 23 +++++ .../test/cpu_bench/spec/x86_64/linux/Makefile | 3 + .../src/test/cpu_bench/spec/x86_64/target.mk | 3 + repos/os/src/test/cpu_bench/target.inc | 7 ++ repos/os/src/test/cpu_bench/target.mk | 5 -- tool/autopilot.list | 1 + 21 files changed, 233 insertions(+), 66 deletions(-) delete mode 100644 repos/os/src/test/cpu_bench/linux/Makefile create mode 100644 repos/os/src/test/cpu_bench/linux/Makefile.inc create mode 100644 repos/os/src/test/cpu_bench/spec/arm/bogomips.s create mode 100644 repos/os/src/test/cpu_bench/spec/arm/linux/Makefile create mode 100644 repos/os/src/test/cpu_bench/spec/arm/target.mk create mode 100644 repos/os/src/test/cpu_bench/spec/arm_64/bogomips.s create mode 100644 repos/os/src/test/cpu_bench/spec/arm_64/linux/Makefile create mode 100644 repos/os/src/test/cpu_bench/spec/arm_64/target.mk create mode 100644 repos/os/src/test/cpu_bench/spec/x86_32/bogomips.s create mode 100644 repos/os/src/test/cpu_bench/spec/x86_32/linux/Makefile create mode 100644 repos/os/src/test/cpu_bench/spec/x86_32/target.mk create mode 100644 repos/os/src/test/cpu_bench/spec/x86_64/bogomips.s create mode 100644 repos/os/src/test/cpu_bench/spec/x86_64/linux/Makefile create mode 100644 repos/os/src/test/cpu_bench/spec/x86_64/target.mk create mode 100644 repos/os/src/test/cpu_bench/target.inc delete mode 100644 repos/os/src/test/cpu_bench/target.mk diff --git a/repos/os/run/cpu_bench.run b/repos/os/run/cpu_bench.run index 4e66dd2d9f..90a62a9e01 100644 --- a/repos/os/run/cpu_bench.run +++ b/repos/os/run/cpu_bench.run @@ -5,52 +5,67 @@ if { [get_cmd_switch --autopilot] } { } } +if {[have_spec linux] || [have_spec riscv]} { + puts "\n Run script is not supported on this platform. \n"; + exit 0 +} + build "core init timer test/cpu_bench" create_boot_directory install_config { - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + } -build_boot_image { - core init test-cpu ld.lib.so timer -} +build_boot_image { core init cpu_bench ld.lib.so } append qemu_args " -nographic " -proc run_test {name serial_id} { - run_genode_until "start $name.*\n" 20 $serial_id - set t1 [clock milliseconds] - run_genode_until "finished $name.*\n" 200 $serial_id - set t2 [clock milliseconds] - return [expr {$t2 - $t1}] +# +# Those value relate to hardware used in CI testsuite used at Genode Labs, +# as well as the initialization of their bootloaders, we use this to measure +# regressions in the platform initialization code +# +proc bogomips_max_time { } { + if {[board] == "rpi"} { return 14300 } + if {[board] == "imx53_qsb"} { return 7520 } + if {[board] == "imx53_qsb_tz"} { return 7520 } + if {[board] == "imx6q_sabrelite"} { return 6320 } + if {[board] == "imx7d_sabre"} { return 9470 } + if {[board] == "imx8q_evk"} { return 7510 } + if {[have_spec x86_64] && [[board] == "pc"]} { return 600 } + if {[have_spec x86_32] && [[board] == "pc"]} { return 3150 } + return 0 } -run_genode_until "Cpu testsuite started" 60 +# run the test +run_genode_until {\[init -\> cpu_bench\] Execute 10G BogoMIPS.*\n} 120 set serial_id [output_spawn_id] -set bogomips [run_test "bogomips" $serial_id] -puts "bogomips: 2G Bogus instructions in $bogomips milliseconds ([expr {2000000.0 / $bogomips}] BogoMIPS)" +set t1 [clock milliseconds] +run_genode_until "Finished execution.*\n" 30 $serial_id +set t2 [clock milliseconds] +set result [expr {$t2 - $t1}] +set bogomips [expr {10000000000 / $result}] +set maximum [bogomips_max_time] +puts "10G bogus instructions in $result msecs ($bogomips BogoMIPS)" +if {$result > $maximum} { + puts "Test failed: bogomips loop lasted longer than $maximum msecs" + exit 1 +} exit 0 + diff --git a/repos/os/src/test/cpu_bench/bogomips.h b/repos/os/src/test/cpu_bench/bogomips.h index d709d8e1be..d36e4e5acc 100644 --- a/repos/os/src/test/cpu_bench/bogomips.h +++ b/repos/os/src/test/cpu_bench/bogomips.h @@ -1,8 +1,18 @@ +/* + * \brief Testing CPU performance + * \author Stefan Kalkowski + * \date 2018-10-22 + * + */ -void bogomips() __attribute__((optimize("O0"))); +/* + * Copyright (C) 2018 Genode Labs GmbH + * + * This file is part of the Genode OS framework, which is distributed + * under the terms of the GNU Affero General Public License version 3. + */ -void bogomips() -{ - for (register unsigned i = 0; i < 1000000000; i++) ; -}; +#pragma once +extern "C" void bogomips(unsigned long); +extern "C" unsigned long bogomips_instr_count(void); diff --git a/repos/os/src/test/cpu_bench/linux/Makefile b/repos/os/src/test/cpu_bench/linux/Makefile deleted file mode 100644 index 9490900b37..0000000000 --- a/repos/os/src/test/cpu_bench/linux/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -INC_DIR = $(PWD)/.. - -cpu_bench: main.cc $(INC_DIR)/bogomips.h - g++ -I$(INC_DIR) -O2 -Wall -Wextra -Weffc++ -std=gnu++11 $< -o $@ - -clean: - rm -f *~ cpu_bench diff --git a/repos/os/src/test/cpu_bench/linux/Makefile.inc b/repos/os/src/test/cpu_bench/linux/Makefile.inc new file mode 100644 index 0000000000..5aa1589e52 --- /dev/null +++ b/repos/os/src/test/cpu_bench/linux/Makefile.inc @@ -0,0 +1,14 @@ +OBJECTS := main.o bogomips.o +GEN_DIR = $(LINUX_DIR)/.. + +cpu_bench: $(OBJECTS) + g++ $(OBJECTS) -o $@ + +main.o: $(LINUX_DIR)/main.cc $(GEN_DIR)/bogomips.h + g++ -c -I$(GEN_DIR) -O2 -Wall -Wextra -Weffc++ -std=gnu++11 $< -o $@ + +bogomips.o: ../bogomips.s + gcc -c -O2 -Wall -Wextra $< -o $@ + +clean: + rm -f *~ cpu_bench bogomips.o main.o diff --git a/repos/os/src/test/cpu_bench/linux/main.cc b/repos/os/src/test/cpu_bench/linux/main.cc index 9e98f30f84..344575c594 100644 --- a/repos/os/src/test/cpu_bench/linux/main.cc +++ b/repos/os/src/test/cpu_bench/linux/main.cc @@ -20,14 +20,14 @@ struct Time void print() const { printf("secs=%ld nsecs=%ld\n", - (long)_timespec.tv_sec, (long)_timespec.tv_nsec); + (long)_timespec.tv_sec, (long)_timespec.tv_nsec); } static Duration duration(Time t1, Time t2) { auto usecs = [&] (timespec ts) { return 1000UL*1000UL*((unsigned long)ts.tv_sec % 1000UL) - + (unsigned long)ts.tv_nsec/1000UL; }; + + (unsigned long)ts.tv_nsec/1000UL; }; return Duration { usecs(t2._timespec) - usecs(t1._timespec) }; } @@ -36,13 +36,18 @@ struct Time int main(int, char**) { - printf("bogomips test:\n"); + unsigned long instr_per_round = bogomips_instr_count(); + unsigned long rounds = 1000UL*1000UL*1000UL / instr_per_round * 10UL; + + printf("Execute 10G BogoMIPS in %lu rounds with %lu instr per round\n", + rounds, instr_per_round); + Time s; - bogomips(); + bogomips(rounds); { Time e; Duration duration = Time::duration(s, e); - printf("2G bogus instructions in %ld msecs (%f BogoMIPS)\n", - duration.usecs/1000, 2000000000 / (float)duration.usecs); + printf("10G bogus instructions in %lu msecs\n", duration.usecs/1000); } } + diff --git a/repos/os/src/test/cpu_bench/main.cc b/repos/os/src/test/cpu_bench/main.cc index 05679330d2..60d654b611 100644 --- a/repos/os/src/test/cpu_bench/main.cc +++ b/repos/os/src/test/cpu_bench/main.cc @@ -14,17 +14,19 @@ #include #include -#include #include -void Component::construct(Genode::Env &env) +void Component::construct(Genode::Env &) { - Timer::Connection timer(env); - timer.msleep(2000); + using namespace Genode; - Genode::log("Cpu testsuite started"); - Genode::log("start bogomips"); - bogomips(); - Genode::log("finished bogomips"); + log("Cpu testsuite started"); + + size_t cnt = 1000*1000*1000 / bogomips_instr_count() * 10; + + log("Execute 10G BogoMIPS in ", cnt, " rounds with ", + bogomips_instr_count(), " instructions each"); + bogomips(cnt); + log("Finished execution"); }; diff --git a/repos/os/src/test/cpu_bench/spec/arm/bogomips.s b/repos/os/src/test/cpu_bench/spec/arm/bogomips.s new file mode 100644 index 0000000000..7adb72ca0f --- /dev/null +++ b/repos/os/src/test/cpu_bench/spec/arm/bogomips.s @@ -0,0 +1,28 @@ + +.section .text + + .balign 4096 + .global bogomips + bogomips: + push { r4, lr } + mov r4, #0 + 1: + cmp r4, r0 + addne r4, r4, #1 + .rept 1 + nop + .endr + bne 1b + 2: + pop { r4, lr } + mov pc, lr + + .global bogomips_instr_count + bogomips_instr_count: + push { r4, r5, lr } + adr r4, 1b + adr r5, 2b + sub r0, r5, r4 + lsr r0, r0, #2 + pop { r4, r5, lr } + mov pc, lr diff --git a/repos/os/src/test/cpu_bench/spec/arm/linux/Makefile b/repos/os/src/test/cpu_bench/spec/arm/linux/Makefile new file mode 100644 index 0000000000..aa06928304 --- /dev/null +++ b/repos/os/src/test/cpu_bench/spec/arm/linux/Makefile @@ -0,0 +1,3 @@ +LINUX_DIR = $(PWD)/../../../linux + +include $(LINUX_DIR)/Makefile.inc diff --git a/repos/os/src/test/cpu_bench/spec/arm/target.mk b/repos/os/src/test/cpu_bench/spec/arm/target.mk new file mode 100644 index 0000000000..eebf7f02df --- /dev/null +++ b/repos/os/src/test/cpu_bench/spec/arm/target.mk @@ -0,0 +1,3 @@ +REQUIRES = arm + +include $(PRG_DIR)/../../target.inc diff --git a/repos/os/src/test/cpu_bench/spec/arm_64/bogomips.s b/repos/os/src/test/cpu_bench/spec/arm_64/bogomips.s new file mode 100644 index 0000000000..44d3d45595 --- /dev/null +++ b/repos/os/src/test/cpu_bench/spec/arm_64/bogomips.s @@ -0,0 +1,24 @@ + +.section .text + + .balign 4096 + .global bogomips + bogomips: + mov x9, x0 + 1: + cbz x9, 2f + sub x9, x9, #1 + .rept 1 + nop + .endr + b 1b + 2: + ret + + .global bogomips_instr_count + bogomips_instr_count: + adr x9, 1b + adr x10, 2b + sub x0, x10, x9 + lsr x0, x0, #2 + ret diff --git a/repos/os/src/test/cpu_bench/spec/arm_64/linux/Makefile b/repos/os/src/test/cpu_bench/spec/arm_64/linux/Makefile new file mode 100644 index 0000000000..aa06928304 --- /dev/null +++ b/repos/os/src/test/cpu_bench/spec/arm_64/linux/Makefile @@ -0,0 +1,3 @@ +LINUX_DIR = $(PWD)/../../../linux + +include $(LINUX_DIR)/Makefile.inc diff --git a/repos/os/src/test/cpu_bench/spec/arm_64/target.mk b/repos/os/src/test/cpu_bench/spec/arm_64/target.mk new file mode 100644 index 0000000000..8c094640e7 --- /dev/null +++ b/repos/os/src/test/cpu_bench/spec/arm_64/target.mk @@ -0,0 +1,3 @@ +REQUIRES = arm_64 + +include $(PRG_DIR)/../../target.inc diff --git a/repos/os/src/test/cpu_bench/spec/x86_32/bogomips.s b/repos/os/src/test/cpu_bench/spec/x86_32/bogomips.s new file mode 100644 index 0000000000..e77caa0fbd --- /dev/null +++ b/repos/os/src/test/cpu_bench/spec/x86_32/bogomips.s @@ -0,0 +1,26 @@ +.section .text + + .balign 4096 + .global bogomips + bogomips: + push %ebp + mov %esp, %ebp + mov 0x8(%ebp), %eax + 1: + cmp $0x0, %eax + je 2f + sub $0x1, %eax + .rept 1 + nop + .endr + jmp 1b + 2: + mov %ebp, %esp + pop %ebp + ret + + .global bogomips_instr_count + bogomips_instr_count: + mov $0x5, %eax + ret + diff --git a/repos/os/src/test/cpu_bench/spec/x86_32/linux/Makefile b/repos/os/src/test/cpu_bench/spec/x86_32/linux/Makefile new file mode 100644 index 0000000000..aa06928304 --- /dev/null +++ b/repos/os/src/test/cpu_bench/spec/x86_32/linux/Makefile @@ -0,0 +1,3 @@ +LINUX_DIR = $(PWD)/../../../linux + +include $(LINUX_DIR)/Makefile.inc diff --git a/repos/os/src/test/cpu_bench/spec/x86_32/target.mk b/repos/os/src/test/cpu_bench/spec/x86_32/target.mk new file mode 100644 index 0000000000..77f537dd3f --- /dev/null +++ b/repos/os/src/test/cpu_bench/spec/x86_32/target.mk @@ -0,0 +1,3 @@ +REQUIRES = x86_32 + +include $(PRG_DIR)/../../target.inc diff --git a/repos/os/src/test/cpu_bench/spec/x86_64/bogomips.s b/repos/os/src/test/cpu_bench/spec/x86_64/bogomips.s new file mode 100644 index 0000000000..8e9e3c378f --- /dev/null +++ b/repos/os/src/test/cpu_bench/spec/x86_64/bogomips.s @@ -0,0 +1,23 @@ +.section .text + + .balign 4096 + .global bogomips + bogomips: + push %rdi + 1: + cmp $0x0, %rdi + je 2f + sub $0x1, %rdi + .rept 1 + nop + .endr + jmp 1b + 2: + pop %rdi + ret + + .global bogomips_instr_count + bogomips_instr_count: + mov $0x5, %rax + ret + diff --git a/repos/os/src/test/cpu_bench/spec/x86_64/linux/Makefile b/repos/os/src/test/cpu_bench/spec/x86_64/linux/Makefile new file mode 100644 index 0000000000..aa06928304 --- /dev/null +++ b/repos/os/src/test/cpu_bench/spec/x86_64/linux/Makefile @@ -0,0 +1,3 @@ +LINUX_DIR = $(PWD)/../../../linux + +include $(LINUX_DIR)/Makefile.inc diff --git a/repos/os/src/test/cpu_bench/spec/x86_64/target.mk b/repos/os/src/test/cpu_bench/spec/x86_64/target.mk new file mode 100644 index 0000000000..fea3e912d0 --- /dev/null +++ b/repos/os/src/test/cpu_bench/spec/x86_64/target.mk @@ -0,0 +1,3 @@ +REQUIRES = x86_64 + +include $(PRG_DIR)/../../target.inc diff --git a/repos/os/src/test/cpu_bench/target.inc b/repos/os/src/test/cpu_bench/target.inc new file mode 100644 index 0000000000..4e9e4d54aa --- /dev/null +++ b/repos/os/src/test/cpu_bench/target.inc @@ -0,0 +1,7 @@ +TARGET = cpu_bench +INC_DIR = $(PRG_DIR)/../.. +SRC_CC = main.cc +SRC_S = bogomips.s +LIBS = base + +vpath main.cc $(PRG_DIR)/../.. diff --git a/repos/os/src/test/cpu_bench/target.mk b/repos/os/src/test/cpu_bench/target.mk deleted file mode 100644 index 38669cdda2..0000000000 --- a/repos/os/src/test/cpu_bench/target.mk +++ /dev/null @@ -1,5 +0,0 @@ -TARGET = test-cpu -SRC_CC = main.cc -INC_DIR = $(PRG_DIR) -LIBS = base -CC_WARN = -Wno-register diff --git a/tool/autopilot.list b/tool/autopilot.list index 836291ef92..ff808b2386 100644 --- a/tool/autopilot.list +++ b/tool/autopilot.list @@ -1,4 +1,5 @@ bomb +cpu_bench cpu_quota cpu_sampler demo