From: Nadav Amit <nadav.amit@gmail.com>
To: Ingo Molnar <mingo@kernel.org>, Nadav Amit <namit@cs.technion.ac.il>
Cc: pbonzini@redhat.com, hpa@zytor.com, mingo@redhat.com,
tglx@linutronix.de, x86@kernel.org, kvm@vger.kernel.org,
linux-kernel@vger.kernel.org,
Linus Torvalds <torvalds@linux-foundation.org>,
Andrew Morton <akpm@linux-foundation.org>,
Peter Zijlstra <a.p.zijlstra@chello.nl>,
Borislav Petkov <bp@alien8.de>
Subject: Re: [PATCH 0/3] x86: structs for cpuid info in x86
Date: Tue, 16 Sep 2014 23:19:09 +0300 [thread overview]
Message-ID: <54189B3D.3040301@gmail.com> (raw)
In-Reply-To: <20140916132226.GA13726@gmail.com>
On 9/16/14 4:22 PM, Ingo Molnar wrote:
>
> * Nadav Amit <namit@cs.technion.ac.il> wrote:
>
>> The code that deals with x86 cpuid fields is hard to follow since it performs
>> many bit operations and does not refer to cpuid field explicitly. To
>> eliminate the need of openning a spec whenever dealing with cpuid fields, this
>> patch-set introduces structs that reflect the various cpuid functions.
>>
>> Thanks for reviewing the patch-set.
>>
>> Nadav Amit (3):
>> x86: Adding structs to reflect cpuid fields
>> x86: Use new cpuid structs in cpuid functions
>> KVM: x86: Using cpuid structs in KVM
>>
>> arch/x86/include/asm/cpuid_def.h | 163 +++++++++++++++++++++++++++++++++++++++
>> arch/x86/kernel/cpu/common.c | 56 ++++++++------
>> arch/x86/kvm/cpuid.c | 36 +++++----
>> 3 files changed, 219 insertions(+), 36 deletions(-)
>> create mode 100644 arch/x86/include/asm/cpuid_def.h
>
> I personally like bitfields in theory (they provide type clarity
> and abstract robustness, compared to open-coded bitmask numeric
> literals that are often used in cpuid using code, obfuscating
> cpuid usage), with the big caveat that for many years I didn't
> like bitfields in practice: older versions of GCC did a really
> poor job of optimizing them.
>
> So such a series would only be acceptable if it's demonstrated
> that both 'latest' and 'reasonably old' GCC versions do a good
> job in that department, compared to the old open-coded bitmask
> ops ...
>
> Comparing the 'size vmlinux' output of before/after kernels would
> probably be a good start in seeing the impact of such a change.
>
> If those results are positive then this technique could be
> propagated to all cpuid using code in arch/x86/, of which
> there's plenty.
Thanks for the quick response. I was not aware GCC behaves this way. I
made some small experiments with GCC-4.8 and GCC-4.4 and in brief my
conclusions are:
1. The assembled code of bitmask and bitfields is indeed different.
2. GCC-4.8 and GCC-4.4 behave pretty much the same, yet GCC-4.8 appears
to make better instructions reordering.
3. Loading/storing a single bitfield seems to be pretty much optimized
(marginal advantage from code size point-of-view for bitmask, same
number of instructions).
4. Loading/storing multiple bitfields seems to be somewhat
under-optimized - multiple accesses to the original value result in ~30%
more instructions and code-size.
So you are correct - bitfields are less optimized. Nonetheless, since
cpuid data is mostly used during startup, and otherwise a single
bitfield is usually accessed in each function - I wonder whether it
worth keeping the optimized but "obfuscate" code. Obviously, I can guess
your answer to this question...
Nadav
next prev parent reply other threads:[~2014-09-16 20:19 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1410870160-28845-1-git-send-email-namit@cs.technion.ac.il>
2014-09-16 13:22 ` [PATCH 0/3] x86: structs for cpuid info in x86 Ingo Molnar
2014-09-16 20:19 ` Nadav Amit [this message]
2014-09-17 12:37 ` Ingo Molnar
2014-09-17 12:45 ` Borislav Petkov
2014-09-17 12:54 ` [RESEND PATCH " Nadav Amit
2014-09-17 12:54 ` [RESEND PATCH 1/3] x86: Adding structs to reflect cpuid fields Nadav Amit
2014-09-17 13:21 ` Borislav Petkov
2014-09-17 13:53 ` Nadav Amit
2014-09-17 14:06 ` Borislav Petkov
2014-09-17 15:04 ` Radim Krčmář
2014-09-17 15:22 ` Borislav Petkov
2014-09-18 0:29 ` Radim Krčmář
2014-09-18 7:19 ` Borislav Petkov
2014-09-18 10:00 ` Radim Krčmář
2014-09-18 13:06 ` Paolo Bonzini
2014-09-18 13:26 ` Borislav Petkov
2014-09-18 13:36 ` Paolo Bonzini
2014-09-19 7:58 ` Borislav Petkov
2014-09-19 8:59 ` Nadav Amit
2014-09-19 10:32 ` Borislav Petkov
2014-09-19 13:40 ` Paolo Bonzini
2014-09-19 14:44 ` Borislav Petkov
2014-09-17 14:10 ` Peter Zijlstra
2014-09-17 12:54 ` [RESEND PATCH 2/3] x86: Use new cpuid structs in cpuid functions Nadav Amit
2014-09-17 12:54 ` [RESEND PATCH 3/3] KVM: x86: Using cpuid structs in KVM Nadav Amit
2014-09-17 14:12 ` [PATCH 0/3] x86: structs for cpuid info in x86 Peter Zijlstra
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=54189B3D.3040301@gmail.com \
--to=nadav.amit@gmail.com \
--cc=a.p.zijlstra@chello.nl \
--cc=akpm@linux-foundation.org \
--cc=bp@alien8.de \
--cc=hpa@zytor.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=mingo@redhat.com \
--cc=namit@cs.technion.ac.il \
--cc=pbonzini@redhat.com \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
--cc=x86@kernel.org \
/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).