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