2018-02-05 21:05:59 +00:00
|
|
|
package sysinfo // import "github.com/docker/docker/pkg/sysinfo"
|
2016-06-25 14:26:00 +00:00
|
|
|
|
2023-04-25 08:05:11 +00:00
|
|
|
import "golang.org/x/sys/unix"
|
2016-06-25 14:26:00 +00:00
|
|
|
|
|
|
|
// numCPU queries the system for the count of threads available
|
|
|
|
// for use to this process.
|
|
|
|
//
|
|
|
|
// Returns 0 on errors. Use |runtime.NumCPU| in that case.
|
|
|
|
func numCPU() int {
|
|
|
|
// Gets the affinity mask for a process: The very one invoking this function.
|
2019-06-18 17:26:56 +00:00
|
|
|
var mask unix.CPUSet
|
2023-04-25 08:05:11 +00:00
|
|
|
err := unix.SchedGetaffinity(0, &mask)
|
2019-06-18 17:26:56 +00:00
|
|
|
if err != nil {
|
2016-06-25 14:26:00 +00:00
|
|
|
return 0
|
|
|
|
}
|
2019-06-18 17:26:56 +00:00
|
|
|
return mask.Count()
|
2016-06-25 14:26:00 +00:00
|
|
|
}
|