All of lore.kernel.org
 help / color / mirror / Atom feed
From: bugzilla@dpdk.org
To: dev@dpdk.org
Subject: [dpdk-dev] [Bug 434] bps calculation does not fit in 64 bit
Date: Sat, 04 Apr 2020 01:31:23 +0000	[thread overview]
Message-ID: <bug-434-3@http.bugs.dpdk.org/> (raw)

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.

                 reply	other threads:[~2020-04-04  1:31 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-434-3@http.bugs.dpdk.org/ \
    --to=bugzilla@dpdk.org \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.