emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] support for accessing CPU/core count (processor-count)


From: Omar Polo
Subject: Re: [PATCH] support for accessing CPU/core count (processor-count)
Date: Sun, 10 Oct 2021 14:07:31 +0200
User-agent: mu4e 1.6.6; emacs 28.0.50

Arthur Miller <arthur.miller@live.com> writes:

> Omar Polo <op@omarpolo.com> writes:
>[...]
>>> What is wrong on just reading this from /cat/cpuinfo on GNU/Linux?
>>>
>>> Windows has "wmic cpu get NumberOfCores,NumberOfLogicalProcessors" which 
>>> works
>>> on cmd prompt, which means executable from elisp as a process. I dont know 
>>> for
>>> apple and *bsds.
>>>
>>> It is just text that can be parsed directly with elisp, so it is easier to
>>> maintain does not need to be compiled etc. I don't see cpu queries as a
>>> performance crucial query. Just a thought.
>>
>> You're right
>>
>>      syscstl -n hw.ncpuonline
>>
>> would do it.  I guess that a rationale for doing this in C would be to
>> make it easier on the elisp side to use it.  We can try to support every
>> OS here instead of leaving the burden on the elisp package authors.
>>
>> (the same thing applies to proced.  You could implement it by parsing ps
>> output I guess, but there are elisp API that calls into C for that.)
>>
>> But I don't know, I don't really have strong opinions.  I've read a bit
>> of code that didn't look right and tried to improve it :)
>
> By the way; I just realize also that native compiler does this, and there is
> also a note about exporting already written c function to lisp:
>
> #begin_src emacs-lisp
> (declare-function w32-get-nproc "w32.c")
> (defvar comp-num-cpus nil)
> (defun comp-effective-async-max-jobs ()
>   "Compute the effective number of async jobs."
>   (if (zerop native-comp-async-jobs-number)
>       (or comp-num-cpus
>           (setf comp-num-cpus
>                 ;; FIXME: we already have a function to determine
>                 ;; the number of processors, see get_native_system_info in 
> w32.c.
>                 ;; The result needs to be exported to Lisp.
>                 (max 1 (/ (cond ((eq 'windows-nt system-type)
>                                  (w32-get-nproc))
>                                 ((executable-find "nproc")
>                                  (string-to-number
>                                   (shell-command-to-string "nproc")))
>                                 ((eq 'berkeley-unix system-type)
>                                  (string-to-number
>                                   (shell-command-to-string "sysctl -n 
> hw.ncpu")))
>                                 (t 1))
>                           2))))
>     native-comp-async-jobs-number))
> #end_src
>
> Maybe you can just extract the cpu number part from Andrea's function and 
> rename
> into some public API independent of native comp?

Thanks for bringing up that bit, as is something that would need to be
tweaked on OpenBSD (refer to my previous mail regarding ncpu vs
ncpuonline.)

Hope to remember to tweak this next time I'll try to get nativecomp on
OpenBSD...



reply via email to

[Prev in Thread] Current Thread [Next in Thread]