Recently, manufacturers have a tendency to put two video cards on laptops - one kind of unpretentious intel for saving energy, and the other - fancy for games and video. As far as I know, this is exactly Lenovo’s sin, and I came under the same trend with my HP TouchSmart tm2-1080er. If, of course, there was a possibility to switch between cards on the preinstalled Windows 7 Home x64, then Windows 7 Professional x32 did not want to turn on the second video card. The situation was no better in Ubuntu too - video cards are determined by both, but only the default Intel prefers to be used. And the power they eat, of course, both - as a result, the laptop works much less than it should. How will we deal with it?
So, we have two video cards:
$ lspci | grep VGA
00:02.0 VGA compatible controller: Intel Corporation Mobile 4 Series Chipset Integrated Graphics Controller (rev 07)
01:00.0 VGA compatible controller: ATI Technologies Inc M93 [Mobility Radeon HD 4500 Series] (rev ff)
Our task is either to learn how to switch between two video cards, or at least turn off the power of the second video card.
Method one. To Kill a Mockingbird.
The first way is simple. We will take a ready-made module written for Lenovo laptops (it also fits for our wonderful HP) and will force it to be screwed to our core. To do this, we will use the deb-packages and the dynamic module screwing system - DKMS.
I called the module simply - hp_acpi_kill.
We take the
source code of the module and save it under the name hp_acpi_kill.c
Now we put near
Makefile .
This is our essential module, written by an unknown enthusiast for openSUSE.
')
Now we need to write a config for DKMS, in order not to recompile the module for each new kernel version. Fortunately, DKMS is very simple, and the config is short.
Download and save as dkms.conf. In this file, we indicate the name of the compiled module, its version, as well as how to compile and install our module. It would seem that you can stop at this - add a module to DKMS, assemble and install it - but we are still users of a convenient distribution, and don’t understand why. Therefore, we wrap our module in a package.
I will not go into the details of building the package, since I already wrote a lot about it on Habré, I’ll just say that in addition to the usual set of files we need the files * .postinst, *. Postrm, * .prerm - so that our module is registered and compiled into DKMS installing the package, and also scrubbed when removed. Download the archive with all the necessary files
here .
We assemble the package with the debuild or dpkg-buildpackage command to choose from, install and add the module name hp_acpi_kill to / etc / modules - now when the system is booted, the discrete video card will turn off and the power consumption will drop sharply.
Looking at the list of devices, we find that our video card is visible to the system, but is not detected:
$ lshw
...
*-generic:0
product: Illegal Vendor ID
vendor: Illegal Vendor ID
physical id: 0
bus info: pci@0000:01:00.0
version: ff
width: 32 bits
clock: 66MHz
capabilities: bus_master vga_palette cap_list rom
configuration: driver=radeon latency=255 maxlatency=255 mingnt=255
resources: irq:31 memory:c0000000-cfffffff ioport:3000(size=256) memory:e4400000-e440ffff memory:e4420000-e443ffff
The second way. vga_switcheroo
Method two will require a little bit of traffic and time from us. The fact is that version 2.6.34 of the kernel has been released not so long ago, which includes a new interesting module - vga_switcheroo, which is precisely designed to switch video cards. On Launchpad and kernel.ubuntu.com, you can even find packages with this kernel, but in the default config the module is turned off - probably because there is no convenient graphic tool for switching video cards.
Therefore, for starters, let's download the source package from the lunchpad (it is designed for Maverick Meerkat, but it will work fine with us):
$ wget launchpad.net/ubuntu/+archive/primary/+files/linux_2.6.34-2.9.dsc
$ wget launchpad.net/ubuntu/+archive/primary/+files/linux_2.6.34-2.9.tar.gz
Unpack it:
$ dpkg-source -x linux_2.6.34-2.9.dsc
Now go to the linux-2.6.34 directory and open the debian.master / config / config.common.ubuntu file with any
favorite editor. Find the line "# CONFIG_VGA_SWITCHEROO is not set" and replace it with "CONFIG_VGA_SWITCHEROO = y" (quotes are not needed).
Just in case, let's open the debian / config / enforce file and add the line “value CONFIG_VGA_SWITCHEROO y” in it - this will help in the assembly to make sure that no infection has spoiled the set parameter.
We compile with the debuild command (it will take a long time to collect, because everything is built when building a package) and install:
$ sudo dpkg -i linux-headers-2.6.34-2_2.6.34-2.9_all.deb linux-headers-2.6.34-2-generic_2.6.34-2.9_i386.deb linux-image-2.6.34-2-generic_2.6.34-2.9_i386.deb
If you have a 64-bit system, instead of i386 in the file name will, of course, amd64.
How do we switch the video card to a new kernel after a reboot? Let's look at the summary of the Soviet information bureau:
$ cat /sys/kernel/debug/vgaswitcheroo/switch
0:+:Pwr:0000:00:02.0
1: :Off:0000:01:00.0
A plus sign shows us an active video card, a Pwr mark - that the video card is on, Off - that it is off. What can be changed? There is a wonderful list of commands that can be passed to vga_switcheroo:
DIS - immediate switching to a discrete video card
IGD - immediate switching to an integrated video card
DDIS - delayed switching to a discrete video card
DIGD - deferred switching to an integrated video card
ON - enable unused video card
OFF - turn off the unused video card
Immediately I say, immediate switching does not give me any immediate effect.
Therefore we will command:
# echo ON > /sys/kernel/debug/vgaswitcheroo/switch #
# echo DDIS > /sys/kernel/debug/vgaswitcheroo/switch #
Now we press in the “end session” system, log in again and turn off the integrated video card:
# echo OFF > /sys/kernel/debug/vgaswitcheroo/switch
We look at the result:
$ $ cat /sys/kernel/debug/vgaswitcheroo/switch
0: :Off:0000:00:02.0
1:+:Pwr:0000:01:00.0
Now you can play games, watch HD videos and not waste food on an Intel card. And you can switch back and spend even less energy on a full-fledged video card, saving battery. Long her years.