github.com/gogf/gkafka@v1.0.1-0.20190702070843-033a14468069/third/golang.org/x/sys/cpu/cpu_linux.go (about) 1 // Copyright 2018 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 //+build !amd64,!amd64p32,!386 6 7 package cpu 8 9 import ( 10 "encoding/binary" 11 "io/ioutil" 12 "runtime" 13 ) 14 15 const ( 16 _AT_HWCAP = 16 17 _AT_HWCAP2 = 26 18 19 procAuxv = "/proc/self/auxv" 20 21 uintSize uint = 32 << (^uint(0) >> 63) 22 ) 23 24 // For those platforms don't have a 'cpuid' equivalent we use HWCAP/HWCAP2 25 // These are initialized in cpu_$GOARCH.go 26 // and should not be changed after they are initialized. 27 var HWCap uint 28 var HWCap2 uint 29 30 func init() { 31 buf, err := ioutil.ReadFile(procAuxv) 32 if err != nil { 33 panic("read proc auxv failed: " + err.Error()) 34 } 35 36 pb := int(uintSize / 8) 37 38 for i := 0; i < len(buf)-pb*2; i += pb * 2 { 39 var tag, val uint 40 switch uintSize { 41 case 32: 42 tag = uint(binary.LittleEndian.Uint32(buf[i:])) 43 val = uint(binary.LittleEndian.Uint32(buf[i+pb:])) 44 case 64: 45 if runtime.GOARCH == "ppc64" { 46 tag = uint(binary.BigEndian.Uint64(buf[i:])) 47 val = uint(binary.BigEndian.Uint64(buf[i+pb:])) 48 } else { 49 tag = uint(binary.LittleEndian.Uint64(buf[i:])) 50 val = uint(binary.LittleEndian.Uint64(buf[i+pb:])) 51 } 52 } 53 switch tag { 54 case _AT_HWCAP: 55 HWCap = val 56 case _AT_HWCAP2: 57 HWCap2 = val 58 } 59 } 60 doinit() 61 }