From: "Radim Krčmář" <rkrcmar@redhat.com>
To: Borislav Petkov <bp@alien8.de>
Cc: Nadav Amit <namit@cs.technion.ac.il>,
Ingo Molnar <mingo@kernel.org>,
Paolo Bonzini <pbonzini@redhat.com>,
"H. Peter Anvin" <hpa@zytor.com>, Ingo Molnar <mingo@redhat.com>,
Thomas Gleixner <tglx@linutronix.de>,
the arch/x86 maintainers <x86@kernel.org>,
kvm <kvm@vger.kernel.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Linus Torvalds <torvalds@linux-foundation.org>,
Andrew Morton <akpm@linux-foundation.org>,
Peter Zijlstra <a.p.zijlstra@chello.nl>
Subject: Re: [RESEND PATCH 1/3] x86: Adding structs to reflect cpuid fields
Date: Thu, 18 Sep 2014 02:29:54 +0200 [thread overview]
Message-ID: <20140918002953.GA6918@potion.redhat.com> (raw)
In-Reply-To: <20140917152221.GF5358@nazgul.tnic>
2014-09-17 17:22+0200, Borislav Petkov:
> On Wed, Sep 17, 2014 at 05:04:33PM +0200, Radim Krčmář wrote:
> > which would result in a similar if-else hack
> >
> > if (family > X)
> > ebx.split.max_monitor_line_size_after_family_X = 0
> > else
> > ebx.split.max_monitor_line_size = 0
> >
> > other options are
> > ebx.split.after_family_X.max_monitor_line_size
> > or even
> > ebx.split.max_monitor_line_size.after_family_X
>
> And how is that better than simply doing
>
> cpuid = cpuid_ebx(5);
>
> if (family > X)
> max_monitor_line_size = cpuid & MASK_FAM_X;
> else
> max_monitor_line_size = cpuid & MASK_BEFORE_FAM_X;
>
> ?
>
> With proper variable naming all is perfectly clear, readable
> and simple. You don't need to open even the CPUID manual - the
> variable tells you you're getting the max monitor line size -
> "ebx.split.max_monitor_line_size_after_family_X" needs me to parse it
> with my eyes first.
I think you proposed to use magic constant in place of of MASK_FAM_X, so
the code above is
if (family > X)
max_monitor_line_size = cpuid & 0x1ffff;
else
max_monitor_line_size = cpuid & 0xffff;
We can nicely oneline it, but that's about all the benefits I can see.
It is prone to typos, hard to search for and limiting our operations to
a simple assignment to a properly named variable.
(I prefer descriptive, horribly long, names to raw constant everywhere,
MASK_MAX_MONITOR_LINE_SIZE_FAM_X.)
Second problem: Most elements don't begin at offset 0, so the usual
retrieval would add a shift, (repurposing max_monitor_line_size)
max_monitor_line_size = (cpuid & MASK_FAM_X) >> OFFSET_FAM_X;
and it's not better when we write it back after doing stuff.
cpuid = (cpuid & ~MASK_FAM_X) | (max_monitor_line_size << OFFSET_FAM_X
& MASK_FAM_X);
All would be fine if we abstracted this with more macros ... wait,
bitfield already does that!
max_monitor_line_size = cpuid.split.max_monitor_line_size_fam_x;
cpuid.split.max_monitor_line_size_fam_x = max_monitor_line_size;
---
OT: I'd remove '.split', but we probably wouldn't agree about '.full'.
next prev parent reply other threads:[~2014-09-18 0:29 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-16 12:22 [PATCH 0/3] x86: structs for cpuid info in x86 Nadav Amit
2014-09-16 12:22 ` [PATCH 1/3] x86: Adding structs to reflect cpuid fields Nadav Amit
2014-09-16 12:22 ` [PATCH 2/3] x86: Use new cpuid structs in cpuid functions Nadav Amit
2014-09-16 12:22 ` [PATCH 3/3] KVM: x86: Using cpuid structs in KVM Nadav Amit
2014-09-16 13:22 ` [PATCH 0/3] x86: structs for cpuid info in x86 Ingo Molnar
2014-09-16 20:19 ` Nadav Amit
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ář [this message]
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=20140918002953.GA6918@potion.redhat.com \
--to=rkrcmar@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.