netperf: use Genode specific alarm timer

Fixes #1021
This commit is contained in:
Alexander Boettcher 2014-01-16 14:37:19 +01:00 committed by Norman Feske
parent fe45cc8c05
commit 041dd2a133
4 changed files with 106 additions and 14 deletions

View File

@ -13,6 +13,20 @@ Index: src/netlib.c
return(temp_cpus);
}
@@ -1095,8 +1095,13 @@
#endif /* WIN32 */
+#ifdef GENODE_BUILD
+void
+start_do_not_use_timer(int time)
+#else
void
start_timer(int time)
+#endif
{
#ifdef WIN32
@@ -3059,7 +3063,9 @@
(which == SEND_BUFFER) ? "SO_SNDBUF" : "SO_RCVBUF",
errno);

View File

@ -10,11 +10,14 @@ SRC_C = netserver.c netlib.c netsh.c nettest_bsd.c dscp.c
SRC_C += nettest_omni.c net_uuid.c
SRC_C += netsys_none.c netsec_none.c netdrv_none.c netrt_none.c netslot_none.c netcpu_none.c
SRC_CC += timer.cc
INC_DIR += $(PRG_DIR)/..
CC_OPT += -DHAVE_CONFIG_H -DGENODE_BUILD
CC_WARN = -Wall -Wno-unused
vpath %.c $(CONTRIB_DIR)/src
vpath timer.cc $(PRG_DIR)/..
# vi: set ft=make :

View File

@ -0,0 +1,89 @@
/*
* \brief Timeout handling for netperf, based on test/alarm
* \author Alexander Boettcher
* \date 2014-01-10
*/
/*
* Copyright (C) 2014-2014 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2.
*/
#include <os/alarm.h>
#include <base/thread.h>
#include <timer_session/connection.h>
using namespace Genode;
class Alarm_thread : Thread<4096>, public Alarm_scheduler
{
private:
Timer::Connection _timer;
Alarm::Time _curr_time; /* jiffies value */
enum { TIMER_GRANULARITY_MSEC = 10 };
/**
* Thread entry function
*/
void entry()
{
while (true) {
_timer.msleep(TIMER_GRANULARITY_MSEC);
Alarm_scheduler::handle(_curr_time);
_curr_time += TIMER_GRANULARITY_MSEC;
}
}
public:
/**
* Constructor
*/
Alarm_thread(): Thread("netperf_alarm"), _curr_time(0) { start(); }
Alarm::Time curr_time() { return _curr_time; }
};
/* defined in "ports/contrib/netperf/src/netlib.c" */
extern "C" int times_up;
class One_shot : public Alarm
{
private:
Alarm_scheduler *_scheduler;
public:
One_shot(Alarm_scheduler *scheduler) : _scheduler(scheduler) { }
void set_timeout(Time absolute_timeout)
{
_scheduler->schedule_absolute(this, absolute_timeout);
}
protected:
bool on_alarm()
{
times_up = 1;
return false;
}
};
extern "C" void
start_timer(int time)
{
static Alarm_thread alarm_thread;
static One_shot oneshot(&alarm_thread);
oneshot.set_timeout(alarm_thread.curr_time() + time * 1000);
}

View File

@ -1,14 +0,0 @@
--- src/netlib.h (revision 644)
+++ src/netlib.h (working copy)
@@ -536,7 +536,11 @@
extern void dump_request();
extern void dump_addrinfo(FILE *dumploc, struct addrinfo *info,
char *host, char *port, int family);
+#ifdef GENODE_BUILD
+static inline void start_timer(int time) { }
+#else
extern void start_timer(int time);
+#endif
extern void stop_timer();
extern void cpu_start(int measure_cpu);
extern void cpu_stop(int measure_cpu, float *elapsed);