diff options
author | florian <florian@3ad0048d-3df7-0310-abae-a5850022a9f2> | 2021-01-07 22:44:49 +0000 |
---|---|---|
committer | florian <florian@3ad0048d-3df7-0310-abae-a5850022a9f2> | 2021-01-07 22:44:49 +0000 |
commit | eeb8d8c6fea7e745293fc57e91635d2db57b89ec (patch) | |
tree | 67a67c56b536407128003be64e6f4c2c8b80f6e8 /rtl/linux | |
parent | e4847f559682318f6ce582fd33d3953214f0f274 (diff) | |
download | fpc-eeb8d8c6fea7e745293fc57e91635d2db57b89ec.tar.gz |
+ linux implementation of System.GetCPUCount
git-svn-id: https://svn.freepascal.org/svn/fpc/trunk@48106 3ad0048d-3df7-0310-abae-a5850022a9f2
Diffstat (limited to 'rtl/linux')
-rw-r--r-- | rtl/linux/ossysc.inc | 6 | ||||
-rw-r--r-- | rtl/linux/ostypes.inc | 11 | ||||
-rw-r--r-- | rtl/linux/system.pp | 20 |
3 files changed, 37 insertions, 0 deletions
diff --git a/rtl/linux/ossysc.inc b/rtl/linux/ossysc.inc index 074ad4b9a8..9d2bfd5232 100644 --- a/rtl/linux/ossysc.inc +++ b/rtl/linux/ossysc.inc @@ -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; + + diff --git a/rtl/linux/ostypes.inc b/rtl/linux/ostypes.inc index b07bed63dc..2d8ffcc980 100644 --- a/rtl/linux/ostypes.inc +++ b/rtl/linux/ostypes.inc @@ -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 } diff --git a/rtl/linux/system.pp b/rtl/linux/system.pp index e6cb6246f2..caa4e116c7 100644 --- a/rtl/linux/system.pp +++ b/rtl/linux/system.pp @@ -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 *****************************************************************************} |