On Montag, 21. Mai 2018 15:17:11 CEST Linus Lüssing
wrote:
> + throughput = total_bytes * 8
>> ilog2(test_time) / 10;
[...]
-----
[...]
throughput = total_bytes * 8 >> log_test_time / 10;
// Straightforward approach?
throughput2 = total_bytes * 8 / test_time * 1000 / 1024 / 100;
[...]
-----
> $ ./test
> Result: 80000000 (log_test_time: 13)
> Result2: 156
> $ file ./test
> ./test: ELF 32-bit LSB pie executable ARM, EABI5 version 1 (SYSV), dynamically
linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 3.2.0,
BuildID[sha1]=d18f32829cdd2bc42cf744cdcafde7cdbd315cb0, not stripped
-----
Thanks for this small example program. Yes, there are parenthesis missing in
the calculation. Right now, following is calculated:
(total_bytes * 8) >> (ilog2(test_time) / 10);
But the author most likely wanted following precedence:
((total_bytes * 8) >> ilog2(test_time)) / 10;
And together with the fixed unit, you would get:
(total_bytes * 8 >> ilog2(test_time) / 100;
Your example program would then show following result because the shifting
stuff is still the wrong approach:
Result: 195 (log_test_time: 13)
Result2: 156
The calculation still has to be changed to something like this to get
// when 0.1 Mbit/s == 100 kbit/s
throughput = total_bytes * 5;
do_div(throughput, test_time * 64);
// when 0.1 Mbit/s == 102.4 kbit/s
throughput = total_bytes * 625;
do_div(throughput, test_time * 8192);
// when 0.1 Mbit/s == 100 kbit/s, and 1kbit/s == 1000 bit (instead of 1024 bit):
throughput = total_bytes;
do_div(throughput, test_time * 125);
Please keep in mind that we must do a check of the divisor (for 0) before
doing this do_div.
Thanks for the code and the correction :-)
Yes, we wanted to avoid 64 bits explicit divisions and we assumed
test_time would have been a power of 2 (otherwise we'd accept a small
error).
Anyway, the last case brought by Sven depicts what we want to implement.
The patch will be changed accordingly.
Cheers,
--
Antonio Quartulli