Askannz / optimus-manager

A Linux program to handle GPU switching on Optimus laptops.
MIT License
2.31k stars 172 forks source link

Must restart system to switch to nvidia #205

Open xonq opened 4 years ago

xonq commented 4 years ago

Describe the bug Can switch to nvidia driver if I set it as startup. Can switch back to intel and relogin to apply. Cannot switch to nvidia unless a full restart is applied. No error trying to switch to nvidia in session, but it just doesn't switch. Modprobe error in the gpu_setup.log below.

System info

Logs boot_setup.log gpu_setup.log prime_setup.log

pacman -Q | grep nvidia
nvidia 440.44-15
nvidia-utils 440.44-3
[root@xonq /]# lsmod | grep "kms\|drm"
nvidia_drm             49152  5
nvidia_modeset       1118208  7 nvidia_drm
drm_kms_helper        212992  2 nvidia_drm,i915
drm                   520192  9 drm_kms_helper,nvidia_drm,i915
agpgart                53248  2 intel_gtt,drm
syscopyarea            16384  1 drm_kms_helper
sysfillrect            16384  1 drm_kms_helper
sysimgblt              16384  1 drm_kms_helper
fb_sys_fops            16384  1 drm_kms_helper
[root@xonq modprobe.d]# grep LoadModule /var/log/Xorg.0.log
[     8.725] (II) LoadModule: "glx"
[     8.741] (II) LoadModule: "nvidia"
[     8.751] (II) LoadModule: "modesetting"
[     8.758] (II) LoadModule: "fb"
[     8.760] (II) LoadModule: "wfb"
[     8.761] (II) LoadModule: "ramdac"
[     8.774] (II) LoadModule: "glxserver_nvidia"
[     8.914] (II) LoadModule: "glamoregl"
[     9.165] (II) LoadModule: "fb"
[     9.244] (II) LoadModule: "dri2"
[     9.746] (II) LoadModule: "libinput"
Askannz commented 4 years ago

Sounds like a typical back of the GPU turning off and not turning back on. I see you're using the bbswitch method here, but does it work with the default optimus-manager config ? (i.e, with all power management features turned off)

xonq commented 4 years ago

It has the same effects with the default config

ejb-11 commented 4 years ago

I think I have found the solution. Under the [Optimus] section of /etc/optimus-manager/optimus-manager.conf I selected switching=none, pci_power_control=yes, pci_remove=yes and pci_reset=no. I am then able to switch both ways (though I have noticed that it complains about the Nvidia device being missing from the PCI bus and then it rescans and finds it).

Impress-me commented 4 years ago

I think I have found the solution. Under the [Optimus] section of /etc/optimus-manager/optimus-manager.conf I selected switching=none, pci_power_control=yes, pci_remove=yes and pci_reset=no. I am then able to switch both ways (though I have noticed that it complains about the Nvidia device being missing from the PCI bus and then it rescans and finds it).

When you switch to intel with this mothed, does your nvidia gpu turn off correctly? When I make it with this mothed, I can switch to nvidia gpu. But when swtich to intel in nvidia, my nvidia is still on.

ejb-11 commented 4 years ago

When you switch to intel with this mothed, does your nvidia gpu turn off correctly? When I make it with this mothed, I can switch to nvidia gpu. But when swtich to intel in nvidia, my nvidia is still on.

Mine switches just fine (I can tell because the battery is consumed much more slowly). Have you tried using the bbswitch option instead?

meop commented 4 years ago

I tried the suggestion from @BushMan01 above.. it did not work for me. What did work was switching nvidia driver option from NVreg_DynamicPowerManagement=0x02 to NVreg_DynamicPowerManagement=0x01. Now I can switch modes successfully in optimus-manager again. 02 is the recommended option in the nvidia guide, linked to from the wiki for this project.. and it used to work fine for me for a long time. Some change in kernel or nvidia driver seems to have broken it.

ahegazy commented 4 years ago

same problem, it doesn't switch with the switch command back and forth, only with --set-startup then restart I notice that the /etc/X11/xorg.conf.d/10-optimus-manager.conf file doesn't contents change from intel

ERROR : cannot get current display manager name : No display-manager.service file found You are about to switch GPUs. This will forcibly close all graphical sessions and all your applications WILL CLOSE. (you can pass the --no-confirm option to disable this warning) Continue ? (y/N)

ahegazy commented 4 years ago

Figured out the problem as per the FAQ you have to

I do not use a display manager (I use startx or xinit) Just like above, you must make sure to run /usr/bin/prime-offload (as normal user) just after the X > server is started, and /usr/bin/prime-switch (as root) after it has stopped.

so prime-switch needed to run as root after every Xserver exit, without display manager you have to make it run manually to make the switch,

Auto

Problem with this

if systemctl -q is-active graphical.target && [[ ! $DISPLAY && $XDG_VTNR -eq 1 ]]; then sudo /usr/bin/prime-switch exec startx fi



## Manually 
- add this [option](https://github.com/Askannz/optimus-manager/wiki/FAQ,-common-issues,-troubleshooting#i-do-not-want-optimus-manager-to-log-me-out-automatically) to `optimus-manager.conf` 
`auto_logout=no`
- this prevents auto logout when switching, so after the switch command, run `/usr/bin/prime-switch` as root
khuedoan commented 4 years ago

Thanks @ahegazy, your solution works great!

Also if anyone using sudo with password like me, you can add this line to /etc/sudoers with visudo to allow the sudo /usr/bin/prime-switch command to run without a password:

%wheel ALL=(ALL) NOPASSWD: /usr/bin/prime-switch
nikkhielseath commented 2 years ago

Thank you @ahegazy :)

chrisco23 commented 1 year ago

@ahegazy thanks but I'm still unable to switch out of Intel and into nvidia (Dell 15" 9550).

I don't have a .bash_profile since I'm mainly using fish now. Although I haven't seen the problem you describe of switching to intel (I'm only wanting to go in the opposite direction).

Under your Manually section, when I do "locate optimus-manager.conf", I get a lot of them.(?):

 locate optimus-manager.conf
/etc/X11/xorg.conf.d/10-optimus-manager.conf
/etc/lightdm/lightdm.conf.d/20-optimus-manager.conf
/etc/sddm.conf.d/20-optimus-manager.conf
/usr/lib/modprobe.d/optimus-manager.conf
/usr/lib/systemd/logind.conf.d/10-optimus-manager.conf
/usr/share/optimus-manager.conf

I never take the laptop out of the house. It is always plugged in. I only want to run nvidia and not intel to see if it helps with screen tearing.

I am not a gamer. I bought a cheapo 43" Insignia TV, just to see a 4K for the first time.

So right now I'm using that as my main monitor, and a Toshiba 40" 1080p TV as a second monitor.

Also, I'm not sure now which string of commands got me there but at one point I was getting just the same thing on both monitors (except the 4k was only taking up half the tv screen).

Any ideas? Thanks!