From 96278de8ac2166c37925f2dfbc0eeb6d368142b9 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sun, 10 Oct 2021 13:59:16 -0700 Subject: New function num-processors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This addresses a FIXME comment in lisp/emacs-lisp/comp.el, relating to the number of subsidiary processes used by comp-run-async-workers in native compilation. * admin/merge-gnulib (GNULIB_MODULES): Add nproc. * doc/lispref/processes.texi (Process Information), etc/NEWS: Document num-processors. * lib/gnulib.mk.in, m4/gnulib-comp.m4: Regenerate. * lib/nproc.c, lib/nproc.h, m4/nproc.m4: New files, copied from Gnulib by admin/merge-gnulib. * lisp/emacs-lisp/comp.el (w32-get-nproc): Remove decl. (comp-effective-async-max-jobs): Use num-processors. * src/process.c: Include nproc.h. (Fnum_processors): New function. (syms_of_process): Define ‘all’, ‘current’, ‘num-processors’. * src/w32proc.c (Fw32_get_nproc): Add FIXME comment. * test/src/process-tests.el (process-num-processors): New test. --- lisp/emacs-lisp/comp.el | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) (limited to 'lisp/emacs-lisp/comp.el') diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el index 63d4a74b546..0052fd0f8db 100644 --- a/lisp/emacs-lisp/comp.el +++ b/lisp/emacs-lisp/comp.el @@ -3876,26 +3876,13 @@ processes from `comp-async-compilations'" do (remhash file-name comp-async-compilations)) (hash-table-count comp-async-compilations)) -(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)))) + (max 1 (/ (num-processors) 2)))) native-comp-async-jobs-number)) (defvar comp-last-scanned-async-output nil) -- cgit v1.2.3