Skip to content

Commit

Permalink
msc: compute throughput as a running average
Browse files Browse the repository at this point in the history
Signed-off-by: Felipe Balbi <[email protected]>
  • Loading branch information
Felipe Balbi committed Nov 12, 2018
1 parent afafc18 commit 666497b
Showing 1 changed file with 40 additions and 66 deletions.
106 changes: 40 additions & 66 deletions src/msc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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);
}
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 666497b

Please sign in to comment.