Skip to content

Commit 7753247

Browse files
committed
NV-CONTROL: set offset for gpu and memory clock
1 parent 8799e4d commit 7753247

File tree

2 files changed

+56
-50
lines changed

2 files changed

+56
-50
lines changed

Xlib/ext/nvcontrol.py

Lines changed: 52 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,8 @@ def query_target_count(self, target):
3535
return int(reply._data.get('count'))
3636

3737

38-
def query_int_attribute(self, target, displays, attr):
38+
def query_int_attribute(self, target, display_mask, attr):
3939
"""return the value of an integer attribute"""
40-
display_mask = _displays2mask(displays)
4140
reply = NVCtrlQueryAttributeReplyRequest(display=self.display,
4241
opcode=self.display.get_extension_major(extname),
4342
target_id=target.id(),
@@ -49,22 +48,20 @@ def query_int_attribute(self, target, displays, attr):
4948
return int(reply._data.get('value'))
5049

5150

52-
def set_int_attribute(self, target, displays, attr, value):
51+
def set_int_attribute(self, target, display_mask, attr, value):
5352
"""set the value of an integer attribute"""
54-
display_mask = _displays2mask(displays)
5553
reply = NVCtrlSetAttributeAndGetStatusReplyRequest(display=self.display,
5654
opcode=self.display.get_extension_major(extname),
5755
target_id=target.id(),
5856
target_type=target.type(),
5957
display_mask=display_mask,
6058
attr=attr,
6159
value=value)
62-
return reply._data.get('flags')
60+
return reply._data.get('flags') != 0
6361

6462

65-
def query_string_attribute(self, target, displays, attr):
63+
def query_string_attribute(self, target, display_mask, attr):
6664
"""return the value of a string attribute"""
67-
display_mask = _displays2mask(displays)
6865
reply = NVCtrlQueryStringAttributeReplyRequest(display=self.display,
6966
opcode=self.display.get_extension_major(extname),
7067
target_id=target.id(),
@@ -76,9 +73,8 @@ def query_string_attribute(self, target, displays, attr):
7673
return str(reply._data.get('string')).strip('\0')
7774

7875

79-
def query_valid_attr_values(self, target, displays, attr):
76+
def query_valid_attr_values(self, target, display_mask, attr):
8077
"""return the value of an integer attribute"""
81-
display_mask = _displays2mask(displays)
8278
reply = NVCtrlQueryValidAttributeValuesReplyRequest(display=self.display,
8379
opcode=self.display.get_extension_major(extname),
8480
target_id=target.id(),
@@ -90,9 +86,8 @@ def query_valid_attr_values(self, target, displays, attr):
9086
return int(reply._data.get('min')), int(reply._data.get('max'))
9187

9288

93-
def query_binary_data(self, target, displays, attr):
89+
def query_binary_data(self, target, display_mask, attr):
9490
"""return binary data"""
95-
display_mask = _displays2mask(displays)
9691
reply = NVCtrlQueryBinaryDataReplyRequest(display=self.display,
9792
opcode=self.display.get_extension_major(extname),
9893
target_id=target.id(),
@@ -105,12 +100,11 @@ def query_binary_data(self, target, displays, attr):
105100

106101

107102
def get_coolers_used_by_gpu(self, target):
108-
display_mask = _displays2mask([])
109103
reply = NVCtrlQueryListCard32ReplyRequest(display=self.display,
110104
opcode=self.display.get_extension_major(extname),
111105
target_id=target.id(),
112106
target_type=target.type(),
113-
display_mask=display_mask,
107+
display_mask=0,
114108
attr=NV_CTRL_BINARY_DATA_COOLERS_USED_BY_GPU)
115109
if not reply._data.get('flags'):
116110
return None
@@ -124,25 +118,25 @@ def get_gpu_count(self):
124118

125119
def get_name(self, target):
126120
"""the GPU product name on which the specified X screen is running"""
127-
return query_string_attribute(self, target, [], NV_CTRL_STRING_PRODUCT_NAME)
121+
return query_string_attribute(self, target, 0, NV_CTRL_STRING_PRODUCT_NAME)
128122

129123

130124
def get_driver_version(self, target):
131125
"""the NVIDIA (kernel level) driver version for the specified screen or GPU"""
132-
return query_string_attribute(self, target, [], NV_CTRL_STRING_NVIDIA_DRIVER_VERSION)
126+
return query_string_attribute(self, target, 0, NV_CTRL_STRING_NVIDIA_DRIVER_VERSION)
133127

134128

135129
def get_vbios_version(self, target):
136130
"""the version of the VBIOS for the specified screen or GPU"""
137-
return query_string_attribute(self, target, [], NV_CTRL_STRING_VBIOS_VERSION)
131+
return query_string_attribute(self, target, 0, NV_CTRL_STRING_VBIOS_VERSION)
138132

139133

140134
def get_gpu_uuid(self, target):
141-
return query_string_attribute(self, target, [], NV_CTRL_STRING_GPU_UUID)
135+
return query_string_attribute(self, target, 0, NV_CTRL_STRING_GPU_UUID)
142136

143137

144138
def get_gpu_utilization(self, target):
145-
string = query_string_attribute(self, target, [], NV_CTRL_STRING_GPU_UTILIZATION)
139+
string = query_string_attribute(self, target, 0, NV_CTRL_STRING_GPU_UTILIZATION)
146140
result = {}
147141
if string is not None and string != '':
148142
for line in string.split(','):
@@ -152,7 +146,7 @@ def get_gpu_utilization(self, target):
152146

153147

154148
def get_performance_modes(self, target):
155-
string = query_string_attribute(self, target, [], NV_CTRL_STRING_PERFORMANCE_MODES)
149+
string = query_string_attribute(self, target, 0, NV_CTRL_STRING_PERFORMANCE_MODES)
156150
result = []
157151
if string is not None and string != '':
158152
for perf in string.split(';'):
@@ -165,18 +159,18 @@ def get_performance_modes(self, target):
165159

166160

167161
def get_vram(self, target):
168-
return query_int_attribute(self, target, [], NV_CTRL_VIDEO_RAM)
162+
return query_int_attribute(self, target, 0, NV_CTRL_VIDEO_RAM)
169163

170164

171165
def get_irq(self, target):
172166
"""Return the interrupt request line used by the GPU driving the screen"""
173-
return query_int_attribute(self, target, [], NV_CTRL_IRQ)
167+
return query_int_attribute(self, target, 0, NV_CTRL_IRQ)
174168

175169

176170
def supports_framelock(self, target):
177171
"""returns whether the underlying GPU supports Frame Lock. All of the
178172
other frame lock attributes are only applicable if this returns True."""
179-
return query_int_attribute(self, target, [], NV_CTRL_FRAMELOCK) == 1
173+
return query_int_attribute(self, target, 0, NV_CTRL_FRAMELOCK) == 1
180174

181175

182176
def gvo_supported(self, screen):
@@ -187,102 +181,110 @@ def gvo_supported(self, screen):
187181

188182
def get_core_temp(self, target):
189183
"""return the current core temperature of the GPU driving the X screen."""
190-
return query_int_attribute(self, target, [], NV_CTRL_GPU_CORE_TEMPERATURE)
184+
return query_int_attribute(self, target, 0, NV_CTRL_GPU_CORE_TEMPERATURE)
191185

192186

193187
def get_core_threshold(self, target):
194188
"""return the current GPU core slowdown threshold temperature. It
195189
reflects the temperature at which the GPU is throttled to prevent
196190
overheating."""
197-
return query_int_attribute(self, target, [], NV_CTRL_GPU_CORE_THRESHOLD)
191+
return query_int_attribute(self, target, 0, NV_CTRL_GPU_CORE_THRESHOLD)
198192

199193

200194
def get_default_core_threshold(self, target):
201195
"""return the default core threshold temperature."""
202-
return query_int_attribute(self, target, [], NV_CTRL_GPU_DEFAULT_CORE_THRESHOLD)
196+
return query_int_attribute(self, target, 0, NV_CTRL_GPU_DEFAULT_CORE_THRESHOLD)
203197

204198

205199
def get_max_core_threshold(self, target):
206200
"""return the maximum core threshold temperature."""
207-
return query_int_attribute(self, target, [], NV_CTRL_GPU_MAX_CORE_THRESHOLD)
201+
return query_int_attribute(self, target, 0, NV_CTRL_GPU_MAX_CORE_THRESHOLD)
208202

209203

210204
def get_ambient_temp(self, target):
211205
"""return the current temperature in the immediate neighbourhood of
212206
the GPU driving the X screen."""
213-
return query_int_attribute(self, target, [], NV_CTRL_AMBIENT_TEMPERATURE)
207+
return query_int_attribute(self, target, 0, NV_CTRL_AMBIENT_TEMPERATURE)
214208

215209

216210
def get_cuda_cores(self, target):
217-
return query_int_attribute(self, target, [], NV_CTRL_GPU_CORES)
211+
return query_int_attribute(self, target, 0, NV_CTRL_GPU_CORES)
218212

219213

220214
def get_memory_bus_width(self, target):
221-
return query_int_attribute(self, target, [], NV_CTRL_GPU_MEMORY_BUS_WIDTH)
215+
return query_int_attribute(self, target, 0, NV_CTRL_GPU_MEMORY_BUS_WIDTH)
222216

223217

224218
def get_total_dedicated_gpu_memory(self, target):
225-
return query_int_attribute(self, target, [], NV_CTRL_TOTAL_DEDICATED_GPU_MEMORY)
219+
return query_int_attribute(self, target, 0, NV_CTRL_TOTAL_DEDICATED_GPU_MEMORY)
226220

227221

228222
def get_used_dedicated_gpu_memory(self, target):
229-
return query_int_attribute(self, target, [], NV_CTRL_USED_DEDICATED_GPU_MEMORY)
223+
return query_int_attribute(self, target, 0, NV_CTRL_USED_DEDICATED_GPU_MEMORY)
230224

231225

232226
def get_pcie_current_link_width(self, target):
233-
return query_int_attribute(self, target, [], NV_CTRL_GPU_PCIE_CURRENT_LINK_WIDTH)
227+
return query_int_attribute(self, target, 0, NV_CTRL_GPU_PCIE_CURRENT_LINK_WIDTH)
234228

235229

236230
def get_pcie_max_link_width(self, target):
237-
return query_int_attribute(self, target, [], NV_CTRL_GPU_PCIE_MAX_LINK_WIDTH)
231+
return query_int_attribute(self, target, 0, NV_CTRL_GPU_PCIE_MAX_LINK_WIDTH)
238232

239233

240234
def get_pcie_generation(self, target):
241-
return query_int_attribute(self, target, [], NV_CTRL_GPU_PCIE_GENERATION)
235+
return query_int_attribute(self, target, 0, NV_CTRL_GPU_PCIE_GENERATION)
242236

243237

244238
def get_video_encoder_utilization(self, target):
245-
return query_int_attribute(self, target, [], NV_CTRL_VIDEO_ENCODER_UTILIZATION)
239+
return query_int_attribute(self, target, 0, NV_CTRL_VIDEO_ENCODER_UTILIZATION)
246240

247241

248242
def get_video_decoder_utilization(self, target):
249-
return query_int_attribute(self, target, [], NV_CTRL_VIDEO_DECODER_UTILIZATION)
243+
return query_int_attribute(self, target, 0, NV_CTRL_VIDEO_DECODER_UTILIZATION)
250244

251245

252246
def get_current_performance_level(self, target):
253-
return query_int_attribute(self, target, [], NV_CTRL_GPU_CURRENT_PERFORMANCE_LEVEL)
247+
return query_int_attribute(self, target, 0, NV_CTRL_GPU_CURRENT_PERFORMANCE_LEVEL)
248+
249+
250+
def get_gpu_nvclock_offset(self, target, perf_level):
251+
return query_int_attribute(self, target, perf_level, NV_CTRL_GPU_NVCLOCK_OFFSET)
254252

255253

256-
def get_gpu_nvclock_offset(self, target):
257-
return query_int_attribute(self, target, [], NV_CTRL_GPU_NVCLOCK_OFFSET)
254+
def set_gpu_nvclock_offset(self, target, perf_level, offset):
255+
return set_int_attribute(self, target, perf_level, NV_CTRL_GPU_NVCLOCK_OFFSET, offset)
258256

259257

260258
def get_gpu_nvclock_offset_range(self, target):
261-
return query_valid_attr_values(self, target, [], NV_CTRL_GPU_NVCLOCK_OFFSET)
259+
return query_valid_attr_values(self, target, 0, NV_CTRL_GPU_NVCLOCK_OFFSET)
260+
261+
262+
def get_mem_transfer_rate_offset(self, target, perf_level):
263+
return query_int_attribute(self, target, perf_level, NV_CTRL_GPU_MEM_TRANSFER_RATE_OFFSET)
262264

263265

264-
def get_mem_transfer_rate_offset(self, target):
265-
return query_int_attribute(self, target, [], NV_CTRL_GPU_MEM_TRANSFER_RATE_OFFSET)
266+
def set_mem_transfer_rate_offset(self, target, perf_level, offset):
267+
return set_int_attribute(self, target, perf_level, NV_CTRL_GPU_MEM_TRANSFER_RATE_OFFSET, offset)
266268

267269

268270
def get_mem_transfer_rate_offset_range(self, target):
269-
return query_valid_attr_values(self, target, [], NV_CTRL_GPU_MEM_TRANSFER_RATE_OFFSET)
271+
return query_valid_attr_values(self, target, 0, NV_CTRL_GPU_MEM_TRANSFER_RATE_OFFSET)
270272

271273

272274
def get_cooler_manual_control_enabled(self, target):
273-
return query_int_attribute(self, target, [], NV_CTRL_GPU_COOLER_MANUAL_CONTROL) == 1
275+
return query_int_attribute(self, target, 0, NV_CTRL_GPU_COOLER_MANUAL_CONTROL) == 1
274276

275277

276278
def set_cooler_manual_control_enabled(self, target, enabled):
277-
return set_int_attribute(self, target, [], NV_CTRL_GPU_COOLER_MANUAL_CONTROL, 1 if enabled else 0) == 1
279+
return set_int_attribute(self, target, 0, NV_CTRL_GPU_COOLER_MANUAL_CONTROL, 1 if enabled else 0) == 1
278280

279281

280282
def get_fan_duty(self, target):
281-
return query_int_attribute(self, target, [], NV_CTRL_THERMAL_COOLER_CURRENT_LEVEL)
283+
return query_int_attribute(self, target, 0, NV_CTRL_THERMAL_COOLER_CURRENT_LEVEL)
282284

283285

284286
def get_fan_rpm(self, target):
285-
return query_int_attribute(self, target, [], NV_CTRL_THERMAL_COOLER_SPEED)
287+
return query_int_attribute(self, target, 0, NV_CTRL_THERMAL_COOLER_SPEED)
286288

287289

288290
def get_max_displays(self, target):
@@ -291,7 +293,7 @@ def get_max_displays(self, target):
291293
Note that this does not indicate the maximum number of bits that can be
292294
set in NV_CTRL_CONNECTED_DISPLAYS, because more display devices can be
293295
connected than are actively in use."""
294-
return query_int_attribute(self, target, [], NV_CTRL_MAX_DISPLAYS)
296+
return query_int_attribute(self, target, 0, NV_CTRL_MAX_DISPLAYS)
295297

296298

297299
def _displaystr2num(st):
@@ -346,7 +348,9 @@ def init(disp, info):
346348
disp.extension_add_method('display', 'nvcontrol_get_video_decoder_utilization', get_video_decoder_utilization)
347349
disp.extension_add_method('display', 'nvcontrol_get_current_performance_level', get_current_performance_level)
348350
disp.extension_add_method('display', 'nvcontrol_get_gpu_nvclock_offset', get_gpu_nvclock_offset)
351+
disp.extension_add_method('display', 'nvcontrol_set_gpu_nvclock_offset', set_gpu_nvclock_offset)
349352
disp.extension_add_method('display', 'nvcontrol_get_mem_transfer_rate_offset', get_mem_transfer_rate_offset)
353+
disp.extension_add_method('display', 'nvcontrol_set_mem_transfer_rate_offset', set_mem_transfer_rate_offset)
350354
disp.extension_add_method('display', 'nvcontrol_get_cooler_manual_control_enabled',
351355
get_cooler_manual_control_enabled)
352356
disp.extension_add_method('display', 'nvcontrol_get_fan_duty', get_fan_duty)

examples/nvcontrol.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
gpu = Gpu(0)
5151
fan = Cooler(0)
5252

53+
perf_level = 3
54+
5355
dic = {
5456
'get_gpu_count': display.nvcontrol_get_gpu_count(),
5557
'get_vram': display.nvcontrol_get_vram(gpu),
@@ -70,8 +72,8 @@
7072
'get_video_encoder_utilization': display.nvcontrol_get_video_encoder_utilization(gpu),
7173
'get_video_decoder_utilization': display.nvcontrol_get_video_decoder_utilization(gpu),
7274
'get_current_performance_level': display.nvcontrol_get_current_performance_level(gpu),
73-
'get_gpu_nvclock_offset': display.nvcontrol_get_gpu_nvclock_offset(gpu),
74-
'get_mem_transfer_rate_offset': display.nvcontrol_get_mem_transfer_rate_offset(gpu),
75+
'get_gpu_nvclock_offset': display.nvcontrol_get_gpu_nvclock_offset(gpu, perf_level),
76+
'get_mem_transfer_rate_offset': display.nvcontrol_get_mem_transfer_rate_offset(gpu, perf_level),
7577
'get_cooler_manual_control_enabled': display.nvcontrol_get_cooler_manual_control_enabled(gpu),
7678
'get_fan_duty': display.nvcontrol_get_fan_duty(fan),
7779
'get_fan_rpm': display.nvcontrol_get_fan_rpm(fan),

0 commit comments

Comments
 (0)