Skip to content

Commit 3f300f3

Browse files
vickmprsmontero
authored andcommitted
B #5968: Fix GPU/vGPU list and handle (#2299)
(cherry picked from commit bd4f53e)
1 parent d39c229 commit 3f300f3

File tree

1 file changed

+27
-22
lines changed
  • src/im_mad/remotes/node-probes.d

1 file changed

+27
-22
lines changed

src/im_mad/remotes/node-probes.d/pci.rb

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ def get_devices(filter = nil)
9191
end.flatten
9292
end
9393

94+
def device_attr?(device, attribute)
95+
addr = "0000:#{device[:bus]}:#{device[:slot]}.#{device[:function]}"
96+
!`ls -l /sys/bus/pci/devices/#{addr}/ | grep #{attribute}`.empty?
97+
end
98+
9499
filter = CONF[:filter]
95100

96101
devices = get_devices(filter)
@@ -111,11 +116,9 @@ def pval(name, value)
111116
next if matched != true
112117
end
113118

114-
# The main device cannot be used, skip it
115-
if CONF[:nvidia_vendors].include?(dev[:vendor]) &&
116-
`ls /sys/class/mdev_bus | grep #{dev[:short_address]}`.empty?
117-
next
118-
end
119+
# Skip NVIDIA cards with virtual functions
120+
next if CONF[:nvidia_vendors].include?(dev[:vendor]) &&
121+
device_attr?(dev, 'virtfn')
119122

120123
puts 'PCI = ['
121124
values = [
@@ -134,27 +137,29 @@ def pval(name, value)
134137
pval('NUMA_NODE', dev[:numa_node])
135138
]
136139

137-
# NVIDIA device
138-
#
139-
# The uuid is based on the address to get always the same
140+
# NVIDIA GPU device
140141
if CONF[:nvidia_vendors].include?(dev[:vendor])
141-
values << pval(
142-
'UUID',
143-
`uuidgen --name '#{dev[:address]}' --namespace '@x500' --sha1`.strip
144-
)
145-
146-
# When having vGPU the name is always Device, so we merge it with vendor
147-
# name, in this way Sunstone shows a better name
142+
# When having NVIDIA GPU the name is always Device, so we merge
143+
# it with vendor name, in this way Sunstone shows a better name
148144
values << pval('DEVICE_NAME',
149145
"#{dev[:vendor_name]} #{dev[:device_name]}")
150146

151-
# Get profiles
152-
addr = "0000:#{dev[:bus]}:#{dev[:slot]}.#{dev[:function]}"
153-
profiles = `ls /sys/class/mdev_bus/#{addr}/mdev_supported_types`
154-
profiles = profiles.split("\n")
155-
156-
# Comma separated value with different profiles
157-
values << pval('PROFILES', profiles.join(','))
147+
# For vGPU, the uuid is based on the address to get always the same
148+
if device_attr?(dev, 'physfn')
149+
values << pval(
150+
'UUID',
151+
`uuidgen --name '#{dev[:address]}' \
152+
--namespace '@x500' --sha1`.strip
153+
)
154+
155+
# Get profiles
156+
addr = "0000:#{dev[:bus]}:#{dev[:slot]}.#{dev[:function]}"
157+
profiles = `ls /sys/class/mdev_bus/#{addr}/mdev_supported_types`
158+
profiles = profiles.split("\n")
159+
160+
# Comma separated value with different profiles
161+
values << pval('PROFILES', profiles.join(','))
162+
end
158163
else
159164
values << pval('DEVICE_NAME', dev[:device_name])
160165
end

0 commit comments

Comments
 (0)