m1cpu: able to read p-core and e-core counts
diff --git a/cpu.go b/cpu.go
index aa261bb..e04c9ee 100644
--- a/cpu.go
+++ b/cpu.go
@@ -5,11 +5,14 @@
// #cgo LDFLAGS: -framework CoreFoundation -framework IOKit
// #include <CoreFoundation/CoreFoundation.h>
// #include <IOKit/IOKitLib.h>
+// #include <sys/sysctl.h>
//
// #define HzToGHz(hz) ((hz) / 1000000000.0)
//
// UInt64 global_pCoreHz;
// UInt64 global_eCoreHz;
+// int global_pCoreCount;
+// int global_eCoreCount;
//
// UInt64 getFrequency(CFTypeRef typeRef) {
// CFDataRef cfData = typeRef;
@@ -27,7 +30,17 @@
// return pCoreHz;
// }
//
+// int sysctl_int(const char * name) {
+// int value = -1;
+// size_t size = 8;
+// sysctlbyname(name, &value, &size, NULL, 0);
+// return value;
+// }
+//
// void initialize() {
+// global_pCoreCount = sysctl_int("hw.perflevel0.physicalcpu");
+// global_eCoreCount = sysctl_int("hw.perflevel1.physicalcpu");
+//
// CFMutableDictionaryRef matching = IOServiceMatching("AppleARMIODevice");
// io_iterator_t iter;
// IOServiceGetMatchingServices(kIOMainPortDefault, matching, &iter);
@@ -68,6 +81,14 @@
// Float64 pCoreGHz() {
// return HzToGHz(global_pCoreHz);
// }
+//
+// int pCoreCount() {
+// return global_pCoreCount;
+// }
+//
+// int eCoreCount() {
+// return global_eCoreCount;
+// }
import "C"
func init() {
@@ -98,3 +119,13 @@
func ECoreGHz() float64 {
return float64(C.eCoreGHz())
}
+
+// PCoreCount returns the number of physical P (performance) cores.
+func PCoreCount() int {
+ return int(C.pCoreCount())
+}
+
+// ECoreCount returns the number of physical E (efficiency) cores.
+func ECoreCount() int {
+ return int(C.eCoreCount())
+}
diff --git a/cpu_test.go b/cpu_test.go
index 1edc836..34f32e1 100644
--- a/cpu_test.go
+++ b/cpu_test.go
@@ -33,4 +33,6 @@
t.Log("eCore Hz", ECoreHz())
t.Log("pCore GHz", PCoreGHz())
t.Log("eCore GHz", ECoreGHz())
+ t.Log("pCore count", PCoreCount())
+ t.Log("eCoreCount", ECoreCount())
}
\ No newline at end of file
diff --git a/incompatible.go b/incompatible.go
index 76c1d8b..0a9ddf2 100644
--- a/incompatible.go
+++ b/incompatible.go
@@ -7,22 +7,32 @@
return false
}
-// PCoreHZ returns the max frequency in Hertz of the P-Core of an Apple Silicon CPU.
+// PCoreHZ requires darwin/arm64
func PCoreHz() uint64 {
panic("m1cpu: not a darwin/arm64 system")
}
-// ECoreHZ returns the max frequency in Hertz of the E-Core of an Apple Silicon CPU.
+// ECoreHZ requires darwin/arm64
func ECoreHz() uint64 {
panic("m1cpu: not a darwin/arm64 system")
}
-// PCoreGHz returns the max frequency in Gigahertz of the P-Core of an Apple Silicon CPU.
+// PCoreGHz requires darwin/arm64
func PCoreGHz() float64 {
panic("m1cpu: not a darwin/arm64 system")
}
-// ECoreGHz returns the max frequency in Gigahertz of the E-Core of an Apple Silicon CPU.
+// ECoreGHz requires darwin/arm64
func ECoreGHz() float64 {
panic("m1cpu: not a darwin/arm64 system")
}
+
+// PCoreCount requires darwin/arm64
+func PCoreCount() int {
+ panic("m1cpu: not a darwin/arm64 system")
+}
+
+// ECoreCount requires darwin/arm64
+func ECoreCount() int {
+ panic("m1cpu: not a darwin/arm64 system")
+}