Thread overview
[Issue 5612] New: core.cpuid broken on 64
Feb 19, 2011
David Simcha
Feb 19, 2011
Russel Winder
Feb 19, 2011
Don
[Issue 5612] core.cpuid not implemented on 64
Feb 19, 2011
David Simcha
Feb 20, 2011
Russel Winder
Feb 20, 2011
Brad Roberts
Feb 20, 2011
Don
Feb 27, 2011
Russel Winder
Feb 27, 2011
Don
Apr 13, 2011
Don
February 19, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5612

           Summary: core.cpuid broken on 64
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: druntime
        AssignedTo: nobody@puremagic.com
        ReportedBy: dsimcha@yahoo.com


--- Comment #0 from David Simcha <dsimcha@yahoo.com> 2011-02-19 07:50:18 PST ---
core.cpuid reports wrong information on 64-bit even were it is correct on 32. In addition to my hardware below, I also have some reports of it not working on other hardware.

Test program (test.d):

import core.cpuid, std.stdio;

void main() {
    writeln(coresPerCPU);
}

Results:

dsimcha@palmetto:~$ dmd -m64 test.d && ./test
1
dsimcha@palmetto:~$ dmd -m32 test.d && ./test
2

cat /proc/cpuinfo on the relevant machine:

dsimcha@palmetto:~$ cat /proc/cpuinfo
processor    : 0
vendor_id    : AuthenticAMD
cpu family    : 15
model        : 107
model name    : AMD Athlon(tm) 64 X2 Dual Core Processor 3600+
stepping    : 1
cpu MHz        : 2706.089
cache size    : 512 KB
fpu        : yes
fpu_exception    : yes
cpuid level    : 1
wp        : yes
flags        : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov
pat pse36 clflush mmx fxsr sse sse2 syscall nx mmxext fxsr_opt rdtscp lm
3dnowext 3dnow constant_tsc rep_good tsc_reliable pni cx16 hypervisor lahf_lm
extapic 3dnowprefetch
bogomips    : 5396.42
TLB size    : 1024 4K pages
clflush size    : 64
cache_alignment    : 64
address sizes    : 40 bits physical, 48 bits virtual
power management: ts fid vid ttp tm stc 100mhzsteps

processor    : 1
vendor_id    : AuthenticAMD
cpu family    : 15
model        : 107
model name    : AMD Athlon(tm) 64 X2 Dual Core Processor 3600+
stepping    : 1
cpu MHz        : 2706.089
cache size    : 512 KB
fpu        : yes
fpu_exception    : yes
cpuid level    : 1
wp        : yes
flags        : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov
pat pse36 clflush mmx fxsr sse sse2 syscall nx mmxext fxsr_opt rdtscp lm
3dnowext 3dnow constant_tsc rep_good tsc_reliable pni cx16 hypervisor lahf_lm
extapic 3dnowprefetch
bogomips    : 5396.42
TLB size    : 1024 4K pages
clflush size    : 64
cache_alignment    : 64
address sizes    : 40 bits physical, 48 bits virtual
power management: ts fid vid ttp tm stc 100mhzsteps

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 19, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5612


Russel Winder <russel@russel.org.uk> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |russel@russel.org.uk


--- Comment #1 from Russel Winder <russel@russel.org.uk> 2011-02-19 08:44:59 PST ---
I ran the program on my twin Xeon workstation running Ubuntu 10.10 Maverick Meerkat:

|> dmd -m32 issue_5612.d && issue_5612
4
|> dmd -m64 issue_5612.d && issue_5612
1
|> uname -a
Linux anglides 2.6.35-25-generic #44-Ubuntu SMP Fri Jan 21 17:40:44 UTC 2011
x86_64 GNU/Linux
|> cat /proc/cpuinfo
processor    : 0
vendor_id    : GenuineIntel
cpu family    : 6
model        : 23
model name    : Intel(R) Xeon(R) CPU           E5410  @ 2.33GHz
stepping    : 6
cpu MHz        : 2327.542
cache size    : 6144 KB
physical id    : 0
siblings    : 4
core id        : 0
cpu cores    : 4
apicid        : 0
initial apicid    : 0
fpu        : yes
fpu_exception    : yes
cpuid level    : 10
wp        : yes
flags        : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov
pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx lm
constant_tsc arch_perfmon pebs bts rep_good aperfmperf pni dtes64 monitor
ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm dca sse4_1 lahf_lm dts tpr_shadow vnmi
flexpriority
bogomips    : 4655.08
clflush size    : 64
cache_alignment    : 64
address sizes    : 38 bits physical, 48 bits virtual
power management:

processor    : 1
vendor_id    : GenuineIntel
cpu family    : 6
model        : 23
model name    : Intel(R) Xeon(R) CPU           E5410  @ 2.33GHz
stepping    : 6
cpu MHz        : 2327.542
cache size    : 6144 KB
physical id    : 1
siblings    : 4
core id        : 0
cpu cores    : 4
apicid        : 4
initial apicid    : 4
fpu        : yes
fpu_exception    : yes
cpuid level    : 10
wp        : yes
flags        : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov
pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx lm
constant_tsc arch_perfmon pebs bts rep_good aperfmperf pni dtes64 monitor
ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm dca sse4_1 lahf_lm dts tpr_shadow vnmi
flexpriority
bogomips    : 4655.03
clflush size    : 64
cache_alignment    : 64
address sizes    : 38 bits physical, 48 bits virtual
power management:

processor    : 2
vendor_id    : GenuineIntel
cpu family    : 6
model        : 23
model name    : Intel(R) Xeon(R) CPU           E5410  @ 2.33GHz
stepping    : 6
cpu MHz        : 2327.542
cache size    : 6144 KB
physical id    : 0
siblings    : 4
core id        : 1
cpu cores    : 4
apicid        : 1
initial apicid    : 1
fpu        : yes
fpu_exception    : yes
cpuid level    : 10
wp        : yes
flags        : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov
pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx lm
constant_tsc arch_perfmon pebs bts rep_good aperfmperf pni dtes64 monitor
ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm dca sse4_1 lahf_lm dts tpr_shadow vnmi
flexpriority
bogomips    : 4655.03
clflush size    : 64
cache_alignment    : 64
address sizes    : 38 bits physical, 48 bits virtual
power management:

processor    : 3
vendor_id    : GenuineIntel
cpu family    : 6
model        : 23
model name    : Intel(R) Xeon(R) CPU           E5410  @ 2.33GHz
stepping    : 6
cpu MHz        : 2327.542
cache size    : 6144 KB
physical id    : 1
siblings    : 4
core id        : 1
cpu cores    : 4
apicid        : 5
initial apicid    : 5
fpu        : yes
fpu_exception    : yes
cpuid level    : 10
wp        : yes
flags        : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov
pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx lm
constant_tsc arch_perfmon pebs bts rep_good aperfmperf pni dtes64 monitor
ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm dca sse4_1 lahf_lm dts tpr_shadow vnmi
flexpriority
bogomips    : 4655.01
clflush size    : 64
cache_alignment    : 64
address sizes    : 38 bits physical, 48 bits virtual
power management:

processor    : 4
vendor_id    : GenuineIntel
cpu family    : 6
model        : 23
model name    : Intel(R) Xeon(R) CPU           E5410  @ 2.33GHz
stepping    : 6
cpu MHz        : 2327.542
cache size    : 6144 KB
physical id    : 0
siblings    : 4
core id        : 2
cpu cores    : 4
apicid        : 2
initial apicid    : 2
fpu        : yes
fpu_exception    : yes
cpuid level    : 10
wp        : yes
flags        : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov
pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx lm
constant_tsc arch_perfmon pebs bts rep_good aperfmperf pni dtes64 monitor
ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm dca sse4_1 lahf_lm dts tpr_shadow vnmi
flexpriority
bogomips    : 4654.99
clflush size    : 64
cache_alignment    : 64
address sizes    : 38 bits physical, 48 bits virtual
power management:

processor    : 5
vendor_id    : GenuineIntel
cpu family    : 6
model        : 23
model name    : Intel(R) Xeon(R) CPU           E5410  @ 2.33GHz
stepping    : 6
cpu MHz        : 2327.542
cache size    : 6144 KB
physical id    : 1
siblings    : 4
core id        : 2
cpu cores    : 4
apicid        : 6
initial apicid    : 6
fpu        : yes
fpu_exception    : yes
cpuid level    : 10
wp        : yes
flags        : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov
pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx lm
constant_tsc arch_perfmon pebs bts rep_good aperfmperf pni dtes64 monitor
ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm dca sse4_1 lahf_lm dts tpr_shadow vnmi
flexpriority
bogomips    : 4655.03
clflush size    : 64
cache_alignment    : 64
address sizes    : 38 bits physical, 48 bits virtual
power management:

processor    : 6
vendor_id    : GenuineIntel
cpu family    : 6
model        : 23
model name    : Intel(R) Xeon(R) CPU           E5410  @ 2.33GHz
stepping    : 6
cpu MHz        : 2327.542
cache size    : 6144 KB
physical id    : 0
siblings    : 4
core id        : 3
cpu cores    : 4
apicid        : 3
initial apicid    : 3
fpu        : yes
fpu_exception    : yes
cpuid level    : 10
wp        : yes
flags        : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov
pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx lm
constant_tsc arch_perfmon pebs bts rep_good aperfmperf pni dtes64 monitor
ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm dca sse4_1 lahf_lm dts tpr_shadow vnmi
flexpriority
bogomips    : 4655.02
clflush size    : 64
cache_alignment    : 64
address sizes    : 38 bits physical, 48 bits virtual
power management:

processor    : 7
vendor_id    : GenuineIntel
cpu family    : 6
model        : 23
model name    : Intel(R) Xeon(R) CPU           E5410  @ 2.33GHz
stepping    : 6
cpu MHz        : 2327.542
cache size    : 6144 KB
physical id    : 1
siblings    : 4
core id        : 3
cpu cores    : 4
apicid        : 7
initial apicid    : 7
fpu        : yes
fpu_exception    : yes
cpuid level    : 10
wp        : yes
flags        : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov
pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx lm
constant_tsc arch_perfmon pebs bts rep_good aperfmperf pni dtes64 monitor
ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm dca sse4_1 lahf_lm dts tpr_shadow vnmi
flexpriority
bogomips    : 4655.04
clflush size    : 64
cache_alignment    : 64
address sizes    : 38 bits physical, 48 bits virtual
power management:

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 19, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5612


Don <clugdbug@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug@yahoo.com.au


--- Comment #2 from Don <clugdbug@yahoo.com.au> 2011-02-19 11:40:40 PST ---
core.cpuid relies on inline assembler. There is currently no 64 bit version of the code, so I wouldn't expect it to work. I would expect it to just be versioned out. Is it actually getting run at all?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 19, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5612


David Simcha <dsimcha@yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|core.cpuid broken on 64     |core.cpuid not implemented
                   |                            |on 64
           Severity|normal                      |enhancement


--- Comment #3 from David Simcha <dsimcha@yahoo.com> 2011-02-19 12:08:36 PST ---
Ok, you're right.  The whole thing's versioned out.  Editing the title and changing to enhancement.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 20, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5612



--- Comment #4 from Russel Winder <russel@russel.org.uk> 2011-02-20 02:51:59 PST ---
I don't agree this is an enhancement, it is a bug, even if the 64-bit stuff is in early days.  OpenMP, OpenMPI, just::thread and all the other C, C++ and Fortran paralellism frameworks handle this correctly.

Why is this being handled by assembly code, all the operating systems must have APIs for handling this?

Of course with Mac hardware with 64-bit processors where the boot ROM is 32-bit the OS boots 32-bit -- since Mac OS X refuses to boot 64-bit in this case.

A hypothesis:  the current assembly code can only deal with a single processor which is why it reports 4 in 32-bit mode on my dual quad-core workstation.  If this is the case should a new bug be raised or can this be handled here?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 20, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5612


Brad Roberts <braddr@puremagic.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |braddr@puremagic.com
           Platform|Other                       |x86_64
         OS/Version|Windows                     |All
           Severity|enhancement                 |major


--- Comment #5 from Brad Roberts <braddr@puremagic.com> 2011-02-20 03:07:29 PST ---
I agree, it's pretty important as parts of druntime and phobos use cpu info. Fixed up the platform as well.

Don, is this something you might be able to own?  You've done a lot of the past cpuid stuff, right?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 20, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5612



--- Comment #6 from Don <clugdbug@yahoo.com.au> 2011-02-20 08:40:20 PST ---
(In reply to comment #4)
> I don't agree this is an enhancement, it is a bug,

It's neither. It is a task. Bugzilla's options are ridiculously limited.

> Why is this being handled by assembly code, all the operating systems must have APIs for handling this?

The most recent ones do, the older ones don't.
Really, this code is primarily intended for determining which features should
be supported for low-level operations used by the runtime; and as such, it must
be available at a very early stage in the initialization process, regardless of
the OS. It replaces several ad-hoc and incorrect functions which had been used
in the runtime.

It would be good to supplement this with systems calls for the most recent OSes, but to do this without breaking older OSes. Although, probably all 64-bit OSes support it, so maybe it's only a issue for 32-bit systems.

 > Of course with Mac hardware with 64-bit processors where the boot ROM is
32-bit
> the OS boots 32-bit -- since Mac OS X refuses to boot 64-bit in this case.
> 
> A hypothesis:  the current assembly code can only deal with a single processor which is why it reports 4 in 32-bit mode on my dual quad-core workstation.  If this is the case should a new bug be raised or can this be handled here?

That should be a new bug. The value should be correct, if the BIOS has done its job in setting the processor APIC values correctly.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 27, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5612



--- Comment #7 from Russel Winder <russel@russel.org.uk> 2011-02-27 05:51:03 PST ---
David has already reported the "cannot cope with multiple CPUs" bug as Issue 4462, dated 2010-07-14.  So no movement on that after 7 months :-(

I think this pair of bugs has to be treated as an urgent blocking bug and attacked immediately.

Can cpuid.d be separated out so that we can work on it?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 27, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5612



--- Comment #8 from Don <clugdbug@yahoo.com.au> 2011-02-27 06:46:37 PST ---
(In reply to comment #7)
> David has already reported the "cannot cope with multiple CPUs" bug as Issue 4462, dated 2010-07-14.  So no movement on that after 7 months :-(
> 
> I think this pair of bugs has to be treated as an urgent blocking bug and attacked immediately.
> 
> Can cpuid.d be separated out so that we can work on it?


Yes. It has absolutely no dependencies on anything. Just copy it. You can compile it as a standalone file.

BTW, there's a good chance the 64 bit code will work as-is, just by changing the version. The reason is that 'cpuid' acts as a 32-bit instruction even on 64 bits.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 13, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5612


Don <clugdbug@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


--- Comment #9 from Don <clugdbug@yahoo.com.au> 2011-04-13 13:50:34 PDT ---
https://github.com/D-Programming-Language/druntime/commit/5959d1e1cfecf0755db4cc14c2b595aa0a797bde

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------