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,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