Merge ~kissiel/plainbox-provider-resource:autoswitch-gpus into plainbox-provider-resource:master

Proposed by Maciej Kisielewski
Status: Merged
Approved by: Maciej Kisielewski
Approved revision: 2d8def920da45fa2b9e332bdb242513ef54b652d
Merged at revision: 90c280c6678b1e15708261644e6d11609814ad6c
Proposed branch: ~kissiel/plainbox-provider-resource:autoswitch-gpus
Merge into: plainbox-provider-resource:master
Diff against target: 46 lines (+20/-1)
1 file modified
bin/graphics_card_resource (+20/-1)
Reviewer Review Type Date Requested Status
Pierre Equoy Approve
Maciej Kisielewski Needs Resubmitting
Review via email: mp+333604@code.launchpad.net

Description of the change

list how to switch to particular GPU from a graphics_card_resource

The records are now printed after they are amended. This way, when we're 'processing' GPU no 2 (usually the discrete one), we can add to the record GPU no 1 information how it's enabled.
This is because it's the manufacturer of the discrete GPU that decides how to switch iGPU -> dGPU and dGPU -> iGPU.

---

This MR also contains changes from https://code.launchpad.net/~kissiel/plainbox-provider-resource/+git/plainbox-provider-resource/+merge/333582. Guess it's best to land the other branch first.

To post a comment you must log in.
Revision history for this message
Sheila Miguez (codersquid) wrote :

I have a very minor comment about a comment.

Revision history for this message
Maciej Kisielewski (kissiel) wrote :

> I have a very minor comment about a comment.

Blah, that comment was ugly! Thanks for pointing that out!

Fixed, amended, pushed.

review: Needs Resubmitting
Revision history for this message
Pierre Equoy (pieq) wrote :
Download full text (3.5 KiB)

Heuristics seems good.

However, I tested it on a laptop with a nVidia discrete GPU (and proprietary nvidia drivers installed) and I get weird results.

First, I make sure I'm using the nvidia GPU, then I run this new version of graphics_card_resource:

-----------------------------------------------------------
$ prime-select query
nvidia

$ ./graphics_card_resource -c /usr/lib/plainbox-provider-resource-generic/bin/udev_resource
bus: pci
category: VIDEO
driver: i915
index: 1
path: /devices/pci0000:00/0000:00:02.0
prime_gpu_offload: Off
product: PCI ID 0x591d
product_id: 22813
product_slug: PCI_ID_0x591d
subproduct_id: 1969
subvendor_id: 4136
switch_to_cmd: false
vendor: Intel Corporation
vendor_id: 32902
vendor_slug: Intel_Corporation

bus: pci
category: VIDEO
driver: nvidia
index: 2
path: /devices/pci0000:00/0000:00:01.0/0000:01:00.0
prime_gpu_offload: Off
product: PCI ID 0x1bb8
product_id: 7096
product_slug: PCI_ID_0x1bb8
subproduct_id: 1969
subvendor_id: 4136
switch_to_cmd: prime-select intel
vendor: NVIDIA Corporation
vendor_id: 4318
vendor_slug: NVIDIA_Corporation
-----------------------------------------------------------

As you can see, the `switch_to_cmd` for intel is set to `false` (not sure if this is a bug or a featureā€¦ :))

Then I switch to intel:
-----------------------------------------------------------
$ sudo prime-select intel
[sudo] password for u:
Info: the current GL alternatives in use are: ['nvidia-384', 'nvidia-384']
Info: the current EGL alternatives in use are: ['nvidia-384', 'nvidia-384']
Info: selecting nvidia-384-prime for the intel profile
update-alternatives: using /usr/lib/nvidia-384-prime/ld.so.conf to provide /etc/ld.so.conf.d/x86_64-linux-gnu_GL.conf (x86_64-linux-gnu_gl_conf) in manual mode
/sbin/ldconfig.real: /usr/lib/nvidia-384/libEGL.so.1 is not a symbolic link

/sbin/ldconfig.real: /usr/lib32/nvidia-384/libEGL.so.1 is not a symbolic link

update-alternatives: using /usr/lib/nvidia-384-prime/ld.so.conf to provide /etc/ld.so.conf.d/x86_64-linux-gnu_EGL.conf (x86_64-linux-gnu_egl_conf) in manual mode
update-alternatives: using /usr/lib/nvidia-384-prime/alt_ld.so.conf to provide /etc/ld.so.conf.d/i386-linux-gnu_GL.conf (i386-linux-gnu_gl_conf) in manual mode
update-alternatives: using /usr/lib/nvidia-384-prime/alt_ld.so.conf to provide /etc/ld.so.conf.d/i386-linux-gnu_EGL.conf (i386-linux-gnu_egl_conf) in manual mode
-----------------------------------------------------------

I reboot, then:

-----------------------------------------------------------
$ prime-select query
intel
u@u-Precision-7720:~$ ./graphics_card_resource -c /usr/lib/plainbox-provider-resource-generic/bin/udev_resource
bus: pci
category: VIDEO
driver: i915
index: 1
path: /devices/pci0000:00/0000:00:02.0
prime_gpu_offload: Off
product: PCI ID 0x591d
product_id: 22813
product_slug: PCI_ID_0x591d
subproduct_id: 1969
subvendor_id: 4136
switch_to_cmd: false
vendor: Intel Corporation
vendor_id: 32902
vendor_slug: Intel_Corporation

bus: pci
category: VIDEO
driver: pcieport
index: 2
path: /devices/pci0000:00/0000:00:01.0/0000:01:00.0
prime_gpu_offload: Off
product: PCI ID 0x1bb8
product_id: 7096
product_slug: PCI_ID_0x1bb8
subproduct_...

Read more...

review: Needs Fixing
Revision history for this message
Maciej Kisielewski (kissiel) wrote :

Thanks for testing.

The code was broken. I used the same index for the list of videocards taken from the 'index' field of the record. The latter being numbered from 1! (Yuck!). So instead of setting switch_to to intel GPU it overwritten the nvidia's one.

_should_ work now :)

If it doesn't, could you provide udev_resource output from those systems? Then I could mock everything on my side.

review: Needs Resubmitting
Revision history for this message
Pierre Equoy (pieq) wrote :
Download full text (5.0 KiB)

I ran additional tests using a laptop with an AMD dGPU and a laptop with an nVidia dGPU.

It seems to work as expected (the proper string if 'amdgpu-pro' or 'nvidia'), but it fails on a nvidia device where the Intel iGPU is selected in prime-settings (it displays 'false'/'false' because the driver for the nvidia GPU is set to `pcieport`, see test 3. below).

Also, while running the test, I installed the latest version of amdgpu-pro (17.40) and discovered that the bin that is called (`/opt/amdgpu-pro/bin/amdgpu-pro-px`) does not exist anymore... This might be a problem with later devices, depending on what version of amdgpu-pro they're using.

Finally, I'm not sure what's the purpose of this additional string, but is it OK to display false/false when using amdgpu open source drivers?

Maciek, I e-mailed you the different output from udev_resource for the given laptops.

1. On a device with the open source amdgpu drivers only:

----------------------------------------------------------------------
bus: pci
category: VIDEO
driver: i915
index: 1
path: /devices/pci0000:00/0000:00:02.0
prime_gpu_offload: Off
product: PCI ID 0x5916
product_id: 22806
product_slug: PCI_ID_0x5916
subproduct_id: 1966
subvendor_id: 4136
switch_to_cmd: false
vendor: Intel Corporation
vendor_id: 32902
vendor_slug: Intel_Corporation

bus: pci
category: VIDEO
driver: amdgpu
index: 2
path: /devices/pci0000:00/0000:00:1c.0/0000:01:00.0
prime_gpu_offload: On
product: PCI ID 0x6907
product_id: 26887
product_slug: PCI_ID_0x6907
subproduct_id: 1966
subvendor_id: 4136
switch_to_cmd: false
vendor: Advanced Micro Devices, Inc. [AMD/ATI]
vendor_id: 4098
vendor_slug: Advanced_Micro_Devices__Inc.__AMD_ATI_
----------------------------------------------------------------------

2. On a device with proprietary amdgpu-pro drivers:

----------------------------------------------------------------------
bus: pci
category: VIDEO
driver: i915
index: 1
path: /devices/pci0000:00/0000:00:02.0
prime_gpu_offload: Off
product: PCI ID 0x5916
product_id: 22806
product_slug: PCI_ID_0x5916
subproduct_id: 1966
subvendor_id: 4136
switch_to_cmd: /opt/amdgpu-pro/bin/amdgpu-pro-px --mode powersaving
vendor: Intel Corporation
vendor_id: 32902
vendor_slug: Intel_Corporation

bus: pci
category: VIDEO
driver: amdgpu-pro
index: 2
path: /devices/pci0000:00/0000:00:1c.0/0000:01:00.0
prime_gpu_offload: Off
product: PCI ID 0x6907
product_id: 26887
product_slug: PCI_ID_0x6907
subproduct_id: 1966
subvendor_id: 4136
switch_to_cmd: /opt/amdgpu-pro/bin/amdgpu-pro-px --mode performa...

Read more...

Revision history for this message
Maciej Kisielewski (kissiel) wrote :

> I ran additional tests using a laptop with an AMD dGPU and a laptop with an
> nVidia dGPU.
Thanks!

> It seems to work as expected (the proper string if 'amdgpu-pro' or 'nvidia'),
> but it fails on a nvidia device where the Intel iGPU is selected in prime-
> settings (it displays 'false'/'false' because the driver for the nvidia GPU is
> set to `pcieport`, see test 3. below).
I fixed that by adding another clause (pcieport)

> Also, while running the test, I installed the latest version of amdgpu-pro
> (17.40) and discovered that the bin that is called (`/opt/amdgpu-pro/bin
> /amdgpu-pro-px`) does not exist anymore... This might be a problem with later
> devices, depending on what version of amdgpu-pro they're using.
As with most those resources we'll have to maintain it as paths change.

> Finally, I'm not sure what's the purpose of this additional string, but is it
> OK to display false/false when using amdgpu open source drivers?
those strings are commands that should be run to change gpu.
running `false` returns status code indicating failure, meaning we cannot switch GPU. This shouldn't really happen, as the switching jobs have additional requirements in them that make the filtering.

> Maciek, I e-mailed you the different output from udev_resource for the given
> laptops.
Thanks.

Revision history for this message
Pierre Equoy (pieq) wrote :

It works fine! Thanks for all the quick updates!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/bin/graphics_card_resource b/bin/graphics_card_resource
2index 19daf11..1bbd806 100755
3--- a/bin/graphics_card_resource
4+++ b/bin/graphics_card_resource
5@@ -19,6 +19,7 @@
6 # along with Checkbox. If not, see <http://www.gnu.org/licenses/>.
7
8 import argparse
9+import collections
10 import subprocess
11 import shlex
12 import string
13@@ -121,6 +122,17 @@ def main():
14 if r.get("category", "") == 'VIDEO')
15 video_devices.sort(key=lambda r: bus_ordering(r))
16
17+ # commands needed to switch to and from particular GPU,
18+ # keyed by the driver name. Defaults to 'false'/'false' commands.
19+ switch_cmds = collections.defaultdict(lambda: ('false', 'false'))
20+ switch_cmds['nvidia'] = ('prime-select nvidia', 'prime-select intel')
21+ # nvidia uses 'pcieport' driver when the dGPU is disabled
22+ switch_cmds['pcieport'] = ('prime-select nvidia', 'prime-select intel')
23+
24+ switch_cmds['amdgpu-pro'] = (
25+ '/opt/amdgpu-pro/bin/amdgpu-pro-px --mode performance',
26+ '/opt/amdgpu-pro/bin/amdgpu-pro-px --mode powersaving')
27+
28 # Lazily add index to each video device
29 try:
30 for index, record in enumerate(video_devices, 1):
31@@ -159,7 +171,14 @@ def main():
32 record['prime_gpu_offload'] = 'On'
33 else:
34 record['prime_gpu_offload'] = 'Off'
35- # Finally, print the record
36+ record['switch_to_cmd'] = switch_cmds[record['driver']][0]
37+ if index == 2 and len(video_devices) == 2:
38+ # we're at GPU number 2 and there are two, so here we assume
39+ # that video_devices[0] is the built-in one
40+ video_devices[0]['switch_to_cmd'] = (
41+ switch_cmds[record['driver']][1])
42+ # Finally, print the records
43+ for record in video_devices:
44 items = ["{key}: {value}".format(key=k, value=record[k])
45 for k in sorted(record.keys())]
46 print("\n".join(items))

Subscribers

People subscribed via source and target branches