Skip to content

Commit

Permalink
base: add new config 'indexjobs', controlling portindex threads
Browse files Browse the repository at this point in the history
  • Loading branch information
mascguy committed Jan 21, 2025
1 parent bdeaa81 commit f5226a0
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 7 deletions.
15 changes: 15 additions & 0 deletions doc/macports.conf.5
Original file line number Diff line number Diff line change
Expand Up @@ -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\&.
Expand Down
5 changes: 5 additions & 0 deletions doc/macports.conf.5.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions doc/macports.conf.in
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
38 changes: 32 additions & 6 deletions src/macports1.0/macports.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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 \
Expand Down Expand Up @@ -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 \
Expand Down Expand Up @@ -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]} {
Expand Down Expand Up @@ -6581,15 +6587,35 @@ proc macports::unobscure_maintainers {list} {
# Get actual number of parallel jobs based on buildmakejobs, which may
# be 0 for automatic selection.
proc macports::get_parallel_jobs {{mem_restrict yes}} {
variable buildmakejobs; variable os_platform
variable buildmakejobs
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
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
Expand Down
2 changes: 1 addition & 1 deletion src/port/portindex.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f5226a0

Please sign in to comment.