Use configure to find the processor count

configure.ac now finds how to count the CPUs in a system. Currently
the getconf method and sysctl methods are supported. Adding more is
easy enough.

Signed-off-by: Dan McGregor <dan.mcgregor@usask.ca>
This commit is contained in:
Dan McGregor 2017-03-01 22:22:13 -06:00
parent f2f782dd1c
commit 6d1bcaa2f5
3 changed files with 12 additions and 1 deletions

View File

@ -81,6 +81,7 @@ export LIBS := @LIBS@
export INTL_LIBS := @INTL_LIBS@ export INTL_LIBS := @INTL_LIBS@
export curses_hdr := @ac_ct_curses_hdr@ export curses_hdr := @ac_ct_curses_hdr@
export gettext := @gettext@ export gettext := @gettext@
export CPU_COUNT := @CPU_COUNT@
# config options to push down to kconfig # config options to push down to kconfig
KCONFIG:= @kconfig_options@ KCONFIG:= @kconfig_options@
@ -192,6 +193,7 @@ define sed_it
-e 's,@@CT_awk@@,$(awk),g;' \ -e 's,@@CT_awk@@,$(awk),g;' \
-e 's,@@CT_wget@@,$(wget),g;' \ -e 's,@@CT_wget@@,$(wget),g;' \
-e 's,@@CT_curl@@,$(curl),g;' \ -e 's,@@CT_curl@@,$(curl),g;' \
-e 's,@@CT_cpucount@@,$(CPU_COUNT),g;' \
$< >$@ $< >$@
endef endef

View File

@ -248,6 +248,15 @@ ACX_SET_KCONFIG_OPTION([stat_flavor_BSD])
test "$acx_cv_stat_flavor" = "GNU" && stat_flavor_GNU=y test "$acx_cv_stat_flavor" = "GNU" && stat_flavor_GNU=y
ACX_SET_KCONFIG_OPTION([stat_flavor_GNU]) ACX_SET_KCONFIG_OPTION([stat_flavor_GNU])
#Find out how to count CPUs
AC_CACHE_CHECK([whether to use getconf or sysctl to count CPUs],
[acx_cv_cpu_count],
[getconf _NPROCESSORS_ONLN >/dev/null 2>&1 && \
acx_cv_cpu_count="getconf _NPROCESSORS_ONLN"
sysctl -n hw.ncpu >/dev/null 2>&1 && \
acx_cv_cpu_count="sysctl -n hw.ncpu"])
AC_SUBST(CPU_COUNT, "$acx_cv_cpu_count")
#-------------------------------------------------------------------- #--------------------------------------------------------------------
# Still boring, but remember the path, now... # Still boring, but remember the path, now...
#-------------------------------------------------------------------- #--------------------------------------------------------------------

View File

@ -534,7 +534,7 @@ if [ -z "${CT_RESTART}" ]; then
fi fi
# Use the number of processors+1 when automatically setting the number of # Use the number of processors+1 when automatically setting the number of
# parallel jobs. Fall back to 1 if the host doesn't use GLIBC. # parallel jobs. Fall back to 1 if the host doesn't use GLIBC.
AUTO_JOBS=$((`getconf _NPROCESSORS_ONLN 2> /dev/null || echo 0` + 1)) AUTO_JOBS=$((`@@CT_cpucount@@ 2>/dev/null || echo 0` + 1))
[ ${CT_PARALLEL_JOBS} -eq 0 ] && JOBSFLAGS="${JOBSFLAGS} -j${AUTO_JOBS}" [ ${CT_PARALLEL_JOBS} -eq 0 ] && JOBSFLAGS="${JOBSFLAGS} -j${AUTO_JOBS}"
[ ${CT_PARALLEL_JOBS} -gt 0 ] && JOBSFLAGS="${JOBSFLAGS} -j${CT_PARALLEL_JOBS}" [ ${CT_PARALLEL_JOBS} -gt 0 ] && JOBSFLAGS="${JOBSFLAGS} -j${CT_PARALLEL_JOBS}"
JOBSFLAGS="${JOBSFLAGS} -l${CT_LOAD}" JOBSFLAGS="${JOBSFLAGS} -l${CT_LOAD}"