From 666497bb254dfc2924368f207e4d0358c442fb37 Mon Sep 17 00:00:00 2001 From: Felipe Balbi Date: Mon, 12 Nov 2018 09:24:34 +0200 Subject: [PATCH] msc: compute throughput as a running average Signed-off-by: Felipe Balbi --- src/msc.c | 106 +++++++++++++++++++++--------------------------------- 1 file changed, 40 insertions(+), 66 deletions(-) diff --git a/src/msc.c b/src/msc.c index 7c70e83..be2938e 100644 --- a/src/msc.c +++ b/src/msc.c @@ -42,7 +42,9 @@ struct usb_msc_test { uint64_t pempty; /* what needs to be filled up still */ float read_tput; /* read throughput */ + unsigned long long read_count; float write_tput; /* write throughput */ + unsigned long long write_count; int fd; /* /dev/sd?? */ int count; /* iteration count */ @@ -170,6 +172,12 @@ static float throughput(struct timespec *start, struct timespec *end, size_t siz return (float) size / ((diff / 1000000000.0) * 1024 * 1024); } +static float throughput_mean(struct timespec *start, struct timespec *end, + size_t size, float mean, int n) +{ + return mean + (throughput(start, end, size) - mean) / n; +} + /** * report_progess - reports the progress of @test * @msc: Mass Storage Test Context @@ -179,7 +187,7 @@ static float throughput(struct timespec *start, struct timespec *end, size_t siz * in order for the user to get progress report. */ static void report_progress(struct usb_msc_test *msc, - enum usb_msc_test_case test, int show_tput) + enum usb_msc_test_case test) { float transferred = 0; unsigned int i; @@ -197,15 +205,8 @@ static void report_progress(struct usb_msc_test *msc, } if (!debug) { - if (show_tput) { - msc->read_tput /= msc->count; - msc->write_tput /= msc->count; - printf("\rtest %2d: sent %10.02f %cB read %10.02f MB/s write %10.02f MB/s ... ", - test, transferred, unit, msc->read_tput, msc->write_tput); - } else { - printf("\rtest %2d: sent %10.02f %cB read MB/s write MB/s ... ", - test, transferred, unit); - } + printf("\rtest %2d: sent %10.02f %cB read %10.02f MB/s write %10.02f MB/s ... ", + test, transferred, unit, msc->read_tput, msc->write_tput); fflush(stdout); } @@ -253,8 +254,9 @@ static int do_write(struct usb_msc_test *msc, unsigned bytes) } } clock_gettime(CLOCK_MONOTONIC_RAW, &end); - msc->write_tput += throughput(&start, &end, ret); - + msc->write_count++; + msc->write_tput = throughput_mean(&start, &end, ret, msc->write_tput, + msc->write_count); msc->offset = ret; @@ -291,7 +293,9 @@ static int do_read(struct usb_msc_test *msc, unsigned bytes) msc->transferred += ret; } clock_gettime(CLOCK_MONOTONIC_RAW, &end); - msc->read_tput += throughput(&start, &end, bytes); + msc->read_count++; + msc->read_tput = throughput_mean(&start, &end, ret, msc->read_tput, + msc->read_count); return 0; @@ -351,7 +355,9 @@ static int do_writev(struct usb_msc_test *msc, const struct iovec *iov, goto err; clock_gettime(CLOCK_MONOTONIC_RAW, &end); - msc->write_tput += throughput(&start, &end, ret); + msc->write_count++; + msc->write_tput = throughput_mean(&start, &end, ret, msc->read_tput, + msc->read_count); msc->pempty -= ret; @@ -396,7 +402,9 @@ static int do_readv(struct usb_msc_test *msc, const struct iovec *iov, goto err; clock_gettime(CLOCK_MONOTONIC_RAW, &end); - msc->read_tput += throughput(&start, &end, ret); + msc->read_count++; + msc->read_tput = throughput_mean(&start, &end, ret, msc->read_tput, + msc->read_count); msc->transferred += ret; return 0; @@ -443,11 +451,9 @@ static int do_test_patterns(struct usb_msc_test *msc) if (ret < 0) break; - report_progress(msc, MSC_TEST_PATTERNS, false); + report_progress(msc, MSC_TEST_PATTERNS); } - report_progress(msc, MSC_TEST_PATTERNS, true); - return ret; } @@ -567,11 +573,9 @@ static int do_test_sg_random_both(struct usb_msc_test *msc) if (ret < 0) goto err; - report_progress(msc, MSC_TEST_SG_RANDOM_BOTH, false); + report_progress(msc, MSC_TEST_SG_RANDOM_BOTH); } - report_progress(msc, MSC_TEST_SG_RANDOM_BOTH, true); - err: return ret; } @@ -664,11 +668,9 @@ static int do_test_sg_random_write(struct usb_msc_test *msc) if (ret < 0) goto err; - report_progress(msc, MSC_TEST_SG_RANDOM_WRITE, false); + report_progress(msc, MSC_TEST_SG_RANDOM_WRITE); } - report_progress(msc, MSC_TEST_SG_RANDOM_WRITE, true); - err: return ret; } @@ -759,11 +761,9 @@ static int do_test_sg_random_read(struct usb_msc_test *msc) if (ret < 0) goto err; - report_progress(msc, MSC_TEST_SG_RANDOM_READ, false); + report_progress(msc, MSC_TEST_SG_RANDOM_READ); } - report_progress(msc, MSC_TEST_SG_RANDOM_READ, true); - err: return ret; } @@ -798,11 +798,9 @@ static int do_test_write_past_last(struct usb_msc_test *msc) ret = 0; } - report_progress(msc, MSC_TEST_WRITE_PAST_LAST, false); + report_progress(msc, MSC_TEST_WRITE_PAST_LAST); } - report_progress(msc, MSC_TEST_WRITE_PAST_LAST, true); - err: return ret; } @@ -826,11 +824,9 @@ static int do_test_lseek_past_last(struct usb_msc_test *msc) goto err; } - report_progress(msc, MSC_TEST_LSEEK_PAST_LAST, false); + report_progress(msc, MSC_TEST_LSEEK_PAST_LAST); } - report_progress(msc, MSC_TEST_LSEEK_PAST_LAST, true); - err: return ret; } @@ -863,11 +859,9 @@ static int do_test_read_past_last(struct usb_msc_test *msc) goto err; } - report_progress(msc, MSC_TEST_READ_PAST_LAST, false); + report_progress(msc, MSC_TEST_READ_PAST_LAST); } - report_progress(msc, MSC_TEST_READ_PAST_LAST, true); - err: return ret; } @@ -931,11 +925,9 @@ static int do_test_sg_128sect(struct usb_msc_test *msc) if (ret < 0) goto err; - report_progress(msc, MSC_TEST_SG_128SECT, false); + report_progress(msc, MSC_TEST_SG_128SECT); } - report_progress(msc, MSC_TEST_SG_128SECT, true); - err: return ret; } @@ -999,11 +991,9 @@ static int do_test_sg_64sect(struct usb_msc_test *msc) if (ret < 0) goto err; - report_progress(msc, MSC_TEST_SG_64SECT, false); + report_progress(msc, MSC_TEST_SG_64SECT); } - report_progress(msc, MSC_TEST_SG_64SECT, true); - err: return ret; } @@ -1067,11 +1057,9 @@ static int do_test_sg_32sect(struct usb_msc_test *msc) if (ret < 0) goto err; - report_progress(msc, MSC_TEST_SG_32SECT, false); + report_progress(msc, MSC_TEST_SG_32SECT); } - report_progress(msc, MSC_TEST_SG_32SECT, true); - err: return ret; } @@ -1135,11 +1123,9 @@ static int do_test_sg_8sect(struct usb_msc_test *msc) if (ret < 0) goto err; - report_progress(msc, MSC_TEST_SG_8SECT, false); + report_progress(msc, MSC_TEST_SG_8SECT); } - report_progress(msc, MSC_TEST_SG_8SECT, true); - err: return ret; } @@ -1203,11 +1189,9 @@ static int do_test_sg_2sect(struct usb_msc_test *msc) if (ret < 0) goto err; - report_progress(msc, MSC_TEST_SG_2SECT, false); + report_progress(msc, MSC_TEST_SG_2SECT); } - report_progress(msc, MSC_TEST_SG_2SECT, true); - err: return ret; } @@ -1255,11 +1239,9 @@ static int do_test_64sect(struct usb_msc_test *msc) if (ret < 0) break; - report_progress(msc, MSC_TEST_64SECT, false); + report_progress(msc, MSC_TEST_64SECT); } - report_progress(msc, MSC_TEST_64SECT, true); - err: return ret; } @@ -1307,11 +1289,9 @@ static int do_test_32sect(struct usb_msc_test *msc) if (ret < 0) break; - report_progress(msc, MSC_TEST_32SECT, false); + report_progress(msc, MSC_TEST_32SECT); } - report_progress(msc, MSC_TEST_32SECT, true); - err: return ret; } @@ -1359,11 +1339,9 @@ static int do_test_8sect(struct usb_msc_test *msc) if (ret < 0) goto err; - report_progress(msc, MSC_TEST_8SECT, false); + report_progress(msc, MSC_TEST_8SECT); } - report_progress(msc, MSC_TEST_8SECT, true); - err: return ret; } @@ -1411,11 +1389,9 @@ static int do_test_1sect(struct usb_msc_test *msc) if (ret < 0) goto err; - report_progress(msc, MSC_TEST_1SECT, false); + report_progress(msc, MSC_TEST_1SECT); } - report_progress(msc, MSC_TEST_1SECT, true); - err: return ret; } @@ -1462,11 +1438,9 @@ static int do_test_simple(struct usb_msc_test *msc) if (ret < 0) goto err; - report_progress(msc, MSC_TEST_SIMPLE, false); + report_progress(msc, MSC_TEST_SIMPLE); } - report_progress(msc, MSC_TEST_SIMPLE, true); - err: return ret; }