mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Satyam Sharma" <satyam.sharma@gmail.com>
To: "Bill Davidsen" <davidsen@tmr.com>
Cc: 7eggert@gmx.de, "H. Peter Anvin" <hpa@zytor.com>,
	"Jonathan Corbet" <corbet@lwn.net>,
	akpm@linux-foundation.org, linux-kernel@vger.kernel.org,
	"Johannes Stezenbach" <js@linuxtv.org>,
	"Jesper Juhl" <jesper.juhl@gmail.com>,
	"Randy Dunlap" <randy.dunlap@oracle.com>,
	"Heikki Orsila" <shdl@zakalwe.fi>,
	"jimmy bahuleyan" <knight.camelot@gmail.com>,
	"Stefan Richter" <stefanr@s5r6.in-berlin.de>
Subject: Re: [PATCH] "volatile considered harmful", take 3
Date: Fri, 18 May 2007 08:43:17 +0530	[thread overview]
Message-ID: <a781481a0705172013k1536e586u6908ded5c8f8df@mail.gmail.com> (raw)
In-Reply-To: <464CEA70.1080908@tmr.com>

Hi Bill,

On 5/18/07, Bill Davidsen <davidsen@tmr.com> wrote:
> Satyam Sharma wrote:
>
> > *Unfortunately* (the trouble with C itself, is that a *committee* has made
> > it into ... something ... that it should not have made it into) -- anyway,
> > unfortunately C took it upon itself to solve a problem that it did not
> > have (and does not even bring about) in the first place: and the
> > half-hearted (or vague, call it what you will) attempt _then_ ends up
> > being a problem -- by making people _feel_ as if they are doing things
> > right, when that is probably not the case.
> >
> > [ And we've not even touched the issue of whether the _same_ compiler's
> > implementation of volatile across archs/platforms is consistent. ]

> It was a fun experience, where I first learned the modern equivalent of
> Occam's Razor, Plauger's "Law of least astonishment," which compiler
> writers regularly violate :-(

Well, here it was a case of the standard committee violating the principle
of solving a problem _where_ it exists in the first place. As far as volatile
is concerned, the _language_ itself had absolutely no problems that
needed fixing ...

> Pardon, I was GE's representative to the original X3J11 committee, and
> 'volatile' was added to "codify existing practice" which is one of the
> goals of a standard. The extension existed, in at least two forms, to
> allow handling of memory mapped hardware. So the committee did not take
> it upon itself, it was a part of the defined duty of the committee.
>
> The intents was simple, clear, and limited, to tell the compiler that
> every read of a variable in source code should result in a read, at that
> point in the logic, and similar for writes. In other words, the code
> should not be moved and should generate a real memory access every time.
> People have tried to do many things with that limited concept since,
> some with "clarification" and some with assuming the compiler knows when
> to ignore volatile.

In fact I wish the standard just left this functionality entirely up to the
implementation.

After all, C (the _language_) does not mandate memory access
reordering / optimization by implementations so dumb compilers
(5.1.2.3:1) that do not do any are still conformant and hence
don't require the volatile extension (5.1.2.3:8). Implementations that
do perform optimization, otoh, _must_ then solve the possible problems
_themselves_ by providing an extension that allows the programmer
to turn it off (wherever necessary) to prevent those side-effects that the
implementation itself brought about by performing optimization in the
first place. That _compiler extension_ could then of course be called
anything (volatile, foo, bar, barrier, ...) and implemented in any way --
whatever is appropriate for that compiler [1].

[ Analogically, C (or any language) does not mandate the hardware
it runs on to reorder / optimize memory accesses. Those that do, must
clearly then also provide instructions like lfence/sfence/mfence as part
of their instruction set to solve potential issues that _their_ behaviour
brings about in the first place. How horribly wrong it would be for a
_language_ to try and go about solving this problem ... ]

So the way I see it, it's just a case of solving a problem _where_ it
exists in the first place.

Satyam

[1] Which begs the question, so if we wished (note past tense here)
to keep generic kernel code compiler-independent, what do we do in
situations where we want to disable _compiler optimizations_ temporarily
for some piece of code? => By defining macros / some API as part of
our codebase in implementation-specific headers that does whatever
needs to be done for _that_ compiler. => Which is precisely what we
have already and why I like/prefer that.

  reply	other threads:[~2007-05-18  3:13 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <8jHg3-1T2-5@gated-at.bofh.it>
     [not found] ` <8jQt5-7As-3@gated-at.bofh.it>
     [not found]   ` <8jSuQ-28J-21@gated-at.bofh.it>
     [not found]     ` <8jT7y-39x-9@gated-at.bofh.it>
2007-05-13  0:00       ` Bodo Eggert
2007-05-14  3:37         ` Satyam Sharma
2007-05-17 23:51           ` Bill Davidsen
2007-05-18  3:13             ` Satyam Sharma [this message]
2007-05-11 17:36 Jonathan Corbet
2007-05-11 21:25 ` Jesper Juhl
2007-05-12  3:21 ` Satyam Sharma
2007-05-12  4:29   ` Jeff Garzik
2007-05-12  5:34   ` H. Peter Anvin
2007-05-12  5:41     ` H. Peter Anvin
2007-05-12  6:15     ` Satyam Sharma
2007-05-12  6:21       ` H. Peter Anvin
2007-05-12  7:02         ` Satyam Sharma
2007-05-12  7:13           ` H. Peter Anvin
2007-05-12  7:28             ` Satyam Sharma
2007-05-12  7:53             ` Stefan Richter
2007-05-12 11:51               ` Heikki Orsila
2007-05-12 18:06               ` H. Peter Anvin
2007-05-12  7:22           ` Stefan Richter
2007-05-12  7:33             ` jimmy bahuleyan
2007-05-12  7:45               ` Jeff Garzik
2007-05-12 19:17         ` Dr. David Alan Gilbert

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=a781481a0705172013k1536e586u6908ded5c8f8df@mail.gmail.com \
    --to=satyam.sharma@gmail.com \
    --cc=7eggert@gmx.de \
    --cc=akpm@linux-foundation.org \
    --cc=corbet@lwn.net \
    --cc=davidsen@tmr.com \
    --cc=hpa@zytor.com \
    --cc=jesper.juhl@gmail.com \
    --cc=js@linuxtv.org \
    --cc=knight.camelot@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=randy.dunlap@oracle.com \
    --cc=shdl@zakalwe.fi \
    --cc=stefanr@s5r6.in-berlin.de \
    /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

all inboxes | Powered by JetHome®