Re:The challenges of working out how many CPUs your program ...
by telotortium on Tuesday July 23, 2024 @03:26PM
(#41049801)
See also my comment for how to determine this: https://news.ycombinator.com/item?id=38185277
[ Parent
| on HN ]
Re:The challenges of working out how many CPUs your program ...
by Daviey on Tuesday July 23, 2024 @06:20PM
(#41051585)
That's good, but i'd prefer not to assume perl is there. Perhaps something like this untested POSIX shell might be better?
if [ -e /sys/fs/cgroup/cpu/cpu.cfs_quota_us ] && [ -e /sys/fs/cgroup/cpu/cpu.cfs_period_us ]; then
read -r quota < /sys/fs/cgroup/cpu/cpu.cfs_quota_us
read -r period < /sys/fs/cgroup/cpu/cpu.cfs_period_us
# Perform division and rounding
GOMAXPROCS=$(( (quota + period - 1) / period ))
else
GOMAXPROCS=$(nproc)
fi
export GOMAXPROCS