Skip to content

Commit

Permalink
New function num-processors
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
eggert committed Oct 10, 2021
1 parent 575e626 commit 96278de
Show file tree
Hide file tree
Showing 12 changed files with 564 additions and 15 deletions.
3 changes: 2 additions & 1 deletion admin/merge-gnulib
Expand Up @@ -39,7 +39,8 @@ GNULIB_MODULES='
free-posix fstatat fsusage fsync futimens
getloadavg getopt-gnu getrandom gettime gettimeofday gitlog-to-changelog
ieee754-h ignore-value intprops largefile libgmp lstat
manywarnings memmem-simple mempcpy memrchr minmax mkostemp mktime nstrftime
manywarnings memmem-simple mempcpy memrchr minmax mkostemp mktime
nproc nstrftime
pathmax pipe2 pselect pthread_sigmask
qcopy-acl readlink readlinkat regex
sig2str sigdescr_np socklen stat-time std-gnu11 stdalign stddef stdio
Expand Down
13 changes: 13 additions & 0 deletions doc/lispref/processes.texi
Expand Up @@ -1047,6 +1047,19 @@ This function returns a list of all processes that have not been deleted.
@end smallexample
@end defun

@defun num-processors &optional query
This function returns the number of processors, a positive integer.
Each usable thread execution unit counts as a processor.
By default, the count includes the number of available processors,
which you can override by setting the
@url{https://www.openmp.org/spec-html/5.1/openmpse59.html,
@env{OMP_NUM_THREADS} environment variable of OpenMP}.
If the optional argument @var{query} is @code{current},
this function ignores @env{OMP_NUM_THREADS};
if @var{query} is @code{all}, this function also counts processors
that are on the system but are not available to the current process.
@end defun

@defun get-process name
This function returns the process named @var{name} (a string), or
@code{nil} if there is none. The argument @var{name} can also be a
Expand Down
4 changes: 4 additions & 0 deletions etc/NEWS
Expand Up @@ -4094,6 +4094,10 @@ Parse a string as a mail address-like string.
** New function 'make-separator-line'.
Make a string appropriate for usage as a visual separator line.

+++
** New function 'num-processors'.
Return the number of processors on the system.

+++
** New function 'object-intervals'.
This function returns a copy of the list of intervals (i.e., text
Expand Down
11 changes: 11 additions & 0 deletions lib/gnulib.mk.in
Expand Up @@ -129,6 +129,7 @@
# minmax \
# mkostemp \
# mktime \
# nproc \
# nstrftime \
# pathmax \
# pipe2 \
Expand Down Expand Up @@ -2378,6 +2379,16 @@ EXTRA_libgnu_a_SOURCES += mktime.c
endif
## end gnulib module mktime-internal

## begin gnulib module nproc
ifeq (,$(OMIT_GNULIB_MODULE_nproc))

libgnu_a_SOURCES += nproc.c

EXTRA_DIST += nproc.h

endif
## end gnulib module nproc

## begin gnulib module nstrftime
ifeq (,$(OMIT_GNULIB_MODULE_nstrftime))

Expand Down

0 comments on commit 96278de

Please sign in to comment.