diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 60dbe12d2..8e2ed946f 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -33,10 +33,7 @@ "message": 5 } }, - "group": { - "kind": "build", - "isDefault": true - } + "group": "build" }, { "label": "B2 Engine Infer", diff --git a/doc/src/history.adoc b/doc/src/history.adoc index 68908489e..23a81932f 100644 --- a/doc/src/history.adoc +++ b/doc/src/history.adoc @@ -23,3 +23,6 @@ Other changes in this release: * Add s390x CPU and support in gcc/clang. -- _Neale Ferguson_ * Support importing pkg-config packages. -- _Dmitry Arkhipov_ * Support for leak sanitizer. -- _Damian Jarek_ +* Fix missing `/manifest` option in clang-win to fix admin elevation for exes with "update" in the name. -- Peter Dimov +* Add `freertos` to `os` feature. -- tee3 +* Default parallel jobs (`-jX`) to the available CPU threads. -- _Rene Rivera_ diff --git a/src/engine/build.bat b/src/engine/build.bat index 8f8f9c779..e0233afed 100644 --- a/src/engine/build.bat +++ b/src/engine/build.bat @@ -175,7 +175,7 @@ set B2_SOURCES=%B2_SOURCES% glob.cpp hash.cpp hcache.cpp hdrmacro.cpp headers.cp set B2_SOURCES=%B2_SOURCES% jambase.cpp jamgram.cpp lists.cpp make.cpp make1.cpp md5.cpp mem.cpp modules.cpp set B2_SOURCES=%B2_SOURCES% native.cpp object.cpp option.cpp output.cpp parse.cpp pathnt.cpp set B2_SOURCES=%B2_SOURCES% pathsys.cpp regexp.cpp rules.cpp scan.cpp search.cpp strings.cpp -set B2_SOURCES=%B2_SOURCES% subst.cpp timestamp.cpp variable.cpp w32_getreg.cpp +set B2_SOURCES=%B2_SOURCES% subst.cpp sysinfo.cpp timestamp.cpp variable.cpp w32_getreg.cpp set B2_SOURCES=%B2_SOURCES% modules/order.cpp set B2_SOURCES=%B2_SOURCES% modules/path.cpp set B2_SOURCES=%B2_SOURCES% modules/property-set.cpp diff --git a/src/engine/build.sh b/src/engine/build.sh index 85c205e20..a1e4cd335 100755 --- a/src/engine/build.sh +++ b/src/engine/build.sh @@ -415,6 +415,7 @@ B2_SOURCES="\ search.cpp \ strings.cpp \ subst.cpp \ + sysinfo.cpp \ timestamp.cpp \ variable.cpp \ w32_getreg.cpp \ diff --git a/src/engine/jam.cpp b/src/engine/jam.cpp index b6185ba60..08c826bdc 100644 --- a/src/engine/jam.cpp +++ b/src/engine/jam.cpp @@ -134,6 +134,7 @@ #include "timestamp.h" #include "variable.h" #include "execcmd.h" +#include "sysinfo.h" /* Macintosh is "special" */ #ifdef OS_MAC @@ -373,6 +374,11 @@ int main( int argc, char * * argv, char * * arg_environ ) return EXITOK; } + /* Set default parallel jobs to match cpu threads. This can be overridden + the usual way with -jX or PARALLELISM env var. */ + b2::system_info sys_info; + globs.jobs = sys_info.cpu_thread_count(); + /* Pick up interesting options. */ if ( ( s = getoptval( optv, 'n', 0 ) ) ) { diff --git a/src/engine/sysinfo.cpp b/src/engine/sysinfo.cpp new file mode 100644 index 000000000..f72121eac --- /dev/null +++ b/src/engine/sysinfo.cpp @@ -0,0 +1,62 @@ +/* Copyright 2019 Rene Rivera + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) + */ + +#include "sysinfo.h" +#include "jam.h" +#include "output.h" + +#ifdef OS_MACOSX +#include +#include +#endif + + +b2::system_info::system_info() +{ +} + +unsigned int b2::system_info::cpu_core_count() +{ + if (cpu_core_count_ == 0) + { + #ifdef OS_MACOSX + int out_hw_ncpu = 0; + size_t len_hw_ncpu = sizeof(out_hw_ncpu); + int result = ::sysctlbyname( + "hw.physicalcpu", &out_hw_ncpu, &len_hw_ncpu, nullptr, 0); + if (result == 0) + { + cpu_core_count_ = out_hw_ncpu; + } + #endif + if (cpu_core_count_ == 0) + { + cpu_core_count_ = 1; + } + } + return cpu_core_count_; +} + +unsigned int b2::system_info::cpu_thread_count() +{ + if (cpu_thread_count_ == 0) + { + #ifdef OS_MACOSX + int out_hw_ncpu = 0; + size_t len_hw_ncpu = sizeof(out_hw_ncpu); + int result = ::sysctlbyname( + "hw.logicalcpu", &out_hw_ncpu, &len_hw_ncpu, nullptr, 0); + if (result == 0) + { + cpu_thread_count_ = out_hw_ncpu; + } + #endif + if (cpu_thread_count_ == 0) + { + cpu_thread_count_ = cpu_core_count(); + } + } + return cpu_thread_count_; +} diff --git a/src/engine/sysinfo.h b/src/engine/sysinfo.h new file mode 100644 index 000000000..28c42558f --- /dev/null +++ b/src/engine/sysinfo.h @@ -0,0 +1,46 @@ +/* Copyright 2019 Rene Rivera + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) + */ + +#ifndef B2_SYSINFO_H +#define B2_SYSINFO_H + +# include "config.h" + +namespace b2 +{ + /* + Provides information about the system, hardware and software, we are + running in. + */ + class system_info + { + public: + + system_info(); + + /* + Returns the number of physical CPU cores if available. Otherwise + returns 1. + + Currently implemented for: OS_MACOSX. + */ + unsigned int cpu_core_count(); + + /* + Returns the number of logical CPU threads is available. Otherwise + returns `spu_core_count()`. + + Currently implemented for: OS_MACOSX. + */ + unsigned int cpu_thread_count(); + + private: + + unsigned int cpu_core_count_ = 0; + unsigned int cpu_thread_count_ = 0; + }; +} + +#endif