Bug 212592

Summary: Default MAKE_JOBS_NUMBER should come from cpuset, not kern.smp.cpus
Product: Ports & Packages Reporter: Colin Percival <cperciva>
Component: Ports FrameworkAssignee: Port Management Team <portmgr>
Status: Closed Feedback Timeout    
Severity: Affects Only Me CC: ports-bugs
Priority: ---    
Version: Latest   
Hardware: Any   
OS: Any   

Description Colin Percival freebsd_committer 2016-09-11 23:52:15 UTC
The default MAKE_JOBS_NUMBER comes from `sysctl -n kern.smp.cpus`.  This is fine in most cases, but if cpuset(1) has been used to limit the CPUs available, we will end up running too many parallel build steps -- one per CPU present, rather than one per CPU available.

Unfortunately cpuset(1) doesn't seem to have an obvious "tell me how many CPUs I have access to" flag, but something like

-_SMP_CPUS!=             ${SYSCTL} -n kern.smp.cpus
+_SMP_CPUS!=             cpuset -g -p $$ | cut -f 2 -d : | tr , '\n' | wc -l

should probably do the job.  (Or, we could just fix cpuset(1) and check OSVERSION to decide whether to query the sysctl or query cpuset.)
Comment 1 Baptiste Daroussin freebsd_committer 2019-09-05 08:45:33 UTC
when trying with:
cpuset -g -p $$ | awk -F: '/^pid [0-9]+ mask/ { print split($$2,a, ",") }'

(your example didn't work out of box, due to cpuset reporting 2 lines now.)

Anyway using this we end up with cpuset: getaffinity: Operation not permitted