From: Keith Owens <kaos@ocs.com.au>
To: David Miller <davem@davemloft.net>
Cc: nmiell@comcast.net, linux-kernel@vger.kernel.org
Subject: Re: [patch 2.6.19-rc6] Stop gcc 4.1.0 optimizing wait_hpet_tick away
Date: Wed, 29 Nov 2006 15:30:27 +1100 [thread overview]
Message-ID: <23328.1164774627@kao2.melbourne.sgi.com> (raw)
In-Reply-To: Your message of "Tue, 28 Nov 2006 20:04:53 -0800." <20061128.200453.104036587.davem@davemloft.net>
David Miller (on Tue, 28 Nov 2006 20:04:53 -0800 (PST)) wrote:
>From: Keith Owens <kaos@ocs.com.au>
>Date: Wed, 29 Nov 2006 14:56:20 +1100
>
>> Secondly, I believe that this is a separate problem from bug 22278.
>> hpet_readl() is correctly using volatile internally, but its result is
>> being assigned to a pair of normal integers (not declared as volatile).
>> In the context of wait_hpet_tick, all the variables are unqualified so
>> gcc is allowed to optimize the comparison away.
>>
>> The same problem may exist in other parts of arch/i386/kernel/time_hpet.c,
>> where the return value from hpet_readl() is assigned to a normal
>> variable. Nothing in the C standard says that those unqualified
>> variables should be magically treated as volatile, just because the
>> original code that extracted the value used volatile. IOW, time_hpet.c
>> needs to declare any variables that hold the result of hpet_readl() as
>> being volatile variables.
>
>I disagree with this.
>
>readl() returns values from an opaque source, and it is declared
>as such to show this to GCC. It's like a function that GCC
>cannot see the implementation of, which it cannot determine
>anything about wrt. return values.
>
>The volatile'ness does not simply disappear the moment you
>assign the result to some local variable which is not volatile.
>
>Half of our drivers would break if this were true.
This is definitely a gcc bug, 4.1.0 is doing something weird. Compile
with CONFIG_CC_OPTIMIZE_FOR_SIZE=n and the bug appears,
CONFIG_CC_OPTIMIZE_FOR_SIZE=y has no problem.
Compile with CONFIG_CC_OPTIMIZE_FOR_SIZE=n and _either_ of the patches
below and the problem disappears.
Index: linux/arch/i386/kernel/time_hpet.c
===================================================================
--- linux.orig/arch/i386/kernel/time_hpet.c 2006-11-29 13:51:33.900462088 +1100
+++ linux/arch/i386/kernel/time_hpet.c 2006-11-29 15:25:47.853245938 +1100
@@ -35,7 +35,8 @@ static void __iomem * hpet_virt_address;
int hpet_readl(unsigned long a)
{
- return readl(hpet_virt_address + a);
+ volatile int v = readl(hpet_virt_address + a);
+ return v;
}
static void hpet_writel(unsigned long d, unsigned long a)
Index: linux-2.6/arch/i386/kernel/time_hpet.c
===================================================================
--- linux-2.6.orig/arch/i386/kernel/time_hpet.c
+++ linux-2.6/arch/i386/kernel/time_hpet.c
@@ -51,7 +51,7 @@ static void hpet_writel(unsigned long d,
*/
static void __devinit wait_hpet_tick(void)
{
- unsigned int start_cmp_val, end_cmp_val;
+ unsigned volatile int start_cmp_val, end_cmp_val;
start_cmp_val = hpet_readl(HPET_T0_CMP);
do {
next prev parent reply other threads:[~2006-11-29 4:30 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-11-29 2:22 [patch 2.6.19-rc6] Stop gcc 4.1.0 optimizing wait_hpet_tick away Keith Owens
2006-11-29 3:08 ` Nicholas Miell
2006-11-29 3:56 ` Keith Owens
2006-11-29 4:04 ` David Miller
2006-11-29 4:30 ` Keith Owens [this message]
2006-11-29 4:57 ` Nicholas Miell
2006-11-30 1:04 ` David Schwartz
2006-12-01 5:50 ` Kyle Moffett
2006-12-01 11:24 ` David Schwartz
2006-12-01 12:08 ` Kyle Moffett
2006-12-01 13:52 ` David Schwartz
2006-12-02 9:02 ` Jan Engelhardt
2006-12-01 12:31 ` Andreas Schwab
2006-12-01 14:03 ` David Schwartz
2006-12-02 10:39 ` Kyle Moffett
2006-12-03 4:29 ` David Schwartz
2006-12-07 14:02 ` Kyle Moffett
2006-12-08 4:22 ` David Schwartz
2006-11-29 9:08 ` Jakub Jelinek
2006-11-29 20:14 ` Willy Tarreau
2006-12-01 5:05 ` Andrew Morton
2006-12-01 5:14 ` Keith Owens
2006-12-01 5:26 ` Willy Tarreau
2006-12-01 6:32 ` Keith Owens
2006-12-01 7:28 ` Willy Tarreau
2006-12-01 7:57 ` Jakub Jelinek
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=23328.1164774627@kao2.melbourne.sgi.com \
--to=kaos@ocs.com.au \
--cc=davem@davemloft.net \
--cc=linux-kernel@vger.kernel.org \
--cc=nmiell@comcast.net \
/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