Saturday, February 11, 2012

Ubuntu GNU/Linux 12.04 (precise) on Sony Vaio SE15 (VPCSE1v9E)

Ubuntu GNU/Linux 12.04 (precise) on Sony Vaio SE15 (VPCSE1v9E), SandyBridge version.

Update 2013: This machine has very poor build quality. If you use it daily it will start falling apart after a year or so of use. Don't buy.

The findings here are not my own. All credits goes to the authors in the Ubuntu forums on vaio S compatibility.

Update Ubuntu 13.10:
Using Ubuntu 13.10  by now, and everything works basically flawless. Still starting to look for a new machine though, as the quality of this one is not so good. Casting eyes on the new Dell XP13 DE, with Linux pre-installed...

Update Ubuntu 12.10:
Using Ubuntu 12.10 I have changed my approach a little bit.
  • Use hacked BIOS with advanced menus. This enables me to permanently disable the Radeon in BIOS. Otherwise it will be re-activated after suspend/resume so power consumption will be high after resume.
  • Use the powersavings script below.
  • Use Kernel 3.7 from Ubuntu Mainline. This have some new power saving improvement.

With the above I can really get 4+ hours out of the battery, stable through suspend/resume cycles.

Update Ubuntu 12.04: In Ubuntu 12.04 no kernel parameters are needed. ASPM does not seem to work anyhow and the i915 parameters are enabled by default in the kernel.
I have also found a weak point of the laptop. The air intake fr cooling is located under the machine, exactly where your leg is if you have the laptop in your lap. When blocking the air intake with your leg the machine overheats and throttles the CPU to a crawl.

The Vaio SE15 is a very nice machine. It is easy to replace an existing HDD with an
SSD, it is very light and has good screen and keyboard.
Installing Ubuntu 12.04, precise pangolin from USB works like a charm, no issues.
Update: Due to inadequate cooling I would not buy this machine again. Extremely nice chassis, but overheats and throttles the CPU very easily.

I used the alternate installer in order to get full disk encryption. The alternate installer completed without any glitches, and boots me directly into Ubuntu.
A minor gotcha is that most times, but not always, I get a blank screen instead of the boot password screen (to unlock full disk encryption). It is not hung though, so just enter your password in the blank screen and it boots.

Using 12.04 everything works out of the box, trackpad (including two finger scrolling), wireless, screen, suspend and resume. I used wired network during install, but connected to wifi ince installed.

Using the Vaio the only thing that needs attention is the switchable graphics, and powersaving features. Powersaving is the area where GNU/Linux, by default, is not as good as the Mac, and requires some technical tweaking.

I use only the Stamina (Integrated Intel graphics) mode of the Vaio, and want Speed (Discrete ATI graphics) to be disabled at all times.
By default the ATI card is powered on even in Stamina mode (the physical switch does not physically power of the ATI graphics), so when booting Ubuntu the first time fans will be always on until you manage to power of the ATI card.

With the settings distilled from Ubuntu forums on vaio S compatibility everything works nice and I get the following results.

Battery drain between 9500 and 12500 mW when idling and doing light work (like writing this). This should give a standard battery life between 4-5 hours using the built in 52170mWh battery.
In reality I am a developer, and with some things open and doing some real work, power consumption is between 15 and 30W, giving battery times of say 2-3 hours.

I also added an instruction how to enable TRIM support if you are using an SSD, and also how to re-enable hibernate in Ubuntu 12.04 (precise).


On to the forum summary of settings.


* 1. Make sure Intel powersaving features are enabled
-----------------------------------------------
sudo vi /etc/default/grub

Add some items to the kernel boot parameters, use the following line

GRUB_CMDLINE_LINUX_DEFAULT="quite splash i915.i915_enable_fbc=1 i915.i915_enable_rc6=1 pcie_aspm=force"

update-grub

pcie_aspm=force does not work btw, if anyone can solve this that would be benefitial. Getting:
"ACPI _OSC control for PCIe not granted, disabling ASPM"
-----------------------------------------------

* 2. Disable (power off) Radeon discrete graphics at all times, and power of bluetooth on boot.
We use vgaswitcheroo for this. It is included by default in Ubuntu 12.04, no need to install anything
We also make sure bluetooth is disabled on boot hrer.

- Power of at boot
sudo vi /etc/rc.local

add the following before 'exit 0'
echo OFF > /sys/kernel/debug/vgaswitcheroo/switch
rfkill block bluetooth


- Install so it runs at resume from suspend
(not sure this is needed, but it does not hurt and does not take ant time)

sudo vi /etc/pm/sleep.d/10_disable_radeon

add the following to the file
#!/bin/sh
# Action script ensures that discrete graphics card is disabled after
# resuming from standby/hibernate
#
#
case "${1}" in
resume|thaw)
echo OFF > /sys/kernel/debug/vgaswitcheroo/switch
;;
esac


sudo chmod +x /etc/pm/sleep.d/10_disable_radeon
-----------------------------------------------


* 3. Add script to enable/disable powersavings in battery vs powered mode
-----------------------------------------------
sudo apt-get install ethtool
sudo vi /etc/pm/power.d/powersavings

add the following to the file

------ Start add from below -----
#!/bin/sh

# Shell script to reduce energy consumption when running battery. Place
# it in /etc/pm/power.d/ and give execution rights.

# This is a modified version of an original script of by Skumpic,
# available here: http://blog.liberailvoip.it/2010/04/27/
# ubuntu-lucid-lynx-acer-aspire-one-impostazioni-ottimizzate-
# autonomia-prestazioni/

# Disable Wake On Lan
ethtool -s eth0 wol d

if on_ac_power; then
# ----- Start AC powered settings #

# Disable laptop mode
echo 0 > /proc/sys/vm/laptop_mode

# Set SATA channel: max performance
for foo in /sys/class/scsi_host/host*/link_power_management_policy;
do echo max_performance > $foo;
done

# Set Max Power for wifi interface
# change value according to your hardware!
iwconfig wlan0 txpower 14   

# Disable wifi power saving
iwconfig wlan0 power off

# CPU Governor: Performance
for foo in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor;
do echo performance > $foo;
done

# Disabile USB autosuspend
for foo in /sys/bus/usb/devices/*/power/control;
do echo on > $foo;
done

# Disable PCI autosuspend
for foo in /sys/bus/pci/devices/*/power/control;
do echo on > $foo;
done

# Disabile audio_card power saving
echo 0 > /sys/module/snd_hda_intel/parameters/power_save_controller
echo 0 > /sys/module/snd_hda_intel/parameters/power_save

# Set maximum display backlight
echo 15 > /sys/class/backlight/acpi_video0/brightness

# ----- End AC powered settings #

else

# ----- Start battery powered settings #

# Enable Laptop-Mode disk writing
echo 5 > /proc/sys/vm/laptop_mode

# Set SATA channel to power saving
for foo in /sys/class/scsi_host/host*/link_power_management_policy;
do echo min_power > $foo;
done

# Activate wifi power saving
iwconfig wlan0 power timeout 500ms

# Reduce wifi txpower
iwconfig wlan0 txpower 5

# Select Ondemand CPU Governor
for foo in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor;
do echo ondemand > $foo;
done

# Activate USB autosuspend
echo auto > /sys/bus/usb/devices/1-1.1/power/control # Fingerprint sensor
echo auto > /sys/bus/usb/devices/1-1.3/power/control # Webcam

# Activate PCI autosuspend
for foo in /sys/bus/pci/devices/*/power/control;
do echo auto > $foo;
done

# Activate audio card power saving
# (sounds shorter than 5 seconds will not be played)
echo 5 > /sys/module/snd_hda_intel/parameters/power_save
echo 1 > /sys/module/snd_hda_intel/parameters/power_save_controller

# Set medium display backlight
echo 5 > /sys/class/backlight/acpi_video0/brightness


# ----- End battery powered settings #

fi

----- Stop add above -----

Make executable

sudo chmod +x /etc/pm/power.d/powersavings
-----------------------------------------------

* 4. Enable TRIM on SSD
-----------------------------------------------
(only if using an SSD)

sudo cp /etc/fstab /etc/fstab_bak-notrim
sudo vi /etc/fstab

look for the root partition entry, something like:
/dev/mapper/host-root / ext4 errors=remount-ro

add discard to the parameters, like
/dev/mapper/host-root / ext4 discard,errors=remount-ro

You can also add the noatime parameter to save some disc writes.

Reboot to enable
-----------------------------------------------

* 5. Re-enable hibernate in Ubuntu 12.04 (Precise)
-----------------------------------------------
In Ubuntu 12.04, Precise, Hibernate is not available by default. It is rather easy to enable though.
When enabled, both hibernate and suspend works well on the Vaio.

sudo vi /etc/polkit-1/localauthority/50-local.d/com.ubuntu.desktop.pkla

Add the following (probably creating the file)
[Re-enable hibernate by default]
Identity=unix-user:*
Action=org.freedesktop.upower.hibernate
ResultActive=yes

Credits for this tip goes to
Askubuntu


Reboot to enable
-----------------------------------------------



You can use acpi_call instead of vgaswitcheroo to disable the radeon video card.
acpi_call causes resume to take a long time, so therefore I recommend vgaswitcheroo,
which is also included by default in Ubuntu (12.04).

This is only kept for reference, don't use if you followed the guide above.

* Use acpi_call to turn of ATI card at all times.
-----------------------------------------------
(also disable bluetooth on boot)

- build and test
sudo apt-get install git
git clone https://github.com/mkottman/acpi_call.git
cd acpi_call
make
sudo insmod acpi_call.ko
lspci -vnnn | grep VGA
sudo chmod +x test_off.sh
./test_off.sh
(Trying \_SB.PCI0.PEG0.PEGP._OFF: works!)

- Install
sudo cp acpi_call.ko /lib/modules/`uname -r`/kernel/
sudo depmod
sudo modprobe acpi_call
sudo vi /etc/modules
- add the following after 'lp'
acpi_call

- Make sure it starts
sudo vi /usr/local/bin/radeon_off_sony_sa.sh

add the following to the file
#!/bin/sh
echo "\_SB.PCI0.PEG0.PEGP._OFF" > /proc/acpi/call

sudo chmod +x /usr/local/bin/radeon_off_sony_sa.sh

- Test
sudo /usr/local/bin/radeon_off_sony_sa.sh
sudo cat /proc/acpi/call

- Install so it runs at boot
sudo vi /etc/rc.local

add the following before 'exit 0'
/usr/local/bin/radeon_off_sony_sa.sh
rfkill block bluetooth

- Install so it runs at resume from suspend
(this can make resume be a little slow, with black screen for a few seconds when resuming)

sudo vi /etc/pm/sleep.d/10_disable_radeon

add the following to the file
#!/bin/sh
# Action script ensures that discrete graphics card is disabled after
# resuming from standby/hibernate
#
#
PATH=/usr/local/bin:/bin
case "${1}" in
resume|thaw)
radeon_off_sony_sa.sh
;;
esac

sudo chmod +x /etc/pm/sleep.d/10_disable_radeon
-----------------------------------------------