mirror of
https://github.com/genodelabs/genode.git
synced 2025-04-12 13:48:30 +00:00
test: add simple cpu benchmark test (fix #3026)
This commit is contained in:
parent
24e6a5ee73
commit
fe3f67f712
56
repos/os/run/cpu_bench.run
Normal file
56
repos/os/run/cpu_bench.run
Normal 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
|
8
repos/os/src/test/cpu_bench/bogomips.h
Normal file
8
repos/os/src/test/cpu_bench/bogomips.h
Normal file
@ -0,0 +1,8 @@
|
||||
|
||||
void bogomips() __attribute__((optimize("O0")));
|
||||
|
||||
void bogomips()
|
||||
{
|
||||
for (register unsigned i = 0; i < 1000000000; i++) ;
|
||||
};
|
||||
|
7
repos/os/src/test/cpu_bench/linux/Makefile
Normal file
7
repos/os/src/test/cpu_bench/linux/Makefile
Normal 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
|
48
repos/os/src/test/cpu_bench/linux/main.cc
Normal file
48
repos/os/src/test/cpu_bench/linux/main.cc
Normal 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);
|
||||
}
|
||||
}
|
30
repos/os/src/test/cpu_bench/main.cc
Normal file
30
repos/os/src/test/cpu_bench/main.cc
Normal 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");
|
||||
};
|
4
repos/os/src/test/cpu_bench/target.mk
Normal file
4
repos/os/src/test/cpu_bench/target.mk
Normal file
@ -0,0 +1,4 @@
|
||||
TARGET = test-cpu
|
||||
SRC_CC = main.cc
|
||||
INC_DIR = $(PRG_DIR)
|
||||
LIBS = base
|
Loading…
x
Reference in New Issue
Block a user