LEFT | RIGHT |
1 // Copyright 2011 The Go Authors. All rights reserved. | 1 // Copyright 2011 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package co | 5 package co |
6 | 6 |
7 import ( | 7 import ( |
8 "bytes" | 8 "bytes" |
9 "fmt" | |
10 "io/ioutil" | 9 "io/ioutil" |
11 "os" | 10 "os" |
12 ) | 11 ) |
13 | 12 |
14 func sysInitOS() { | 13 func sysInitOS() { |
15 » f, err := os.Open("/proc/cpuingo") | 14 » f, err := os.Open("/proc/cpuinfo") |
16 if err != nil { | 15 if err != nil { |
17 » » fmt.Fprintf(os.Stderr, "co.SysConf: failed to open /proc/cpuinfo
(%s)\n", err) | 16 » » print("co.SysConf: failed to open /proc/cpuinfo (", err.String()
, ")\n") |
18 return | 17 return |
19 } | 18 } |
20 » info, err := ioutil.RealAll(f) | 19 » info, err := ioutil.ReadAll(f) |
21 if err != nil { | 20 if err != nil { |
22 » » fmt.Fprintf(os.Stderr, "co.SysConf: failed to read /proc/cpuinfo
(%s)\n", err) | 21 » » print("co.SysConf: failed to read /proc/cpuinfo (", err.String()
, ")\n") |
23 return | 22 return |
24 } | 23 } |
25 siblings := sysParam(info, "siblings") | 24 siblings := sysParam(info, "siblings") |
| 25 assignMax(&siblings, 1) |
26 cores := sysParam(info, "cpu cores") | 26 cores := sysParam(info, "cpu cores") |
27 » sysConf[ConfThreadCount] = bytes.Count(info, "processor") | 27 » assignMax(&cores, 1) |
| 28 » sysConf[ConfThreadCount] = bytes.Count(info, bytes.NewBufferString("proc
essor").Bytes()) |
28 sysConf[ConfProcessorCount] = sysConf[ConfThreadCount] / siblings | 29 sysConf[ConfProcessorCount] = sysConf[ConfThreadCount] / siblings |
29 sysConf[ConfCoreCount] = sysConf[ConfProcessorCount] * cores | 30 sysConf[ConfCoreCount] = sysConf[ConfProcessorCount] * cores |
30 sysConf[ConfNumaNodeCount] = sysConf[ConfProcessorCount] | 31 sysConf[ConfNumaNodeCount] = sysConf[ConfProcessorCount] |
31 sysConf[ConfCacheLineSize] = sysParam(info, "cache_alignment") | 32 sysConf[ConfCacheLineSize] = sysParam(info, "cache_alignment") |
32 } | 33 } |
LEFT | RIGHT |