clbr / radeontop

GNU General Public License v3.0
804 stars 70 forks source link

Fix auto-detection of radeon device #33

Closed Lekensteyn closed 8 years ago

Lekensteyn commented 8 years ago

If the Bus ID is not given, do not assume that /dev/dri/card0 is the radeon device. This is not the case on this desktop PC with integrated Intel graphics and an AMD GPU.

Note that drmOpen("radeon", NULL) will fail when it is in use, that is why the Bus ID is explicitly given here.


Split off from #32. Without this patch I cannot test #32 because /dev/dri/card0 is the Intel GPU and not the AMD one. The -b 1 option also does not work because drmGetBusid(fd) always returns an empy string for some reason.

clbr commented 8 years ago

The code is good, so just pending a confirmation that -b still works both ways from someone with 2+ Radeons (just to be safe).

clbr commented 8 years ago

Re your edit: maybe open a libdrm bug? It might also be a kernel issue, but they'll tell you if it is.

Lekensteyn commented 8 years ago

drmGetBusid() returns a zero string if there is no master (see drm_getunique() in the Linux kernel. It does not seem reliable. I've called for testing in #radeon, no replies so far. What kernel/libdrm versions do you intend to support btw?

clbr commented 8 years ago

Everything within 5 years or so. Radeontop even runs on BSD, though with some changes.

Lekensteyn commented 8 years ago

It took some time to find a machine with multiple GPUs, but here you go:

[root@archiso ~]# lspci |grep 'VGA|Displ|3D' -E
00:01.0 VGA compatible controller: Advanced Micro Devices, Inc. [AMD/ATI] Kaveri [Radeon R6 Graphics]
01:00.0 Display controller: Advanced Micro Devices, Inc. [AMD/ATI] Jet PRO [Radeon R5 M230]
[root@archiso ~]# strace -e file -o st.txt ./radeontop -l1 -d - 
Dumping to -, line limit 1.
1469730448.422991: gpu 0.00%, ee 0.00%, vgt 0.00%, ta 0.00%, sx 0.00%, sh 0.00%, spi 0.00%, sc 0.00%, pa 0.00%, db 0.00%, cb 0.00%, vram 1.48% 15.11mb
[root@archiso ~]# strace -e file -o st0.txt ./radeontop -l1 -d - -b 0
Dumping to -, line limit 1.
1469730456.323370: gpu 0.00%, ee 0.00%, vgt 0.00%, ta 0.00%, sx 0.00%, sh 0.00%, spi 0.00%, sc 0.00%, pa 0.00%, db 0.00%, cb 0.00%, vram 1.48% 15.11mb
[root@archiso ~]# strace -e file -o st1.txt ./radeontop -l1 -d - -b 1
Dumping to -, line limit 1.
1469730463.468306: gpu 0.00%, ee 0.00%, vgt 0.00%, ta 0.00%, sx 0.00%, sh 0.00%, spi 0.00%, sc 0.00%, pa 0.00%, db 0.00%, cb 0.00%, vram 0.21% 4.29mb
[root@archiso ~]# strace -e file -o st2.txt ./radeontop -l1 -d - -b 2
Can't find Radeon cards

Based on the straces, i can see that both -b 0 and no -b open /dev/dri/card0. -b 1 opens /dev/dri/card0 twice, but eventually it uses /dev/dri/card1. Using gdb on radeontop and /proc/.../fd/ I also verified that drmOpen(NULL, "pci:0000:01:00.0") returns a fd to /dev/dri/card1.

Without this patch, option -b1 fails partially with:

[root@archiso radeontop]# ./radeontop -l1 -d- -b1
Failed to open DRM node, no VRAM support.
Dumping to -, line limit 1.
1469736741.156072: gpu 0.00%, ee 0.00%, vgt 0.00%, ta 0.00%, sx 0.00%, sh 0.00%, spi 0.00%, sc 0.00%, pa 0.00%, db 0.00%, cb 0.00%

Tested on an Asus X550ZE which has an APU and a dedicated GPU. Software versions at the time of testing: