Opinion on ordering of writel vs. stores to RAM
Quoted 7 lines · Benjamin Herrenschmidt
Quoted 3 lines · Jesse Barnes
Ok, that's fine, though I think you'd only want the very weak semantics (as provided by your __raw* routines) on write combined memory typically?
Well, that and memory with no side effects (like frame buffers)
Oh no, it's great for regular device driver work. I used this type of system all the time on a different PowerPC OS.
Suppose you need to set up a piece of hardware. Assume that the hardware isn't across some nasty bridge. You do this:
hw->x = 42;hw->y = 19;eieio();hw->p = 11;hw->q = 233;hw->r = 87;eieio()hw->n = 101;hw->m = 5;eieio()
In that ficticious example, I get 7 writes to the hardware device with only 3 "eieio" operations. It's not hard at all. Sometimes a "sync" is used instead, also explicitly.
To get even more speed, you can mark memory as non-coherent. You can even do this for RAM. There are cache control instructions to take care of any problems; simply ask the CPU to write things out as needed.
Linux should probably do this:
Plain stuff is like x86. If you want the performance of loose ordering, ask for it when you get the mapping and use read/write functions that have a "_" prefix. If you mix the "_" versions with a plain x86-like mapping or the other way, the behavior you get will be an arch-specific middle ground.
Quoted 18 lines
Oh no, it's great for regular device driver work. I used this type of system all the time on a different PowerPC OS.
Suppose you need to set up a piece of hardware. Assume that the hardware isn't across some nasty bridge. You do this:
hw->x= 42;hw->y= 19;eieio();hw->p= 11;hw->q= 233;hw->r= 87;eieio()hw->n= 101;hw->m= 5;eieio()
Quoted 3 lines
In that ficticious example, I get 7 writes to the hardware device with only 3 "eieio" operations. It's not hard at all. Sometimes a "sync" is used instead, also explicitly.
You can do that with my proposed __writel which is a simple store as writes to non-cacheable and guarded storage have to stay in order according to the PowerPC architecture. No need for __raw.
Quoted 1 line
To get even more speed, you can mark memory as non-coherent.
Ugh ? MMIO space is always marked non-coherent. You are not supposed to set the M bit if the I is set in the page tables. If you are talking about main memory, then it's a completely different discussion.
Quoted 3 lines
You can even do this for RAM. There are cache control instructions to take care of any problems; simply ask the CPU to write things out as needed.
Sure, though that's not the topic.
Quoted 7 lines
Linux should probably do this:
Plain stuff is like x86. If you want the performance of loose ordering, ask for it when you get the mapping and use read/write functions that have a "_" prefix. If you mix the "_" versions with a plain x86-like mapping or the other way, the behavior you get will be an arch-specific middle ground.
No. I want precisely defined semantics in all cases.
Ben.
Quoted 18 lines · Benjamin Herrenschmidt
Quoted 18 lines
Oh no, it's great for regular device driver work. I used this type of system all the time on a different PowerPC OS.
Suppose you need to set up a piece of hardware. Assume that the hardware isn't across some nasty bridge. You do this:
hw->x= 42;hw->y= 19;eieio();hw->p= 11;hw->q= 233;hw->r= 87;eieio()hw->n= 101;hw->m= 5;eieio()
Quoted 7 lines
Quoted 3 lines
In that ficticious example, I get 7 writes to the hardware device with only 3 "eieio" operations. It's not hard at all. Sometimes a "sync" is used instead, also explicitly.
You can do that with my proposed
__writelwhich is a simple store as writes to non-cacheable and guarded storage have to stay in order according to the PowerPC architecture. No need for__raw.
Oops, I forgot about store-store ordering being automatic. Pretend I had some loads in my example.
A proper interface would be more explicit about what the fence does, so that driver authors shouldn't need to know this detail.
Quoted 5 lines
Quoted 1 line
To get even more speed, you can mark memory as non-coherent.
Ugh ? MMIO space is always marked non-coherent. You are not supposed to set the M bit if the I is set in the page tables. If you are talking about main memory, then it's a completely different discussion.
OK, a different discussion... though memory being used for DMA seems rather related. You need to flush before a DMA out, or invalidate before a DMA in.
Quoted 9 lines
Quoted 7 lines
Linux should probably do this:
Plain stuff is like x86. If you want the performance of loose ordering, ask for it when you get the mapping and use read/write functions that have a "_" prefix. If you mix the "_" versions with a plain x86-like mapping or the other way, the behavior you get will be an arch-specific middle ground.
No. I want precisely defined semantics in all cases.
So you say: never mix strict mappings with loose operations, and never mix loose mappings with strict operations.
That is an excellent rule. I see no need to stop people from actively trying to shoot their feet though. I'm certainly not suggesting that people be mixing things.
For some CPUs, you want to be specifying things when you set up the mapping. For other CPUs, the read/write code is how this gets determined. So developers specify both.
Quoted 3 lines
Oops, I forgot about store-store ordering being automatic. Pretend I had some loads in my example.
Well, in 99% of the cases, you want MMIO loads to be orderd vs. MMIO stores and thus you can use __writel and __readl (which will only do an eieio in __readl). If you are really that picky, then, of course you can go use the __raw_* versions.
Quoted 3 lines
A proper interface would be more explicit about what the fence does, so that driver authors shouldn't need to know this detail.
What detail ? Isn't my document explicit enough ? If not, please let me know what is not clear in the definition of the 4 ordering rules and the matching fences.
Quoted 3 lines
OK, a different discussion... though memory being used for DMA seems rather related. You need to flush before a DMA out, or invalidate before a DMA in.
This is already documented elsewhere.
Quoted 2 lines
So you say: never mix strict mappings with loose operations, and never mix loose mappings with strict operations.
I don't want the concept of "lose mappings" in the generic driver interface for now anyway :)
It's too implementation specific and I want to know that a given access is strictly ordered or relaxed just by looking at the accessor used, not having to go look for where the driver did the ioremap. We can still provide arch specific things where we feel it's useful but let's move one step at a time with the generic accessors.
The only "lose" mapping that we'll introduce next is write combining, but that's also a different debate. Again, one thing at a time :)
Quoted 7 lines
That is an excellent rule. I see no need to stop people from actively trying to shoot their feet though. I'm certainly not suggesting that people be mixing things.
For some CPUs, you want to be specifying things when you set up the mapping. For other CPUs, the read/write code is how this gets determined. So developers specify both.
For now, we are assuming that if the mapping controls ordering, then it's strictly order. We'll see if we hit an arch where that becomes a problem.
Ben.
Quoted 8 lines · Benjamin Herrenschmidt
Quoted 3 lines
Oops, I forgot about store-store ordering being automatic. Pretend I had some loads in my example.
Well, in 99% of the cases, you want MMIO loads to be orderd vs. MMIO stores and thus you can use
__writeland__readl(which will only do an eieio in__readl). If you are really that picky, then, of course you can go use the __raw_* versions.
If I could get the __raw_* versions for every arch, and there wouldn't be any endianness troubles, it'd do.
I think a single or double "_" is enough warning to enable full foot-shooting ability though.
Quoted 7 lines
Quoted 3 lines
A proper interface would be more explicit about what the fence does, so that driver authors shouldn't need to know this detail.
What detail ? Isn't my document explicit enough ? If not, please let me know what is not clear in the definition of the 4 ordering rules and the matching fences.
The driver code is not very self-documenting this way.
If I see an io_to_io_barrier(), how am I to tell if it is read to read, write to write, read to write, write to read, read/write to read, read/write to write, read to read/write, write to read/write, or read/write to read/write?
Considering just reads and writes to MMIO, there are 9 possible types of fence. SPARC seems to cover a decent number of these distinctly; the instruction takes an immediate value as flags.
Quoted 11 lines
Quoted 2 lines
So you say: never mix strict mappings with loose operations, and never mix loose mappings with strict operations.
I don't want the concept of "lose mappings" in the generic driver interface for now anyway :)
It's too implementation specific and I want to know that a given access is strictly ordered or relaxed just by looking at the accessor used, not having to go look for where the driver did the ioremap. We can still provide arch specific things where we feel it's useful but let's move one step at a time with the generic accessors.
I suppose the "sparse" tool could match up mapping type with accessor type. That'd let you rely on the accessor to be doing what you expect when you read the code.
Loose mappings are only arch-specific in implementation. Generic non-arch driver code ought to be able to take advantage of the performance benefits of loose mappings. (that is: full any-any reordering)
Quoted 10 lines
If I see an
io_to_io_barrier(), how am I to tell if it is read to read, write to write, read to write, write to read, read/write to read, read/write to write, read to read/write, write to read/write, or read/write to read/write?Considering just reads and writes to MMIO, there are 9 possible types of fence. SPARC seems to cover a decent number of these distinctly; the instruction takes an immediate value as flags.
We need to decide wether a single one doing a full MMIO fence (and not memory) is enough or if the performance different justifies maybe having io_to_io_{wmb,rmb,mb}. I don't see any real use for more combinations.
David ? It's your call here. What do you think ?
Ben.
Quoted 6 lines · Benjamin Herrenschmidt
Quoted 6 lines
If I see an
io_to_io_barrier(), how am I to tell if it is read to read, write to write, read to write, write to read, read/write to read, read/write to write, read to read/write, write to read/write, or read/write to read/write?
Quoted 8 lines
Quoted 4 lines
Considering just reads and writes to MMIO, there are 9 possible types of fence. SPARC seems to cover a decent number of these distinctly; the instruction takes an immediate value as flags.
We need to decide wether a single one doing a full MMIO fence (and not memory) is enough or if the performance different justifies maybe having io_to_io_{wmb,rmb,mb}. I don't see any real use for more combinations.
Remember: it's more than just performance. It's documentation in the code.