This repository was archived by the owner on Dec 9, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
feat: discovery of native rdma devices #151
Open
vsoch
wants to merge
3
commits into
google:main
Choose a base branch
from
vsoch:add/rdma-raw-devices
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -19,7 +19,6 @@ package inventory | |||||
| import ( | ||||||
| "context" | ||||||
| "fmt" | ||||||
| "net" | ||||||
| "strings" | ||||||
| "sync" | ||||||
| "time" | ||||||
|
|
@@ -118,74 +117,79 @@ func (db *DB) GetPodNamespace(pod string) string { | |||||
| func (db *DB) Run(ctx context.Context) error { | ||||||
| defer close(db.notifications) | ||||||
|
|
||||||
| nlHandle, err := netlink.NewHandle() | ||||||
| if err != nil { | ||||||
| return fmt.Errorf("error creating netlink handle %v", err) | ||||||
| } | ||||||
| // Resources are published periodically or if there is a netlink notification | ||||||
| // indicating a new interfaces was added or changed | ||||||
| // indicating a new interfaces was added or changed. | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| nlChannel := make(chan netlink.LinkUpdate) | ||||||
| doneCh := make(chan struct{}) | ||||||
| defer close(doneCh) | ||||||
| if err := netlink.LinkSubscribe(nlChannel, doneCh); err != nil { | ||||||
| klog.Error(err, "error subscribing to netlink interfaces, only syncing periodically", "interval", maxInterval.String()) | ||||||
| } | ||||||
|
|
||||||
| // Obtain data that will not change after the startup | ||||||
| // Obtain data that will not change after the startup. | ||||||
| db.instance = getInstanceProperties(ctx) | ||||||
| // TODO: it is not common but may happen in edge cases that the default gateway changes | ||||||
| // revisit once we have more evidence this can be a potential problem or break some use | ||||||
| // cases. | ||||||
| gwInterfaces := getDefaultGwInterfaces() | ||||||
|
|
||||||
| for { | ||||||
| err := db.rateLimiter.Wait(ctx) | ||||||
| if err != nil { | ||||||
| klog.Error(err, "unexpected rate limited error trying to get system interfaces") | ||||||
| } | ||||||
|
|
||||||
| devices := []resourceapi.Device{} | ||||||
| ifaces, err := nlHandle.LinkList() | ||||||
| // Device lookup map is used to prevent duplicated. | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| devices := make(map[string]*resourceapi.Device) | ||||||
|
|
||||||
| // Keep track of seen devices to not register an RDMA device twice. | ||||||
| seenRdmaDevices := sets.New[string]() | ||||||
|
|
||||||
| // Kernel network interfaces are first priority. | ||||||
| netlinkDevices, err := db.discoverNetlinkDevices() | ||||||
| if err != nil { | ||||||
| klog.Error(err, "unexpected error trying to get system interfaces") | ||||||
| return err | ||||||
| } | ||||||
| for _, iface := range ifaces { | ||||||
| klog.V(7).InfoS("Checking network interface", "name", iface.Attrs().Name) | ||||||
| if gwInterfaces.Has(iface.Attrs().Name) { | ||||||
| klog.V(4).Infof("iface %s is an uplink interface", iface.Attrs().Name) | ||||||
| continue | ||||||
| } | ||||||
| for pciAddr, device := range netlinkDevices { | ||||||
|
|
||||||
| if ignoredInterfaceNames.Has(iface.Attrs().Name) { | ||||||
| klog.V(4).Infof("iface %s is in the list of ignored interfaces", iface.Attrs().Name) | ||||||
| // Do not add un-named netowrk device interfaces. | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| ifName, ok := device.Basic.Attributes["dra.net/ifName"] | ||||||
| if !ok { | ||||||
| continue | ||||||
| } | ||||||
|
|
||||||
| // skip loopback interfaces | ||||||
| if iface.Attrs().Flags&net.FlagLoopback != 0 { | ||||||
| continue | ||||||
| // If it has RDMA, mark as seen. | ||||||
| if rdmaName, err := rdmamap.GetRdmaDeviceForNetdevice(*ifName.StringValue); err == nil && rdmaName != "" { | ||||||
| klog.V(4).Infof("Found netdev '%s' with associated RDMA device '%s'. Merging.", *ifName.StringValue, rdmaName) | ||||||
| seenRdmaDevices.Insert(pciAddr) | ||||||
| } | ||||||
| devices[*ifName.StringValue] = device | ||||||
|
|
||||||
| } | ||||||
| // We only allow rdma devices that have PCI addresses. | ||||||
| for pciAddr, rdmaDevice := range db.discoverRawRdmaDevices() { | ||||||
|
|
||||||
| // publish this network interface | ||||||
| device, err := db.netdevToDRAdev(iface) | ||||||
| if err != nil { | ||||||
| klog.V(2).Infof("could not obtain attributes for iface %s : %v", iface.Attrs().Name, err) | ||||||
| // Have we already seen it? | ||||||
| _, ok := seenRdmaDevices[pciAddr] | ||||||
| if ok { | ||||||
| continue | ||||||
| } | ||||||
| devices[rdmaDevice.Name] = rdmaDevice | ||||||
| } | ||||||
|
|
||||||
| devices = append(devices, *device) | ||||||
| klog.V(4).Infof("Found following network interface %s", iface.Attrs().Name) | ||||||
| // Create the final list to publish. | ||||||
| finalDevices := make([]resourceapi.Device, 0, len(devices)) | ||||||
| for _, device := range devices { | ||||||
| finalDevices = append(finalDevices, *device) | ||||||
| } | ||||||
|
|
||||||
| klog.V(4).Infof("Found %d devices", len(devices)) | ||||||
| if len(devices) > 0 || db.hasDevices { | ||||||
| db.hasDevices = len(devices) > 0 | ||||||
| db.notifications <- devices | ||||||
| klog.V(4).Infof("Found %d devices", len(finalDevices)) | ||||||
| if len(finalDevices) > 0 || db.hasDevices { | ||||||
| db.hasDevices = len(finalDevices) > 0 | ||||||
| db.notifications <- finalDevices | ||||||
| } | ||||||
|
|
||||||
| // Wait for the next event or timeout. | ||||||
| select { | ||||||
| // trigger a reconcile | ||||||
| // Trigger a reconcile. | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Note: |
||||||
| case <-nlChannel: | ||||||
| // drain the channel so we only sync once | ||||||
| // Drain the channel so we only sync once. | ||||||
| for len(nlChannel) > 0 { | ||||||
| <-nlChannel | ||||||
| } | ||||||
|
|
@@ -208,13 +212,14 @@ func (db *DB) netdevToDRAdev(link netlink.Link) (*resourceapi.Device, error) { | |||||
| } | ||||||
| // Set the device name. It will be normalized only if necessary. | ||||||
| device.Name = names.SetDeviceName(ifName) | ||||||
| // expose the real interface name as an attribute in case it is normalized. | ||||||
|
|
||||||
| // expose the real interface name as an attribute in case it is normalized. | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| device.Attributes["dra.net/ifName"] = resourceapi.DeviceAttribute{StringValue: &ifName} | ||||||
|
|
||||||
| linkType := link.Type() | ||||||
| linkAttrs := link.Attrs() | ||||||
|
|
||||||
| // identify the namespace holding the link as the other end of a veth pair | ||||||
| // Identify the namespace holding the link as the other end of a veth pair. | ||||||
| netnsid := link.Attrs().NetNsID | ||||||
| if podName := db.GetPodName(netnsid); podName != "" { | ||||||
| device.Attributes["dra.net/pod"] = resourceapi.DeviceAttribute{StringValue: &podName} | ||||||
|
|
@@ -252,15 +257,15 @@ func (db *DB) netdevToDRAdev(link netlink.Link) (*resourceapi.Device, error) { | |||||
| device.Attributes["dra.net/alias"] = resourceapi.DeviceAttribute{StringValue: &linkAttrs.Alias} | ||||||
| device.Attributes["dra.net/type"] = resourceapi.DeviceAttribute{StringValue: &linkType} | ||||||
|
|
||||||
| // Get eBPF properties from the interface using the legacy tc hooks | ||||||
| // Get eBPF properties from the interface using the legacy tc hooks. | ||||||
| isEbpf := false | ||||||
| filterNames, ok := getTcFilters(link) | ||||||
| if ok { | ||||||
| isEbpf = true | ||||||
| device.Attributes["dra.net/tcFilterNames"] = resourceapi.DeviceAttribute{StringValue: ptr.To(strings.Join(filterNames, ","))} | ||||||
| } | ||||||
|
|
||||||
| // Get eBPF properties from the interface using the tcx hooks | ||||||
| // Get eBPF properties from the interface using the tcx hooks. | ||||||
| programNames, ok := getTcxFilters(link) | ||||||
| if ok { | ||||||
| isEbpf = true | ||||||
|
|
@@ -300,7 +305,7 @@ func addPCIAttributes(device *resourceapi.Device, ifName string, path string) { | |||||
| klog.Infof("Could not get bdf address : %v", err) | ||||||
| } else { | ||||||
| if err := setPciRootAttr(device, address); err != nil { | ||||||
| klog.Infof("Could not get pci root attribute : %v", err) | ||||||
| klog.Infof("could not get pci root for %s: %v", ifName, err) | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -316,7 +321,7 @@ func addPCIAttributes(device *resourceapi.Device, ifName string, path string) { | |||||
| device.Attributes["dra.net/pciSubsystem"] = resourceapi.DeviceAttribute{StringValue: &entry.Subsystem} | ||||||
| } | ||||||
| } else { | ||||||
| klog.Infof("could not get pci vendor information : %v", err) | ||||||
| klog.Infof("could not get pci vendor information for %s: %v", ifName, err) | ||||||
| } | ||||||
|
|
||||||
| numa, err := numaNode(ifName, path) | ||||||
|
|
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is only necessary when developing on "real" clusters, right? We might clarify that.
A lot of this is developed locally, where the image name is ~arbitrary, because we don't push it to a remote host anyhow.