From: Benjamin Herrenschmidt <benh@kernel.crashing.org>
To: Jeff Garzik <jgarzik@pobox.com>
Cc: Jesse Barnes <jbarnes@virtuousgeek.org>,
Linux Kernel list <linux-kernel@vger.kernel.org>,
Alan Cox <alan@lxorguk.ukuu.org.uk>,
"David S. Miller" <davem@davemloft.net>,
Paul Mackerras <paulus@samba.org>,
Linus Torvalds <torvalds@osdl.org>, Andrew Morton <akpm@osdl.org>,
Segher Boessenkool <segher@kernel.crashing.org>
Subject: Re: [RFC] MMIO accessors & barriers documentation
Date: Tue, 12 Sep 2006 08:56:34 +1000 [thread overview]
Message-ID: <1158015394.3879.82.camel@localhost.localdomain> (raw)
In-Reply-To: <4505DB10.7080807@pobox.com>
On Mon, 2006-09-11 at 17:54 -0400, Jeff Garzik wrote:
> Benjamin Herrenschmidt wrote:
> > Ah ? What about the comment in e1000 saying that it needs a wmb()
> > between descriptor updates in memory and the mmio to kick them ? That
> > would typically be a memory_to_io_wb(). Or are your MMIOs ordered cs.
> > your cacheable stores ?
>
> That's likely just following existing practice found in many network
> drivers. The following two design patterns have been copied across a
> great many network drivers:
Well, I was mentioning that one specifically because this comment:
/* Force memory writes to complete before letting h/w
* know there are new descriptors to fetch. (Only
* applicable for weak-ordered memory model archs,
* such as IA-64). */
Which made me ask wether, ia64 was or was not ordering memory store
followed by MMIO store, that is does ia64 -current- accessors provide
rule #2 (memory W + MMIO W) currently or not and would it benefit from
not having to provide it with my new partially relaxed accessors ?
> 1) When in a loop, reading through a DMA ring, put an "rmb()" at the top
> of the loop, to ensure that the compiler does not optimize out all
> memory loads after the first.
and rmb is heavy handed for a compiler barrier :) what you might need on
some platforms is an rmb between the MMIO read of whatever status/index
register and the following memory reads of descriptors, and you may want
an rmb in case where it matters if the chip has been changing a value
behind your back (which it generally doesn't) but that's pretty much
it....
> 2) Use "wmb()" to ensure that just-written-to memory is visible to a PCI
> device that will be reading said memory region via DMA.
That will definitely help on PowerPC with our current accessors which
are mostly ordered except for that rule #2 I mentioned above.
> I don't claim that either of these is correct, just that's existing
> practice, perhaps in some case perpetuated by my own arch ignorance.
No worries :) That's also why I'm trying to describe precisely what
semantics are provided by the MMIO accessors with real world examples in
a way that is not arch dependant. The 4 "rules" I've listed in the first
part are precisely what should be needed for drivers, then I list the
accessors and what rules they are guaranteed to comply with, then I list
the barriers allowing to implement those ordering rules when the
accessors don't.
> So, in a perfect world where I was designing my own API, I would create
> two new API functions:
>
> prepare_to_read_dma_memory()
> and
> make_memory_writes_visible_to_dmaing_devices()
>
> and leave the existing APIs untouched. Those are the two fundamental
> operations that are needed.
Well, the argument currently is to make writel and readl imply the above
barriers by making them fully ordered (and slow on some platforms) and
so also provide more weakly ordered routines along with barriers for
people who know what they do. The above 2 barriers are what I've called
io_to_memory_rb() and memory_to_io_wb() (actually,
prepare_to_read_dma_memory() by itself doesn't really make much sense.
It does in conjunction with an MMIO read to flush DMA buffers, in which
case the barrier provides an ordering guarantee that the memory reads
will only be performed after the MMIO read has fully completed).
Ben.
next prev parent reply other threads:[~2006-09-11 22:57 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-09-11 4:03 [RFC] MMIO accessors & barriers documentation Benjamin Herrenschmidt
2006-09-11 8:57 ` Alan Cox
2006-09-11 9:17 ` Benjamin Herrenschmidt
2006-09-11 10:07 ` Alan Cox
2006-09-11 9:59 ` Benjamin Herrenschmidt
2006-09-11 17:26 ` Alan Cox
2006-09-11 21:29 ` Benjamin Herrenschmidt
2006-09-12 5:48 ` Eric W. Biederman
2006-09-12 5:56 ` Benjamin Herrenschmidt
2006-09-12 6:27 ` Eric W. Biederman
2006-09-12 7:13 ` Benjamin Herrenschmidt
2006-09-12 15:19 ` Segher Boessenkool
2006-09-12 21:22 ` Benjamin Herrenschmidt
2006-09-13 0:12 ` Segher Boessenkool
2006-09-13 1:34 ` Benjamin Herrenschmidt
2006-09-11 18:39 ` Jesse Barnes
2006-09-11 21:45 ` Benjamin Herrenschmidt
2006-09-11 21:54 ` Jeff Garzik
2006-09-11 22:56 ` Benjamin Herrenschmidt [this message]
2006-09-11 23:08 ` Roland Dreier
2006-09-11 23:18 ` Benjamin Herrenschmidt
2006-09-11 23:24 ` Jeff Garzik
2006-09-12 0:46 ` Benjamin Herrenschmidt
2006-09-12 15:32 ` Segher Boessenkool
2006-09-11 22:05 ` Jesse Barnes
2006-09-11 23:01 ` Benjamin Herrenschmidt
-- strict thread matches above, loose matches on Subject: below --
2006-09-12 5:33 Albert Cahalan
2006-09-12 5:48 ` Benjamin Herrenschmidt
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=1158015394.3879.82.camel@localhost.localdomain \
--to=benh@kernel.crashing.org \
--cc=akpm@osdl.org \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=davem@davemloft.net \
--cc=jbarnes@virtuousgeek.org \
--cc=jgarzik@pobox.com \
--cc=linux-kernel@vger.kernel.org \
--cc=paulus@samba.org \
--cc=segher@kernel.crashing.org \
--cc=torvalds@osdl.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