[fpc-devel] AMD & Intel CPUCount

Ewald ewald at yellowcouch.org
Fri Dec 28 15:46:30 CET 2012


Hmmm, that's weird. The results of the Xeon are what I was expecting.

Quite frankly I don't know how to fix it. Maybe getting the maximum
amount of threads sharing the caches might prove helpfull, but then
again it is guesswork. Anyway, can you give this code a try?

Than if I take the highest value from this and the previous program it
*might* provide a sensible result. (?)

program cpucount;

{$mode objfpc}
{$asmmode att}

Function GetCores: LongWord;
Var cnt: LongWord;
Begin
    Asm
        MOV $0, __RESULT
        MOV $0, cnt
        .LStart:
            MOV $4, %eax
            MOV cnt, %ecx
            CPUID

            MOV %eax, %ebx
            SHR $14, %ebx
            AND $0xFFF, %ebx
            ADD $1, %ebx
            CMP __RESULT, %ebx
            JLE .LLessOrEqual
                MOV %ebx, __RESULT
           
            .LLessOrEqual:
            AND $0xF, %eax
           
            ADD $1, cnt
       
        CMP $0, %eax
        JNE .LStart
    End ['eax', 'ebx', 'ecx', 'edx'];
End;

Begin
    Writeln('#max threads sharing caches: ', GetCores);
End.



Once upon a time, on 12/28/2012 08:12 AM to be precise, Ludo Brands said:
>
> Inconsistent results here with hyperthreading:
> Xeon W3530 (4 cores hyperthreading) reports #CPU cores: 8.
> /proc/cpuinfo lists 8 processors and 4 cpu cores
> Intel Atom 230 (1 core hyperthreading) reports #CPU cores: 1 while
> /proc/cpuinfo reports 2 processors and 1 cpu core.
>
>
> processor    : 7
> vendor_id    : GenuineIntel
> cpu family    : 6
> model        : 26
> model name    : Intel(R) Xeon(R) CPU           W3530  @ 2.80GHz
> stepping    : 5
> microcode    : 0x11
> cpu MHz        : 2801.000
> cache size    : 8192 KB
> physical id    : 0
> siblings    : 8
> core id        : 3
> cpu cores    : 4
> ....
>
>
> processor    : 1
> vendor_id    : GenuineIntel
> cpu family    : 6
> model        : 28
> model name    : Intel(R) Atom(TM) CPU  230   @ 1.60GHz
> stepping    : 2
> cpu MHz        : 1599.570
> cache size    : 512 KB
> physical id    : 0
> siblings    : 2
> core id        : 0
> cpu cores    : 1
> ....
>
>
> AMD Athlon X2 5600+ reports #CPU cores: 2. /proc/cpuinfo reports 2
> processors and 2 cores.
>
> Ludo
> _______________________________________________
> fpc-devel maillist  -  fpc-devel at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-devel
>


-- 
Ewald




More information about the fpc-devel mailing list