Received: from list by lists.gnu.org with archive (Exim 4.71) id 1RA7g3-0000bf-GS for mharc-grub-devel@gnu.org; Sat, 01 Oct 2011 18:04:59 -0400 Received: from eggs.gnu.org ([140.186.70.92]:41661) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RA7g0-0000YW-Vc for grub-devel@gnu.org; Sat, 01 Oct 2011 18:04:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RA7fz-0006uD-V3 for grub-devel@gnu.org; Sat, 01 Oct 2011 18:04:56 -0400 Received: from smtp-out3.iol.cz ([194.228.2.91]:51485) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RA7fz-0006s8-Lw for grub-devel@gnu.org; Sat, 01 Oct 2011 18:04:55 -0400 Received: from antivir5.iol.cz (unknown [192.168.30.212]) by smtp-out3.iol.cz (Postfix) with ESMTP id 8F276BC80DE for ; Sat, 1 Oct 2011 22:04:53 +0000 (UTC) Received: from localhost (antivir5.iol.cz [127.0.0.1]) by antivir5.iol.cz (Postfix) with ESMTP id 7CB821E80AC for ; Sun, 2 Oct 2011 00:04:53 +0200 (CEST) X-Virus-Scanned: amavisd-new at iol.cz Received: from antivir5.iol.cz ([127.0.0.1]) by localhost (antivir5.iol.cz [127.0.0.1]) (amavisd-new, port 10224) with LMTP id ek5-Ut29LR7d for ; Sun, 2 Oct 2011 00:04:53 +0200 (CEST) Received: from port8.iol.cz (unknown [192.168.30.98]) by antivir5.iol.cz (Postfix) with ESMTP id 519DD1E80A5 for ; Sun, 2 Oct 2011 00:04:53 +0200 (CEST) X-SBRS: None X-SBRS-none: None X-RECVLIST: MTA-OUT-IOL X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AtAfACSOh05VRnXk/2dsb2JhbABBhGV5hFSfCIFOAQQBAQQBCAEBGQ8BBR8BLAIDBQIBAxoCBSECAhQBBBQGJAYbAgECAwGHYggCBKcCkEiBLYRkMmEEpSI Received: from 228.117.broadband3.iol.cz (HELO pracovna) ([85.70.117.228]) by port8.iol.cz with ESMTP; 02 Oct 2011 00:04:53 +0200 Message-ID: From: =?UTF-8?Q?Ale=C5=A1_Nesrsta?= To: "The development of GNU GRUB" References: <1309029199.2532.35.camel@pracovna> <201106252151.12483.szymon@janc.net.pl> <1309120668.3268.153.camel@pracovna><4E28A149.4010008@gmail.com> <1314463338.2555.56.camel@pracovna><4E85E22C.2010804@gmail.com> <1317456941.3063.76.camel@pracovna> <4E875653.40902@gmail.com> Subject: Re: [PATCH] EHCI driver - USB 2.0 support - alignment... Date: Sun, 2 Oct 2011 00:03:58 +0200 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="UTF-8"; reply-type=original X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.5931 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.6109 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-Received-From: 194.228.2.91 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 01 Oct 2011 22:04:58 -0000 Hi Vladimir, see below... >> Currently I have only note to discussed "packed" attribute "problem": >> ... >> 2. AFAIK (but maybe it is not true, maybe it was never true...?) >> compilers are using default alignment of variables usually according t= o >> native length of CPU "word". So, as we have 64-bit machines now, it >> could be only question of time when compilers will use 64 bits alignme= nt >> as default. >Reading and writing into a byte aligned on word doesn't bring any >advantage and wastes memory and decreases portability so no compiler >will ever do it. >The whole reason to align is because of performance advantages and >instruction availability. Aah, it looks like we are both speaking about different things ! I am talking about alignment of structure MEMBERS. You are probably talking about alignment of WHOLE STRUCTURE. First to alignment of whole structure: Structure(s), we are talking about, are special structures related to HW=20 which must be in any case aligned to 32 BYTES. This is solved by grub_memalign allocation in driver code. I.e., structur= e=20 will never 1 BYTE or 1 WORD aligned, so there should not be any performan= ce=20 problem. Now to alignment of members in structure: In these special HW related structures are DWORD variables which must be=20 placed in memory immediately one after another without any space between=20 them. I.e., offsets of structure members in structure should look like that: 0x00000000 variable1 0x00000004 variable2 0x00000008 variable3 0x0000000c variable4 I am afraid new compilers in future can use default alignment 64 bits, so= =20 offsets of structure members in structure can, without any attribute, loo= k=20 like that: 0x00000000 variable1 0x00000008 variable2 0x00000010 variable3 0x00000018 variable4 To prevent this wrong situation, I am using "packed" attribute for=20 structure - it will prevent any change of structure members alignment in=20 future. Independent of default compiler alignment, the variables will be=20 placed in memory immediately one after another. As all variables are of=20 DWORD type and whole structure (begin of structure) is always aligned to = 32=20 bytes (i.e. to multiple of DWORD), there also should not be any problem w= ith=20 performance. Even if it looks maybe little bit confusing and surprising, using of=20 "packed" attribute for whole structure does mean it is applied for any=20 member of structure (and not for whole structure) alignment - according e= .g.=20 this ( http://gcc.gnu.org/onlinedocs/gcc/Type-Attributes.html ): "... packed This attribute, attached to struct or union type definition, specifies th= at=20 each member (other than zero-width bitfields) of the structure or union i= s=20 placed to minimize the memory required. When attached to an enum definiti= on,=20 it indicates that the smallest integral type should be used. Specifying this attribute for struct and union types is equivalent to=20 specifying the packed attribute on each of the structure or union members= .=20 Specifying the -fshort-enums flag on the line is equivalent to specifying= =20 the packed attribute on all enum definitions. ..." Best regards Ales > --=20 > Regards > Vladimir '=CF=86-coder/phcoder' Serbinenko Best regards Ales=20