smc

package module
v0.0.0-...-4a31024 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2026 License: MIT Imports: 6 Imported by: 1

README

go-smc

Golang library to read temperatures and fan speeds from the macOS System Management Controller (SMC). Works on both Intel and Apple Silicon Macs.

go get github.com/caseymrm/go-smc
smc.OpenSMC()
defer smc.CloseSMC()

fmt.Println("CPU temperature:", smc.ReadTemperature(), "°C")
fmt.Println("Fan speeds:",       smc.ReadFanSpeeds(),  "RPM")

for key, tempC := range smc.ReadTemperatures() {
    fmt.Printf("  %s = %.2f °C\n", key, tempC)
}

Apple Silicon

Both fan and temperature reads go through AppleSMC on all architectures — only the keys and data type differ:

Reading Intel Apple Silicon
CPU temperature TC0P (sp78) Tp01Tp16 (flt)
Fan speed F0AcF17Ac (fpe2) F0AcF17Ac (flt)

ReadTemperature() returns the hottest sensor across whatever keys the SoC populates (M1 reports fewer than M2/M3/M4). ReadTemperatures() returns the full map of populated sensors if you need per-cluster detail.

Fanless Macs (M1/M2 MacBook Air, Mac mini, etc.) have no F*Ac keys at all; ReadFanSpeeds() returns an empty slice there.

License

MIT — see LICENSE.

The C in smc.c / smc.h is an independent reimplementation written against two references, both cited in the file headers:

  • Apple's APSL-licensed PowerManagement source, for the AppleSMC IOKit ABI (struct layout, ioctl indices).
  • beltex/SMCKit (MIT, Swift), for the shape of a clean reader.

It is not derived from the GPL "Apple SMC Tool" by devnull (2006) that's copied across many SMC projects. Earlier versions of this repo bundled that GPL file under an MIT LICENSE, which was an error; #1 tracked and resolved that conflict.

Documentation

Overview

Package smc reads sensor values (temperatures, fan speeds) from the macOS AppleSMC kernel extension. It works on both Intel and Apple Silicon Macs; the difference is the set of keys and their data type:

  • Intel: temperatures live under TC0P / TC0E / TC0F (sp78), fans under F0Ac…F17Ac (fpe2).
  • Apple Silicon: temperatures live under Tp01…Tp16 (flt — IEEE 754 single precision), fans under F0Ac…F17Ac (also flt).

AppleSMC fan keys do not exist at all on fanless Macs (e.g. M1/M2 MacBook Air); ReadFanSpeeds returns an empty slice on those.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloseSMC

func CloseSMC()

CloseSMC closes the persistent SMC connection opened by OpenSMC.

func OpenSMC

func OpenSMC()

OpenSMC keeps the SMC connection open for the lifetime of the process. Otherwise each Read* call opens and closes it.

func ReadFanSpeeds

func ReadFanSpeeds() []int

ReadFanSpeeds returns the current speed of each active fan in RPM, in fan-index order. Returns an empty slice on fanless Macs (M1/M2 MacBook Air, etc.) where the SMC has no F*Ac keys.

Reads keys F0Ac through F17Ac and stops at the first one that does not respond. AppleSMC reports these as sp78/fpe2 on Intel and as IEEE-754 float on Apple Silicon; both formats are handled.

func ReadTemperature

func ReadTemperature() float64

ReadTemperature returns a representative CPU temperature in degrees Celsius, or 0.0 if no temperature sensor could be read.

  • On Intel, this is the TC0P (CPU proximity) sensor.
  • On Apple Silicon, this is the maximum across all populated per-cluster CPU sensors (Tp01…Tp16) — i.e. the hottest core cluster, which is generally the most useful single value for thermal monitoring.

func ReadTemperatures

func ReadTemperatures() map[string]float64

ReadTemperatures returns every CPU-cluster temperature sensor the kernel acknowledges, keyed by SMC key (e.g. "Tp01"). On Intel this will typically be a single entry under "TC0P"; on Apple Silicon it will be several Tp* entries. Empty if no sensors respond.

Types

This section is empty.

Jump to

Keyboard shortcuts

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