Below UNIX command:
$ lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 4
On-line CPU(s) list: 0-3
Thread(s) per core: 2
Core(s) per socket: 2
Socket(s): 1
shows,
CPU(s): 4
Thread(s) per core: 2
which is 4 X 2 = 8 logical processors. Correct me.
Below is another Linux command:
$ cat /proc/cpuinfo
processor : 0
....
cpu cores : 2
.....
processor : 1
.....
cpu cores : 2
.....
processor : 2
.....
cpu cores : 2
.....
processor : 3
.....
cpu cores : 2
.....
$
But the below program shows only 4 logical processors:
package main
import (
"fmt"
"runtime"
)
func main() {
fmt.Println(runtime.GOMAXPROCS(0)) // gives 4
fmt.Println(runtime.NumCPU()) // gives 4
}
Output:
$ go install github.com/myhub/cs61a
$ bin/cs61a
4
4
code$
More details:
$ go version
go version go1.14.1 linux/amd64
$ uname -a
Linux mohet01-ubuntu 4.15.0-99-generic #100-Ubuntu SMP Wed Apr 22 20:32:56 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
Documentation says,
NumCPU returns the number of logical CPUs usable by the current process.
My understanding is,
Go scheduler creates OS threads(M
) which will be equivalent to number of logical processors.
Why runtime api does not give value as 8?