m1cpu: fetch l1, l2 cache data for p/e cores
diff --git a/cpu.go b/cpu.go index e04c9ee..5a5d9b3 100644 --- a/cpu.go +++ b/cpu.go
@@ -13,6 +13,12 @@ // UInt64 global_eCoreHz; // int global_pCoreCount; // int global_eCoreCount; +// int global_pCoreL1InstCacheSize; +// int global_eCoreL1InstCacheSize; +// int global_pCoreL1DataCacheSize; +// int global_eCoreL1DataCacheSize; +// int global_pCoreL2CacheSize; +// int global_eCoreL2CacheSize; // // UInt64 getFrequency(CFTypeRef typeRef) { // CFDataRef cfData = typeRef; @@ -40,6 +46,12 @@ // void initialize() { // global_pCoreCount = sysctl_int("hw.perflevel0.physicalcpu"); // global_eCoreCount = sysctl_int("hw.perflevel1.physicalcpu"); +// global_pCoreL1InstCacheSize = sysctl_int("hw.perflevel0.l1icachesize"); +// global_eCoreL1InstCacheSize = sysctl_int("hw.perflevel1.l1icachesize"); +// global_pCoreL1DataCacheSize = sysctl_int("hw.perflevel0.l1dcachesize"); +// global_eCoreL1DataCacheSize = sysctl_int("hw.perflevel1.l1dcachesize"); +// global_pCoreL2CacheSize = sysctl_int("hw.perflevel0.l2cachesize"); +// global_eCoreL2CacheSize = sysctl_int("hw.perflevel1.l2cachesize"); // // CFMutableDictionaryRef matching = IOServiceMatching("AppleARMIODevice"); // io_iterator_t iter; @@ -89,6 +101,30 @@ // int eCoreCount() { // return global_eCoreCount; // } +// +// int pCoreL1InstCacheSize() { +// return global_pCoreL1InstCacheSize; +// } +// +// int pCoreL1DataCacheSize() { +// return global_pCoreL1DataCacheSize; +// } +// +// int pCoreL2CacheSize() { +// return global_pCoreL2CacheSize; +// } +// +// int eCoreL1InstCacheSize() { +// return global_eCoreL1InstCacheSize; +// } +// +// int eCoreL1DataCacheSize() { +// return global_eCoreL1DataCacheSize; +// } +// +// int eCoreL2CacheSize() { +// return global_eCoreL2CacheSize; +// } import "C" func init() { @@ -129,3 +165,27 @@ func ECoreCount() int { return int(C.eCoreCount()) } + +// PCoreCacheSize returns the sizes of the P (performance) core cache sizes +// in the order of +// +// - L1 instruction cache +// - L1 data cache +// - L2 cache +func PCoreCache() (int, int, int) { + return int(C.pCoreL1InstCacheSize()), + int(C.pCoreL1DataCacheSize()), + int(C.pCoreL2CacheSize()) +} + +// ECoreCacheSize returns the sizes of the E (efficiency) core cache sizes +// in the order of +// +// - L1 instruction cache +// - L1 data cache +// - L2 cache +func ECoreCache() (int, int, int) { + return int(C.eCoreL1InstCacheSize()), + int(C.eCoreL1DataCacheSize()), + int(C.eCoreL2CacheSize()) +}
diff --git a/cpu_test.go b/cpu_test.go index 34f32e1..704d13a 100644 --- a/cpu_test.go +++ b/cpu_test.go
@@ -28,6 +28,16 @@ must.Greater(t, 1, ghz) } +func Test_PCoreCount(t *testing.T) { + n := PCoreCount() + must.Positive(t, n) +} + +func Test_ECoreCount(t *testing.T) { + n := ECoreCount() + must.Positive(t, n) +} + func Test_Show(t *testing.T) { t.Log("pCore Hz", PCoreHz()) t.Log("eCore Hz", ECoreHz()) @@ -35,4 +45,10 @@ t.Log("eCore GHz", ECoreGHz()) t.Log("pCore count", PCoreCount()) t.Log("eCoreCount", ECoreCount()) + + pL1Inst, pL1Data, pL2 := PCoreCache() + t.Log("pCore Caches", pL1Inst, pL1Data, pL2) + + eL1Inst, eL1Data, eL2 := ECoreCache() + t.Log("eCore Caches", eL1Inst, eL1Data, eL2) } \ No newline at end of file