cpuinfo_other.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. //go:build !linux
  2. /*
  3. Copyright The containerd Authors.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. */
  14. package platforms
  15. import (
  16. "fmt"
  17. "runtime"
  18. "github.com/containerd/containerd/errdefs"
  19. )
  20. func getCPUVariant() (string, error) {
  21. var variant string
  22. if runtime.GOOS == "windows" || runtime.GOOS == "darwin" {
  23. // Windows/Darwin only supports v7 for ARM32 and v8 for ARM64 and so we can use
  24. // runtime.GOARCH to determine the variants
  25. switch runtime.GOARCH {
  26. case "arm64":
  27. variant = "v8"
  28. case "arm":
  29. variant = "v7"
  30. default:
  31. variant = "unknown"
  32. }
  33. } else if runtime.GOOS == "freebsd" {
  34. // FreeBSD supports ARMv6 and ARMv7 as well as ARMv4 and ARMv5 (though deprecated)
  35. // detecting those variants is currently unimplemented
  36. switch runtime.GOARCH {
  37. case "arm64":
  38. variant = "v8"
  39. default:
  40. variant = "unknown"
  41. }
  42. } else {
  43. return "", fmt.Errorf("getCPUVariant for OS %s: %v", runtime.GOOS, errdefs.ErrNotImplemented)
  44. }
  45. return variant, nil
  46. }