Skip to content

Commit cff69b9

Browse files
dswarbrickSuperQ
andauthored
infiniband: do not make assumptions about counters based on HCA name (#678)
Some users have reported cases of systemd "predictable network interface naming" apparently also renaming the HCA device. This means we can no longer make assumptions about which counter(s) should be present based on the HCA name (i.e., irdma*, mlx5_*). The previous approach was quite brittle anyway, since there will undoubtedly be other IB / RoCE drivers in future which implement the hw_counters directory (but not the older counters directory). Signed-off-by: Daniel Swarbrick <[email protected]> Signed-off-by: Ben Kochie <[email protected]> Co-authored-by: Ben Kochie <[email protected]>
1 parent ee82f2f commit cff69b9

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

Diff for: sysfs/class_infiniband.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -280,16 +280,19 @@ func (fs FS) parseInfiniBandPort(name string, port string) (*InfiniBandPort, err
280280
return nil, fmt.Errorf("could not parse rate file in %q: %w", portPath, err)
281281
}
282282

283-
// Intel irdma and Broadcom RoCE does not expose /sys/class/infiniband/<device>/ports/<port-num>/counters
284-
if !strings.HasPrefix(ibp.Name, "irdma") && !strings.HasPrefix(ibp.Name, "bnxt_re") {
283+
// Since the HCA may have been renamed by systemd, we cannot infer the kernel driver used by the
284+
// device, and thus do not know what type(s) of counters should be present. Attempt to parse
285+
// either / both "counters" (and potentially also "counters_ext"), and "hw_counters", subject
286+
// to their availability on the system - irrespective of HCA naming convention.
287+
if _, err := os.Stat(filepath.Join(portPath, "counters")); err == nil {
285288
counters, err := parseInfiniBandCounters(portPath)
286289
if err != nil {
287290
return nil, err
288291
}
289292
ibp.Counters = *counters
290293
}
291294

292-
if strings.HasPrefix(ibp.Name, "irdma") || strings.HasPrefix(ibp.Name, "mlx5_") {
295+
if _, err := os.Stat(filepath.Join(portPath, "hw_counters")); err == nil {
293296
hwCounters, err := parseInfiniBandHwCounters(portPath)
294297
if err != nil {
295298
return nil, err

0 commit comments

Comments
 (0)