[netperf-dev] netperf2 commit notice r585 - in trunk: . src
raj at netperf.org
raj at netperf.org
Tue May 22 16:51:27 PDT 2012
Author: raj
Date: 2012-05-22 16:51:27 -0700 (Tue, 22 May 2012)
New Revision: 585
Modified:
trunk/Release_Notes
trunk/src/netlib.c
trunk/src/netlib.h
trunk/src/nettest_bsd.c
trunk/src/nettest_omni.c
Log:
WANT_INTERVALS support for Windows courtesy of Jonathan Cook
Modified: trunk/Release_Notes
===================================================================
--- trunk/Release_Notes 2012-05-22 01:17:54 UTC (rev 584)
+++ trunk/Release_Notes 2012-05-22 23:51:27 UTC (rev 585)
@@ -1,5 +1,8 @@
These are the Release Notes for post Revision 2.5.0 top-of-trunk netperf:
+*) Initial pass at support for --enable-intervals (WANT_INTERVALS) for
+ Windows, courtesy of Jonathan Cook.
+
*) When in demo mode (./configure --enable-demo and a global -D
<interval> option netperf will make sure it emits "one last
interval result" when the test is terminated. This should assist
Modified: trunk/src/netlib.c
===================================================================
--- trunk/src/netlib.c 2012-05-22 01:17:54 UTC (rev 584)
+++ trunk/src/netlib.c 2012-05-22 23:51:27 UTC (rev 585)
@@ -111,7 +111,7 @@
#include <winsock2.h>
#define netperf_socklen_t socklen_t
#include <windows.h>
-
+#include <mmsystem.h>
/* the only time someone should need to define DONT_IPV6 in the
"sources" file is if they are trying to compile on Windows 2000 or
NT4 and I suspect this may not be their only problem :) */
@@ -264,6 +264,7 @@
#ifdef WIN32
HANDLE hAlarm = INVALID_HANDLE_VALUE;
+int timed_out=0;
#endif
int times_up;
@@ -315,6 +316,16 @@
#ifdef WANT_INTERVALS
+#ifdef WIN32
+HANDLE WinTimer;
+UINT timerRes;
+void stop_itimer()
+{
+ CancelWaitableTimer(WinTimer);
+ CloseHandle(WinTimer);
+ timeEndPeriod(timerRes);
+}
+#else
static unsigned int usec_per_itvl;
@@ -337,6 +348,7 @@
}
return;
}
+#endif /* WIN32 */
#endif /* WANT_INTERVALS */
@@ -893,7 +905,7 @@
/* signal catcher */
/* */
/************************************************************************/
-
+#ifndef WIN32
void
#if defined(__hpux)
catcher(sig, code, scp)
@@ -970,8 +982,8 @@
}
return;
}
+#endif /* WIN32 */
-
void
install_signal_catchers()
@@ -1046,7 +1058,9 @@
/* Give the other threads time to notice that times_up has
changed state before taking the harsh step of closing the
sockets. */
-
+#ifdef WIN32
+ timed_out=0;
+#endif
if (WaitForSingleObject(hAlarm, PAD_TIME/2*1000) ==
WAIT_TIMEOUT) {
/* We have yet to find a good way to fully emulate
@@ -1056,7 +1070,10 @@
It is rather kludgy, but should be sufficient to
get this puppy shipped. The concept can be
attributed/blamed :) on Robin raj 1/96 */
-
+#ifdef WIN32
+ timed_out=1;
+#endif
+
if (win_kludge_socket != INVALID_SOCKET) {
HandlesClosedFlags |= 1;
closesocket(win_kludge_socket);
@@ -1183,7 +1200,43 @@
void
start_itimer(unsigned int interval_len_msec )
{
-
+#ifdef WIN32
+ LARGE_INTEGER liDueTime;
+ TIMECAPS ptc;
+ MMRESULT mmr;
+
+ /* make sure timer resolution is at least as small as interval length */
+ timerRes=interval_len_msec;
+ mmr=timeGetDevCaps(&ptc, sizeof (ptc));
+ if (mmr==TIMERR_NOERROR){
+ if (interval_len_msec<ptc.wPeriodMin){
+ timerRes=ptc.wPeriodMin;
+ fprintf(where, "Timer cannot be set to %dmsec. Minimum timer resolution: %d\n", interval_len_msec, ptc.wPeriodMin);
+ fflush(where);
+ }
+ }
+ /* timeBeginPeriod() affects a global Windows setting.
+ Windows uses the lowest value (that is, highest resolution) requested by any process. */
+ mmr=timeBeginPeriod(timerRes);
+ /* Create a waitable timer. */
+ WinTimer = CreateWaitableTimer(NULL, FALSE, "IntervalTimer");
+ if (NULL == WinTimer)
+ {
+ fprintf(where, "CreateWaitableTimer failed (%d)\n", GetLastError());
+ fflush(where);
+ exit(1);
+ }
+ /*The time after which the state of the timer is to be set to signaled the first time,
+ in 100 nanosecond intervals. Negative values indicate relative time. */
+ liDueTime.QuadPart=-10000LL*interval_len_msec;
+ /* Set the timer to wait for interval_len_msec and periodically signal every interval_len_msec */
+ if (!SetWaitableTimer(WinTimer, &liDueTime, interval_len_msec, NULL, NULL, TRUE))
+ {
+ fprintf(where,"SetWaitableTimer failed (%d)\n", GetLastError());
+ fflush(where);
+ exit(1);
+ }
+#else
unsigned int ticks_per_itvl;
struct itimerval new_interval;
@@ -1235,6 +1288,7 @@
perror("netperf: setitimer");
exit(1);
}
+ #endif /* WIN32*/
}
#endif /* WANT_INTERVALS */
@@ -3512,7 +3566,7 @@
sec = time2.tv_sec - time1.tv_sec;
usec = time2.tv_usec - time1.tv_usec;
lib_elapsed = (float)sec + ((float)usec/(float)1000000.0);
-
+ /* if (timed_out) lib_elapsed-=PAD_TIME/2; */
*elapsed = lib_elapsed;
}
Modified: trunk/src/netlib.h
===================================================================
--- trunk/src/netlib.h 2012-05-22 01:17:54 UTC (rev 584)
+++ trunk/src/netlib.h 2012-05-22 23:51:27 UTC (rev 585)
@@ -646,6 +646,7 @@
#ifdef WANT_INTERVALS
extern void start_itimer(unsigned int interval_len_msec);
+extern void stop_itimer(void);
#endif
/* these are all for the confidence interval stuff */
extern double confidence;
@@ -662,6 +663,7 @@
#endif
#ifdef WIN32
+extern HANDLE WinTimer;
#if 0
/* Should really use safe string functions; but not for now... */
#include <strsafe.h>
Modified: trunk/src/nettest_bsd.c
===================================================================
--- trunk/src/nettest_bsd.c 2012-05-22 01:17:54 UTC (rev 584)
+++ trunk/src/nettest_bsd.c 2012-05-22 23:51:27 UTC (rev 585)
@@ -245,6 +245,17 @@
#ifdef WANT_INTERVALS
int interval_count;
#ifndef WANT_SPIN
+#ifdef WIN32
+#define INTERVALS_INIT() \
+ if (interval_burst) { \
+ /* zero means that we never pause, so we never should need the \
+ interval timer. we used to use it for demo mode, but we deal \
+ with that with a variant on watching the clock rather than \
+ waiting for a timer. raj 2006-02-06 */ \
+ start_itimer(interval_wate); \
+ } \
+ interval_count = interval_burst;
+#else
sigset_t signal_set;
#define INTERVALS_INIT() \
if (interval_burst) { \
@@ -264,8 +275,28 @@
fflush(where); \
exit(1); \
}
+#endif /* WIN32 */
+#ifdef WIN32
#define INTERVALS_WAIT() \
+ /* in this case, the interval count is the count-down counter \
+ to decide to sleep for a little bit */ \
+ if ((interval_burst) && (--interval_count == 0)) { \
+ /* call WaitForSingleObject and wait for the interval timer to get us \
+ out */ \
+ if (debug > 1) { \
+ fprintf(where,"about to suspend\n"); \
+ fflush(where); \
+ } \
+ if (WaitForSingleObject(WinTimer, INFINITE) != WAIT_OBJECT_0) { \
+ fprintf(where, "WaitForSingleObject failed (%d)\n", GetLastError()); \
+ fflush(where); \
+ exit(1); \
+ } \
+ interval_count = interval_burst; \
+ }
+#else
+#define INTERVALS_WAIT() \
/* in this case, the interval count is the count-down couter \
to decide to sleep for a little bit */ \
if ((interval_burst) && (--interval_count == 0)) { \
@@ -284,6 +315,7 @@
} \
interval_count = interval_burst; \
}
+#endif /* WIN32 */
#else
/* first out timestamp */
#ifdef HAVE_GETHRTIME
@@ -2124,6 +2156,12 @@
close(send_socket);
+#if defined(WANT_INTERVALS)
+#ifdef WIN32
+ stop_itimer();
+#endif
+#endif /* WANT_INTERVALS */
+
if (!no_control) {
/* Get the statistics from the remote end. The remote will have
calculated service demand and all those interesting
@@ -2832,6 +2870,12 @@
}
stop_timer();
+
+#if defined(WANT_INTERVALS)
+#ifdef WIN32
+ stop_itimer();
+#endif
+#endif /* WANT_INTERVALS */
/* this call will always give us the local elapsed time for the
test, and will also store-away the necessaries for cpu
@@ -4642,7 +4686,13 @@
close(send_socket);
- /* Get the statistics from the remote end. The remote will have */
+ #if defined(WANT_INTERVALS)
+#ifdef WIN32
+ stop_itimer();
+#endif
+#endif /* WANT_INTERVALS */
+
+ /* Get the statistics from the remote end. The remote will have */
/* calculated service demand and all those interesting things. If it */
/* wasn't supposed to care, it will return obvious values. */
@@ -6139,6 +6189,12 @@
/* measured? how long */
/* did we really run? */
+#if defined(WANT_INTERVALS)
+#ifdef WIN32
+ stop_itimer();
+#endif
+#endif /* WANT_INTERVALS */
+
if (!no_control) {
/* Get the statistics from the remote end. The remote will have
calculated CPU utilization. If it wasn't supposed to care, it
@@ -6813,6 +6869,12 @@
cpu_stop(local_cpu_usage,
&elapsed_time);
+#if defined(WANT_INTERVALS)
+#ifdef WIN32
+ stop_itimer();
+#endif
+#endif /* WANT_INTERVALS */
+
if (!no_control) {
/* Get the statistics from the remote end */
recv_response();
@@ -7784,6 +7846,12 @@
/* measured? how long */
/* did we really run? */
+#if defined(WANT_INTERVALS)
+#ifdef WIN32
+ stop_itimer();
+#endif
+#endif /* WANT_INTERVALS */
+
if (!no_control) {
/* Get the statistics from the remote end. The remote will have
calculated service demand and all those interesting
@@ -11380,6 +11448,12 @@
/* calculated service demand and all those interesting things. If it */
/* wasn't supposed to care, it will return obvious values. */
+#if defined(WANT_INTERVALS)
+#ifdef WIN32
+ stop_itimer();
+#endif
+#endif /* WANT_INTERVALS */
+
recv_response();
if (!netperf_response.content.serv_errno) {
if (debug)
Modified: trunk/src/nettest_omni.c
===================================================================
--- trunk/src/nettest_omni.c 2012-05-22 01:17:54 UTC (rev 584)
+++ trunk/src/nettest_omni.c 2012-05-22 23:51:27 UTC (rev 585)
@@ -168,6 +168,18 @@
#endif
#ifndef WANT_SPIN
+#ifdef WIN32
+#define INTERVALS_INIT() \
+ if (interval_burst) { \
+ /* zero means that we never pause, so we never should need the \
+ interval timer. we used to use it for demo mode, but we deal \
+ with that with a variant on watching the clock rather than \
+ waiting for a timer. raj 2006-02-06 */ \
+ start_itimer(interval_wate); \
+ } \
+ interval_count = interval_burst; \
+ interval_wait_microseconds = 0;
+#else
sigset_t signal_set;
#define INTERVALS_INIT() \
if (interval_burst) { \
@@ -188,8 +200,32 @@
fflush(where); \
exit(1); \
}
+#endif /* WIN32 */
+#ifdef WIN32
#define INTERVALS_WAIT() \
+ /* in this case, the interval count is the count-down counter \
+ to decide to sleep for a little bit */ \
+ if ((interval_burst) && (--interval_count == 0)) { \
+ /* call WaitForSingleObject and wait for the interval timer to get us \
+ out */ \
+ if (debug > 1) { \
+ fprintf(where,"about to suspend\n"); \
+ fflush(where); \
+ } \
+ HIST_timestamp(&intvl_wait_start); \
+ if (WaitForSingleObject(WinTimer, INFINITE) != WAIT_OBJECT_0) { \
+ fprintf(where, "WaitForSingleObject failed (%d)\n", GetLastError()); \
+ fflush(where); \
+ exit(1); \
+ } \
+ HIST_timestamp(&intvl_two); \
+ interval_wait_microseconds += \
+ delta_micro(&intvl_wait_start,&intvl_two); \
+ interval_count = interval_burst; \
+ }
+#else
+#define INTERVALS_WAIT() \
/* in this case, the interval count is the count-down couter \
to decide to sleep for a little bit */ \
if ((interval_burst) && (--interval_count == 0)) { \
@@ -212,6 +248,7 @@
delta_micro(&intvl_wait_start,&intvl_two); \
interval_count = interval_burst; \
}
+#endif /* WIN32 */
#else
#define INTERVALS_INIT() \
@@ -3822,7 +3859,7 @@
if ((!no_control) &&
(NETPERF_RECV_ONLY(direction)) &&
((test_trans == 0) && (test_bytes == 0)))
- pad_time = PAD_TIME;
+ pad_time = 0;
start_timer(test_time + pad_time);
}
else {
@@ -4500,7 +4537,7 @@
there is no such thing as a free lunch is there :) raj
20110121 */
if (interval_burst) {
- rtt_elapsed_time -= (float)interval_wait_microseconds / 1000000.0;
+ rtt_elapsed_time -= (float)(interval_wait_microseconds / 1000000.0);
}
#endif /* WANT_INTERVALS */
@@ -4578,8 +4615,14 @@
still be reported as one */
confidence_iteration--;
- /* at some point we may want to actually display some results :) */
+#if defined(WANT_INTERVALS)
+#ifdef WIN32
+ stop_itimer();
+#endif
+#endif /* WANT_INTERVALS */
+/* at some point we may want to actually display some results :) */
+
retrieve_confident_values(&elapsed_time,
&thruput,
&local_cpu_utilization,
@@ -5090,6 +5133,7 @@
if (omni_request->test_length >= 0) {
times_up = 0;
units_remaining = 0;
+ test_time=omni_request->test_length;
/* if we are the sender and only sending, then we don't need/want
the padding, otherwise, we need the padding */
if (!(NETPERF_XMIT_ONLY(omni_request->direction)) &&
@@ -5363,7 +5407,13 @@
cpu_stop(omni_request->flags & OMNI_MEASURE_CPU,&elapsed_time);
close(s_listen);
- if (timed_out) {
+#if defined(WANT_INTERVALS)
+#ifdef WIN32
+ stop_itimer();
+#endif
+#endif /* WANT_INTERVALS */
+
+ if (timed_out) {
/* we ended the test by time, which may have been PAD_TIME seconds
longer than we wanted to run. so, we want to subtract pad_time
from the elapsed_time. if we didn't pad the timer pad_time will
@@ -5484,6 +5534,12 @@
strncpy(omni_results->bus,"Bug If Seen DRVINFO",32);
}
+#if defined(WANT_INTERVALS)
+#ifdef WIN32
+ stop_itimer();
+#endif
+#endif /* WANT_INTERVALS */
+
if (debug) {
fprintf(where,
"%s: test complete, sending results.\n",
More information about the netperf-dev
mailing list