Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Must restart system to switch to nvidia #205

Open
xonq opened this issue Jan 29, 2020 · 11 comments
Open

Must restart system to switch to nvidia #205

xonq opened this issue Jan 29, 2020 · 11 comments

Comments

@xonq
Copy link

xonq commented Jan 29, 2020

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

  • Arch 5.4.15-arch1-1
  • KDE
  • Dell G3, nvidia 1050M GTX
  • latest Git version (optimus-manager-git)

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
Copy link
Owner

Askannz commented Jan 30, 2020

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
Copy link
Author

xonq commented Jan 30, 2020

It has the same effects with the default config

@ejb-11
Copy link

ejb-11 commented Feb 6, 2020

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
Copy link

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
Copy link

ejb-11 commented Mar 7, 2020

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
Copy link

meop commented May 8, 2020

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
Copy link

ahegazy commented May 10, 2020

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

  • there is no switch log, only bootsetup log
  • i am on arch, with i3wm
  • legacy Nvidia proprietary driver
  • no power management config
    PS: i get this message when switching
$ optimus-manager --switch nvidia

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
Copy link

ahegazy commented May 12, 2020

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

  • In the ~/.xinitrc you run your window manager for example exec i3 replace it with only i3
  • Edit the /etc/sudoers adding this line YourUserName ALL = NOPASSWD: /usr/bin/prime-switch
    to prevent it from requiring a password when writing sudo /usr/bin/prine-switch
  • after the window manager running command write your sudo /usr/bin/prime-switch
    Then end of the .xinitrc will be
i3
sudo /usr/bin/prime-switch

-that's it

Problem with this

  • when switching from nvidia to intel, we run prime-switch before the xserver is fully killed so this error is produced
    Setting up base state Unloading modules ['nvidia_drm', 'nvidia_modeset', 'nvidia'] (if loaded) Cannot setup GPU : kernel setup error : Cannot unload modules ['nvidia_drm', 'nvidia_modeset', 'nvidia'] : Failed to execute 'modprobe -r nvidia_drm nvidia_modeset nvidia' : modprobe: FATAL: Module nvidia_drm is in use.

soultion

  • Instead of making it run at the end of xserver, run it before running xserver
  • So i have my .bash_profile having the startx command
  • before it add sudo /usr/bin/prine-switch
  • so my .bash_profile is
#
# ~/.bash_profile
#
[[ -f ~/.bashrc ]] && . ~/.bashrc

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 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
Copy link

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
Copy link

Thank you @ahegazy :)

@chrisco23
Copy link

@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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants