unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Arthur Miller <arthur.miller@live.com>
To: Omar Polo <op@omarpolo.com>
Cc: Campbell Barton <ideasman42@gmail.com>, emacs-devel@gnu.org
Subject: Re: [PATCH] support for accessing CPU/core count (processor-count)
Date: Sun, 10 Oct 2021 18:48:17 +0200	[thread overview]
Message-ID: <AM9PR09MB497749E0C5E706F7386C141096B49@AM9PR09MB4977.eurprd09.prod.outlook.com> (raw)
In-Reply-To: <87o87xf5ag.fsf@omarpolo.com> (Omar Polo's message of "Sun, 10 Oct 2021 14:07:31 +0200")

Omar Polo <op@omarpolo.com> writes:

> 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.
There is no difference in usage on Lisp side if you implement a function as a C
built-in or a Lisp function.

However, difference in maintaining it is huge. For any change, entire Emacs has
to be recompiled, but if you do it in Lisp you can tweak it whenever, advice it,
etc.

I can't imagine number of CPUs change under the running Emacs process; at least
not on platforms I am aware off, so quering cpu number will probably be done in
some 'with-eval-after-load', i.e. not performance critical code.

>>> 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.
Sorry for answering this as aftertought; I think there is a little bit of
missunderstanding going on. What I meant, is not that every user should do this
on their own. I just meant you should implement this in Lisp rather than in
C. An API to query number of physical cores is definitely a good thing to have.

>>> (the same thing applies to proced.  You could implement it by parsing ps
>> make it easier on the elisp side to use it.  We can try to support every
>>> 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...
And that is the beauty of having it as a Lisp function. You can just tweak it,
don't need to recompile entire Emacs :). 



  reply	other threads:[~2021-10-10 16:48 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-10  0:02 [PATCH] support for accessing CPU/core count (processor-count) Campbell Barton
2021-10-10  7:54 ` Omar Polo
2021-10-10  9:38   ` Arthur Miller
2021-10-10  9:43     ` Omar Polo
2021-10-10 10:52       ` Arthur Miller
2021-10-10 12:07         ` Omar Polo
2021-10-10 16:48           ` Arthur Miller [this message]
2021-10-10 18:17             ` Omar Polo
2021-10-10 19:45               ` Arthur Miller
2021-10-10 21:04                 ` Omar Polo
2021-10-11  8:15                   ` Arthur Miller
2021-10-11  8:20                   ` Arthur Miller
2021-10-11  8:23                     ` Omar Polo
2021-10-11 15:55                       ` Arthur Miller
2021-10-10 21:32                 ` Andreas Schwab
2021-10-11  8:03                   ` Arthur Miller
2021-10-11  8:14                     ` Andreas Schwab
2021-10-11 15:53                       ` Arthur Miller
2021-10-11 16:49                         ` Andreas Schwab
2021-10-11 17:14                           ` Arthur Miller
2021-10-10 10:13     ` Campbell Barton
2021-10-10 10:38     ` Andreas Schwab
2021-10-10 11:21       ` Arthur Miller
2021-10-10 11:57         ` Andreas Schwab
2021-10-10 16:35           ` Arthur Miller
2021-10-10 17:27             ` Andreas Schwab
2021-10-10 18:13               ` Arthur Miller
2021-10-10 19:16                 ` Stefan Monnier
2021-10-10 19:50                   ` Arthur Miller
2021-10-10 22:58                     ` Campbell Barton
2021-10-11  8:01                       ` Arthur Miller
2021-10-10 12:21   ` Stefan Kangas
2021-10-10 16:03     ` Omar Polo
2021-10-10 21:11     ` Paul Eggert
2021-10-10 21:16       ` Omar Polo
2021-10-11 17:17       ` Arthur Miller
2021-10-10 10:50 ` Andy Moreton
2021-10-10 11:21   ` Arthur Miller
2021-10-10 12:09 ` Stefan Kangas
2021-10-10 22:43   ` Campbell Barton
2021-10-11  1:34 ` Po Lu
2021-10-11  1:51   ` Campbell Barton
2021-10-11  3:04     ` Po Lu
2021-10-11  4:01       ` Campbell Barton
2021-10-11  8:20         ` Lars Ingebrigtsen
2021-10-11 13:00           ` Eli Zaretskii
2021-10-11 15:12           ` Stefan Monnier
2021-10-11 16:07             ` Eli Zaretskii
2021-10-11 21:14               ` Andy Moreton
2021-10-11 22:13                 ` Ken Brown
2021-10-12  2:27                 ` Eli Zaretskii
2021-10-12 10:39               ` Lars Ingebrigtsen
2021-10-12 14:09                 ` Eli Zaretskii
2021-10-12 19:58                   ` Paul Eggert
2021-10-13  2:24                     ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=AM9PR09MB497749E0C5E706F7386C141096B49@AM9PR09MB4977.eurprd09.prod.outlook.com \
    --to=arthur.miller@live.com \
    --cc=emacs-devel@gnu.org \
    --cc=ideasman42@gmail.com \
    --cc=op@omarpolo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).