m1cpu

package module
v0.1.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 5, 2023 License: MPL-2.0 Imports: 0 Imported by: 1

README

m1cpu

Go Reference MPL License Run CI Tests

The go-m1cpu module is a library for inspecting Apple Silicon CPUs in Go.

Use the m1cpu Go package for looking up the CPU frequency for Apple M1 and M2 CPUs.

Install

go get github.com/shoenig/go-m1cpu@latest

CGO

This package requires the use of CGO.

Extracting the CPU properties is done via Apple's IOKit framework, which is accessible only through system C libraries.

Example

Simple Go program to print Apple Silicon M1/M2 CPU speeds.

package main

import (
	"fmt"

	"github.com/shoenig/go-m1cpu"
)

func main() {
	fmt.Println("Apple Silicon", m1cpu.IsAppleSilicon())

	fmt.Println("pCore GHz", m1cpu.PCoreGHz())
	fmt.Println("eCore GHz", m1cpu.ECoreGHz())

	fmt.Println("pCore Hz", m1cpu.PCoreHz())
	fmt.Println("eCore Hz", m1cpu.ECoreHz())
}

Using go test to print out available information.

➜ go test -v -run Show
=== RUN   Test_Show
    cpu_test.go:42: pCore Hz 3504000000
    cpu_test.go:43: eCore Hz 2424000000
    cpu_test.go:44: pCore GHz 3.504
    cpu_test.go:45: eCore GHz 2.424
    cpu_test.go:46: pCore count 8
    cpu_test.go:47: eCoreCount 4
    cpu_test.go:50: pCore Caches 196608 131072 16777216
    cpu_test.go:53: eCore Caches 131072 65536 4194304
--- PASS: Test_Show (0.00s)

License

Open source under the MPL

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ECoreCache added in v0.1.4

func ECoreCache() (int, int, int)

ECoreCacheSize requires darwin/arm64

Example
l1inst, l1data, l2 := ECoreCache()
fmt.Println(l1inst, l1data, l2)
Output:

func ECoreCount added in v0.1.1

func ECoreCount() int

ECoreCount requires darwin/arm64

Example
value := ECoreCount()
fmt.Println(value)
Output:

func ECoreGHz

func ECoreGHz() float64

ECoreGHz requires darwin/arm64

Example
value := ECoreGHz()
fmt.Println(value)
Output:

func ECoreHz

func ECoreHz() uint64

ECoreHZ requires darwin/arm64

Example
value := ECoreHz()
fmt.Println(value)
Output:

func IsAppleSilicon

func IsAppleSilicon() bool

IsAppleSilicon return false on this platform.

Example
value := IsAppleSilicon()
fmt.Println(value)
Output:

func ModelName added in v0.1.4

func ModelName() string

ModelName requires darwin/arm64

Example
value := ModelName()
fmt.Println(value)
Output:

func PCoreCache added in v0.1.4

func PCoreCache() (int, int, int)

PCoreCacheSize requires darwin/arm64

Example
l1inst, l1data, l2 := PCoreCache()
fmt.Println(l1inst, l1data, l2)
Output:

func PCoreCount added in v0.1.1

func PCoreCount() int

PCoreCount requires darwin/arm64

Example
value := PCoreCount()
fmt.Println(value)
Output:

func PCoreGHz

func PCoreGHz() float64

PCoreGHz requires darwin/arm64

Example
value := PCoreGHz()
fmt.Println(value)
Output:

func PCoreHz

func PCoreHz() uint64

PCoreHZ requires darwin/arm64

Example
value := PCoreHz()
fmt.Println(value)
Output:

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL