[fpc-devel] AMD & Intel CPUCount

Ewald ewald at yellowcouch.org
Fri Dec 28 20:47:24 CET 2012


Once upon a time, on 12/28/2012 08:27 PM to be precise, Ludo Brands said:
> On 28/12/2012 20:01, Ewald wrote:
>> Well, it is as you say, the `max cores per packge` just doesn't make any
>> sense at all. How can a processor hav  e a maximum of one core per
>> physical package, while in reality it has two threads sharing the same
>> cache? Either I'm missing something here, or the behaviour of CPUID has
>> changed over the years.
> Atom 230 is one of the first atoms.
> http://www.intel.com/content/www/us/en/processors/atom/atom-200-specification-update.html
> lists a few bugs with cpuid but not this one.
Well, maybe we have just uncovered another bug? ;-)

>> Either way: it leaves me with a method that is not 100% reliable.
> This uses libc but on the Xeon and Atom it gives the correct result
> using debian and ubuntu:
>
> program cpucount;
>
> {$mode objfpc}{$H+}
>
> function sysconf (__name : longint) : longint; cdecl; external 'c'
> name 'sysconf';
> const
>   _SC_UIO_MAXIOV = 60;
>   _SC_NPROCESSORS_CONF = (_SC_UIO_MAXIOV)+23;
>
> begin
>   writeln('Number of processors: ',sysconf(_SC_NPROCESSORS_CONF));
> end.
>
> _SC_NPROCESSORS_CONF is defined in POSIX.2:
> http://www.kernel.org/doc/man-pages/online/pages/man3/sysconf.3.html
>
Cool! And since it only depends on libc, it could be integrated nicely
into cthreads for that matter :-)

-- 
Ewald




More information about the fpc-devel mailing list