1
2
3
4
5
6
7 package cpu
8
9 import (
10 "errors"
11 "io"
12 "os"
13 "strings"
14 )
15
16 func readLinuxProcCPUInfo() error {
17 f, err := os.Open("/proc/cpuinfo")
18 if err != nil {
19 return err
20 }
21 defer f.Close()
22
23 var buf [1 << 10]byte
24 n, err := io.ReadFull(f, buf[:])
25 if err != nil && err != io.ErrUnexpectedEOF {
26 return err
27 }
28 in := string(buf[:n])
29 const features = "\nFeatures : "
30 i := strings.Index(in, features)
31 if i == -1 {
32 return errors.New("no CPU features found")
33 }
34 in = in[i+len(features):]
35 if i := strings.Index(in, "\n"); i != -1 {
36 in = in[:i]
37 }
38 m := map[string]*bool{}
39
40 initOptions()
41 for _, o := range options {
42 m[o.Name] = o.Feature
43 }
44
45 m["evtstrm"] = &ARM64.HasEVTSTRM
46
47 for _, f := range strings.Fields(in) {
48 if p, ok := m[f]; ok {
49 *p = true
50 }
51 }
52 return nil
53 }
54
View as plain text