From 2a3282f872e4e415923626dbd86ce5b34b08be32 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 17 Jun 2007 20:03:31 +0000 Subject: r23533: added --option torture:targetrate=rate to target a particular throughput in MBytes/sec (This used to be commit 35477e8e3d58acce467648f3bd83a43d135caefa) --- source4/torture/nbench/nbio.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'source4/torture/nbench/nbio.c') diff --git a/source4/torture/nbench/nbio.c b/source4/torture/nbench/nbio.c index a382c92ceb..f093ad82b0 100644 --- a/source4/torture/nbench/nbio.c +++ b/source4/torture/nbench/nbio.c @@ -57,6 +57,29 @@ static struct { struct timeval starttime; } *children; +void nbio_target_rate(double rate) +{ + static double last_bytes; + static struct timeval last_time; + double tdelay; + + if (last_bytes == 0) { + last_bytes = children[nbio_id].bytes; + last_time = timeval_current(); + return; + } + + tdelay = (children[nbio_id].bytes - last_bytes)/(1.0e6*rate) - timeval_elapsed(&last_time); + if (tdelay > 0) { + msleep(tdelay*1000); + } else { + children[nbio_id].max_latency = MAX(children[nbio_id].max_latency, -tdelay); + } + + last_time = timeval_current(); + last_bytes = children[nbio_id].bytes; +} + void nbio_time_reset(void) { children[nbio_id].starttime = timeval_current(); @@ -68,7 +91,7 @@ void nbio_time_delay(double targett) if (targett > elapsed) { msleep(1000*(targett - elapsed)); } else if (elapsed - targett > children[nbio_id].max_latency) { - children[nbio_id].max_latency = elapsed - targett; + children[nbio_id].max_latency = MAX(elapsed - targett, children[nbio_id].max_latency); } } -- cgit