From: ebiederm@xmission.com (Eric W. Biederman)
To: Kay Sievers <kay@vrfy.org>
Cc: Vivek Goyal <vgoyal@redhat.com>,
linux kernel mailing list <linux-kernel@vger.kernel.org>,
Kexec Mailing List <kexec@lists.infradead.org>,
Andrew Morton <akpm@linux-foundation.org>,
Greg Kroah-Hartmann <gregkh@linuxfoundation.org>
Subject: Re: [PATCH] printk: Export struct log size and member offsets through vmcoreinfo
Date: Fri, 20 Jul 2012 02:50:15 -0700 [thread overview]
Message-ID: <87bojasqw8.fsf@xmission.com> (raw)
In-Reply-To: <CAPXgP13W_aqky++LkHeHBUzKFTYNiTJQpchpHLCVDAdYihu5ig@mail.gmail.com> (Kay Sievers's message of "Fri, 20 Jul 2012 11:23:10 +0200")
Kay Sievers <kay@vrfy.org> writes:
> On Thu, Jul 19, 2012 at 4:08 PM, Vivek Goyal <vgoyal@redhat.com> wrote:
>> On Thu, Jul 19, 2012 at 09:57:36AM -0400, Vivek Goyal wrote:
>>> On Thu, Jul 19, 2012 at 11:38:57AM +0200, Kay Sievers wrote:
>
>>> > If we would swap the 5 + 3 bit field byte declaration, and add
>>> > __packed, we can still not rely on the level to be consistently the
>>> > lower 3 bits of the byte, right?
>>
>> I think I missed your point in last response. Are you saying that retain
>> bit fields for flags and level, and add __packed() and that will make sure
>> level bits are always lowest 3bits?
>
> It was more a question, I don't know how reliable that would be.
>
>> I am really not sure how that is going
>> to work. Also if you want to add more fields to struct log down the line,
>> it will be a problem to determine the offset of byte where level bits are
>> stored.
>
> I guess, we could make sure that it's always the lowest 3 bits of a
> byte. But the question if that is safe to do at all still remains. :)
Using bit fields in interfaces is probably not a good idea in practice.
The order of the bits is constrained by whatever your C ABI is. However
the C abi can choose different orders on different architectures.
So if my memory is correct you can not use bitfields portably to choose
the low 3 bits of a byte, without a lot of #ifdef LITTLE_ENDIAN_BIT_FIELD
and the like.
So as general advice bitfields are good for saving space for purely
internal structures (if your compiler generates good code for them)
but for interfacing with other code or hardware you don't want to use
them. Too much complexity for too little gain.
If bitfields were easily portable the kernel would be full of them as
they would make talking with hardware control registers much easier.
Eric
prev parent reply other threads:[~2012-07-20 9:50 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-18 17:18 [PATCH] printk: Export struct log size and member offsets through vmcoreinfo Vivek Goyal
2012-07-18 17:27 ` Kay Sievers
2012-07-18 17:56 ` Vivek Goyal
2012-07-19 9:38 ` Kay Sievers
2012-07-19 13:57 ` Vivek Goyal
2012-07-19 14:08 ` Vivek Goyal
2012-07-20 9:23 ` Kay Sievers
2012-07-20 9:50 ` Eric W. Biederman [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=87bojasqw8.fsf@xmission.com \
--to=ebiederm@xmission.com \
--cc=akpm@linux-foundation.org \
--cc=gregkh@linuxfoundation.org \
--cc=kay@vrfy.org \
--cc=kexec@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=vgoyal@redhat.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).