test: add simple cpu benchmark test (fix #3026)

This commit is contained in:
Stefan Kalkowski 2018-10-30 14:40:20 +01:00 committed by Christian Helmuth
parent 24e6a5ee73
commit fe3f67f712
6 changed files with 153 additions and 0 deletions

View File

@ -0,0 +1,56 @@
if { [get_cmd_switch --autopilot] } {
if {[have_include "power_on/qemu"]} {
puts "\nRun script does not support Qemu.\n"
exit 0
}
}
build "core init test/cpu_bench"
create_boot_directory
install_config {
<config prio_levels="2">
<parent-provides>
<service name="ROM"/>
<service name="IRQ"/>
<service name="IO_MEM"/>
<service name="IO_PORT"/>
<service name="PD"/>
<service name="RM"/>
<service name="CPU"/>
<service name="LOG"/>
</parent-provides>
<default-route> <any-service> <parent/> <any-child/> </any-service> </default-route>
<default caps="200"/>
<start name="timer" caps="64" priority="0">
<resource name="RAM" quantum="1M"/>
<provides><service name="Timer"/></provides>
</start>
<start name="test-cpu" priority="-1">
<resource name="RAM" quantum="1M"/>
</start>
</config>
}
build_boot_image {
core init test-cpu ld.lib.so timer
}
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}]
}
run_genode_until "Cpu testsuite started.*\n" 60
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)"
exit 0

View File

@ -0,0 +1,8 @@
void bogomips() __attribute__((optimize("O0")));
void bogomips()
{
for (register unsigned i = 0; i < 1000000000; i++) ;
};

View File

@ -0,0 +1,7 @@
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

View File

@ -0,0 +1,48 @@
#include <time.h>
#include <stdio.h>
#include <bogomips.h>
struct Duration { unsigned long usecs; };
struct Time
{
timespec _timespec { 0, 0 };
Time()
{
clock_gettime(CLOCK_REALTIME, &_timespec);
}
Time(timespec timespec) : _timespec(timespec) { }
void print() const
{
printf("secs=%ld nsecs=%ld\n",
(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; };
return Duration { usecs(t2._timespec) - usecs(t1._timespec) };
}
};
int main(int, char**)
{
printf("bogomips test:\n");
Time s;
bogomips();
{
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);
}
}

View File

@ -0,0 +1,30 @@
/*
* \brief Testing CPU performance
* \author Stefan Kalkowski
* \date 2018-10-22
*
*/
/*
* 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.
*/
#include <base/component.h>
#include <base/log.h>
#include <timer_session/connection.h>
#include <bogomips.h>
void Component::construct(Genode::Env &env)
{
Timer::Connection timer(env);
timer.msleep(2000);
Genode::log("Cpu testsuite started");
Genode::log("start bogomips");
bogomips();
Genode::log("finished bogomips");
};

View File

@ -0,0 +1,4 @@
TARGET = test-cpu
SRC_CC = main.cc
INC_DIR = $(PRG_DIR)
LIBS = base