Bug 3798 – core.cpuid locks systems with Xeon E5530 CPU
Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
Other
OS
Linux
Creation time
2010-02-12T11:25:00Z
Last change time
2015-06-09T01:27:39Z
Assigned to
nobody
Creator
dsimcha
Comments
Comment #0 by dsimcha — 2010-02-12T11:25:40Z
At my workplace, we've got a bunch of Linux boxes around. On the ones with the following cpuinfo, importing core.cpuid causes any D program to hang with 100% CPU usage during execution of static this() before main() is even called:
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 26
model name : Intel(R) Xeon(R) CPU E5530 @ 2.40GHz
stepping : 5
cpu MHz : 2393.863
cache size : 8192 KB
physical id : 1
siblings : 8
core id : 0
cpu cores : 4
apicid : 16
initial apicid : 16
fpu : yes
fpu_exception : yes
cpuid level : 11
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 rdtscp lm constant_tsc arch_perfmon pebs bts rep_good xtopology tsc_reliable nonstop_tsc pni dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm dca sse4_1 sse4_2 popcnt lahf_lm ida tpr_shadow vnmi flexpriority ept vpid
bogomips : 4787.72
clflush size : 64
cache_alignment : 64
address sizes : 40 bits physical, 48 bits virtual
power management:
According to GDB, the function where the program hangs is core.cpuid.getCpuInfo0B().
Comment #1 by dsimcha — 2010-02-12T12:24:55Z
ASsa temporary workaround, I'm using:
if (0) { //max_cpuid >=0x0B) {
// For Intel i7 and later, use function 0x0B to determine
// cores and hyperthreads.
getCpuInfo0B();
} else {
if (hyperThreadingBit) maxThreads = (apic>>>16) & 0xFF;
else maxThreads = maxCores;
}
The problem appears to be that the termination condition for the following loop never becomes true:
do {
asm {
mov EAX, 0x0B;
mov ECX, level;
cpuid;
mov a, EAX;
mov b, EAX;
mov c, ECX;
mov d, EDX;
}
if (b!=0) {
// I'm not sure about this. The docs state that there
// are 2 hyperthreads per core if HT is factory enabled.
if (level==0) maxThreads = b & 0xFFFF;
else if (level==1) maxCores = b & 0xFFFF;
}
} while (a!=0 || b!=0);
Comment #2 by clugdbug — 2010-02-12T20:35:48Z
(In reply to comment #1)
> The problem appears to be that the termination condition for the following loop
> never becomes true:
>
> do {
> asm {
> mov EAX, 0x0B;
> mov ECX, level;
> cpuid;
> mov a, EAX;
> mov b, EAX;
> mov c, ECX;
> mov d, EDX;
> }
> if (b!=0) {
> // I'm not sure about this. The docs state that there
> // are 2 hyperthreads per core if HT is factory enabled.
> if (level==0) maxThreads = b & 0xFFFF;
> else if (level==1) maxCores = b & 0xFFFF;
>
> }
> } while (a!=0 || b!=0);
Please add ++level; as the last line of that loop, so that it ends as:
++level;
} while (a!=0 || b!=0);
Does that fix it? I don't have access to a Core i7, so I'm flying blind based on the Intel manuals.
Comment #3 by dsimcha — 2010-02-13T07:54:38Z
> Please add ++level; as the last line of that loop, so that it ends as:
> ++level;
> } while (a!=0 || b!=0);
>
> Does that fix it? I don't have access to a Core i7, so I'm flying blind based
> on the Intel manuals.
Yep, that fixes it. Please fold into druntime for the next release.
Comment #4 by clugdbug — 2010-02-13T12:49:21Z
(In reply to comment #3)
> > Please add ++level; as the last line of that loop, so that it ends as:
> > ++level;
> > } while (a!=0 || b!=0);
> >
> > Does that fix it? I don't have access to a Core i7, so I'm flying blind based
> > on the Intel manuals.
>
> Yep, that fixes it. Please fold into druntime for the next release.
Excellent! Druntime svn 245.