From: Nadav Amit <namit@cs.technion.ac.il>
To: bp@alien8.de
Cc: mingo@kernel.org, nadav.amit@gmail.com, pbonzini@redhat.com,
hpa@zytor.com, mingo@redhat.com, tglx@linutronix.de,
x86@kernel.org, kvm@vger.kernel.org,
linux-kernel@vger.kernel.org, torvalds@linux-foundation.org,
akpm@linux-foundation.org, a.p.zijlstra@chello.nl,
Nadav Amit <namit@cs.technion.ac.il>
Subject: [RESEND PATCH 2/3] x86: Use new cpuid structs in cpuid functions
Date: Wed, 17 Sep 2014 15:54:13 +0300 [thread overview]
Message-ID: <1410958454-7501-3-git-send-email-namit@cs.technion.ac.il> (raw)
In-Reply-To: <1410958454-7501-1-git-send-email-namit@cs.technion.ac.il>
The current code that decodes cpuid fields is somewhat cryptic, since it uses
many bit operations. Using cpuid structs instead for clarifying the code.
Introducign no functional change.
Signed-off-by: Nadav Amit <namit@cs.technion.ac.il>
---
arch/x86/kernel/cpu/common.c | 56 +++++++++++++++++++++++++++-----------------
1 file changed, 34 insertions(+), 22 deletions(-)
diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
index e4ab2b4..b57c160 100644
--- a/arch/x86/kernel/cpu/common.c
+++ b/arch/x86/kernel/cpu/common.c
@@ -41,6 +41,7 @@
#include <asm/pat.h>
#include <asm/microcode.h>
#include <asm/microcode_intel.h>
+#include <asm/cpuid_def.h>
#ifdef CONFIG_X86_LOCAL_APIC
#include <asm/uv/uv.h>
@@ -444,13 +445,17 @@ static void get_model_name(struct cpuinfo_x86 *c)
void cpu_detect_cache_sizes(struct cpuinfo_x86 *c)
{
- unsigned int n, dummy, ebx, ecx, edx, l2size;
+ unsigned int n, dummy, dummy2, l2size;
+ union cpuid8_5_ecx_edx ecx5, edx5;
+ union cpuid8_6_ebx ebx6;
+ union cpuid8_6_ecx ecx6;
n = c->extended_cpuid_level;
if (n >= 0x80000005) {
- cpuid(0x80000005, &dummy, &ebx, &ecx, &edx);
- c->x86_cache_size = (ecx>>24) + (edx>>24);
+ cpuid(0x80000005, &dummy, &dummy2, &ecx5.full, &edx5.full);
+ c->x86_cache_size = ecx5.split.cache_size +
+ edx5.split.cache_size;
#ifdef CONFIG_X86_64
/* On K8 L1 TLB is inclusive, so don't count it */
c->x86_tlbsize = 0;
@@ -460,11 +465,11 @@ void cpu_detect_cache_sizes(struct cpuinfo_x86 *c)
if (n < 0x80000006) /* Some chips just has a large L1. */
return;
- cpuid(0x80000006, &dummy, &ebx, &ecx, &edx);
- l2size = ecx >> 16;
+ cpuid(0x80000006, &dummy, &ebx6.full, &ecx6.full, &dummy2);
+ l2size = ecx6.split.cache_size;
#ifdef CONFIG_X86_64
- c->x86_tlbsize += ((ebx >> 16) & 0xfff) + (ebx & 0xfff);
+ c->x86_tlbsize += ebx6.split.dtlb_entries + ebx6.split.itlb_entries;
#else
/* do processor-specific cache resizing */
if (this_cpu->legacy_cache_size)
@@ -505,9 +510,10 @@ void cpu_detect_tlb(struct cpuinfo_x86 *c)
void detect_ht(struct cpuinfo_x86 *c)
{
#ifdef CONFIG_X86_HT
- u32 eax, ebx, ecx, edx;
+ u32 eax, ecx, edx;
int index_msb, core_bits;
static bool printed;
+ union cpuid1_ebx ebx;
if (!cpu_has(c, X86_FEATURE_HT))
return;
@@ -518,9 +524,9 @@ void detect_ht(struct cpuinfo_x86 *c)
if (cpu_has(c, X86_FEATURE_XTOPOLOGY))
return;
- cpuid(1, &eax, &ebx, &ecx, &edx);
+ cpuid(1, &eax, &ebx.full, &ecx, &edx);
- smp_num_siblings = (ebx & 0xff0000) >> 16;
+ smp_num_siblings = ebx.split.max_logical_proc;
if (smp_num_siblings == 1) {
printk_once(KERN_INFO "CPU0: Hyper-Threading is disabled\n");
@@ -591,20 +597,22 @@ void cpu_detect(struct cpuinfo_x86 *c)
c->x86 = 4;
/* Intel-defined flags: level 0x00000001 */
if (c->cpuid_level >= 0x00000001) {
- u32 junk, tfms, cap0, misc;
+ u32 junk, cap0;
+ union cpuid1_eax tfms;
+ union cpuid1_ebx misc;
- cpuid(0x00000001, &tfms, &misc, &junk, &cap0);
- c->x86 = (tfms >> 8) & 0xf;
- c->x86_model = (tfms >> 4) & 0xf;
- c->x86_mask = tfms & 0xf;
+ cpuid(0x00000001, &tfms.full, &misc.full, &junk, &cap0);
+ c->x86 = tfms.split.family_id;
+ c->x86_model = tfms.split.model;
+ c->x86_mask = tfms.split.stepping_id;
if (c->x86 == 0xf)
- c->x86 += (tfms >> 20) & 0xff;
+ c->x86 += tfms.split.extended_family_id;
if (c->x86 >= 0x6)
- c->x86_model += ((tfms >> 16) & 0xf) << 4;
+ c->x86_model += tfms.split.extended_model_id << 4;
- if (cap0 & (1<<19)) {
- c->x86_clflush_size = ((misc >> 8) & 0xff) * 8;
+ if (cap0 & (1 << (X86_FEATURE_CLFLUSH & 31))) {
+ c->x86_clflush_size = misc.split.clflush_size * 8;
c->x86_cache_alignment = c->x86_clflush_size;
}
}
@@ -654,10 +662,11 @@ void get_cpu_cap(struct cpuinfo_x86 *c)
}
if (c->extended_cpuid_level >= 0x80000008) {
- u32 eax = cpuid_eax(0x80000008);
+ union cpuid_8_8_eax eax;
- c->x86_virt_bits = (eax >> 8) & 0xff;
- c->x86_phys_bits = eax & 0xff;
+ eax.full = cpuid_eax(0x80000008);
+ c->x86_virt_bits = eax.split.virt_as;
+ c->x86_phys_bits = eax.split.phys_as;
}
#ifdef CONFIG_X86_32
else if (cpu_has(c, X86_FEATURE_PAE) || cpu_has(c, X86_FEATURE_PSE36))
@@ -814,7 +823,10 @@ static void generic_identify(struct cpuinfo_x86 *c)
get_cpu_cap(c);
if (c->cpuid_level >= 0x00000001) {
- c->initial_apicid = (cpuid_ebx(1) >> 24) & 0xFF;
+ union cpuid1_ebx ebx;
+
+ ebx.full = cpuid_ebx(1);
+ c->initial_apicid = ebx.split.initial_apicid;
#ifdef CONFIG_X86_32
# ifdef CONFIG_X86_HT
c->apicid = apic->phys_pkg_id(c->initial_apicid, 0);
--
1.9.1
next prev parent reply other threads:[~2014-09-17 12:54 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
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 ` Nadav Amit [this message]
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=1410958454-7501-3-git-send-email-namit@cs.technion.ac.il \
--to=namit@cs.technion.ac.il \
--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=nadav.amit@gmail.com \
--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).