github.com/lrita/numa@v1.0.2/getcpu_linux.go (about)

     1  //go:build !amd64
     2  // +build !amd64
     3  
     4  package numa
     5  
     6  import (
     7  	"syscall"
     8  	"unsafe"
     9  )
    10  
    11  // GetCPUAndNode returns the node id and cpu id which current caller running on.
    12  // https://man7.org/linux/man-pages/man2/getcpu.2.html
    13  func GetCPUAndNode() (cpu int, node int) {
    14  	_, _, errno := syscall.RawSyscall(syscall.SYS_GETCPU,
    15  		uintptr(unsafe.Pointer(&cpu)),
    16  		uintptr(unsafe.Pointer(&node)),
    17  		0)
    18  	if errno != 0 {
    19  		cpu = 0
    20  		node = 0
    21  	}
    22  	return
    23  }