numcpu_linux.go 467 B

1234567891011121314151617
  1. package sysinfo // import "github.com/docker/docker/pkg/sysinfo"
  2. import "golang.org/x/sys/unix"
  3. // numCPU queries the system for the count of threads available
  4. // for use to this process.
  5. //
  6. // Returns 0 on errors. Use |runtime.NumCPU| in that case.
  7. func numCPU() int {
  8. // Gets the affinity mask for a process: The very one invoking this function.
  9. var mask unix.CPUSet
  10. err := unix.SchedGetaffinity(0, &mask)
  11. if err != nil {
  12. return 0
  13. }
  14. return mask.Count()
  15. }