netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Roland Dreier <rdreier@cisco.com>
To: David Miller <davem@davemloft.net>
Cc: bhutchings@solarflare.com, jdb@comx.dk, netdev@vger.kernel.org
Subject: Re: NIU driver: Sun x8 Express Quad Gigabit Ethernet Adapter
Date: Wed, 12 Nov 2008 14:58:23 -0800	[thread overview]
Message-ID: <ada8wromu0g.fsf@cisco.com> (raw)
In-Reply-To: <20081112.142625.120012106.davem@davemloft.net> (David Miller's message of "Wed, 12 Nov 2008 14:26:25 -0800 (PST)")

 > Just google "C order of evaluation" and you will get hundreds
 > of tables, and all of them will have an entry for "|" (not
 > just "||") which says that operands are evaluated left to
 > right.

You're talking about associativity, which says how an expression like
"a | b | c" is implicitly parenthesized.  The order of evaluation is
undefined -- in fact the C standard I have says:

  Except as specified later (for the function-call (), &&, ||, ?:, and
  comma operators), the order of evaluation of subexpressions and the
  order in which side effects take place are both unspecified.

So there is no rule about which subexpression is evaluated first in an
expression like "a | b".

 > And since these MMIO reads are volatile operations, there is
 > no way the compiler can execute them out of order.

"volatile" just means that accessing a volatile expression is considered
a side effect -- and side effects are only ordered with respect to
sequence points.

So according to my understanding of the C standard, there is no required
on which readl() is done first in an expression like "readl(a) | readl(b)".

 > And the plain truth is that no compiler does, and that is what
 > matters in the end.

I think it's cleaner to avoid relying on undefined behavior (eg gcc 4.5
will probably break things), especially when the fix is so simple --
something the following should work fine:

diff --git a/drivers/net/niu.c b/drivers/net/niu.c
index 9acb5d7..1fb0d2f 100644
--- a/drivers/net/niu.c
+++ b/drivers/net/niu.c
@@ -51,8 +51,8 @@ MODULE_VERSION(DRV_MODULE_VERSION);
 #ifndef readq
 static u64 readq(void __iomem *reg)
 {
-	return (((u64)readl(reg + 0x4UL) << 32) |
-		(u64)readl(reg));
+	u64 v = readl(reg);
+	return v | (u64) readl(reg + 0x4UL) << 32;
 }
 
 static void writeq(u64 val, void __iomem *reg)

  reply	other threads:[~2008-11-12 22:58 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-04 14:45 NIU driver: Sun x8 Express Quad Gigabit Ethernet Adapter Jesper Dangaard Brouer
2008-11-04 21:42 ` David Miller
2008-11-05  7:05   ` Jesper Dangaard Brouer
2008-11-05  7:33     ` David Miller
2008-11-05  9:30       ` Jesper Dangaard Brouer
2008-11-05  9:34         ` David Miller
2008-11-11 19:19 ` Jesper Krogh
2008-11-11 23:50   ` David Miller
2008-11-12  0:18     ` David Miller
2008-11-12  9:36       ` Jesper Dangaard Brouer
2008-11-12  9:49         ` David Miller
2008-11-12 10:04           ` Jesper Dangaard Brouer
2008-11-12 11:01           ` Jesper Dangaard Brouer
2008-11-12 11:52             ` David Miller
2008-11-12 12:11               ` David Miller
2008-11-12 12:49                 ` Jesper Dangaard Brouer
2008-11-13  8:50                   ` Jesper Dangaard Brouer
2008-11-13 22:08                     ` David Miller
2008-11-14 12:38                       ` NIU driver: Sun x8 Express Quad Gigabit Ethernet Adapter (rmmod BUG) Jesper Dangaard Brouer
2008-11-14 18:49                         ` Jesper Dangaard Brouer
2008-11-15  0:21                           ` David Miller
2008-11-19 12:10                             ` Jesper Dangaard Brouer
2008-11-12 12:54                 ` NIU driver: Sun x8 Express Quad Gigabit Ethernet Adapter Ben Hutchings
2008-11-12 13:21                   ` Jesper Dangaard Brouer
2008-11-12 21:46                   ` David Miller
2008-11-12 21:50                     ` Ben Hutchings
2008-11-12 22:26                       ` David Miller
2008-11-12 22:58                         ` Roland Dreier [this message]
2008-11-12 17:56                 ` Jesper Krogh
2008-11-12 21:43                   ` David Miller
2008-11-12 21:31                 ` Jesper Dangaard Brouer
2008-11-12 23:10                   ` Matheos Worku
2008-11-13  9:10                 ` Jesper Dangaard Brouer
2008-11-13 22:19                   ` David Miller
2008-11-13 10:29                 ` Jesper Dangaard Brouer
2008-11-13 22:15                   ` David Miller
2008-11-19 22:58                     ` NIU driver: Sun x8 Express Quad Gigabit Ethernet Adapter (perf + regression IRQs) Jesper Dangaard Brouer
2008-11-19 23:11                       ` David Miller
2008-11-20 19:48                         ` Regression: Bisected, IRQ and MSI allocations screwed without sparse irq Jesper Dangaard Brouer
2008-11-21  0:34                           ` Thomas Gleixner
2008-11-21 10:33                             ` Jesper Dangaard Brouer
2008-11-21 16:40                               ` Thomas Gleixner
2008-11-21 19:35                                 ` Jesper Dangaard Brouer
2008-11-21 21:11                                   ` Thomas Gleixner
2008-11-21 23:06                                   ` 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=ada8wromu0g.fsf@cisco.com \
    --to=rdreier@cisco.com \
    --cc=bhutchings@solarflare.com \
    --cc=davem@davemloft.net \
    --cc=jdb@comx.dk \
    --cc=netdev@vger.kernel.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 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).