emmericp / ixy

A simple yet fast user space network driver for Intel 10 Gbit/s NICs written from scratch
BSD 3-Clause "New" or "Revised" License
1.2k stars 125 forks source link

ppms function doesn't calculate packets per microsecond #26

Closed MathieuBordere closed 4 years ago

MathieuBordere commented 4 years ago
/**
 * Calculate packets per microsecond based on the received number of packets and the elapsed time in nanoseconds since the
 * last calculation.
 * @param received_pkts Number of received packets.
 * @param elapsed_time_nanos Time elapsed in nanoseconds since the last calculation.
 * @return Packets per microsecond.
 */
static uint64_t ppms(uint64_t received_pkts, uint64_t elapsed_time_nanos) {
    return received_pkts / (elapsed_time_nanos / 1000000);
}

micro = 10 ^ -6 nano = 10 ^ -9

By using (elapsed_time_nanos / 1000000), this function calculates the amount of received packets per millisecond, so I don't know if the comments are wrong micro -> milli or the divisor is wrong 1000000 -> 1000.

emmericp commented 4 years ago

You are right, thanks for spotting this :)

The code is correct, it's the comment that is wrong. It's supposed to switch at 1.2 million packets per second, i.e. 1200 packets per millisecond which is the constant being used here: https://github.com/emmericp/ixy/blob/1e1aff492ad2d66405303412c01caf0ad099053e/src/interrupts.h#L10

emmericp commented 4 years ago

fixed here: https://github.com/emmericp/ixy/commit/2359e5b55f47ba47e8f222115d9e6c3258678149