Skip to content

Commit 654ac53

Browse files
committed
source/pci: Group identical PCI entries
Signed-off-by: Oleg Zhurakivskyy <[email protected]>
1 parent b9b4c85 commit 654ac53

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

Diff for: source/pci/utils.go

+13-1
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,25 @@ func detectPci() ([]nfdv1alpha1.InstanceFeature, error) {
8080

8181
// Iterate over devices
8282
devInfo := make([]nfdv1alpha1.InstanceFeature, 0, len(devices))
83+
devGrouped := make(map[string]map[string]int)
8384
for _, device := range devices {
8485
info, err := readPciDevInfo(filepath.Join(sysfsBasePath, device.Name()))
8586
if err != nil {
8687
klog.ErrorS(err, "failed to read PCI device info")
8788
continue
8889
}
89-
devInfo = append(devInfo, *info)
90+
if _, ok := devGrouped[info.Attributes["vendor"]][info.Attributes["device"]]; !ok {
91+
devGrouped[info.Attributes["vendor"]] = make(map[string]int)
92+
devGrouped[info.Attributes["vendor"]][info.Attributes["device"]] = 1
93+
devInfo = append(devInfo, *info)
94+
} else {
95+
devGrouped[info.Attributes["vendor"]][info.Attributes["device"]] += 1
96+
}
97+
}
98+
99+
for _, dev := range devInfo {
100+
count := devGrouped[dev.Attributes["vendor"]][dev.Attributes["device"]]
101+
dev.Attributes["count"] = string(count)
90102
}
91103

92104
return devInfo, nil

0 commit comments

Comments
 (0)