You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

proc_cpuinfo_linux.go 1.1KB

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