Re: [B.A.T.M.A.N.] [PATCH v2 6/7] batman-adv: ELP - use tp meter to estimate the throughput if otherwise not available

Sven Eckelmann
2018-05-21T19:06:26Z

[-- Attachment #1: Type: text/plain, Size: 1836 bytes --]

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.

Kind regards,
Sven

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 833 bytes --]