External 4K monitor only gets 1K under Ubuntu GNOME with ASUS laptop, G940MX

Hi, I have a problem getting my external Samsung 4k monitor working with the proper resolution under Ubuntu GNOME 16.04.
It works fine on Windows. I’m using the 384.47 drivers from the nvidia PPA. The laptop is an ASUS UX560-something. Nvidia 940MX.

This is the Xorg log with a “–mode-debug” option enabled: http://eize.ninja/d/Xorg.0.log.2017.07.25

This Samsung monitor has a DP and two HDMI jacks. HDMI 1 supporting 30Hz and HDMI 2 supporting 60Hz. I connect to HDMI 2 (in Xorg log it’s called HDMI-1-2 if I’m not mistaken).
From what I saw in the logs, the DP seems to recognize the 4k resolution just fine, but both HDMIs are not playing nicely. The laptop only has an HDMI port so I can’t check DP.

I’m not sure what to do, I’m not very familiar with X or nvidia hacking so please bear with me. Trying to find a clue on the net or these forums only suggested updating the drivers, which I already got updated. Still searching.

Thanks.

Since you have a plain Optimus laptop, your HDMI is connected to your Intel GPU so monitor detection is done by the Intel modesetting driver, the Nvidia driver can’t do anything there. You can confirm by switching to Intel using ‘prime-select intel’ and reboot. Then the Nvidia gpu is off and everything is running on the Intel gpu. So if this is a bug, it’s in the intel driver.
BUT - to drive a 4k@60 display over HDMI you will need HDMI 2.0 and that’s where the mess starts. Nearly no laptop vendor will tell you which HDMI version the laptop supports. Please check in Windows, if your 4k display really runs at 60Hz. You can check that from the Intel or Nvidia Panel in systray. Often it will run at 24-30Hz only but the monitor’s OSD will lie and say 60Hz since its logic is scaling.
Check all this and report back.

Some research done, up till now no Intel GPU supports HDMI 2.0, only 1.4 with max 300MHz. 4k@60 only possible over DisplayPort which your laptop doesn’t provide.
So you’re limited to 30Hz with your hardware. Unfortunately, the modesetting driver doesn’t generate a modeline for this automatically so you have to set it by hand:

xrandr --newmode "3840x2160_30"  297 3840 4016 4104 4400 2160 2168 2178 2250 +hsync +vsync
xrandr --addmode HDMI-1-2 "3840x2160_30"
xrandr --output HDMI-1-2 --mode "3840x2160_30"

should work.

Hi, partial success!

I plugged the computer into the 30Hz HDMI port of the monitor just to be on the safe side and ran your commands. Both on nvidia and intel PRIME I got a 4K resolution! (with intel the HDMI-1-2 output was HDMI-2). However, some strange things do occur that I did not yet solve or know how to approach.

I have to run the xrandr commands after being logged in for now (defaulting it with gdm3 would be nice to know but out of scope now). When I do so and get the proper resolution, I need to set my monitor as the primary display and I try doing that with the built-in GNOME display app. When the screens go black for a moment they either don’t turn on or turn on with the whole system frozen: cursor not responding on a still image or image is black, alt+F[1-7] not working, and only alt+sys rq+REISUB works and reboots. This also happens when I try to rearrange the monitor to be right-of the laptop (defaults to left-of). I managed to run xrandr ... --mode "3480..." --left-of eDP-1-1 and that worked, but when running it for the first time it won’t (so I have to set up 4K ‘twice’).

So all of this is very strange, the system is not stable.
Also the movement of windows for example is a bit jerky and ‘tearing’ even though I use nvidia. Is it because it’s 30Hz?

Bottom line I continue to work now with a script running the xrandr commands. I’ll have to continue later.

What you describe as jerky might well be due to 30Hz, I would describe it as stroboscopic effect.
Are you running PRIME Sync? You can see this by issuing xrandr --prop
While the system seems frozen, can you ssh into it and run nvidia-bug-report.sh?
Please also run this while you’re switched once to intel and once to nvidia. Attach all resulting files to your post.
When you say ‘Both on nvidia and intel PRIME’ how do you switch? Using prime-select intel/nvidia? Or by bios switch Hybrid/Discrete?
Did you check in Windows at what refresh rate the monitor runs?

xrandr --prop doesn’t have any “PRIME” or “sync” grepped (I searched case insensitive).

nvidia-bug-report.sh will have to wait a few days until I’m free to run it easily some evening.

Regarding the nvidia/intel PRIME - emm, I either switched with prime-select intel/nvidia and rebooted each time I chose one. Not by any bios switch that I’m not sure what it is (like a “graphics boost” button on the laptop keyboard?).

I booted Windows. Though the intel panel reported 60Hz on both HDMI jacks 1 and 2, the monitor itself reported 30Hz (maybe it doesn’t lie after all). I installed the nvidia drivers and rebooted again (it’s mostly a fresh installation) and the monitor reported 30Hz on HDMI 2, didn’t check HDMI 1 because I assume it’s 30Hz. It can’t be 60Hz according to the monitor’s manual while HDMI 2 can.

It’s worth mentioning I have problems with waking up from sleep while nvidia PRIME is selected but that’s another thread that I posted in: https://devtalk.nvidia.com/default/topic/1017185/problem-with-resume-from-suspend-ubuntu-16-04-gt-940mx-/

Seems like something is always lying ;)
Unfortunately, you will have to live with only running at 30Hz as it’s a hardware limitation.
I was a little bit confused by your wording, using ‘nvidia PRIME’ and ‘(plain) intel’ would be more clear.
On second glance at your log, my question if you’re running sync was pointless since you’re running xserver 1.18, sync only being availyble since 1.19. So no additional problems from that.
Without sync there’s also the tearing you’re observing. Though I don’t know what will happen if you upgrade and activate sync with running at 60Hz on one display and 30Hz on the other one. Something to explore for you later;)
Concerning your suspend/resume problem, while you’re at it producing logs you could also run acpidump and attach the resulting file. There are currently some acpi kernel bugs affecting laptops with nvidia gpus.
As a shot in the dark, you could add

acpi_osi=! acpi_osi="Windows 2009"

to your kernel commandline, reboot and see what happens.
See this how to insert it to grub config:
https://devtalk.nvidia.com/default/topic/1010972/linux/problems-with-opensuse-and-my-asus-rog-gl752vw-dh71/post/5159554/#5159554

Hello @generix, sorry for the late response. I finally managed to find some time to SSH into the machine while it’s frozen after waking up. Here’s the NVIDIA bug report - https://drive.google.com/open?id=0B6qX0y_VgqzMLU1XR2wzTHVpS2M

Regarding “Windows 2009” in grub config - it didn’t work. I tried that about a month ago though, and there was an update since then to some stuff on the machine. Is it worth trying again?

Hmm, I didn’t run acpidump. I will try to so tomorrow. Is it just running the command acpidump after I wake up and SSH into the machine?

Thanks!

No need to suspend/resume for acpidump. It just extracts the acpitables from your bios. This can be done at any time.
Though I’m not really sure this is an acpi problem anymore. From the logs you provided, I can see that the nvidia gpu is very well awake after resume, the kernel driver responds to nvidia-smi queries, no errors at all at kernel level, but the X driver seems to be not responding. I’m out of ideas right now.

Maybe another test case to get some more info:
boot
switch to VT
login, get root
stop X (systemctl stop display-manager)
suspend (systemctl suspend)
wait, resume
issue lspci -vvv three times, see if it hangs
if not, start x (systemctl start displaymanager)
if it freezes again, wait for 5 minutes, then ssh in and run nvidia-bug-report.sh
Maybe some hang check gets triggered so there’s additional info.