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

feat: add cpu socket number in cpu.topology

Signed-off-by: AhmedGrati <ahmedgrati1999@gmail.com>
This commit is contained in:
AhmedGrati 2023-12-08 18:23:23 +01:00
parent 794630f7df
commit ebb08369d3
2 changed files with 31 additions and 0 deletions

View file

@ -867,6 +867,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) {