Sunday, February 1, 2015

Ubuntu postinstall tuning

SSD tuning

All I did here was to add noatime for the mount command. In my opinion it’s a game of diminishing returns, with increasing risk of problems, to implement all the special SSD performance enhancing tricks you may find various places on the net. The noatime flag however is worth it, as it disables the writing of a new value in the file access time/date field every time a file is accessed. This feature is rarely used, and as files are accessed a lot turning this off saves a lot of small writes to the SSD that wears the drive unecessarily and probably slow things down:
$ sudo nano /etc/fstab
then add ",noatime" in options for the / mount. Reboot and try mount to verify that / is mounted with noatime option:
$ mount
/dev/sda5 on / type ext4 (rw,noatime,errors=remount-ro)
(...)

Increasing trackpoint speed

The trackpoint is one of my favorite navigational devices for laptops. But it must be set to a pretty high speed to work well for me. If you simply increase the general mouse speed it will also affect the touchpad and external mouse speeds. It has to be done at the trackpoint driver level. I couldn’t find the settings in any GUI config, but it is possible to adjust by command line:
1. Experiment with the speed / sensivity values with:
$ echo -n 80 > /sys/devices/platform/i8042/serio1/serio2/speed 

$ echo -n 250 > /sys/devices/platform/i8042/serio1/serio2/sensitivity
2. To make the favorite settings permanent, create a /etc/udev/rules.d/trackpoint.rules file containing:
SUBSYSTEM=="serio", DRIVERS=="psmouse", WAIT_FOR="/sys/devices/platform/i8042/serio1/serio2/sensitivity", ATTR{sensitivity}="250", ATTR{speed}="80"
3. Reboot or use the following to load the new settings:
$ sudo udevadm control --reload-rules
$ sudo udevadm trigger 

Improving fan control

The built-in hardware fan control has a tendency to ramp up to ~4000 RPM and stay there, which is quite audible and not at all necessary. I managed to implement a custom temperature regulation (use at your own risk!) with the thinkfan tool:
1. Install required packages
$ sudo apt-get install lm-sensors thinkfan
Run sensors once and let the tool configure the sensors.
2. Enable software fan control by creating file /etc/modprobe.d/thinkfan.conf containing:
options thinkpad_acpi fan_control=1
3. Create or edit /etc/thinkfan.conf to select the right sensors and fan speed rules. This is what I use:
sensor /sys/devices/platform/coretemp.0/temp1_input (0)
sensor /sys/devices/platform/coretemp.0/temp2_input (0)
sensor /sys/devices/platform/coretemp.0/temp3_input (0)
sensor /sys/devices/virtual/hwmon/hwmon0/temp1_input (0)

(0,     0,      40)
(1,     35,     45)
(2,     40,     51)
(3,     42,     53)
(4,     46,     60)
(5,     53,     66)
(7,     60,     72)
(127,   70,     32767)
4. I prefer to run the thinkfan tool with 5 seconds poll interval (-s 5) and no “exaggeration” on rising temperature (-b 0). I installed the tool as an upstart service by creating /etc/init/thinkfanservice.conf containing:
exec /usr/sbin/thinkfan -s 5 -b 0.0 -q -n

respawn

start on runlevel [2]
5. Check status / start / stop of service with:
sudo initctl status thinkfanservice
sudo initctl start thinkfanservice
sudo initctl stop thinkfanservice
You can test the current temperatures and fan speed with the sensors command:
$ sensors
acpitz-virtual-0
Adapter: Virtual device
temp1:        +38.0°C  (crit = +97.0°C)

thinkpad-isa-0000
Adapter: ISA adapter
fan1:        1973 RPM

coretemp-isa-0000
Adapter: ISA adapter
Physical id 0:  +42.0°C  (high = +86.0°C, crit = +100.0°C)
Core 0:         +42.0°C  (high = +86.0°C, crit = +100.0°C)
Core 1:         +39.0°C  (high = +86.0°C, crit = +100.0°C)

Battery life optimization

I managed to tweak battery life to a pretty respectable typical 5 hours. This is what I did:
1. Bluetooth radio default off. I don’t use bluetooth and don’t want to manually turn it off all the time. This is the only way I found to reliably turn it off after boot, in a way where you can still turn it on using the tray icon:
Edit /etc/rc.local and add:
rfkill block bluetooth
2. Install power mode changing script. This script sets a lot of hardware settings depending on AC / battery power state. Create file /etc/pm/power.d/power with execution rights containing:
#!/bin/sh

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

 if on_ac_power; then

 # Start AC powered settings --------------------------------------------#

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

 #NMI watchdog should be turned on
 for foo in /proc/sys/kernel/nmi_watchdog;
 do echo 1 > $foo;
 done

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

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

 # Disable USB autosuspend
 for foo in /sys/bus/usb/devices/*/power/level;
 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
 
 # End AC powered settings ----------------------------------------------#

 else

 # Start battery powered settings ---------------------------------------#

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

 #NMI watchdog should be turned on
 for foo in /proc/sys/kernel/nmi_watchdog;
 do echo 0 > $foo;
 done

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

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

 # Activate USB autosuspend
 for foo in /sys/bus/usb/devices/*/power/level;
 do echo auto > $foo;
 done

 # 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 1 seconds will not be played)
 echo 1 > /sys/module/snd_hda_intel/parameters/power_save
 echo 1 > /sys/module/snd_hda_intel/parameters/power_save_controller

 # End battery powered settings -----------------------------------------#

 fi

Source: linux-mint-on-lenovo-tp420s