@@ -20,6 +20,7 @@ import (
2020 "os"
2121 "path"
2222 "regexp"
23+ "runtime"
2324
2425 "strconv"
2526 "strings"
@@ -37,6 +38,8 @@ import (
3738var (
3839 coreRegExp = regexp .MustCompile (`(?m)^core id\s*:\s*([0-9]+)$` )
3940 nodeRegExp = regexp .MustCompile (`(?m)^physical id\s*:\s*([0-9]+)$` )
41+ bookRegExp = regexp .MustCompile (`(?m)^book id\s*:\s*([0-9]+)$` )
42+ drawerRegExp = regexp .MustCompile (`(?m)^drawer id\s*:\s*([0-9]+)$` )
4043 // Power systems have a different format so cater for both
4144 cpuClockSpeedMHz = regexp .MustCompile (`(?:cpu MHz|CPU MHz|clock)\s*:\s*([0-9]+\.[0-9]+)(?:MHz)?` )
4245 memoryCapacityRegexp = regexp .MustCompile (`MemTotal:\s*([0-9]+) kB` )
@@ -96,6 +99,41 @@ func GetSockets(procInfo []byte) int {
9699 return numSocket
97100}
98101
102+ // GetBooks returns number of CPU books reading from sysfs cpu path
103+ func GetBooks (procInfo []byte ) int {
104+ if runtime .GOARCH != "s390x" {
105+ return 0
106+ }
107+ numBook := getUniqueMatchesCount (string (procInfo ), bookRegExp )
108+ if numBook == 0 {
109+ // read number of books from /sys/bus/cpu/devices/cpu*/topology/book_id to deal with processors
110+ // for which 'book id' is not available in /proc/cpuinfo
111+ numBook = sysfs .GetUniqueCPUPropertyCount (cpuAttributesPath , sysfs .CPUBookID )
112+ }
113+ if numBook == 0 {
114+ klog .Errorf ("Cannot read number of books correctly, number of books set to %d" , numBook )
115+ }
116+ return numBook
117+ }
118+
119+ // GetDrawer returns number of CPU drawerss reading from sysfs cpu path
120+ func GetDrawers (procInfo []byte ) int {
121+ if runtime .GOARCH != "s390x" {
122+ return 0
123+ }
124+ numDrawer := getUniqueMatchesCount (string (procInfo ), drawerRegExp )
125+ if numDrawer == 0 {
126+ // read number of books from /sys/bus/cpu/devices/cpu*/topology/book_id to deal with processors
127+ // read number of drawers from /sys/bus/cpu/devices/cpu*/topology/drawer_id to deal with processors
128+ // for which 'drawer id' is not available in /proc/cpuinfo
129+ numDrawer = sysfs .GetUniqueCPUPropertyCount (cpuAttributesPath , sysfs .CPUDrawerID )
130+ }
131+ if numDrawer == 0 {
132+ klog .Errorf ("Cannot read number of drawers correctly, number of drawers set to %d" , numDrawer )
133+ }
134+ return numDrawer
135+ }
136+
99137// GetClockSpeed returns the CPU clock speed, given a []byte formatted as the /proc/cpuinfo file.
100138func GetClockSpeed (procInfo []byte ) (uint64 , error ) {
101139 // First look through sys to find a max supported cpu frequency.
0 commit comments