Feature request: modify bumblebee to unload nvidia modules if power management is done by the kernel

Bug #1791883 reported by Rocko
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
bumblebee (Ubuntu)
New
Undecided
Unassigned

Bug Description

It would be great to implement something like feature request bumblebee#978 (https://github.com/Bumblebee-Project/Bumblebee/issues/978), because bbswitch doesn't work with later kernels unless you disable pci power management at boot with pcie_port_pm=off added to GRUB_CMDLINE_LINUX_DEFAULT in /etc/default/grub (see https://github.com/Bumblebee-Project/bbswitch/issues/140 for more details) and in fact later kernels automatically activate and suspend the card as required, replacing the functionality of bbswitch.

To confirm this, I tried modifying the Ubuntu bumblebee source package, but it fails to build in Cosmic on my laptop with a number of reference errors like so (even though I do have libkmod2 installed):

/usr/bin/ld: src/module.o: in function `module_is_loaded':
/home/rocko/src/bumblebee-3.2.1/src/module.c:46: undefined reference to `kmod_module_new_from_name'

So I modified the bumblebee develop branch from git (https://github.com/Bumblebee-Project/Bumblebee/tree/develop) with the attached patch and built it to confirm that bumblebee works when allowing the kernel to manage power management. The most relevant part of the patch is this:

@@ -227,8 +228,12 @@ static void switch_and_unload(void)
   char driver[BUFFER_SIZE];

   if (bb_config.pm_method == PM_DISABLED && bb_status.runmode != BB_RUN_EXIT) {
- /* do not disable the card if PM is disabled unless exiting */
- return;
+ /* RR: unload the driver loaded by the graphics card */
+ bb_log(LOG_INFO, "PM disabled, unloading nvidia drivers anyway\n");
+ if (pci_get_driver(driver, pci_bus_id_discrete, sizeof driver)) {
+ module_unload(driver);
+ }
+ return;
   }

   //if card is on and can be switched, switch it off

but I have also included changing configuration defaults like PM_METHOD=none and setting up the Ubuntu library paths for nvidia and primus in Ubuntu 18.04/18.10 (see https://bugs.launchpad.net/ubuntu/+source/bumblebee/+bug/1758243 for why).

Then I configured and built it with:

autoreconf -f
./configure CONF_DRIVER=nvidia CONF_DRIVER_MODULE_NVIDIA=nvidia CONF_PM_METHOD=none \
      CONF_LDPATH_NVIDIA=/usr/lib/x86_64-linux-gnu:/usr/lib/i386-linux-gnu \
      CONF_MODPATH_NVIDIA=/usr/lib/x86_64-linux-gnu/nvidia/xorg,/usr/lib/xorg/modules,/usr/lib/xorg/modules/input \
      --prefix=/usr --sysconfdir=/etc
make clean
make && sudo make install

I disabled bbswitch via /etc/modprobe.d/bbswitch:

blacklist bbswitch

and then on reboot, optirun seems to be working fine:

$ optirun glxinfo|grep NVIDIA
server glx vendor string: NVIDIA Corporation
OpenGL vendor string: NVIDIA Corporation
OpenGL core profile version string: 4.6.0 NVIDIA 396.54
OpenGL core profile shading language version string: 4.60 NVIDIA
OpenGL version string: 4.6.0 NVIDIA 396.54
OpenGL shading language version string: 4.60 NVIDIA

and afterwards, the nvidia card is turned off:

$ cat /sys/bus/pci/devices/0000\:01\:00.0/power/runtime_status
suspended

This works even after a suspend/resume cycle.

ProblemType: Bug
DistroRelease: Ubuntu 18.10
Package: bumblebee 3.2.1-17 [modified: usr/bin/bumblebee-bugreport usr/bin/optirun usr/sbin/bumblebeed usr/share/doc/bumblebee/README.markdown]
Uname: Linux 4.19.0-041900rc3-generic x86_64
ApportVersion: 2.20.10-0ubuntu9
Architecture: amd64
CurrentDesktop: ubuntu:GNOME
Date: Tue Sep 11 13:30:22 2018
InstallationDate: Installed on 2017-08-16 (390 days ago)
InstallationMedia: Ubuntu 17.04 "Zesty Zapus" - Release amd64 (20170412)
SourcePackage: bumblebee
UpgradeStatus: Upgraded to cosmic on 2018-08-15 (26 days ago)
mtime.conffile..etc.bumblebee.bumblebee.conf: 2018-09-10T12:33:56.368908
mtime.conffile..etc.bumblebee.xorg.conf.nvidia: 2018-09-10T12:33:56.368908

Revision history for this message
Rocko (rockorequin) wrote :
description: updated
Revision history for this message
Ubuntu Foundations Team Bug Bot (crichton) wrote :

The attachment "bumblebee-git-develop.diff" seems to be a patch. If it isn't, please remove the "patch" flag from the attachment, remove the "patch" tag, and if you are a member of the ~ubuntu-reviewers, unsubscribe the team.

[This is an automated message performed by a Launchpad user owned by ~brian-murray, for any issues please contact him.]

tags: added: patch
Rocko (rockorequin)
tags: removed: patch
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.