muyinliu / cl-cpus

A Common Lisp feature to get number of CPUs on Linux/Mac/Windows
ISC License
29 stars 3 forks source link

Make it work for macOS #3

Open auvi opened 6 years ago

muyinliu commented 6 years ago

I'm NOT sure sysconf is compatible for old version of macOS. sysconf seems not compatible with macOS 10.10 when I started up cl-cpus. Might need some check.

auvi commented 6 years ago

what does your macOS /usr/include/unistd.h define _SC_NPROCESSORS_ONLN as? mine shows as

#define _SC_NPROCESSORS_ONLN        58

in the macOS code I modified the Linux version and got the 58 from /usr/include/unistd.h

and if you do a man 3 sysconf in macOS you'll find

     _SC_NPROCESSORS_ONLN
             The number of processors currently online.

also your code loads the file cl-cpus-bsd.lisp and as macOS is based on BSD its *features* variable gets a :BSD

mine is here:

* *features*

(:QUICKLISP :ASDF3.3 :ASDF3.2 :ASDF3.1 :ASDF3 :ASDF2 :ASDF :OS-MACOSX :OS-UNIX
 :NON-BASE-CHARS-EXIST-P :ASDF-UNICODE :64-BIT :64-BIT-REGISTERS
 :ALIEN-CALLBACKS :ANSI-CL :ASH-RIGHT-VOPS :BSD :C-STACK-IS-CONTROL-STACK
 :CALL-SYMBOL :COMMON-LISP :COMPACT-INSTANCE-HEADER :COMPARE-AND-SWAP-VOPS
 :COMPLEX-FLOAT-VOPS :CYCLE-COUNTER :DARWIN :DARWIN9-OR-BETTER :FLOAT-EQL-VOPS
 :FP-AND-PC-STANDARD-SAVE :GENCGC :IEEE-FLOATING-POINT :IMMOBILE-CODE
 :IMMOBILE-SPACE :INLINE-CONSTANTS :INODE64 :INTEGER-EQL-VOP :LINKAGE-TABLE
 :LITTLE-ENDIAN :MACH-EXCEPTION-HANDLER :MACH-O :MEMORY-BARRIER-VOPS
 :MULTIPLY-HIGH-VOPS :OS-PROVIDES-BLKSIZE-T :OS-PROVIDES-DLADDR
 :OS-PROVIDES-DLOPEN :OS-PROVIDES-PUTWC :OS-PROVIDES-SUSECONDS-T
 :PACKAGE-LOCAL-NICKNAMES :RAW-INSTANCE-INIT-VOPS :RAW-SIGNED-WORD
 :RELOCATABLE-HEAP :SB-CORE-COMPRESSION :SB-DOC :SB-EVAL :SB-LDB
 :SB-PACKAGE-LOCKS :SB-SIMD-PACK :SB-SOURCE-LOCATIONS :SB-THREAD :SB-THREAD
 :SB-UNICODE :SBCL :STACK-ALLOCATABLE-CLOSURES :STACK-ALLOCATABLE-FIXED-OBJECTS
 :STACK-ALLOCATABLE-LISTS :STACK-ALLOCATABLE-VECTORS
 :STACK-GROWS-DOWNWARD-NOT-UPWARD :SYMBOL-INFO-VOPS :UD2-BREAKPOINTS
 :UNBIND-N-VOP :UNDEFINED-FUN-RESTARTS :UNIX :UNWIND-TO-FRAME-AND-CALL-VOP
 :X86-64)
muyinliu commented 6 years ago

I have upgraded macOS from 10.10.5 to 10.13.4 recently. On macOS 10.13.4 shows #define _SC_NPROCESSORS_ONLN 58. But I don't have macOS 10.10.5 for now...Sorry, it might take some time to install macOS 10.10 to VM and check. What's the version of your macOS?

auvi commented 6 years ago

I am on macOS High Sierra 10.13.3 If you need to look at unistd.h and its history you can looks at apple's GitHub mirror https://github.com/apple/darwin-xnu/commits/master/bsd/sys/unistd.h

muyinliu commented 6 years ago

I take a look at the source code of Java & Golang, all of them make number of CPU constant while process starting up. Maybe I should do so...

Note: I'm downloading old versions of macOS(such as 10.10 Yosemite) and testing...Just give me some time. Thanks.

muyinliu commented 6 years ago

I decide to init number-of-processors while loading to solve #4 on macOS. Please please checkout v0.0.2 and test. Thanks.

auvi commented 6 years ago

I am getting some weird values:

CL-USER(1): (ql:quickload 'cl-cpus)
To load "cl-cpus":
  Load 1 ASDF system:
    cl-cpus
; Loading "cl-cpus"
.
(CL-CPUS)
CL-USER(2): (cpus:get-number-of-processors)

17322791
CL-USER(3):
muyinliu commented 6 years ago

Please provide the version info of the Common Lisp in this case.

auvi commented 6 years ago
$ sbcl --version
SBCL 1.4.6

$ uname -a
Darwin <hostname> 15.6.0 Darwin Kernel Version 15.6.0: Mon Oct  2 22:20:08 PDT 2017; root:xnu-3248.71.4~1/RELEASE_X86_64 x86_64
muyinliu commented 6 years ago

Thanks.

I have Mac OS X Server 10.6 Snow Leopard installed in Parallels Desktop and test the code you provided. It works fine! I also have FreeBSD 11 installed and works fine too! I will have more tests.

auvi commented 6 years ago

i tried again with your code:

CL-USER(1): (ql:quickload 'cl-cpus)
To load "cl-cpus":
  Load 1 ASDF system:
    cl-cpus
; Loading "cl-cpus"
.
(CL-CPUS)
CL-USER(2): (cpus:get-number-of-processors)

17322791
CL-USER(3): 

then i tried again with my pull request:

CL-USER(1): (ql:quickload 'cl-cpus)
To load "cl-cpus":
  Load 1 ASDF system:
    cl-cpus
; Loading "cl-cpus"
..................................................
[package cl-cpus]
(CL-CPUS)
CL-USER(2): (cpus:get-number-of-processors)

4
CL-USER(3): 

Please let me know if you need to investigate the pull request I sent. If it is okay with you I can go for a screen share via Skype etc. 谢谢!