mirror of
https://github.com/genodelabs/genode.git
synced 2025-06-23 17:17:38 +00:00
test: add simple cpu benchmark test (fix #3026)
This commit is contained in:
committed by
Christian Helmuth
parent
24e6a5ee73
commit
fe3f67f712
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
|
Reference in New Issue
Block a user