golang.org/x/sys@v0.9.0/cpu/proc_cpuinfo_linux.go (about) 1 // Copyright 2022 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 //go:build linux && arm64 6 // +build linux,arm64 7 8 package cpu 9 10 import ( 11 "errors" 12 "io" 13 "os" 14 "strings" 15 ) 16 17 func readLinuxProcCPUInfo() error { 18 f, err := os.Open("/proc/cpuinfo") 19 if err != nil { 20 return err 21 } 22 defer f.Close() 23 24 var buf [1 << 10]byte // enough for first CPU 25 n, err := io.ReadFull(f, buf[:]) 26 if err != nil && err != io.ErrUnexpectedEOF { 27 return err 28 } 29 in := string(buf[:n]) 30 const features = "\nFeatures : " 31 i := strings.Index(in, features) 32 if i == -1 { 33 return errors.New("no CPU features found") 34 } 35 in = in[i+len(features):] 36 if i := strings.Index(in, "\n"); i != -1 { 37 in = in[:i] 38 } 39 m := map[string]*bool{} 40 41 initOptions() // need it early here; it's harmless to call twice 42 for _, o := range options { 43 m[o.Name] = o.Feature 44 } 45 // The EVTSTRM field has alias "evstrm" in Go, but Linux calls it "evtstrm". 46 m["evtstrm"] = &ARM64.HasEVTSTRM 47 48 for _, f := range strings.Fields(in) { 49 if p, ok := m[f]; ok { 50 *p = true 51 } 52 } 53 return nil 54 }