Skip to content

Conversation

everpeace
Copy link

@everpeace everpeace commented Jun 13, 2025

fixes #400
ref: #213

This PR puts the standardized device attribute resource.kubernetes.io/pcieRoot to GPU and MIG devices.

Copy link

copy-pr-bot bot commented Jun 13, 2025

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@everpeace everpeace force-pushed the add-pcieRoot-device-attribute branch from ba062f0 to bb72e60 Compare June 13, 2025 11:35
@everpeace everpeace marked this pull request as ready for review June 13, 2025 11:45
@everpeace everpeace marked this pull request as draft June 13, 2025 11:54
@everpeace
Copy link
Author

everpeace commented Jun 13, 2025

@klueska Sorry, I just deleted my comment because I also thought https://github.com/NVIDIA/go-nvml is the right place where we should place the pcie root resolution logic as you pointed out. I will update the repo soon🙇

Comment on lines +565 to +577
func resolvePCIeRootFromBusID(pciBusID string) (string, error) {
devicePath, err := os.Readlink(filepath.Join("/sys/bus/pci/devices", pciBusID))
if err != nil {
return "", fmt.Errorf("error resolving PCIe root from Bus ID '%s': %v", pciBusID, err)
}

regex := regexp.MustCompile(`^/sys/devices/pci[0-9a-f]{4}:[0-9a-f]{2}/.*$`)
if !regex.MatchString(devicePath) {
return "", fmt.Errorf("unexpected device path for PCIe device '%s': %s", pciBusID, devicePath)
}

return strings.Split(devicePath, "/")[2], nil
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to make sure that everyone agrees on the same way to represent the value of this attributes in every driver (not just on the name of the attribute).

Seems like we should add a new pkg in our library code to build these standard atrributes for all drivers to use:
https://github.com/kubernetes/kubernetes/tree/master/staging/src/k8s.io/dynamic-resource-allocation

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

@everpeace everpeace Jun 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to make sure that everyone agrees on the same way to represent the value of this attributes in every driver (not just on the name of the attribute).

I think the KEP suggests DRA drivers scan /sys/devices/:

DRA drivers MAY determine this value by inspecting the hierarchical path of the device's entry in sysfs (e.g., /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0), where the pci<domain>:<bus> segment at the beginning of the real path identifies the Root Complex (e.g., pci0000:00).

This matches the official Linux Kernel Doc: https://docs.kernel.org/PCI/sysfs-pci.html. So, I think it's quite a standard way to resolve PCI Root(Domain and Bus).


Seems like we should add a new pkg in our library code to build these standard atrributes for all drivers to use:
https://github.com/kubernetes/kubernetes/tree/master/staging/src/k8s.io/dynamic-resource-allocation

Yeah, agreed. However, I think these API will be bumped to v1 soon. I expect the v1 API will include standardized device attribute constant. So, I will catch up to it later.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no API, as such, associated with that library pkg. It is free to change from release-to-release (even with breaking changes).

As such, I do think it's better to implement this logic in one place rather than to start with fragmented implementations in different drivers. You can even define the constant for the attribute there.

I can see it as a new standard-attributes package with a set of library calls to get specific standard attributes.

Happy to review such a change there.

Copy link
Author

@everpeace everpeace Jun 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As such, I do think it's better to implement this logic in one place rather than to start with fragmented implementations in different drivers. You can even define the constant for the attribute there.

Ah! I got it, completely agreed!!!

I can see it as a new standard-attributes package with a set of library calls to get specific standard attributes.
Happy to review such a change there.

I'm interested in it. But, would you know any good OSS libraries to handle PCI devices?? Is Kubernetes ok to depend https://github.com/NVIDIA/go-nvml. I'm not sure. OR, implementing a thin helper method which takes a BusID in BDF format and scan /sys/devices dir like my implementation here??

WDYT??

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You definitely wont be able to pull in https://github.com/NVIDIA/go-nvml directly. It will need to be generically implemented against standard linux interfaces.

I think its pretty clear how you would get the root complex given a BudID in BDF format, so lets start there.

What I'm less clear on is how to get it for CPUs (which a DRA driver for will be coming soon).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think its pretty clear how you would get the root complex given a BudID in BDF format, so lets start there.

Cool. Thanks. Let me try 👍

Copy link
Contributor

@aojea aojea Jun 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to make sure that everyone agrees on the same way to represent the value of this attributes in every driver (not just on the name of the attribute).

I was just precisely talked about this in google/dranet#114 (comment) that @michaelasp is implementing , we need to ensure we all expose the same value

As such, I do think it's better to implement this logic in one place rather than to start with fragmented implementations in different drivers. You can even define the constant for the attribute there.

+1000 I ended doing my own parsing https://github.com/google/dranet/blob/main/pkg/inventory/sysfs.go#L112-L195 but I prefer if we standardize the logic too

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 on this, having a standard library to get this value would make it less prone to parsing issues and misinterpretation of the kep.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opened a PR

kubernetes/kubernetes#132296

PTAL 🙇

@klueska
Copy link
Collaborator

klueska commented Jun 13, 2025

@klueska Sorry, I just deleted my comment because I also thought https://github.com/NVIDIA/go-nvml is the right place where we should place the pcie root resolution logic as you pointed out. I will update the repo soon🙇

go-nvml is just a thin wrapper around the underlying C library for NVML -- we can't just add custom methods in there

@everpeace
Copy link
Author

everpeace commented Jul 22, 2025

@klueska
I'm closing this PR in favor of #429, which includes the 'resource.kubernetes.io/pcieRoot' device attribute support via kubernetes/kubernetes#132296, and more.

@everpeace everpeace closed this Jul 22, 2025
@everpeace everpeace deleted the add-pcieRoot-device-attribute branch July 23, 2025 12:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

Add standard attribute 'resource.kubernetes.io/pcieRoot' to devices
4 participants