Skip to content

Commit

Permalink
iio_readdev/iio_writedev: Fix benchmark feature
Browse files Browse the repository at this point in the history
The --benchmark/-B option previously introduced in iio_readdev and
iio_writedev did not really work as intended. For each buffer, it would
compute the transfer speed, and eventually computed the mean value after
every 10 transfers.

The problem was that some transfers can appear almost instant, for
instance when there is already a block of samples available to dequeue
on the kernel side. In that case, the apparent transfer speed would be
extremely high, and the resulting mean value would be completely wrong.

Address this issue by computing the cumulated time spent transferring
data every 10 transfers, and derive the transfer rate from this result.

The value computed was also wrong for a different reason: it displayed
MiB/s (where one MiB == 1,048,576 bytes) but actually computed MB/s
(where one MB == 1,000,000 bytes).

Signed-off-by: Paul Cercueil <paul@crapouillou.net>
  • Loading branch information
pcercuei committed Jan 11, 2022
1 parent 113e029 commit 1b88be0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions tests/iio_readdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -398,16 +398,16 @@ int main(int argc, char **argv)

if (benchmark) {
after = get_time_us();
rate = buffer_size * sample_size * 1000000ull / (after - before);

total += rate;
total += after - before;

if (++i == REFILL_PER_BENCHMARK) {
mib = rate > 1000000;
rate = buffer_size * sample_size *
REFILL_PER_BENCHMARK * 1000000ull / total;
mib = rate > 1048576;

fprintf(stderr, "\33[2K\rThroughput: %" PRIu64 " %ciB/s",
total / (REFILL_PER_BENCHMARK * 1000 * (mib ? 1000 : 1)),
mib ? 'M' : 'K');
rate / (1024 * (mib ? 1024 : 1)),
mib ? 'M' : 'K');

i = 0;
total = 0;
Expand Down
12 changes: 6 additions & 6 deletions tests/iio_writedev.c
Original file line number Diff line number Diff line change
Expand Up @@ -443,16 +443,16 @@ int main(int argc, char **argv)

if (benchmark) {
after = get_time_us();
rate = buffer_size * sample_size * 1000000ull / (after - before);

total += rate;
total += after - before;

if (++i == REFILL_PER_BENCHMARK) {
mib = rate > 1000000;
rate = buffer_size * sample_size *
REFILL_PER_BENCHMARK * 1000000ull / total;
mib = rate > 1048576;

fprintf(stderr, "\33[2K\rThroughput: %" PRIu64 " %ciB/s",
total / (REFILL_PER_BENCHMARK * 1000 * (mib ? 1000 : 1)),
mib ? 'M' : 'K');
rate / (1024 * (mib ? 1024 : 1)),
mib ? 'M' : 'K');

i = 0;
total = 0;
Expand Down

0 comments on commit 1b88be0

Please sign in to comment.