From: Eric Dumazet <eric.dumazet@gmail.com>
To: eilong@broadcom.com
Cc: David Miller <davem@davemloft.net>,
dmitry@broadcom.com, zenczykowski@gmail.com, maze@google.com,
netdev@vger.kernel.org, yuvalmin@broadcom.com
Subject: Re: [PATCH] bnx2x: fix occasional statistics off-by-4GB error
Date: Sun, 17 Mar 2013 16:17:31 -0700 [thread overview]
Message-ID: <1363562251.29475.109.camel@edumazet-glaptop> (raw)
In-Reply-To: <1363553608.4752.5.camel@lb-tlvb-eilong.il.broadcom.com>
On Sun, 2013-03-17 at 22:53 +0200, Eilon Greenstein wrote:
> This is not such a trivial issue - the HW/FW is guaranteeing the atomic
> read and this is why we can always use 32b variables.
>
I am glad you qualify the following code as 'trivial'
/* difference = minuend - subtrahend */
#define DIFF_64(d_hi, m_hi, s_hi, d_lo, m_lo, s_lo) \
do { \
if (m_lo < s_lo) { \
/* underflow */ \
d_hi = m_hi - s_hi; \
if (d_hi > 0) { \
/* we can 'loan' 1 */ \
d_hi--; \
d_lo = m_lo + (UINT_MAX - s_lo) + 1; \
} else { \
/* m_hi <= s_hi */ \
d_hi = 0; \
d_lo = 0; \
} \
} else { \
/* m_lo >= s_lo */ \
if (m_hi < s_hi) { \
d_hi = 0; \
d_lo = 0; \
} else { \
/* m_hi >= s_hi */ \
d_hi = m_hi - s_hi; \
d_lo = m_lo - s_lo; \
} \
} \
} while (0)
All the macros and _hi/_ho fields found in
drivers/net/ethernet/broadcom/bnx2x/bnx2x_stats.h
are really badly designed.
It hurts so much the common sense its not even funny.
All you really needed is to have normal host structures containing u64
fields, and you only needed one single helper to convert from hw u32:u32
to host u64.
Because gcc handles u64 operations very well, even on 32bit hosts, and
it knows about the carry flag.
next prev parent reply other threads:[~2013-03-17 23:17 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-15 21:03 bnx2x statistics occasionally wrong by near multiples of 4GB Maciej Żenczykowski
2013-03-15 21:56 ` [PATCH] bnx2x: fix occasional statistics off-by-4GB error Maciej Żenczykowski
2013-03-17 13:10 ` Dmitry Kravkov
2013-03-17 18:24 ` David Miller
2013-03-17 19:37 ` Eilon Greenstein
2013-03-17 20:25 ` Eric Dumazet
2013-03-17 20:53 ` Eilon Greenstein
2013-03-17 23:17 ` Eric Dumazet [this message]
2013-03-18 7:27 ` Eilon Greenstein
2013-03-18 6:18 ` Maciej Żenczykowski
2013-03-18 10:06 ` Eilon Greenstein
2013-03-18 17:13 ` David Miller
2013-03-18 19:54 ` Maciej Żenczykowski
2013-03-18 20:05 ` David Miller
2013-03-18 20:06 ` Maciej Żenczykowski
2013-03-18 20:35 ` Eric Dumazet
2013-03-18 20:36 ` Maciej Żenczykowski
2013-03-21 21:23 ` Maciej Żenczykowski
2013-03-21 21:25 ` David Miller
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=1363562251.29475.109.camel@edumazet-glaptop \
--to=eric.dumazet@gmail.com \
--cc=davem@davemloft.net \
--cc=dmitry@broadcom.com \
--cc=eilong@broadcom.com \
--cc=maze@google.com \
--cc=netdev@vger.kernel.org \
--cc=yuvalmin@broadcom.com \
--cc=zenczykowski@gmail.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox