linux-acpi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rafael@kernel.org>
To: David Laight <David.Laight@aculab.com>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>,
	Bjorn Helgaas <helgaas@kernel.org>,
	Zhang Rui <rui.zhang@intel.com>,
	Xiaofei Tan <tanxiaofei@huawei.com>,
	"rjw@rjwysocki.net" <rjw@rjwysocki.net>,
	"lenb@kernel.org" <lenb@kernel.org>,
	"bhelgaas@google.com" <bhelgaas@google.com>,
	"linux-acpi@vger.kernel.org" <linux-acpi@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-pci@vger.kernel.org" <linux-pci@vger.kernel.org>,
	"linuxarm@openeuler.org" <linuxarm@openeuler.org>
Subject: Re: [PATCH v2 04/15] ACPI: table: replace __attribute__((packed)) by __packed
Date: Thu, 1 Apr 2021 19:29:37 +0200	[thread overview]
Message-ID: <CAJZ5v0h0XMkrYYyOLd8bDcngxnei7VbAh=cYWA4Sy3qm2b69iQ@mail.gmail.com> (raw)
In-Reply-To: <a0ec3dbdffc145ac909089048e552eb6@AcuMS.aculab.com>

On Thu, Apr 1, 2021 at 4:23 PM David Laight <David.Laight@aculab.com> wrote:
>
> From: Rafael J. Wysocki
> > Sent: 01 April 2021 14:50
> ...
> > So what exactly is wrong with using "packed"?  It is way easier to
> > understand for a casual reader of the code.
>
> Because it is usually wrong!
>
> If I have:
>         struct foo {
>                 u64 val;
>         } __packed;
>
> And then have:
> u64 bar(struct foo *foo)
> {
>         return foo->val;
> }
>
> The on some cpu the compiler has to generate the equivalent of:
>         u8 *x = (void *)&foo->val;
>         return x[0] | x[1] << 8 | x[2] << 16 | x[3] << 24 | x[4] << 32 | x[5] << 40 | x[6] << 48 | x[7] << 56;
>
> If you can guarantee that the structure is 32bit aligned
> then it can generate the simpler:
>         u32 *x = (void *)&foo->val;
>         return x[0] | x[1] << 32;
>
> (Yes I've missed out the 64-bit casts)
>
> This is why you should almost never use __packed.
>
> There are historic structures with 64 bit items on 4 byte boundaries
> (and 32 bit values on 2 byte boundaries).
> Typically most of the fields are shorter so can be read directly
> (although they might need a byte-swapping load).

The possible overhead impact is clear to me, but I really don't like
the "local" typedef idea.

It at least would need to be accompanied by a comment explaining why
it is there and why using it is better than using __packed and why
this needs to be defined locally and not in some generic header file.

Also, the FPDT code is just one function that parses the entire table
and there is no object passing between functions in it etc, so is
__packed still problematic in there?

  reply	other threads:[~2021-04-01 17:43 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-27  7:46 [PATCH v2 00/15] acpi: fix some coding style issues Xiaofei Tan
2021-03-27  7:46 ` [PATCH v2 01/15] ACPI: APD: fix a block comment align issue Xiaofei Tan
2021-03-27  7:46 ` [PATCH v2 02/15] ACPI: processor: fix some coding style issues Xiaofei Tan
2021-03-27  7:46 ` [PATCH v2 03/15] ACPI: debug: " Xiaofei Tan
2021-03-27  7:46 ` [PATCH v2 04/15] ACPI: table: replace __attribute__((packed)) by __packed Xiaofei Tan
2021-03-29 10:09   ` David Laight
2021-03-30  2:23     ` Xiaofei Tan
2021-03-30  7:31       ` Zhang Rui
2021-03-30  7:59         ` Zhang Rui
2021-03-30  8:14           ` David Laight
2021-03-30 17:00             ` Rafael J. Wysocki
2021-03-31 15:55             ` Zhang Rui
2021-03-31 16:14               ` David Laight
2021-03-31 17:22               ` Bjorn Helgaas
2021-04-01  8:59                 ` David Laight
2021-04-01 13:49                   ` Rafael J. Wysocki
2021-04-01 14:23                     ` David Laight
2021-04-01 17:29                       ` Rafael J. Wysocki [this message]
2021-03-27  7:46 ` [PATCH v2 05/15] ACPI: ipmi: remove useless return statement for void function Xiaofei Tan
2021-03-27  7:46 ` [PATCH v2 06/15] ACPI: LPSS: fix some coding style issues Xiaofei Tan
     [not found]   ` <CAHp75Vc+0hxLS_Ab7_VZfrG2jiQzvia9S=o+Gc+wg+vVk1Z39w@mail.gmail.com>
2021-03-27  9:55     ` Xiaofei Tan
     [not found]   ` <CAHp75Vd0hVqsfsZK=d1dz98Kbchqz-w4RqQQp6FwisxSGG5BzA@mail.gmail.com>
2021-03-27  9:58     ` Xiaofei Tan
2021-03-27 13:39     ` Joe Perches
2021-03-27 16:39       ` Andy Shevchenko
2021-03-27  7:46 ` [PATCH v2 07/15] ACPI: memhotplug: fix a coding style issue Xiaofei Tan
2021-03-27  7:46 ` [PATCH v2 08/15] ACPI: acpi_pad: " Xiaofei Tan
2021-03-27  7:46 ` [PATCH v2 09/15] ACPI: battery: fix some coding style issues Xiaofei Tan
2021-03-27  7:46 ` [PATCH v2 10/15] ACPI: button: " Xiaofei Tan
2021-03-27  7:46 ` [PATCH v2 11/15] ACPI: CPPC: " Xiaofei Tan
2021-03-27  7:46 ` [PATCH v2 12/15] ACPI: custom_method: fix a coding style issue Xiaofei Tan
2021-03-27  7:46 ` [PATCH v2 13/15] ACPI: PM: fix some coding style issues Xiaofei Tan
2021-03-27  7:46 ` [PATCH v2 14/15] ACPI: sysfs: " Xiaofei Tan
2021-03-27  7:46 ` [PATCH v2 15/15] ACPI: dock: " Xiaofei Tan
     [not found] ` <CAHp75VcwuFYWRYfVPxbqa4TFGgqOhHc_soefmTAZcGGk3bLuhw@mail.gmail.com>
2021-03-27 10:00   ` [PATCH 00/15] acpi: " Xiaofei Tan

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='CAJZ5v0h0XMkrYYyOLd8bDcngxnei7VbAh=cYWA4Sy3qm2b69iQ@mail.gmail.com' \
    --to=rafael@kernel.org \
    --cc=David.Laight@aculab.com \
    --cc=bhelgaas@google.com \
    --cc=helgaas@kernel.org \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linuxarm@openeuler.org \
    --cc=rjw@rjwysocki.net \
    --cc=rui.zhang@intel.com \
    --cc=tanxiaofei@huawei.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).