bayasdev / envycontrol

Easy GPU switching for Nvidia Optimus laptops under Linux
https://bayas.dev/envycontrol
MIT License
1.18k stars 60 forks source link

Prime Offload not working after switching to hybrid mode - Ubuntu 22.04 #77

Closed danielkrajnik closed 1 year ago

danielkrajnik commented 1 year ago

Running __NV_PRIME_RENDER_OFFLOAD=1 __VK_LAYER_NV_optimus=NVIDIA_only __GLX_VENDOR_LIBRARY_NAME=nvidia vkcube still uses intel iGPU:

MESA-INTEL: warning: Performance support disabled, consider sysctl dev.i915.perf_stream_paranoid=0

Selected GPU 0: Intel(R) UHD Graphics (CML GT2), type: 1

neofetch: image

I've run strace on sudo envycontrol --switch hybrid (if that's of any help):

strace: Process 102252 attached
read(0, "y\n", 1024)                    = 2
newfstatat(AT_FDCWD, "/lib/udev/rules.d", {st_mode=S_IFDIR|0755, st_size=135, ...}, 0) = 0
openat(AT_FDCWD, "/lib/udev/rules.d/80-nvidia-pm.rules", O_WRONLY|O_CREAT|O_TRUNC|O_CLOEXEC, 0666) = 3
newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=0, ...}, AT_EMPTY_PATH) = 0
ioctl(3, TCGETS, 0x7ffe51ec9710)        = -1 ENOTTY (Inappropriate ioctl for device)
brk(0x55cd7174a000)                     = 0x55cd7174a000
lseek(3, 0, SEEK_CUR)                   = 0
lseek(3, 0, SEEK_CUR)                   = 0
write(3, "# Automatically generated by Env"..., 1177) = 1177
close(3)                                = 0
newfstatat(AT_FDCWD, "/etc/modprobe.d", {st_mode=S_IFDIR|0755, st_size=16, ...}, 0) = 0
openat(AT_FDCWD, "/etc/modprobe.d/nvidia.conf", O_WRONLY|O_CREAT|O_TRUNC|O_CLOEXEC, 0666) = 3
newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=0, ...}, AT_EMPTY_PATH) = 0
ioctl(3, TCGETS, 0x7ffe51ec9710)        = -1 ENOTTY (Inappropriate ioctl for device)
lseek(3, 0, SEEK_CUR)                   = 0
lseek(3, 0, SEEK_CUR)                   = 0
write(3, "# Automatically generated by Env"..., 176) = 176
close(3)                                = 0
newfstatat(AT_FDCWD, "/etc/debian_version", {st_mode=S_IFREG|0644, st_size=13, ...}, 0) = 0
write(1, "Rebuilding initramfs...\n", 24) = 24
openat(AT_FDCWD, "/dev/null", O_RDWR|O_CLOEXEC) = 3
pipe2([4, 5], O_CLOEXEC)                = 0
rt_sigprocmask(SIG_BLOCK, ~[RTMIN RT_1], [], 8) = 0
vfork()                                 = 106238
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
close(5)                                = 0
close(3)                                = 0
read(4, "", 50000)                      = 0
close(4)                                = 0
wait4(106238, 0x7ffe51ec8f1c, 0, NULL)  = ? ERESTARTSYS (To be restarted if SA_RESTART is set)
--- SIGWINCH {si_signo=SIGWINCH, si_code=SI_KERNEL} ---
wait4(106238, [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0, NULL) = 106238
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=106238, si_uid=0, si_status=0, si_utime=0, si_stime=0} ---
write(1, "Successfully rebuilt initramfs!\n", 32) = 32
write(1, "Graphics mode set to: hybrid\nPle"..., 78) = 78
write(1, "\n", 1)                       = 1
rt_sigaction(SIGINT, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER|SA_ONSTACK, sa_restorer=0x7ff645c84520}, {sa_handler=0x55cd706c9990, sa_mask=[], sa_flags=SA_RESTORER|SA_ONSTACK, sa_restorer=0x7ff645c84520}, 8) = 0
munmap(0x7ff64531e000, 299008)          = 0
munmap(0x7ff645367000, 1048576)         = 0
exit_group(0)                           = ?
+++ exited with 0 +++

I've run prime-select on-demand and systemctl disable gpu-manager.service before switching to the hybrid mode.

xrandr --listproviders:

Providers: number : 2
Provider 0: id: 0x42 cap: 0x9, Source Output, Sink Offload crtcs: 3 outputs: 1 associated providers: 1 name:modesetting
Provider 1: id: 0x1fa cap: 0x2, Sink Output crtcs: 4 outputs: 8 associated providers: 1 name:NVIDIA-G0

any suggestions where the problems may reside will be welcomed with a lot of gratitude

bayasdev commented 1 year ago

Hybrid mode works out of the box without any tool, the only thing Envycontrol does is enabling modeset and Preserve VRAM kernel driver options.

On Sun, Jan 29, 2023, 09:00 danielkrajnik @.***> wrote:

I can't run __NV_PRIME_RENDER_OFFLOAD=1 VK_LAYER_NV_optimus=NVIDIA_only GLX_VENDOR_LIBRARY_NAME=nvidia glxgears - still uses intel iGPU.

I've run strace on sudo envycontrol --switch hybrid (shown below).

Noticed that xorg.conf isn't created and /usr/share/sddm/scripts/Xsetup isn't modified either - I thought that they need to be changed? I haven't found anywhere in the repo any suggestion that users should do it manually?

I was hoping that it will work out of the box :). Then again, I'm using Ubuntu...

strace: Process 102252 attached read(0, "y\n", 1024) = 2 newfstatat(AT_FDCWD, "/lib/udev/rules.d", {st_mode=S_IFDIR|0755, st_size=135, ...}, 0) = 0 openat(AT_FDCWD, "/lib/udev/rules.d/80-nvidia-pm.rules", O_WRONLY|O_CREAT|O_TRUNC|O_CLOEXEC, 0666) = 3 newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=0, ...}, AT_EMPTY_PATH) = 0 ioctl(3, TCGETS, 0x7ffe51ec9710) = -1 ENOTTY (Inappropriate ioctl for device) brk(0x55cd7174a000) = 0x55cd7174a000 lseek(3, 0, SEEK_CUR) = 0 lseek(3, 0, SEEK_CUR) = 0 write(3, "# Automatically generated by Env"..., 1177) = 1177 close(3) = 0 newfstatat(AT_FDCWD, "/etc/modprobe.d", {st_mode=S_IFDIR|0755, st_size=16, ...}, 0) = 0 openat(AT_FDCWD, "/etc/modprobe.d/nvidia.conf", O_WRONLY|O_CREAT|O_TRUNC|O_CLOEXEC, 0666) = 3 newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=0, ...}, AT_EMPTY_PATH) = 0 ioctl(3, TCGETS, 0x7ffe51ec9710) = -1 ENOTTY (Inappropriate ioctl for device) lseek(3, 0, SEEK_CUR) = 0 lseek(3, 0, SEEK_CUR) = 0 write(3, "# Automatically generated by Env"..., 176) = 176 close(3) = 0 newfstatat(AT_FDCWD, "/etc/debian_version", {st_mode=S_IFREG|0644, st_size=13, ...}, 0) = 0 write(1, "Rebuilding initramfs...\n", 24) = 24 openat(AT_FDCWD, "/dev/null", O_RDWR|O_CLOEXEC) = 3 pipe2([4, 5], O_CLOEXEC) = 0 rt_sigprocmask(SIG_BLOCK, ~[RTMIN RT_1], [], 8) = 0 vfork() = 106238 rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0 close(5) = 0 close(3) = 0 read(4, "", 50000) = 0 close(4) = 0 wait4(106238, 0x7ffe51ec8f1c, 0, NULL) = ? ERESTARTSYS (To be restarted if SA_RESTART is set) --- SIGWINCH {si_signo=SIGWINCH, si_code=SI_KERNEL} --- wait4(106238, [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0, NULL) = 106238 --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=106238, si_uid=0, si_status=0, si_utime=0, si_stime=0} --- write(1, "Successfully rebuilt initramfs!\n", 32) = 32 write(1, "Graphics mode set to: hybrid\nPle"..., 78) = 78 write(1, "\n", 1) = 1 rt_sigaction(SIGINT, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER|SA_ONSTACK, sa_restorer=0x7ff645c84520}, {sa_handler=0x55cd706c9990, sa_mask=[], sa_flags=SA_RESTORER|SA_ONSTACK, sa_restorer=0x7ff645c84520}, 8) = 0 munmap(0x7ff64531e000, 299008) = 0 munmap(0x7ff645367000, 1048576) = 0 exit_group(0) = ? +++ exited with 0 +++

— Reply to this email directly, view it on GitHub https://github.com/bayasdev/envycontrol/issues/77, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALY7IYJEHHCKLJQA4NOSAOTWUZZZPANCNFSM6AAAAAAUKIM4L4 . You are receiving this because you are subscribed to this thread.Message ID: @.***>

danielkrajnik commented 1 year ago

thanks, hmm I'm just not sure where to find information what steps are required after running --switch hybrid to get prime offload to work - sorry, I'm sure it's a really basic question, but I'm digging through strace logs on vkcube command just to figure out what's missing (losing hope a bit 😅...).

Envycontrol has helped me a lot already, but any suggestion how to make the prime offload to work would be really appreciated.

danielkrajnik commented 1 year ago

Seriously, this makes no sense. There is no information how to set it up at all

bayasdev commented 1 year ago

PRIME offloading works, try running Firefox with __NV_PRIME_RENDER_OFFLOAD=1 __GLX_VENDOR_LIBRARY_NAME=nvidia firefox and go to about:support it should say EGL Vendor is Nvidia Corporation.

danielkrajnik commented 1 year ago

thanks for checking this again, but trying to run firefox with these variables didn't work - please see excerpt from the output of about:supprt here: image

I have really tried everything from every guide for months now and can't get it to work or even just make any sense of it. Prime offload on ubuntu 22.04 is still really a bottomless pit that you keep throwing stuff into and never hear it echo back.

Is it any better on arch? Would it make sense to migrate the entire system?

bayasdev commented 1 year ago

Try the same command after envycontrol --reset and rebooting

On Sun, Jan 29, 2023, 13:22 danielkrajnik @.***> wrote:

thanks for checking this again, but it trying to run firefox with these variables didn't work - please see excerpt from the output of about:supprt here: [image: image] https://user-images.githubusercontent.com/15096799/215347643-b90a7f5e-d2af-49eb-8a06-57c81f3b4aab.png

— Reply to this email directly, view it on GitHub https://github.com/bayasdev/envycontrol/issues/77#issuecomment-1407735093, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALY7IYPW6CPVHDYZ3E6INBDWU2YPBANCNFSM6AAAAAAUKIM4L4 . You are receiving this because you commented.Message ID: @.***>

danielkrajnik commented 1 year ago

@bayasdev Sorry, it yields the same results: image

danielkrajnik commented 1 year ago

It's really confusing, because nvidia driver is installed correctly, programs like nvidia-smi and nvtop work fine, second monitor sometimes works. But prime offloading doesn't seem to do anything :(

xrandr --listproviders

Provider 0: id: 0x42 cap: 0x9, Source Output, Sink Offload crtcs: 3 outputs: 1 associated providers: 1 name:modesetting
Provider 1: id: 0x1fa cap: 0x2, Sink Output crtcs: 4 outputs: 8 associated providers: 1 name:NVIDIA-G0

nvtop

image

lsmod | grep -i nvidia

nvidia_wmi_ec_backlight    16384  0
nvidiafb               61440  0
vgastate               24576  1 nvidiafb
fb_ddc                 16384  1 nvidiafb
nvidia_uvm           1310720  0
nvidia_drm             69632  1
nvidia_modeset       1146880  2 nvidia_drm
nvidia              40849408  76 nvidia_uvm,nvidia_modeset
bayasdev commented 1 year ago

Sorry, I can't reproduce your problem but it sounds to me like some config in your setup is conflicting.

Since you have a Legion, you can disable Optimus from your BIOS and enjoy a better experience on Linux.

danielkrajnik commented 1 year ago

No worries, but I may try to install an entire system from scratch then, hopefully it will eventually click.

danielkrajnik commented 1 year ago

solved, I didn't install the nvidia driver properly. Running sudo apt install nvidia-driver-515 repaired it. Sorry, it was a really stupid error completely my fault (I thought just installing nvidia-dkms-515 was enough).