News for hackers. Stuff that matters.
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

There are no comments on this comment yet.