Skip to content

Commit

Permalink
Use numcpus.GetConfigured in getNprocsConf on Linux
Browse files Browse the repository at this point in the history
GetConfigured added in github.com/tklauser/numcpus v0.3.0 already
implements the same functionality, so use it.
  • Loading branch information
tklauser committed Aug 17, 2021
1 parent f6b503c commit 7a5cfaa
Showing 1 changed file with 2 additions and 16 deletions.
18 changes: 2 additions & 16 deletions sysconf_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,23 +117,9 @@ func getNprocs() int64 {
}

func getNprocsConf() int64 {
// TODO(tk): read /sys/devices/system/cpu/present instead?
d, err := os.Open("/sys/devices/system/cpu")
count, err := numcpus.GetConfigured()
if err == nil {
defer d.Close()
fis, err := d.Readdir(-1)
if err == nil {
count := int64(0)
for _, fi := range fis {
if name := fi.Name(); fi.IsDir() && strings.HasPrefix(name, "cpu") {
_, err := strconv.ParseInt(name[3:], 10, 64)
if err == nil {
count++
}
}
}
return count
}
return int64(count)
}

// TODO(tk): fall back to reading /proc/cpuinfo on legacy systems
Expand Down

0 comments on commit 7a5cfaa

Please # to comment.