DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [Bug 434] bps calculation does not fit in 64 bit
@ 2020-04-04  1:31 bugzilla
  0 siblings, 0 replies; only message in thread
From: bugzilla @ 2020-04-04  1:31 UTC (permalink / raw)
  To: dev

https://bugs.dpdk.org/show_bug.cgi?id=434

            Bug ID: 434
           Summary: bps calculation does not fit in 64 bit
           Product: DPDK
           Version: 20.02
          Hardware: x86
                OS: Linux
            Status: UNCONFIRMED
          Severity: normal
          Priority: Normal
         Component: testpmd
          Assignee: dev@dpdk.org
          Reporter: cfb@hpe.com
  Target Milestone: ---

The bps calculation in config.c:nic_stats_display() does not fit in a 64 bit
for higher clock rates and network speeds. The code:

        mbps_rx = diff_cycles > 0 ?
                diff_bytes_rx * rte_get_tsc_hz() / diff_cycles : 0;
        mbps_tx = diff_cycles > 0 ?
                diff_bytes_tx * rte_get_tsc_hz() / diff_cycles : 0;

        printf("\n  Throughput (since last show)\n");
        printf("  Rx-pps: %12"PRIu64"          Rx-bps: %12"PRIu64"\n  Tx-pps:
%12"
               PRIu64"          Tx-bps: %12"PRIu64"\n", mpps_rx, mbps_rx * 8,
               mpps_tx, mbps_tx * 8);



multiplies two 64 bit values (diff_bytes_[rt]x and rte_get_tsc_hz()), then
divides them by a 64 bit value (diff_cycles). The problem occurs when high data
rates result in diff_bytes_[rt]x wih values that require more than 32 bits or
rte_get_tsc_hz() returns a value that requires more than 32 bits.
The failure occurred on a system with a 2 GHz CPU and a data rate that returned
a value over 18,000,000,000,000 bytes/second.

rte_get_tsc_hz() returned 2,000,000,000, which fits in 32 bits.
However, 18,000,000,000,000 requires 36 bits.

The multiplication overflows a 64 bit. The overflowed result is then divided by
diff_cycles, then multiplied by 8 in the printf() statement (to convert from
byte/sec to bits/sec), resulting in erratic results.

There are a number of possible solutions, however, most will result some loss
of precision. The simplest is to move from bps to Mbps (or even Kbps) by
performing a division on rte_get_tsc_hz() (or diff_bytes_[rt]x) before
multiplying.

-- 
You are receiving this mail because:
You are the assignee for the bug.

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-04-04  1:31 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-04  1:31 [dpdk-dev] [Bug 434] bps calculation does not fit in 64 bit bugzilla

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).