diff --git a/doc/macports.conf.5 b/doc/macports.conf.5 index bd9d53df4b..deb896e201 100644 --- a/doc/macports.conf.5 +++ b/doc/macports.conf.5 @@ -301,6 +301,21 @@ T} .sp 1 .RE .PP +indexjobs +.RS 4 +Number of threads to use when indexing ports\&. 0 is a special value meaning "the number of CPU cores\&." +.TS +tab(:); +lt lt. +T{ +\fBDefault:\fR +T}:T{ +0 +T} +.TE +.sp 1 +.RE +.PP portautoclean .RS 4 Automatic cleaning of the build directory of a given port after it has been installed\&. diff --git a/doc/macports.conf.5.txt b/doc/macports.conf.5.txt index 9eb6295734..14543d5e67 100644 --- a/doc/macports.conf.5.txt +++ b/doc/macports.conf.5.txt @@ -113,6 +113,11 @@ buildmakejobs:: physical memory plus one, whichever is less." *Default:*;; 0 +indexjobs:: + Number of threads to use when indexing ports. 0 is a special value meaning + "the number of CPU cores." + *Default:*;; 0 + portautoclean:: Automatic cleaning of the build directory of a given port after it has been installed. diff --git a/doc/macports.conf.in b/doc/macports.conf.in index 590b7414c0..9302a7810a 100644 --- a/doc/macports.conf.in +++ b/doc/macports.conf.in @@ -127,6 +127,11 @@ variants_conf @MPCONFIGDIR_EXPANDED@/variants.conf # - gigabytes of physical memory + 1 #buildmakejobs 0 +# Number of threads to use when indexing ports. If set +# to 0, the number of threads will be the number of +# automatically-detected CPU cores +#indexjobs 0 + # umask value to use when a port installs its files. #destroot_umask 022 diff --git a/src/macports1.0/macports.tcl b/src/macports1.0/macports.tcl index 4f0513317d..8ed5946dc5 100644 --- a/src/macports1.0/macports.tcl +++ b/src/macports1.0/macports.tcl @@ -56,6 +56,7 @@ namespace eval macports { startupitem_autostart startupitem_type startupitem_install \ place_worksymlink xcodeversion xcodebuildcmd xcodecltversion xcode_license_unaccepted \ configureccache ccache_size configuredistcc configurepipe buildnicevalue buildmakejobs \ + indexjobs \ universal_archs build_arch macosx_sdk_version macosx_deployment_target \ macportsuser proxy_override_env proxy_http proxy_https proxy_ftp proxy_rsync proxy_skip \ master_site_local patch_site_local archive_site_local buildfromsource \ @@ -81,6 +82,7 @@ namespace eval macports { rsync_server rsync_options rsync_dir startupitem_autostart startupitem_type startupitem_install \ place_worksymlink macportsuser sudo_user \ configureccache ccache_dir ccache_size configuredistcc configurepipe buildnicevalue buildmakejobs \ + indexjobs \ applications_dir applications_dir_frozen current_phase frameworks_dir frameworks_dir_frozen \ developer_dir universal_archs build_arch os_arch os_endian os_version os_major os_minor \ os_platform os_subplatform macos_version macos_version_major macosx_version macosx_sdk_version \ @@ -950,6 +952,7 @@ proc mportinit {{up_ui_options {}} {up_options {}} {up_variations {}}} { macports::configurepipe \ macports::buildnicevalue \ macports::buildmakejobs \ + macports::indexjobs \ macports::host_blacklist \ macports::preferred_hosts \ macports::keeplogs \ @@ -1538,6 +1541,9 @@ match macports.conf.default." if {![info exists buildmakejobs]} { set buildmakejobs 0 } + if {![info exists indexjobs]} { + set indexjobs 0 + } # default user to run as when privileges can be dropped if {![info exists macportsuser]} { @@ -6584,12 +6590,32 @@ proc macports::get_parallel_jobs {{mem_restrict yes}} { variable buildmakejobs; variable os_platform if {[string is integer -strict $buildmakejobs] && $buildmakejobs > 0} { set jobs $buildmakejobs - } elseif {$os_platform eq "darwin" && $buildmakejobs == 0 - && ![catch {sysctl hw.activecpu} cpus]} { + } else { + set jobs [macports::calc_auto_max_jobs $mem_restrict] + } + return $jobs +} + +# Get actual number of parallel jobs based on indexjobs, which may +# be 0 for automatic selection. +proc macports::get_index_jobs {{mem_restrict no}} { + variable indexjobs; variable os_platform + if {[string is integer -strict $indexjobs] && $indexjobs > 0} { + set jobs $indexjobs + } else { + set jobs [macports::calc_auto_max_jobs $mem_restrict] + } + return $jobs +} + +# Calculate jobs based on automatic selection. +proc macports::calc_auto_max_jobs {{mem_restrict yes}} { + variable os_platform + if {$os_platform eq "darwin" && ![catch {sysctl hw.activecpu} cpus]} { set jobs $cpus - if {$mem_restrict && ![catch {sysctl hw.memsize} memsize] - && $jobs > $memsize / (1024 * 1024 * 1024) + 1} { - set jobs [expr {$memsize / (1024 * 1024 * 1024) + 1}] + if {$mem_restrict && ![catch {sysctl hw.memsize} memsize]} { + set memsize_gb [expr {($memsize / round(pow(1024,3))) + 1}] + set jobs [expr min($jobs, $memsize_gb)] } } else { set jobs 2 diff --git a/src/port/portindex.tcl b/src/port/portindex.tcl index 1ef9502676..a71cfa240a 100644 --- a/src/port/portindex.tcl +++ b/src/port/portindex.tcl @@ -211,7 +211,7 @@ proc init_threads {} { append worker_init_script \ [list set oldmtime $oldmtime] \n } - set maxjobs [macports::get_parallel_jobs no] + set maxjobs [macports::get_index_jobs] set poolid [tpool::create -minworkers 1 -maxworkers $maxjobs -initcmd $worker_init_script] set pending_jobs [dict create] set nextjobnum 0