public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: "H. Peter Anvin" <hpa@zytor.com>
To: Linus Torvalds <torvalds@linux-foundation.org>,
	David Miller <davem@davemloft.net>
Cc: ast@plumgrid.com, dborkman@redhat.com,
	"Ingo Molnar" <mingo@kernel.org>,
	"Will Drewry" <wad@chromium.org>,
	"Steven Rostedt" <rostedt@goodmis.org>,
	"Peter Zijlstra" <a.p.zijlstra@chello.nl>,
	"Hagen Paul Pfeifer" <hagen@jauu.net>,
	"Jesse Gross" <jesse@nicira.com>,
	"Thomas Gleixner" <tglx@linutronix.de>,
	"Eric Dumazet" <edumazet@google.com>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	"Frédéric Weisbecker" <fweisbec@gmail.com>,
	"Arnaldo Carvalho de Melo" <acme@infradead.org>,
	penberg@iki.fi, "Arjan van de Ven" <arjan@infradead.org>,
	"Christoph Hellwig" <hch@infradead.org>,
	"Pavel Emelyanov" <xemul@parallels.com>,
	"Linux Kernel Mailing List" <linux-kernel@vger.kernel.org>,
	"Network Development" <netdev@vger.kernel.org>
Subject: Re: [PATCH v8 net-next 1/3] filter: add Extended BPF interpreter and converter
Date: Mon, 10 Mar 2014 19:20:52 -0700	[thread overview]
Message-ID: <9b7e4f89-468b-4d02-91ea-3e91d61934bd@email.android.com> (raw)
In-Reply-To: <CA+55aFx7rdm9DGOTTgAKTHNkdfrvQYhT9PRs5MhUPr1gQzWEgA@mail.gmail.com>

Bool vs bitfield are orthogonal, at least under gcc, unless I'm completely out to sea.  It is probably not a good idea to create a bitfield when it doesn't buy you anything, lest you generate rmw instructions when byte stores would do.

On March 10, 2014 7:02:18 PM PDT, Linus Torvalds <torvalds@linux-foundation.org> wrote:
>On Mon, Mar 10, 2014 at 6:51 PM, David Miller <davem@davemloft.net>
>wrote:
>> From: Alexei Starovoitov <ast@plumgrid.com>
>> Date: Sun,  9 Mar 2014 23:04:02 -0700
>>
>>> +     unsigned int            jited:1;
>>
>> The C language has a proper type for boolean states, please therefore
>> use 'bool', true, and false.
>
>No, the C standard actually has no such thing.
>
>In a structure, a bitfield is actually better than bool, because it
>takes only one bit. A "bool" takes at least a byte.
>
>Now, in this case it may not be an issue (looks like there are no
>other uses that can use the better packing, so bit/byte/word is all
>the same), but I really really want to make it clear that it is not at
>all true that "bool" is somehow better than a single-bit bitfield. The
>bitfield can pack *much* better, and I would actually say that it's
>generally a *better* idea to use a bitfield, because you can much more
>easily expand on it later by adding other bitfields.
>
>There are very few actual real advantages to "bool". The magic casting
>behavior is arguably an advantage (the implicit cast in assigning to a
>bitfield truncates to the low bits, the implicit cast on assignment to
>"bool" does a test against zero), but is also quite arguably a
>possible source of confusion and can cause problems down the line when
>converting from bool to a bitfield (for the afore-mentioned packing
>reasons).
>
>So please don't sell "bool" as some kind of panacea. It has at least
>as many problems as it has advantages.
>
>I would generally suggest that people only use "bool" for function
>return types, and absolutely nothing else. Seriously.
>
>              Linus

-- 
Sent from my mobile phone.  Please pardon brevity and lack of formatting.

  parent reply	other threads:[~2014-03-11  2:20 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-10  6:04 [PATCH v8 net-next 0/3] filter: add Extended BPF interpreter and converter, seccomp Alexei Starovoitov
2014-03-10  6:04 ` [PATCH v8 net-next 1/3] filter: add Extended BPF interpreter and converter Alexei Starovoitov
2014-03-11  1:51   ` David Miller
2014-03-11  2:02     ` Linus Torvalds
2014-03-11  2:05       ` Linus Torvalds
2014-03-11  2:20       ` H. Peter Anvin [this message]
2014-03-11  2:57         ` Alexei Starovoitov
2014-03-11  2:24       ` David Miller
2014-03-11  2:33         ` H. Peter Anvin
2014-03-11  2:39           ` David Miller
2014-03-11  3:05           ` Linus Torvalds
2014-03-11  9:51         ` David Laight
2014-03-11  3:02       ` Joe Perches
2014-03-10  6:04 ` [PATCH v8 net-next 2/3] seccomp: convert seccomp to use extended BPF Alexei Starovoitov
2014-03-10  6:04 ` [PATCH v8 net-next 3/3] doc: filter: add Extended BPF documentation Alexei Starovoitov

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=9b7e4f89-468b-4d02-91ea-3e91d61934bd@email.android.com \
    --to=hpa@zytor.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@infradead.org \
    --cc=akpm@linux-foundation.org \
    --cc=arjan@infradead.org \
    --cc=ast@plumgrid.com \
    --cc=davem@davemloft.net \
    --cc=dborkman@redhat.com \
    --cc=edumazet@google.com \
    --cc=fweisbec@gmail.com \
    --cc=hagen@jauu.net \
    --cc=hch@infradead.org \
    --cc=jesse@nicira.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=penberg@iki.fi \
    --cc=rostedt@goodmis.org \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    --cc=wad@chromium.org \
    --cc=xemul@parallels.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