diff --git a/ports/src/app/netperf/netlib.patch b/ports/src/app/netperf/netlib.patch index fb58b5e8b..fe3d50441 100644 --- a/ports/src/app/netperf/netlib.patch +++ b/ports/src/app/netperf/netlib.patch @@ -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); diff --git a/ports/src/app/netperf/target.inc b/ports/src/app/netperf/target.inc index d4e434422..24c835b7c 100644 --- a/ports/src/app/netperf/target.inc +++ b/ports/src/app/netperf/target.inc @@ -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 : diff --git a/ports/src/app/netperf/timer.cc b/ports/src/app/netperf/timer.cc new file mode 100644 index 000000000..d3c6bf1e3 --- /dev/null +++ b/ports/src/app/netperf/timer.cc @@ -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 +#include +#include + + +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); +} diff --git a/ports/src/app/netperf/timer.patch b/ports/src/app/netperf/timer.patch deleted file mode 100644 index af5672c4f..000000000 --- a/ports/src/app/netperf/timer.patch +++ /dev/null @@ -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);