fix nvidia_smi power_readings for new drivers (#15759)
Ilya Mashchenko committed
Aug 7, 2023 at 18:09 UTC
939d29e140a11ff343031edfb492447a639569f4
1 file changed
+24
-16
collectors/python.d.plugin/nvidia_smi/nvidia_smi.chart.py
+24
-16
@@ -62,20 +62,22 @@ POWER_STATES = ['P' + str(i) for i in range(0, 16)]
62
63
# PCI Transfer data rate in gigabits per second (Gb/s) per generation
64
PCI_SPEED = {
65
- "1": 2.5,
66
- "2": 5,
67
- "3": 8,
68
- "4": 16,
69
- "5": 32
65
+ "1": 2.5,
66
+ "2": 5,
67
+ "3": 8,
68
+ "4": 16,
69
+ "5": 32
70
}
71
# PCI encoding per generation
72
PCI_ENCODING = {
73
- "1": 2/10,
74
- "2": 2/10,
75
- "3": 2/130,
76
- "4": 2/130,
77
- "5": 2/130
73
+ "1": 2 / 10,
74
+ "2": 2 / 10,
75
+ "3": 2 / 130,
76
+ "4": 2 / 130,
77
+ "5": 2 / 130
78
}
79
+
80
+
81
def gpu_charts(gpu):
82
fam = gpu.full_name()
83
@@ -88,7 +90,8 @@ def gpu_charts(gpu):
90
]
91
},
92
PCI_BANDWIDTH_PERCENT: {
91
- 'options': [None, 'PCI Express Bandwidth Percent', 'percentage', fam, 'nvidia_smi.pci_bandwidth_percent', 'area'],
93
+ 'options': [None, 'PCI Express Bandwidth Percent', 'percentage', fam, 'nvidia_smi.pci_bandwidth_percent',
94
+ 'area'],
95
'lines': [
96
['rx_util_percent', 'rx_percent'],
97
['tx_util_percent', 'tx_percent'],
@@ -358,7 +361,8 @@ class GPU:
361
362
@handle_attr_error
363
def pci_link_width(self):
361
- return self.root.find('pci').find('pci_gpu_link_info').find('link_widths').find('max_link_width').text.split('x')[0]
364
+ info = self.root.find('pci').find('pci_gpu_link_info')
365
+ return info.find('link_widths').find('max_link_width').text.split('x')[0]
366
367
def pci_bw_max(self):
368
link_gen = self.pci_link_gen()
@@ -368,7 +372,7 @@ class GPU:
372
# Maximum PCIe Bandwidth = SPEED * WIDTH * (1 - ENCODING) - 1Gb/s.
373
# see details https://enterprise-support.nvidia.com/s/article/understanding-pcie-configuration-for-maximum-performance
374
# return max bandwidth in kilobytes per second (kB/s)
371
- return (PCI_SPEED[link_gen] * link_width * (1- PCI_ENCODING[link_gen]) - 1) * 1000 * 1000 / 8
375
+ return (PCI_SPEED[link_gen] * link_width * (1 - PCI_ENCODING[link_gen]) - 1) * 1000 * 1000 / 8
376
377
@handle_attr_error
378
def rx_util(self):
@@ -434,14 +438,19 @@ class GPU:
438
def mem_clock(self):
439
return self.root.find('clocks').find('mem_clock').text.split()[0]
440
441
+ @handle_attr_error
442
+ def power_readings(self):
443
+ elem = self.root.find('power_readings')
444
+ return elem if elem else self.root.find('gpu_power_readings')
445
+
446
@handle_attr_error
447
def power_state(self):
439
- return str(self.root.find('power_readings').find('power_state').text.split()[0])
448
+ return str(self.power_readings().find('power_state').text.split()[0])
449
450
@handle_value_error
451
@handle_attr_error
452
def power_draw(self):
444
- return float(self.root.find('power_readings').find('power_draw').text.split()[0]) * 100
453
+ return float(self.power_readings().find('power_draw').text.split()[0]) * 100
454
455
@handle_attr_error
456
def processes(self):
@@ -492,7 +501,6 @@ class GPU:
501
data['rx_util_percent'] = str(int(int(self.rx_util()) * 100 / self.pci_bw_max()))
502
data['tx_util_percent'] = str(int(int(self.tx_util()) * 100 / self.pci_bw_max()))
503
495
-
504
for v in POWER_STATES:
505
data['power_state_' + v.lower()] = 0
506
p_state = self.power_state()