Re: drivers/block/ub.c

From: Scott Wood
Date: Mon Jun 28 2004 - 15:51:22 EST


On Mon, Jun 28, 2004 at 01:25:31PM -0700, David S. Miller wrote:
> That's true. But if one were to propose such a feature to the gcc
> guys, I know the first question they would ask. "If no padding of
> the structure is needed, why are you specifying this new
> __nopadding__ attribute?"

It would benefit other structures that *do* need it, but only for a
few fields.

> I think it's bad to just "smack this attribute onto any structure that
> _MIGHT_ need it on some platform" I never do that in my drivers,
> and they work on all platforms. For example, if you have a simple
> DMA descriptor structure such as:
>
> struct txd {
> u32 dma_addr;
> u32 length;
> };
>
> It is just total and utter madness to put a packed or the proposed
> __nopadding__ attribute on that structure. Yet this seems to be
> what was suggested now and at the beginning of this thread.

As long as GCC generates code as it does, sure, it's madness.

However, what if it were to be run on a machine that can't address
smaller quantities than 64-bit? Such a machine sounds silly, but it
could happen (just as early Alphas couldn't directly load or store
smaller than 32-bit quantities), and thus the compiler might want to
pad them so that they don't share a word. If a way exists to express
to the compiler that the format of the struct is intended to be
exactly as specified, without causing any detrimental effect, why not
make use of it?

As an aside, what would *really* be nice is if GCC had an attribute
that lets one specify the endianness of the field, so that one
doesn't have to mess around with conversion functions/macros
uglifying the code. It'd probably be faster, too, as the optimizer
could deal with the loads and stores like any other.

-Scott
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/