2005-09-30 02:04:30

by Suresh Siddha

[permalink] [raw]
Subject: [Patch] x86, x86_64: fix cpu model for family 0x6

Andi, please pickup this patch and push to Andrew/Linus.

thanks,
suresh

--
According to cpuid instruction in IA32 SDM-Vol2, when computing cpu model,
we need to consider extended model ID for family 0x6 also.

Signed-off-by: Suresh Siddha <[email protected]>

--- linux-2.6.14-rc2-git7/arch/i386/kernel/cpu/common.c~ 2005-09-29 17:44:12.030688920 -0700
+++ linux-2.6.14-rc2-git7/arch/i386/kernel/cpu/common.c 2005-09-29 17:44:30.967810040 -0700
@@ -233,10 +233,10 @@ static void __init early_cpu_detect(void
cpuid(0x00000001, &tfms, &misc, &junk, &cap0);
c->x86 = (tfms >> 8) & 15;
c->x86_model = (tfms >> 4) & 15;
- if (c->x86 == 0xf) {
+ if (c->x86 == 0xf)
c->x86 += (tfms >> 20) & 0xff;
+ if (c->x86 == 0x6 || c->x86 == 0xf)
c->x86_model += ((tfms >> 16) & 0xF) << 4;
- }
c->x86_mask = tfms & 15;
if (cap0 & (1<<19))
c->x86_cache_alignment = ((misc >> 8) & 0xff) * 8;
--- linux-2.6.14-rc2-git7/arch/x86_64/kernel/setup.c~ 2005-09-29 18:05:26.503939536 -0700
+++ linux-2.6.14-rc2-git7/arch/x86_64/kernel/setup.c 2005-09-29 18:06:42.318413984 -0700
@@ -1059,10 +1059,10 @@ void __cpuinit early_identify_cpu(struct
c->x86 = (tfms >> 8) & 0xf;
c->x86_model = (tfms >> 4) & 0xf;
c->x86_mask = tfms & 0xf;
- if (c->x86 == 0xf) {
+ if (c->x86 == 0xf)
c->x86 += (tfms >> 20) & 0xff;
+ if (c->x86 == 0x6 || c->x86 == 0xf)
c->x86_model += ((tfms >> 16) & 0xF) << 4;
- }
if (c->x86_capability[0] & (1<<19))
c->x86_clflush_size = ((misc >> 8) & 0xff) * 8;
} else {


2005-09-30 08:11:09

by Andi Kleen

[permalink] [raw]
Subject: Re: [Patch] x86, x86_64: fix cpu model for family 0x6

On Friday 30 September 2005 04:04, Siddha, Suresh B wrote:

> According to cpuid instruction in IA32 SDM-Vol2, when computing cpu model,
> we need to consider extended model ID for family 0x6 also.

I'm confused. Is there any 64bit capable CPU with family == 6?

-Andi

2005-09-30 13:09:48

by Petr Vandrovec

[permalink] [raw]
Subject: Re: [Patch] x86, x86_64: fix cpu model for family 0x6

Siddha, Suresh B wrote:
> Andi, please pickup this patch and push to Andrew/Linus.
>
> thanks,
> suresh
>
> --
> According to cpuid instruction in IA32 SDM-Vol2, when computing cpu model,
> we need to consider extended model ID for family 0x6 also.
>
> Signed-off-by: Suresh Siddha <[email protected]>
>
> --- linux-2.6.14-rc2-git7/arch/i386/kernel/cpu/common.c~ 2005-09-29 17:44:12.030688920 -0700
> +++ linux-2.6.14-rc2-git7/arch/i386/kernel/cpu/common.c 2005-09-29 17:44:30.967810040 -0700
> @@ -233,10 +233,10 @@ static void __init early_cpu_detect(void
> cpuid(0x00000001, &tfms, &misc, &junk, &cap0);
> c->x86 = (tfms >> 8) & 15;
> c->x86_model = (tfms >> 4) & 15;
> - if (c->x86 == 0xf) {
> + if (c->x86 == 0xf)
> c->x86 += (tfms >> 20) & 0xff;
> + if (c->x86 == 0x6 || c->x86 == 0xf)

Are you sure this is correct? You just incremented c->x86 by extended
family, so I believe test should be

if (c->x86 == 0x6 || c->x86 >= 0xf)

or maybe just

if (c->x86 >= 0x6)

as chips with family 7..14 will either never appear, or they'll follow
existing rules (I believe all chips ever built return upper bits of tfms
zeroed, so maybe we could get rid of all these 'if' completely).
Petr Vandrovec

2005-09-30 18:23:29

by Suresh Siddha

[permalink] [raw]
Subject: Re: [Patch] x86, x86_64: fix cpu model for family 0x6

On Fri, Sep 30, 2005 at 03:09:46PM +0200, Petr Vandrovec wrote:
> Siddha, Suresh B wrote:
> > - if (c->x86 == 0xf) {
> > + if (c->x86 == 0xf)
> > c->x86 += (tfms >> 20) & 0xff;
> > + if (c->x86 == 0x6 || c->x86 == 0xf)
>
> Are you sure this is correct? You just incremented c->x86 by extended
> family, so I believe test should be
>
> if (c->x86 == 0x6 || c->x86 >= 0xf)

My bad. Your suggestion might work. But let me just follow what SDM Vol-2a
says here. New patch appended.

Andi, please apply.

thanks,
suresh

--

According to cpuid instruction in IA32 SDM-Vol2, when computing cpu model,
we need to consider extended model ID for family 0x6 also.

Signed-off-by: Suresh Siddha <[email protected]>

--- linux-2.6.14-rc2-git7/arch/x86_64/kernel/setup.c~ 2005-09-29 18:05:26.503939536 -0700
+++ linux-2.6.14-rc2-git7/arch/x86_64/kernel/setup.c 2005-09-30 10:17:37.964209680 -0700
@@ -1059,10 +1059,10 @@ void __cpuinit early_identify_cpu(struct
c->x86 = (tfms >> 8) & 0xf;
c->x86_model = (tfms >> 4) & 0xf;
c->x86_mask = tfms & 0xf;
- if (c->x86 == 0xf) {
- c->x86 += (tfms >> 20) & 0xff;
+ if (c->x86 == 0x6 || c->x86 == 0xf)
c->x86_model += ((tfms >> 16) & 0xF) << 4;
- }
+ if (c->x86 == 0xf)
+ c->x86 += (tfms >> 20) & 0xff;
if (c->x86_capability[0] & (1<<19))
c->x86_clflush_size = ((misc >> 8) & 0xff) * 8;
} else {
--- linux-2.6.14-rc2-git7/arch/x86_64/kernel/setup.c~ 2005-09-29 18:05:26.503939536 -0700
+++ linux-2.6.14-rc2-git7/arch/x86_64/kernel/setup.c 2005-09-30 10:17:37.964209680 -0700
@@ -1059,10 +1059,10 @@ void __cpuinit early_identify_cpu(struct
c->x86 = (tfms >> 8) & 0xf;
c->x86_model = (tfms >> 4) & 0xf;
c->x86_mask = tfms & 0xf;
- if (c->x86 == 0xf) {
- c->x86 += (tfms >> 20) & 0xff;
+ if (c->x86 == 0x6 || c->x86 == 0xf)
c->x86_model += ((tfms >> 16) & 0xF) << 4;
- }
+ if (c->x86 == 0xf)
+ c->x86 += (tfms >> 20) & 0xff;
if (c->x86_capability[0] & (1<<19))
c->x86_clflush_size = ((misc >> 8) & 0xff) * 8;
} else {

2005-09-30 22:24:21

by Suresh Siddha

[permalink] [raw]
Subject: Re: [Patch] x86, x86_64: fix cpu model for family 0x6

On Sat, Oct 01, 2005 at 12:02:16AM +0200, Andi Kleen wrote:
> I applied an earlier mix of your original one and Petr's suggestions. Hope
> it's ok.

Andi I prefer to follow the SDM guidelines. Who knows if future families
comeup with a different rule or use/initialize these extended model/family
bits differently. I am just being paranoid.

> + if (c->x86 >= 0xf)

And also you have a typo. It should be 0x6.

Anyhow, I prefer my second patch.

thanks,
suresh

2005-09-30 22:57:08

by Dave Jones

[permalink] [raw]
Subject: Re: [Patch] x86, x86_64: fix cpu model for family 0x6

On Sat, Oct 01, 2005 at 12:37:39AM +0200, Petr Vandrovec wrote:
> Siddha, Suresh B wrote:
> >On Sat, Oct 01, 2005 at 12:02:16AM +0200, Andi Kleen wrote:
> >
> >>I applied an earlier mix of your original one and Petr's suggestions.
> >>Hope it's ok.
> >
> >
> >Andi I prefer to follow the SDM guidelines. Who knows if future families
> >comeup with a different rule or use/initialize these extended model/family
> >bits differently. I am just being paranoid.
>
> And which chance is bigger - that such hypothetical processor will use
> extended model, and your code will get incorrect answer everywhere, or
> that such hypothetical processor will not use extended model, and your
> code will be right?
>
> >>+ if (c->x86 >= 0xf)
> >
> >
> >And also you have a typo. It should be 0x6.
>
> It is intentional. Maybe it could do BUG_ON(c->x86 < 0xf).

<complete speculation> Pentium M is family 6, so maybe this is
an indication we'll see em64t capable P-M's soon ? :)

Dave

2005-10-01 01:37:42

by Suresh Siddha

[permalink] [raw]
Subject: Re: [Patch] x86, x86_64: fix cpu model for family 0x6

On Sat, Oct 01, 2005 at 12:46:48AM +0200, Andi Kleen wrote:
> On Saturday 01 October 2005 00:23, Siddha, Suresh B wrote:
>
> > And also you have a typo. It should be 0x6.
>
> Fixed.

Thanks. Lets go ahead with Petrs suggestion then.

2005-09-30 22:02:10

by Andi Kleen

[permalink] [raw]
Subject: Re: [Patch] x86, x86_64: fix cpu model for family 0x6

On Friday 30 September 2005 20:23, Siddha, Suresh B wrote:
> On Fri, Sep 30, 2005 at 03:09:46PM +0200, Petr Vandrovec wrote:
> > Siddha, Suresh B wrote:
> > > - if (c->x86 == 0xf) {
> > > + if (c->x86 == 0xf)
> > > c->x86 += (tfms >> 20) & 0xff;
> > > + if (c->x86 == 0x6 || c->x86 == 0xf)
> >
> > Are you sure this is correct? You just incremented c->x86 by extended
> > family, so I believe test should be
> >
> > if (c->x86 == 0x6 || c->x86 >= 0xf)
>
> My bad. Your suggestion might work. But let me just follow what SDM Vol-2a
> says here. New patch appended.
>
> Andi, please apply.
I applied an earlier mix of your original one and Petr's suggestions. Hope
it's ok.

x86-64/i386: Fix CPU model for family 6

From: Suresh Siddha <[email protected]>

According to cpuid instruction in IA32 SDM-Vol2, when computing cpu model,
we need to consider extended model ID for family 0x6 also.

AK: Also added fixes/simplifcation from Petr Vandrovec

Signed-off-by: Suresh Siddha <[email protected]>
Signed-off-by: Andi Kleen <[email protected]>

Index: linux/arch/i386/kernel/cpu/common.c
===================================================================
--- linux.orig/arch/i386/kernel/cpu/common.c
+++ linux/arch/i386/kernel/cpu/common.c
@@ -233,10 +233,10 @@ static void __init early_cpu_detect(void
cpuid(0x00000001, &tfms, &misc, &junk, &cap0);
c->x86 = (tfms >> 8) & 15;
c->x86_model = (tfms >> 4) & 15;
- if (c->x86 == 0xf) {
+ if (c->x86 == 0xf)
c->x86 += (tfms >> 20) & 0xff;
+ if (c->x86 >= 0x6)
c->x86_model += ((tfms >> 16) & 0xF) << 4;
- }
c->x86_mask = tfms & 15;
if (cap0 & (1<<19))
c->x86_cache_alignment = ((misc >> 8) & 0xff) * 8;
Index: linux/arch/x86_64/kernel/setup.c
===================================================================
--- linux.orig/arch/x86_64/kernel/setup.c
+++ linux/arch/x86_64/kernel/setup.c
@@ -1059,10 +1059,10 @@ void __cpuinit early_identify_cpu(struct
c->x86 = (tfms >> 8) & 0xf;
c->x86_model = (tfms >> 4) & 0xf;
c->x86_mask = tfms & 0xf;
- if (c->x86 == 0xf) {
+ if (c->x86 == 0xf)
c->x86 += (tfms >> 20) & 0xff;
+ if (c->x86 >= 0xf)
c->x86_model += ((tfms >> 16) & 0xF) << 4;
- }
if (c->x86_capability[0] & (1<<19))
c->x86_clflush_size = ((misc >> 8) & 0xff) * 8;
} else {

2005-09-30 22:37:41

by Petr Vandrovec

[permalink] [raw]
Subject: Re: [Patch] x86, x86_64: fix cpu model for family 0x6

Siddha, Suresh B wrote:
> On Sat, Oct 01, 2005 at 12:02:16AM +0200, Andi Kleen wrote:
>
>>I applied an earlier mix of your original one and Petr's suggestions. Hope
>>it's ok.
>
>
> Andi I prefer to follow the SDM guidelines. Who knows if future families
> comeup with a different rule or use/initialize these extended model/family
> bits differently. I am just being paranoid.

And which chance is bigger - that such hypothetical processor will use
extended model, and your code will get incorrect answer everywhere, or
that such hypothetical processor will not use extended model, and your
code will be right?

>>+ if (c->x86 >= 0xf)
>
>
> And also you have a typo. It should be 0x6.

It is intentional. Maybe it could do BUG_ON(c->x86 < 0xf).
Petr

2005-09-30 22:46:35

by Andi Kleen

[permalink] [raw]
Subject: Re: [Patch] x86, x86_64: fix cpu model for family 0x6

On Saturday 01 October 2005 00:23, Siddha, Suresh B wrote:

> And also you have a typo. It should be 0x6.

Fixed.

> Anyhow, I prefer my second patch.

It doesn't even apply - you patched x86_64/kernel/setup.c twice.

-Andi