mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-24 04:19:26 +02:00
+ linux implementation of System.GetCPUCount
git-svn-id: trunk@48106 -
This commit is contained in:
parent
63c603cf32
commit
d2b0bcdf1f
rtl/linux
@ -732,3 +732,9 @@ begin
|
||||
fpsetrlimit:=do_syscall(syscall_nr_setrlimit,TSysParam(Resource),TSysParam(rlim));
|
||||
end;
|
||||
|
||||
function FpSchedGetAffinity(pid : pid_t;cpusetsize : size_t;mask : pcpu_set_t) : cint;
|
||||
begin
|
||||
FpSchedGetAffinity := do_syscall(syscall_nr_sched_getaffinity,TSysParam(pid),TSysParam(cpusetsize),TSysParam(mask));
|
||||
end;
|
||||
|
||||
|
||||
|
@ -430,6 +430,17 @@ type
|
||||
tiovec=iovec;
|
||||
piovec=^tiovec;
|
||||
|
||||
cpu_set_t = record
|
||||
{$ifdef CPU64}
|
||||
__bits : array[0..15] of culong;
|
||||
{$else CPU64}
|
||||
__bits : array[0..0] of culong;
|
||||
{$endif CPU64}
|
||||
end;
|
||||
|
||||
tcpu_set_t = cpu_set_t;
|
||||
pcpu_set_t = ^tcpu_set_t;
|
||||
|
||||
{$if defined(cpupowerpc)}
|
||||
const
|
||||
{ FP exception related constants for prctl(); PowerPC specific }
|
||||
|
@ -113,6 +113,8 @@ procedure OsSetupEntryInformation(constref info: TEntryInformation); forward;
|
||||
|
||||
{$endif FPC_LOAD_SOFTFPU}
|
||||
|
||||
{$define HAS_GETCPUCOUNT}
|
||||
|
||||
{$I system.inc}
|
||||
|
||||
{$ifdef android}
|
||||
@ -458,6 +460,24 @@ Begin
|
||||
randseed:=longint(Fptime(nil));
|
||||
End;
|
||||
|
||||
function GetCPUCount: LongWord;
|
||||
var
|
||||
cpus : tcpu_set_t;
|
||||
BytesWritten,i : cint;
|
||||
begin
|
||||
Result := 1;
|
||||
{ same approach as nproc uses:
|
||||
we return the number of available CPUs }
|
||||
BytesWritten:=FpSchedGetAffinity(0,sizeof(cpus),@cpus);
|
||||
if BytesWritten>0 then
|
||||
begin
|
||||
Result := 0;
|
||||
for i:=0 to BytesWritten-1 do
|
||||
Result:=Result+Popcnt((PByte(@cpus)+i)^);
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
{*****************************************************************************
|
||||
cmdline
|
||||
*****************************************************************************}
|
||||
|
Loading…
Reference in New Issue
Block a user