22 January 2010

Enabling Laptop mode tools on closing laptop lid

Laptop mode tools enables different laptop behaviors depending on power supply type (AC/DC) or battery level. I don't know why but in my Ubuntu (Karmic) it was disabled by default (as opposed to the comment in the file). In order to enable it, following line has to be changed in /etc/default/acpi-support:
ENABLE_LAPTOP_MODE=true
Then I started configuring the file /etc/laptop-mode/laptop-mode.conf and all the files in /etc/laptop-mode/conf.d/. There are many different options for various energy savings for various hardware, fortunately the files are well documented and everything is clear.

Enabling laptop mode when lid is closed
What I wanted in my configuration was to enable some settings when laptop lid is closed. When I close the lid I mean that the laptop is doing nothing or something not important and don't need its full power. Especially I wanted to slow down CPU in order to make it quiet even when some background tasks are being done. I found and configured correctly the file: /etc/laptop-mode/conf.d/cpufreq.conf configuring:
CONTROL_CPU_FREQUENCY=1
LM_AC_CPU_GOVERNOR=powersave
Then I edited again main configuration file /etc/laptop-mode/laptop-mode.conf:
 ENABLE_LAPTOP_MODE_WHEN_LID_CLOSED=1
To my surprise it didn't work.

Solving issue with lid closing detection
The laptop mode tools didn't react on lid close. In order to workaround this problem I edited ACPI scrpit: /etc/acpi/lid.sh adding following lines before [if [ `CheckPolicy` = 0 ]; then exit; fi] line

# pziemniak: enable laptop_mode
grep -q closed /proc/acpi/button/lid/*/state
if [ $? = 0 ]
then
    laptop_mode start
else
    laptop_mode auto
fi
# pziemniak: enable laptop_mode end

In the code I just enable the laptop mode when lid is closed and disable when opened. Laptop_mode shouldn't be normally (by end user) executed this way but following the documentation it is allowed to call it from some handlers and scripts.
There might be some better solution where to put this code but I didn't have time to look for it. I also wanted to distinguish it in the file in order to prevent accidental overrides.

Problems with Radeon HD 3470 in Ubuntu

My laptop has an Ati Mobility Radeon HD 3470 which from what I see is really badly supported. With open drivers the performance is very week and with proprietary strange, slow-downs occur.

The slowdowns are only with windows decorations (compiz). When application is maximized it takes up some time before animation starts and during this time system is unresponsive. The bigger the application window the bigger the delay and on my laptop it is up to 1 second. Fortunately a quick google search revealed some workaround.

Nobackfill
The workaround is a patched version of xserver. The con is that with this version there is no delay and compiz works just great. The drawback is that sometimes artefacts appear on the screen for short period of time. Looks like xserver doesn't clear buffer on new region allocation what results in shortly visible mess on parts of the screen that are to be redrawn. Fortunately it doesn't occur so often and is not annoying. It appears to me sometimes when starting video playbeck or sometimes in wine while opening window menus.

The repository with patched version of xserver can be found here:
https://launchpad.net/~launchpad-weyland/+archive/xserver-nobackfill/

Suspend and hibernation on Asus F5SL

What I liked in Windows was reliability of suspend/hibernate functionalities. I used to move my laptop from place to place only putting it into sleep mode or sometimes into hibernation. I did it also overnight. The main advantage was of course that all the programs on the systems were just like I left them so I could continue my work.

Unfortunately on Ubuntu (Karmic Koala) I had no luck with my laptop. First problem I had was that one of CPU cores was 100% utilized after resume and CDROM did not work. The other problem was that sleep, hibernation and then resume was really slow as compared to Windows systems.

scsiadd
Solving the problem with 100% CPU utilization. First I just removed my CD-ROM drive from laptop and it worked;) Of course this is not the best solution. I could not solve the problem completely so I just found some workaround - remove CD-ROM device upon sleep/hibernation. In order to be able to do that scsiadd package is required

sudo apt-get install scsiadd

then instructions for removing and adding device in my laptop were (scsi device id = 2 in my case):

sudo scsiadd -r 2 0 0 0
sudo scsiadd -a 2 0 0 0

Both command work before suspending the machine but once it was suspended it is not possible to add the CD-ROM back. I'll post if I find better solution but up to now it is all I can get with my F5SL.

In order to automate the removal of CD-ROM upon suspend I've written the following script /etc/pm/sleep.d/10_cdrom:
#!/bin/sh

case "$1" in
resume|thaw)
scsiadd -a 2 0 0 0
;;
suspend|hibernate)
scsiadd -r 2 0 0 0
exit 0 # necessary since 'scsiadd -r' might return error and disallow suspending
;;
esac
tuxonice
The problem with slow and unstable suspend/hibernation/resume I solved by installing tuxonice. Now suspend is as fast as in Windows XP/7 and so far equally reliable. The only problem I still have is with resume - sometimes resume hangs and I need to restart my computer and then it continues to resume. Don't know the problem yet but hopefully the computer still resumes.

Tuxonice requires some kernel patches, but appropriate kernel version can be found on the web page http://www.tuxonice.net/downloads/. There are also repositories, for Ubuntu Karmic add following line to /etc/apt/sources.list:
deb http://ppa.launchpad.net/tuxonice/ppa/ubuntu karmic main

Next just install the modified kernel. I also downloaded Userspace UI from their page since the Ubuntu's one did not work for me. I compiled the version tuxoniceui_text since it was enough. Finally I changed a line in /etc/pm/config.d/00sleep_module:
# The sleep/wake system to use. Valid values are:
# kernel The built-in kernel suspend/resume support.
# Use this if nothing else is supported on your system.
# uswsusp If your system has support for the userspace
# suspend programs (s2ram/s2disk/s2both), then use this.
# tuxonice If your system has support for tuxonice, use this.
#
# The system defaults to "kernel" if this is commented out.
SLEEP_MODULE="tuxonice"

Now finally suspend and hibernation works on my laptop!

Check also http://pziemniak.blogspot.com/2010/01/ethernet-and-wifi-not-working-after.html for other suspend issues.

Ethernet and wifi not working after long suspend

I noticed that after suspend my wifi stops working. The same seems to happen with my ethernet when the suspend time is longer.

Reloading appropriate modules seems to help. For my wireless it is ath5k and for ethernet sis190:
sudo modprobe -r ath5k; sudo modprobe ath5k
sudo modprobe -r sis190; sudo modprobe sis190
Then I found out that  in /etc/pm/config.d/ a file can be added for specifying which modules should be unloaded when suspending machine. Adding both my modules to file /etc/pm/config.d/00unload_modules:
SUSPEND_MODULES="$SUSPEND_MODULES ath5k sis190"
solved the issue. Not sure about $SUSPEND_MODULES some sources have it some not.

By the way I added also some additional modules: usbhid and usb_storage. It might help when I suspend and resume with different devices connected to my USB. Since I remove usb_storage, the usb memory should got disconnected safely.

Still however I have a problem with my ethernet. As soon as I change the MAC it stops working and only reloading the module helps:/