netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Miller <davem@davemloft.net>
To: rdreier@cisco.com
Cc: sri@us.ibm.com, shemminger@osdl.org, netdev@vger.kernel.org
Subject: Re: Excess use of packed attribute
Date: Wed, 09 Aug 2006 21:11:36 -0700 (PDT)	[thread overview]
Message-ID: <20060809.211136.57445905.davem@davemloft.net> (raw)
In-Reply-To: <ada3bc5sql0.fsf@cisco.com>

From: Roland Dreier <rdreier@cisco.com>
Date: Wed, 09 Aug 2006 11:37:31 -0700

> Agreed (although not really RISC -- sparc64 and ia64 have this
> problem, while ppc is fine with unaligned access).  However
> __attribute__((packed,aligned)) has just been brought to my attention.
> For example, on sparc64,
> 
> 	struct foo { char x; int a; } __attribute__((packed,aligned));
> 	struct bar { char x; int b; } __attribute__((packed));
> 	
> 	int c(struct foo *x) { return x->a; }
> 	int d(struct bar *x) { return x->b; }
> 
> compiles to:
 ...
> which suggests that adding "aligned" is a good idea for many of the
> uses of "packed".  However I don't know how all gcc version do with
> this.  Anyone have any comments on "__attribute__((packed,aligned))"?

Good find.

It might usable in some of the questionable cases, however it changes
the size of the struct which eliminates most of the gains.

For example:

davem@sunset:~/src/GIT/net-2.6$ cat foo.c
#include <stdio.h>

struct foo_packed {
	char x; int a;
} __attribute__((packed));

struct foo_packed_aligned {
	char x; int a;
} __attribute__((packed,aligned));

int main(void)
{
	printf("foo_packed: sizeof(%Zd)\n",
	       sizeof(struct foo_packed));
	printf("foo_packed_aligned: sizeof(%Zd)\n",
	       sizeof(struct foo_packed_aligned));

	return 0;
}
davem@sunset:~/src/GIT/net-2.6$ gcc -O -o foo foo.c
davem@sunset:~/src/GIT/net-2.6$ ./foo
foo_packed: sizeof(5)
foo_packed_aligned: sizeof(8)
davem@sunset:~/src/GIT/net-2.6$ 

This doesn't work for things like packet headers, for example.

Oh well.

      reply	other threads:[~2006-08-10  4:11 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-08-07 20:34 Excess use of packed attribute Stephen Hemminger
2006-08-07 23:20 ` David Miller
2006-08-09 19:17   ` Ville Nuorvala
2006-08-08  0:02 ` Sridhar Samudrala
2006-08-08  0:39   ` David Miller
2006-08-09 18:37     ` Roland Dreier
2006-08-10  4:11       ` David Miller [this message]

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=20060809.211136.57445905.davem@davemloft.net \
    --to=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    --cc=rdreier@cisco.com \
    --cc=shemminger@osdl.org \
    --cc=sri@us.ibm.com \
    /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;
as well as URLs for NNTP newsgroup(s).