1
0
Fork 0
mirror of https://github.com/kubernetes-sigs/node-feature-discovery.git synced 2024-12-14 11:57:51 +00:00

Merge pull request #1497 from AhmedGrati/feat-add-cpu-socket-number

feat: add cpu socket count in `cpu.topology`
This commit is contained in:
Kubernetes Prow Robot 2023-12-15 13:29:51 +01:00 committed by GitHub
commit 3ea2a38d73
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 0 deletions

View file

@ -940,6 +940,7 @@ The following features are available for matching:
| | | **`bf.enabled`** | bool | `true` if Intel SST-BF (Intel Speed Select Technology - Base frequency) has been enabled, otherwise does not exist |
| **`cpu.topology`** | attribute | | | CPU topology related features |
| | | **`hardware_multithreading`** | bool | Hardware multithreading, such as Intel HTT, is enabled |
| | | **`socket_count`** | int | Number of CPU Sockets |
| **`cpu.coprocessor`** | attribute | | | CPU Coprocessor related features |
| | | **`nx_gzip`** | bool | Nest Accelerator GZIP support is enabled |
| **`kernel.config`** | attribute | | | Kernel configuration options |

View file

@ -20,6 +20,7 @@ import (
"fmt"
"os"
"strconv"
"strings"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/klog/v2"
@ -276,9 +277,38 @@ func discoverTopology() map[string]string {
features["hardware_multithreading"] = strconv.FormatBool(ht)
}
if socketCount, err := getCPUSocketCount(); err != nil {
klog.ErrorS(err, "failed to get sockets count")
} else {
features["socket_count"] = strconv.FormatInt(socketCount, 10)
}
return features
}
func getCPUSocketCount() (int64, error) {
files, err := os.ReadDir(hostpath.SysfsDir.Path("bus/cpu/devices"))
if err != nil {
return 0, err
}
uniquePhysicalIDs := sets.NewString()
for _, file := range files {
// Try to read physical_package_id from topology
physicalID, err := os.ReadFile(hostpath.SysfsDir.Path("bus/cpu/devices", file.Name(), "topology/physical_package_id"))
if err != nil {
return 0, err
}
id := strings.TrimSpace(string(physicalID))
if err != nil {
return 0, err
}
uniquePhysicalIDs.Insert(id)
}
return int64(uniquePhysicalIDs.Len()), nil
}
// Check if any (online) CPUs have thread siblings
func haveThreadSiblings() (bool, error) {