Bug 101837

Summary: libdrm fails to get bus id
Product: DRI Reporter: Daniel Power <me>
Component: libdrmAssignee: Default DRI bug account <dri-devel>
Status: RESOLVED MOVED QA Contact:
Severity: normal    
Priority: medium CC: cand
Version: DRI git   
Hardware: Other   
OS: All   
Whiteboard:
i915 platform: i915 features:

Description Daniel Power 2017-07-19 07:57:12 UTC
radeontop is unable to display VRAM information because openDRM() returns -1

Graphics card: R9 270X
Distribution: Archlinux
Kernel Version: 4.11.9
libdrm version: 2.4.81 (also tested latest from git)
kernel driver: radeon

Output of radeontop with LIBGL_DEBUG=verbose enabled:

drmOpenDevice: node name is /dev/dri/card0
drmOpenDevice: open result is 4, (OK)
drmOpenByBusid: Searching for BusID pci:0000:01:00.0
drmOpenDevice: node name is /dev/dri/card0
drmOpenDevice: open result is 4, (OK)
drmOpenByBusid: drmOpenMinor returns 4
drmOpenByBusid: Interface 1.4 failed, trying 1.1
drmOpenByBusid: drmGetBusid reports 
drmOpenDevice: node name is /dev/dri/card1
drmOpenByBusid: drmOpenMinor returns -1
drmOpenDevice: node name is /dev/dri/card2
drmOpenByBusid: drmOpenMinor returns -1
drmOpenDevice: node name is /dev/dri/card3
drmOpenByBusid: drmOpenMinor returns -1
drmOpenDevice: node name is /dev/dri/card4
drmOpenByBusid: drmOpenMinor returns -1
drmOpenDevice: node name is /dev/dri/card5
drmOpenByBusid: drmOpenMinor returns -1
drmOpenDevice: node name is /dev/dri/card6
drmOpenByBusid: drmOpenMinor returns -1
drmOpenDevice: node name is /dev/dri/card7
drmOpenByBusid: drmOpenMinor returns -1
drmOpenDevice: node name is /dev/dri/card8
drmOpenByBusid: drmOpenMinor returns -1
drmOpenDevice: node name is /dev/dri/card9
drmOpenByBusid: drmOpenMinor returns -1
drmOpenDevice: node name is /dev/dri/card10
drmOpenByBusid: drmOpenMinor returns -1
drmOpenDevice: node name is /dev/dri/card11
drmOpenByBusid: drmOpenMinor returns -1
drmOpenDevice: node name is /dev/dri/card12
drmOpenByBusid: drmOpenMinor returns -1
drmOpenDevice: node name is /dev/dri/card13
drmOpenByBusid: drmOpenMinor returns -1
drmOpenDevice: node name is /dev/dri/card14
drmOpenByBusid: drmOpenMinor returns -1
drmOpenDevice: node name is /dev/dri/card15
drmOpenByBusid: drmOpenMinor returns -1
Failed to open DRM node, no VRAM support.
Collecting data, please wait....

Output of lspci -vnn:

01:00.0 VGA compatible controller: Advanced Micro Devices, Inc. [AMD/ATI] Curacao XT / Trinidad XT [Radeon R7 370 / R9 270X/370X] (prog-if 00 [VGA controller])
	Subsystem: Hightech Information System Ltd. Device 2336
	Control: I/O+ Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx+
	Status: Cap+ 66MHz- UDF- FastB2B- ParErr- DEVSEL=fast >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx-
	Latency: 0, Cache Line Size: 64 bytes
	Interrupt: pin A routed to IRQ 49
	NUMA node: 0
	Region 0: Memory at c0000000 (64-bit, prefetchable) [size=256M]
	Region 2: Memory at fea00000 (64-bit, non-prefetchable) [size=256K]
	Region 4: I/O ports at e000 [size=256]
	Expansion ROM at 000c0000 [disabled] [size=128K]
	Capabilities: [48] Vendor Specific Information: Len=08 <?>
	Capabilities: [50] Power Management version 3
		Flags: PMEClk- DSI- D1+ D2+ AuxCurrent=0mA PME(D0-,D1+,D2+,D3hot+,D3cold-)
		Status: D0 NoSoftRst- PME-Enable- DSel=0 DScale=0 PME-
	Capabilities: [58] Express (v2) Legacy Endpoint, MSI 00
		DevCap:	MaxPayload 256 bytes, PhantFunc 0, Latency L0s <4us, L1 unlimited
			ExtTag+ AttnBtn- AttnInd- PwrInd- RBE+ FLReset-
		DevCtl:	Report errors: Correctable- Non-Fatal- Fatal- Unsupported-
			RlxdOrd- ExtTag+ PhantFunc- AuxPwr- NoSnoop+
			MaxPayload 128 bytes, MaxReadReq 512 bytes
		DevSta:	CorrErr+ UncorrErr- FatalErr- UnsuppReq+ AuxPwr- TransPend-
		LnkCap:	Port #0, Speed 8GT/s, Width x16, ASPM L0s L1, Exit Latency L0s <64ns, L1 <1us
			ClockPM- Surprise- LLActRep- BwNot- ASPMOptComp+
		LnkCtl:	ASPM Disabled; RCB 64 bytes Disabled- CommClk+
			ExtSynch- ClockPM- AutWidDis- BWInt- AutBWInt-
		LnkSta:	Speed 5GT/s, Width x16, TrErr- Train- SlotClk+ DLActive- BWMgmt- ABWMgmt-
		DevCap2: Completion Timeout: Not Supported, TimeoutDis-, LTR-, OBFF Not Supported
		AtomicOpsCap: 32bit- 64bit- 128bitCAS-
		DevCtl2: Completion Timeout: 50us to 50ms, TimeoutDis-, LTR-, OBFF Disabled
		AtomicOpsCtl: ReqEn-
		LnkCtl2: Target Link Speed: 8GT/s, EnterCompliance- SpeedDis-
			 Transmit Margin: Normal Operating Range, EnterModifiedCompliance- ComplianceSOS-
			 Compliance De-emphasis: -6dB
		LnkSta2: Current De-emphasis Level: -3.5dB, EqualizationComplete-, EqualizationPhase1-
			 EqualizationPhase2-, EqualizationPhase3-, LinkEqualizationRequest-
	Capabilities: [a0] MSI: Enable+ Count=1/1 Maskable- 64bit+
		Address: 00000000fee00000  Data: 0000
	Capabilities: [100 v1] Vendor Specific Information: ID=0001 Rev=1 Len=010 <?>
	Capabilities: [150 v2] Advanced Error Reporting
		UESta:	DLP- SDES- TLP- FCP- CmpltTO- CmpltAbrt- UnxCmplt- RxOF- MalfTLP- ECRC- UnsupReq- ACSViol-
		UEMsk:	DLP- SDES- TLP- FCP- CmpltTO- CmpltAbrt- UnxCmplt- RxOF- MalfTLP- ECRC- UnsupReq- ACSViol-
		UESvrt:	DLP+ SDES+ TLP- FCP+ CmpltTO- CmpltAbrt- UnxCmplt- RxOF+ MalfTLP+ ECRC- UnsupReq- ACSViol-
		CESta:	RxErr- BadTLP- BadDLLP- Rollover- Timeout- NonFatalErr+
		CEMsk:	RxErr- BadTLP- BadDLLP- Rollover- Timeout- NonFatalErr+
		AERCap:	First Error Pointer: 00, GenCap+ CGenEn- ChkCap+ ChkEn-
	Capabilities: [200 v1] #15
	Capabilities: [270 v1] #19
	Capabilities: [2b0 v1] Address Translation Service (ATS)
		ATSCap:	Invalidate Queue Depth: 00
		ATSCtl:	Enable+, Smallest Translation Unit: 00
	Capabilities: [2c0 v1] Page Request Interface (PRI)
		PRICtl: Enable- Reset-
		PRISta: RF- UPRGI- Stopped+
		Page Request Capacity: 00000020, Page Request Allocation: 00000000
	Capabilities: [2d0 v1] Process Address Space ID (PASID)
		PASIDCap: Exec+ Priv+, Max PASID Width: 10
		PASIDCtl: Enable- Exec- Priv-
	Kernel driver in use: radeon
	Kernel modules: radeon, amdgpu


Original issue posted on radeontop github: https://github.com/clbr/radeontop/issues/48
Comment 1 Michel Dänzer 2017-07-19 11:01:08 UTC
Please attach the corresponding dmesg output and Xorg log file.
Comment 2 Daniel Power 2017-07-20 02:46:39 UTC
dmesg: https://pastebin.com/fcz5mEb0
xorg: https://pastebin.com/2dacJqTe
Comment 3 Emil Velikov 2017-07-20 11:16:37 UTC
DanielP an orthogonal solution is to simply not use drmOpen. While it works, sometimes, there's a lot of hidden gotchas.

Simply replace the pciaccess + drmOpen with drmDevice2 - see libdrm/tests/drmdevice.c.

Notes:
* radeon-top does _not_ need to open the card node, hence no need for auth - directly or via xcb
* using pciaccess, or drmDevice2 with DRM_DEVICE_GET_PCI_REVISION will wake up your discrete GPU, even if you're looking for the stats of you APU - you want to avoid that if possible.
* do not forget to close the fd - currently it's leaked.
Comment 4 Lauri Kasanen 2017-07-21 06:30:41 UTC
The DRM node must be opened (and kept open for the lifetime of the app) to make the VRAM queries, or to make the register queries on kernels that prohibit direct access (e.g. Ubuntu).
Comment 5 Emil Velikov 2017-07-21 12:32:57 UTC
(In reply to Lauri Kasanen from comment #4)
> The DRM node must be opened (and kept open for the lifetime of the app) to
> make the VRAM queries, or to make the register queries on kernels that
> prohibit direct access (e.g. Ubuntu).

Right - the fd is required for the queries. Yet the app does not seem to close it upon exit ;-)
Comment 6 Lauri Kasanen 2017-07-21 13:10:32 UTC
Yes. That is done by the OS. This is standard practice in the embedded world, saving pointless code.
Comment 7 Emil Velikov 2017-07-21 14:56:01 UTC
(In reply to Lauri Kasanen from comment #6)
> Yes. That is done by the OS. This is standard practice in the embedded
> world, saving pointless code.
This is getting really off-topic. We might want to spend that time on more productive things;-) AFAICT the app is _not_ made for the embedded world, plus "pointless" is fairly subjective. That said, if you don't want to do it, so be it.
Comment 8 Daniel Power 2017-07-22 06:34:16 UTC
I appreciate your suggestions to make changes to radeontop. I have made note of that in my bug report to radeontop. However, I am not a C developer, and don't know how to make the changes myself.

I created this bug report at the suggestion of the radeontop developer, since the openDrm functionality works for other users, but fails on my system. So he believes it is a bug in libdrm.

If this is not a bug with lidrm, I will pass it along to the radeontop developer, and hopefully he can do something about it.
Comment 9 GitLab Migration User 2019-09-24 17:09:14 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to freedesktop.org's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.freedesktop.org/mesa/drm/issues/18.

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.