add new DMA_ADDR_T_SIZE define
Quoted 6 lines
3. use run-time checks all over the place, of the "sizeof(dma_addr_t)==sizeof(u64)" kind, which adds unnecessary overhead to
all platforms.
Actually, these aren't technically run time checks. Although the cpp can't be used for sizeof(), the compiler (at least gcc) does seem to have enough sense to optimise away if(..) branches it has enough information to know won't be taken at compile time.
As long as this optimisation works, I think the if(sizeof(..)) checks are fine for this.
James
Quoted 5 lines · James Bottomley
Quoted 4 lines
3. use run-time checks all over the place, of the "sizeof(dma_addr_t)==sizeof(u64)" kind, which adds unnecessary overhead to
all platforms.
Quoted 7 lines
Actually, these aren't technically run time checks. Although the cpp can't be used for
sizeof(), the compiler (at least gcc) does seem to have enough sense to optimise away if(..) branches it has enough information to know won't be taken at compile time.As long as this optimisation works, I think the if(sizeof(..)) checks are fine for this.
Well, yes and no. Indeed those checks are optimized away, but as a result of using them most data-access macros must be converted to inline functions. And, last I heard at least, gcc was optimizing inline functions much worse than preprocessor macros.
There are various other things that are made easier by a preprocessor directive -- constructing the right data structures, for instance.
However, if such a patch is ultimately not getting accepted, these checks is probably what I'll end up using...
Thanks,
Ion
Signature · 2 lines
It is better to keep your mouth shut and be thought a fool,
than to open it and remove all doubt.Quoted 4 lines · Ion Badulescu
Well, yes and no. Indeed those checks are optimized away, but as a result of using them most data-access macros must be converted to inline functions. And, last I heard at least, gcc was optimizing inline functions much worse than preprocessor macros.
Not true, you can still use macros and GCC is saner with inlines these days.
Your arguments are nice to encourage your patch to be accepted, they are however not correct.
Quoted 2 lines · David S. Miller
I don't think you are making things any better by adding a new ifdef to all the drivers.
I'm adding an ifdef to types.h, not to all the drivers -- the drivers can use it if they choose to.
Quoted 3 lines
And frankly, trying to super-optimize a driver
because it has two different descriptor format is a mess you as a driver author choose to get involved in.
Indeed. But why would you want to make my life miserable if you make that choice? Take a look at starfire.c to see how all that 32/64 bit code is neatly handled by a few very simple macros, and the only really hideous part is the #ifdef which decides if dma_addr_t is 32- or 64-bit.
I would gladly define my own macros if cpp groked sizeof(). But it doesn't, that's why I want this simple macro where it belongs: next to the definition of dma_addr_t.
Quoted 3 lines
Nearly all cards today are 64-bit DMA address descriptors only. So if anything, this new ifdef will get less and less used over time.
Not true. Even if the only descriptors available are 64-bit, there is no reason why I should have to care about the upper 32 bits when I know that my dma_addr_t will always be 32-bit, at compile time. I can simply memset(0) the entire descriptor and initialize only the bottom 32 bits.
What you're saying is, in essence, "screw your card, screw your 32-bit platform, the future is all-64-bit anyway and/or everyone has gobs of memory and is using highmem". A little bit exagerated, of course, but...
Quoted 9 lines
Quoted 3 lines
3. use run-time checks all over the place, of the "sizeof(dma_addr_t)==sizeof(u64)" kind, which adds unnecessary overhead to all platforms.
The compiler optimizes this completely away, it becomes a compile time test and the unused code block and the test never make it into the assembler.
So this argument is bogus, as is the define.
It's not completely bogus, although I already conceded that the code is indeed optimized away by the compiler. What the compiler does not optimize away is the larger data structures needed to hold 64 bit values.
As I said in a different email, this is what I'll end up using if the new define is not accepted.
Quoted 8 lines · David S. Miller
Quoted 4 lines · Ion Badulescu
Well, yes and no. Indeed those checks are optimized away, but as a result of using them most data-access macros must be converted to inline functions. And, last I heard at least, gcc was optimizing inline functions much worse than preprocessor macros.
Not true, you can still use macros and GCC is saner with inlines these days.
I'm curious about this, actually. If I do something like
#if DMA_ADDR_T_SIZE == 64
#define cpu_to_dma(x) cpu_to_le64(x)
#else
#define cpu_to_dma(x) cpu_to_le32(x)
#endif
descr.addr = cpu_to_dma(dma_addr)
or
if (sizeof(dma_addr_t) == sizeof(u64))
descr64.addr = cpu_to_le64(dma_addr); else descr32.addr = cpu_to_le32(dma_addr);
then the compiler generates equivalent code? Even if that's true, which code fragment strikes you as uglier and/or harder to read, particularly if it's repeated multiple times in close succession?
Or maybe you are suggesting an abomination like
void assign_dma_addr(descr64_t *descr64, descr32_t *descr32, dma_addt_t dma_addr)
{
if (sizeof(dma_addr_t) == sizeof(u64))
descr64->addr = cpu_to_le64(dma_addr);
else
descr32->addr = cpu_to_le32(dma_addr);
}or, worse, the gcc-specific abomination
#define cpu_to_dma(x) \
({ dma_addr_t dma_addr; \
if (sizeof(dma_addr_t) == sizeof(u64)) \
dma_addr = cpu_to_le64(x); \
else \
dma_addr = cpu_to_le32(x); \ dma_addr; \
});
And all these just for avoiding a very clearly-defined #ifdef's in a header file?...
Quoted 2 lines
Your arguments are nice to encourage your patch to be accepted, they are however not correct.
I think you're being a bit harsh here. :) "Some arguments were not 100% correct" would be a better description...
Ion
Signature · 2 lines
It is better to keep your mouth shut and be thought a fool,
than to open it and remove all doubt. From: Ion Badulescu <[email protected]>
Date: Wed, 19 Feb 2003 17:41:39 -0500 (EST)
Quoted 3 lines
Nearly all cards today are 64-bit DMA address descriptors only. So if anything, this new ifdef will get less and less used over time.
Not true. Even if the only descriptors available are 64-bit, there is no reason why I should have to care about the upper 32 bits when I know that my dma_addr_t will always be 32-bit, at compile time. I can simply memset(0) the entire descriptor and initialize only the bottom 32 bits.
Yes true, storing the two consequetive 32-bit values is better for store buffer compression of the cpu. Using memset is much more inefficient because you push the full set of data once then you push non-compressible stores to the same data through the cpu.
I'm not talking out of my ass, I've measured this.
Quoted 7 lines · David S. Miller
Yes true, storing the two consequetive 32-bit values is better for store buffer compression of the cpu. Using memset is much more inefficient because you push the full set of data once then you push non-compressible stores to the same data through the cpu.
I'm not talking out of my ass, I've measured this.
So is the current wisdom something like "always treat dma_addr_t as a u64 and be happy"?
Ion
Signature · 2 lines
It is better to keep your mouth shut and be thought a fool,
than to open it and remove all doubt. From: Ion Badulescu <[email protected]>
Date: Wed, 19 Feb 2003 17:53:02 -0500 (EST)
So is the current wisdom something like "always treat dma_addr_t as a u64 and be happy"?
Yes.