summaryrefslogtreecommitdiff
path: root/m4
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2021-10-10 13:59:16 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2021-10-10 14:00:26 -0700
commit96278de8ac2166c37925f2dfbc0eeb6d368142b9 (patch)
tree566142705adf60d95c200aa188e51466d2504c94 /m4
parent575e626105b506b008eb9b0a03bb27aeecee54d4 (diff)
downloademacs-96278de8ac2166c37925f2dfbc0eeb6d368142b9.tar.gz
New function num-processors
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.
Diffstat (limited to 'm4')
-rw-r--r--m4/gnulib-comp.m45
-rw-r--r--m4/nproc.m454
2 files changed, 59 insertions, 0 deletions
diff --git a/m4/gnulib-comp.m4 b/m4/gnulib-comp.m4
index a795fe76518..e314edcfb53 100644
--- a/m4/gnulib-comp.m4
+++ b/m4/gnulib-comp.m4
@@ -139,6 +139,7 @@ AC_DEFUN([gl_EARLY],
# Code from module mktime-internal:
# Code from module multiarch:
# Code from module nocrash:
+ # Code from module nproc:
# Code from module nstrftime:
# Code from module open:
# Code from module openat-h:
@@ -413,6 +414,7 @@ AC_DEFUN([gl_INIT],
fi
gl_TIME_MODULE_INDICATOR([mktime])
gl_MULTIARCH
+ gl_NPROC
gl_FUNC_GNU_STRFTIME
gl_PATHMAX
gl_FUNC_PIPE2
@@ -1221,6 +1223,8 @@ AC_DEFUN([gl_FILE_LIST], [
lib/mkostemp.c
lib/mktime-internal.h
lib/mktime.c
+ lib/nproc.c
+ lib/nproc.h
lib/nstrftime.c
lib/open.c
lib/openat-priv.h
@@ -1370,6 +1374,7 @@ AC_DEFUN([gl_FILE_LIST], [
m4/mode_t.m4
m4/multiarch.m4
m4/nocrash.m4
+ m4/nproc.m4
m4/nstrftime.m4
m4/off_t.m4
m4/open-cloexec.m4
diff --git a/m4/nproc.m4 b/m4/nproc.m4
new file mode 100644
index 00000000000..887c66bee81
--- /dev/null
+++ b/m4/nproc.m4
@@ -0,0 +1,54 @@
+# nproc.m4 serial 5
+dnl Copyright (C) 2009-2021 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_NPROC],
+[
+ gl_PREREQ_NPROC
+])
+
+# Prerequisites of lib/nproc.c.
+AC_DEFUN([gl_PREREQ_NPROC],
+[
+ dnl Persuade glibc <sched.h> to declare CPU_SETSIZE, CPU_ISSET etc.
+ AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
+
+ AC_CHECK_HEADERS([sys/pstat.h sys/sysmp.h sys/param.h],,,
+ [AC_INCLUDES_DEFAULT])
+ dnl <sys/sysctl.h> requires <sys/param.h> on OpenBSD 4.0.
+ AC_CHECK_HEADERS([sys/sysctl.h],,,
+ [AC_INCLUDES_DEFAULT
+ #if HAVE_SYS_PARAM_H
+ # include <sys/param.h>
+ #endif
+ ])
+
+ AC_CHECK_FUNCS([sched_getaffinity sched_getaffinity_np \
+ pstat_getdynamic sysmp sysctl])
+
+ dnl Test whether sched_getaffinity has the expected declaration.
+ dnl glibc 2.3.[0-2]:
+ dnl int sched_getaffinity (pid_t, unsigned int, unsigned long int *);
+ dnl glibc 2.3.3:
+ dnl int sched_getaffinity (pid_t, cpu_set_t *);
+ dnl glibc >= 2.3.4:
+ dnl int sched_getaffinity (pid_t, size_t, cpu_set_t *);
+ if test $ac_cv_func_sched_getaffinity = yes; then
+ AC_CACHE_CHECK([for glibc compatible sched_getaffinity],
+ [gl_cv_func_sched_getaffinity3],
+ [AC_COMPILE_IFELSE(
+ [AC_LANG_PROGRAM(
+ [[#include <errno.h>
+ #include <sched.h>]],
+ [[sched_getaffinity (0, 0, (cpu_set_t *) 0);]])],
+ [gl_cv_func_sched_getaffinity3=yes],
+ [gl_cv_func_sched_getaffinity3=no])
+ ])
+ if test $gl_cv_func_sched_getaffinity3 = yes; then
+ AC_DEFINE([HAVE_SCHED_GETAFFINITY_LIKE_GLIBC], [1],
+ [Define to 1 if sched_getaffinity has a glibc compatible declaration.])
+ fi
+ fi
+])