
I am an ordinary Linux user and so you should not expect very clever moves or non-standard programmer solutions from this article. All manuals. But once the result is achieved, it means that someone other than me may find it useful.
A lot has been written about how to make a laptop work under Linux as long as possible, including on the habr. To some extent, I will once again bring together all the tips together, from the obvious to the obscure ones, at the same time I will describe several problems and solutions that I found to be quite “individual”.
I installed Ubuntu 10.10 on an
Acer Aspire Timeline 5810TG laptop . This machine has a screen of almost 16 inches and is relatively productive, but the battery is capacious enough to set personal records with it.
The content of the post.
1. Disable the discrete graphics card.
2. Useful commands for energy saving.
3. Laptop problems (related to energy saving) and their solutions.
4. Automation.
5. Additional tips.
')
1. Disable the discrete graphics card.
My laptop has the ability to switch between Intel's integrated graphics chip, low-power and low-power, and the relatively strong and power-consuming ATI Radeon HD4330 card. Many owners of laptops with switchable graphics are having problems working with Linux systems. A search for “ubuntu switchable graphics” on ubuntuformus gives out more than 50
pages of topics.
I rarely need a productive graphics card, so I set out to turn it off by default with the ability to turn on quickly and painlessly.
I read a lot of those 50 pages of forum topics. And you just had to look at the ubuntu wiki,
or even try to use Habrapoisk .
In versions of the kernel, starting with 2.6.34, there is a vga_switcheroo mechanism that allows switching between video cards. That is, in Ubuntu 10.10, it is by default. About how to use it, it was well written
here (see the second method) almost a year ago, I will quickly remind you what's what.
First, perform
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 M92 LP [Mobility Radeon HD 4300 Series] (rev ff)
Knowing which GPU is designated as, let's see which one is in which state.
cat /sys/kernel/debug/vgaswitcheroo/switch 0: :Pwr:0000:01:00.0 1:+:Pwr:0000:00:02.0
The plus sign is against the video chip currently in use, Pwr means that the video card is turned on and consumes power.
Important: all of my few acquaintances who have laptops with two video cards have the same picture: whatever you do, when you boot the system, both cards work, while the output uses the built-in “weak” graphics. This is good for us, because de-energizing inactive video cards is happening without blood.
Team
echo OFF > /sys/kernel/debug/vgaswitcheroo/switch
disables unused GPU right away. Therefore, we turn to the file
/etc/rc.local , adding the above command to it (before the exit 0 line). So, when booting the system, the discrete video card will already be disabled and I will not have to worry about anything.
0: :Off:0000:01:00.0 1:+:Pwr:0000:00:02.0
Important: as far as I can tell, vga_switcheroo does not work if proprietary drivers are installed on a discrete graphics card.
By the way, if you want to switch between video cards via a graphical interface, install the
Ubuntu Control Center . The program is a control panel of Ubuntu settings, but we are only interested in the option of switching between GPUs (of course, here it also happens using vga_switcheroo).

Be careful with UCC: first, it works crookedly, for example, I had to switch to a discrete video card first, and then to a built-in one to de-energize a discrete one (or echo OFF> / sys / kernel / debug / vgaswitcheroo / switch first and then switch to the integrated GPU). But it works. Secondly, switching occurs immediately, that is, without demand, the session is completed and it is necessary to log in again.
You can read more about switchable graphics in
the blog post I referred to above, as well as in
Ubuntu Wiki and in
this blog . I will not return to this issue.
2. Useful tips on energy saving.
These tips were collected from
lesswatts ,
ubuntuforums ,
powertop hints were taken into account, something was found by chance.
1) If you have Ubuntu on a laptop, you absolutely have the laptop_mode package, which optimizes the performance of the computer depending on the power source. A value of 0 sent to / proc / sys / vm / laptop_mode turns off power saving mode, 5 sets the most aggressive. More information about how laptop_mode saves energy, you can read
anywhere .
echo 0 > /proc/sys/vm/laptop_mode
2) Power saving mode for SATA devices.
echo min_power > /sys/class/scsi_host/host0/link_power_management_policy echo min_power > /sys/class/scsi_host/host1/link_power_management_policy echo min_power > /sys/class/scsi_host/host2/link_power_management_policy echo min_power > /sys/class/scsi_host/host3/link_power_management_policy echo min_power > /sys/class/scsi_host/host4/link_power_management_policy echo min_power > /sys/class/scsi_host/host5/link_power_management_policy
I do not know why I have as many as six devices in / sys / class / scsi_host / :) To enable maximum performance, execute commands with max_performance instead of min_power.
3) By default, Ubuntu has four processor profiles:
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors conservative ondemand userspace powersave performance
conservative: slowly raises the processor frequency depending on the load on the system and sharply resets the frequency to the minimum when idle.
ondemand: quickly increases the frequency of the processor when the load increases and slowly resets the frequency to a minimum when idle.
powersave and performance obviously correspond to the minimum and maximum CPU frequencies.
Many independent users are not strongly advised to use the performance mode, so even to work from the network, when saving on watts does not make sense, I use ondemand mode.
4) The 'sched_mc_power_savings' parameter from / sys / devices / system / cpu / allows using a power-saving mode of the processor if it has more than one core due to the special load distribution between the cores.
echo 1 > /sys/devices/system/cpu/sched_mc_power_savings
5) Integrated audio chips from Intel (which belong to the so-called High Definition Audio - HDA) also have the ability to save watts if the audio chip is not used
echo 0 > /sys/module/snd_hda_intel/parameters/power_save
6) In order to gain even a little bit more battery life, you can prevent the system from occasionally “polling” the cd / dvd drive for the presence of a disk there.
hal-disable-polling --device /dev/cdrom
7) You can turn off the webcam to the devil with the driver. I did not check separately, but they report that the case is very good when working on battery power.
modprobe -r uvcvideo
Naturally, skip this step if you have to use Skype or else you need a camera for something.
8) Dirty ratio - the maximum memory size (in percent) for storing dirty data before the process that generated it is forced to record it. The higher the value, obviously, the less often the recording is done and the less activity the hard disk and the system.
echo 10 > /proc/sys/vm/dirty_ratio echo 90 > /proc/sys/vm/dirty_ratioe
9) Dirty background ratio - the minimum amount of memory (in percent), where it is allowed to store different data instead of writing to disk. This parameter should be much less than dirty_ratio to allow writing pieces of dirty data in one pass.
echo 5 > /proc/sys/vm/dirty_background_ratio
10) Dirty Writeback sentisecs - how often the kernel should check if there is any “dirty” (changed) data to write to the disk (in ccts). The higher the value, obviously, the less often the disk is used to write dirty data.
echo 6000 > /proc/sys/vm/dirty_writeback_centisecs echo 60000 > /proc/sys/vm/dirty_writeback_centisecs
11) Turning on the power-saving mode PCI Express, as people say, saves quite a lot of battery power.
echo default > /sys/module/pcie_aspm/parameters/policy echo powersave > /sys/module/pcie_aspm/parameters/policy
3. Some problems of the laptop (related to energy saving) and their solutions.
Problem 1 . Changing the brightness of the screen does not work. Brightness is always at its maximum. This is a critical moment for energy saving, since the bright backlight of the display eats up a lot of electricity. This problem is observed on many laptops, especially on Acer's. Symptom: changing the brightness with the gnome-applet does not have the effect, how many do not drag the slider, switching the keys FN + Right, FN + Left, or similar Fn-combinations hangs the system, only a hard reset helps.
The solution was not the most practical, but rather simple:
sudo setpci -s 00:02.0 F4.B=XX
Here XX takes values ​​from 00 to FF in hexadecimal. For battery operation, I chose the value 40, for network operation - FF.
Problem 2. The Bluetooth radio was turned on every time the system was booted, despite the fact that the Bluetooth module was turned off manually and removed from startup. Another solution that someone will like very ugly: add rfkill block bluetooth to /etc/rc.local.
4. Automation.
Of course, every time to drive teams into the terminal is a sad business. Even every time you manually start the bash-script too quickly get bored. However, the transition to power saving mode within the described methods can be automated very easily: just add the code to /etc/acpi/power.sh
<source lang = "bash" $ sudo gedit /etc/acpi/power.sh
The code will be
if on_ac_power; then < > else < > fi
You can add it right after the line #! / Bin / sh
Through experiments, I was delighted to find out that this script runs every time the system starts. In addition, after looking at the contents of the ac and battery files in / etc / acpi / events /, I saw that the script was supposed to be called when the laptop was plugged in and disconnected from it. This is logical, but for some reason it did not work. The solution came quickly, it was necessary only to give the necessary power.sh script permissions:
$sudo chmod +x /etc/acpi/power.sh
Now everything has become automated as much as possible.
Here is what my script for energy saving looks like.
if on_ac_power; then echo 0 > /proc/sys/vm/laptop_mode echo 10 > /proc/sys/vm/dirty_ratio echo 5 > /proc/sys/vm/dirty_background_ratio echo 6000 > /proc/sys/vm/dirty_writeback_centisecs echo 0 > /sys/module/snd_hda_intel/parameters/power_save echo max_performance > /sys/class/scsi_host/host0/link_power_management_policy echo max_performance > /sys/class/scsi_host/host1/link_power_management_policy echo max_performance > /sys/class/scsi_host/host2/link_power_management_policy echo max_performance > /sys/class/scsi_host/host3/link_power_management_policy echo max_performance > /sys/class/scsi_host/host4/link_power_management_policy echo max_performance > /sys/class/scsi_host/host5/link_power_management_policy echo ondemand > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor modprobe uvcvideo echo default > /sys/module/pcie_aspm/parameters/policy setpci -s 00:02.0 F4.B=FF hal-disable-polling --enable-polling --device /dev/cdrom echo 0 > /sys/devices/system/cpu/sched_mc_power_savings else echo 5 > /proc/sys/vm/laptop_mode echo 90 > /proc/sys/vm/dirty_ratio echo 1 > /proc/sys/vm/dirty_background_ratio echo 60000 > /proc/sys/vm/dirty_writeback_centisecs echo 10 > /sys/module/snd_hda_intel/parameters/power_save echo min_power > /sys/class/scsi_host/host0/link_power_management_policy echo min_power > /sys/class/scsi_host/host1/link_power_management_policy echo min_power > /sys/class/scsi_host/host2/link_power_management_policy echo min_power > /sys/class/scsi_host/host3/link_power_management_policy echo min_power > /sys/class/scsi_host/host4/link_power_management_policy echo min_power > /sys/class/scsi_host/host5/link_power_management_policy echo ondemand > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor echo ondemand > /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor modprobe -r uvcvideo echo powersave > /sys/module/pcie_aspm/parameters/policy setpci -s 00:02.0 F4.B=40 hal-disable-polling --device /dev/cdrom echo 1 > /sys/devices/system/cpu/sched_mc_power_savings fi
So, what has been achieved? Here are some screenshots.
There is Wi-Fi, Google Chrome with a stack of tabs, the owner of the laptop (me) has the usual web surfing mode:

The same Wi-Fi and chrome, plus qutIM, Transmission, plays Exaile music, the OpenOffice.org Calc sheet is open with something financial and mathematical. In general, my standard set:

Video in full screen mode for an unknown reason eats very few resources. Leaving only qutIM (and Wi-Fi connection, of course) work, you can watch movies (normal SD, Xvid) for almost nine hours!
The results are not rigged and not momentary. All true. Before taking screenshots, I worked with a laptop in my usual mode for about 10 minutes. If you leave the fully charged laptop and do nothing with it for a couple of minutes, you can see the numbers like 13 hours. But we are interested only in the result in everyday conditions, is not it?
Overview.
Brief guide to action: take the script specified above, add it to /etc/acpi/power.sh, make power.sh executable, then add the commands to turn off bluetooth and a discrete video card in /etc/rc.local.
That's all I did. the results you saw above.
5. Additional tips.
How else can you improve the situation? Yes, a lot like, I guess. From what I know, but did not apply:
1) Many in the forums advise the team
hdparm -B 1 -S 12 / dev / sda
The unit here means the most "aggressive" mode of saving energy of the hard disk. Personally, I could not tolerate that the disk slows down after just a couple of seconds after doing nothing, and to accelerate again he has to spend a moment, which creates a lag effect. Often parked head hdd. Not very nice, besides, I dare to suggest that it also wears the screw faster than usual. 255 instead of 1 disables hard drive power saving altogether. You can experiment with it in your own home, I don’t mind :) By the way, picking / lib / hdparm / hdparm-functions allows you to find such a piece of code:
if hdparm_is_on_battery; then hdparm_set_option -B128 else hdparm_set_option -B254 fi
which hints as if the parameter is set to 128 when switching the power to the battery. I think the installation unit could win a few tens of minutes of work. But the comfort of work is more important. By the way, by the way, I want to note that the things described before this do not contribute any kind of discomfort to the work with a laptop.
2) Powertop, in the absence of other prompts, all the time offers to reduce power consumption to disable USB-ports for devices that are not storage media. You can use it to save even more energy, but personally I can't use a laptop without a mouse. I hate touchpads.
3) You can apply the noatime option to the file system. It means that the log of the last access time to the file will not be logged. This will reduce the activity of the system and the hard disk. By default, in Ubuntu 10.10, as I understand it from the manuals, there is relatime mode, which, if I'm not mistaken, updates the access time only if changes are made to the file. More on this, for example,
here .
Conclusion
Is it possible to achieve the same amazing time in Windows? It is possible, if not the same, then close. In Win7, this is done by installing two driver packages and two or three programs (which even without a GUI, just work in the background) from Acer, of course, there are no analogues for Linux.
So in this matter, you can additionally be happy for ubuntu: everything is done by means of the system (kernel), and if you have, for example, this post, everything happens in a couple of minutes and five copies.
PS I apologize for amateurishness, if one is noticed. We have recently met with Ubuntu.