Linux (Gnome Ubuntu 17.04) on Lenovo ThinkPad P50: Configuration for displays, Optimus and trackpad

I've updated my P50 to ubuntu-gnome-desktop 17.04. 

This is a few hours work since you need to carefully remove all non-standard PPAa (use ppa-purge), remove other PPAs and uninstall left over apps. I also reversed out my use of hte HWE xserver stack. Then you do a distribution upgrade to 16.10 and then another one to 17.04

 

It's worth it though. 17.04 comes with the just-released Gnome, and it's very good. I haven't used gnome for a long, long time. It's very impressive, but you can make up your mind on that.

Here's some great things about it:

The three monitors just work. I'm using libinput (see below) and the gnome control panel supports that quite well, although it doesn't pick up the trackpoint which means I still use a script to get it to work in natural scrolling. 

The touchpad is remarkably better. I no longer need to use a very slow acceleration to get rid of the jerkiness. I don't know why, I thought I was picking up the latest and greatest synaptic drivers in 16.04 because of the PPAs I used, but it is a much better experience.

I am not using a custom prime switch script either, it works. 17.04 is also ready for nvidia optimus Prime Sync, but I will wait for the next nvidia binary release with the lastest bug fixes before I try it again. 

 

 

 

Linux (Ubuntu 16.04) on Lenovo ThinkPad P50: Configuration for displays, Optimus and trackpad

Xubuntu 16.04 on the Lenovo ThinkPad P50 is almost painless and provides good battery life, multi-displays. As for the usual questions: suspend/resume is 100% reliable for me under all circumstances. Wifi is perfect. Multi-monitor works. Stability is completely rock-solid; it’s better than my last five years of Macs, and better than any Windows experience I’ve had. My machine is the core i7 model, with the Full HD display, not the hiDPI. There are some tweaks, and if you use 16.04, there are steps you can take to get later versions of the graphics stack, instead of waiting for 16.04.3.

 

Linux on the Lenovo Thinkpad P50 is great, although the choice of Xubuntu over other distributions makes this much easier (although it seems the updates to graphics have fixed this).

I bought my Thinkpad P50 online from B&H Photography (New York); new, it was about half the Australian retail price. Mine was a returned unit, so it was even cheaper still. It included the residual of the 3 year warranty (which is international, despite B&H saying it wasn't). I bought the base model and added a 1TB SSD and 32 GB Ram.

I avoided the HiDPI screen despite being a Retina user on the macs because it seems Linux is not very good yet with mixing HiDPI and std resolution displays, and of course, there isn’t much point having the battery and cost disadvantages of HiDPI when you mostly look at legacy external monitors.

I’ll give a shout out to https://www.bhphotovideo.com/ ; have bought several computers, been great.

 

three screens

Three screens running from xubuntu 16.04



Updated May 2017.

 Overview of the OS components

Ubuntu 16.04.2 (HWE) 

see https://wiki.ubuntu.com/Kernel/LTSEnablementStack to make sure you are on 16.04.2

 

using 4.8 kernel and the latest stable nvidia driver from this PPA https://launchpad.net/~graphics-drivers/+archive/ubuntu/ppa

I also use these repositories for some backported stable upstream stuff regarding display drivers.

 https://launchpad.net/~ubuntu-x-swat/+archive/ubuntu/updates

https://launchpad.net/~canonical-x/+archive/ubuntu/x-staging

 

After installation I added tlp for battery management http://linrunner.de/en/tlp/docs/tlp-linux-advanced-power-management.html

It idles at < 7W. 


My P50 came with BIOS settings Secure Boot off and UEFI on. I didn’t change either.

Thinkpad P50 System updates & Thunderbolt firmware

I fully updated the machine using Lenovo’s Windows 7 utility; I was mostly interested in the latest BIOS updates. My Thinkpad P50 is dual boot (actually, quad boot would be more accurate; I have a couple of other Linux distributions installed so I can test big updates before committing to them).

Note: It's also a good idea to update the Thunderbolt firmware if you use HDMI, because it provides the HDMI out port. This update is not included in the standard Lenovo system updates, it seems. You can only do this in Windows.

Google for Intel Alpine Ridge Thunderbolt Firmware for Windows 10 (64-bit), 8.1 (64-bit), 7 (64-bit) - ThinkPad P50.

 The firmware update may complain that you don't have a Thunderbolt device connected. Continue anyway; despite the messages, it will do the firmware update. You'll see a message about the update taking up to three minutes. 

The HDMI port before this update doesn't always detect a monitor (same in Windows), requiring a few reboot cycles until it starts working again. This was the only serious problem I had with the P50. 
The May 2017 Thunderbolt firmware updates fixed this. Before this update, the external monitor on my HDMI port did not always start (same with Windows) and it would take a few reboots before it reappeared. This hasn't happended since the update. I wish I had learnt about the Thunderbolt firmware update earlier.

 

External monitors & Optimus 

I use two external monitors. One monitor is attached to the display port, one to the HDMI port, since I don’t have a dock.

I’m using the nvidia binaries from Ubuntu repositories, which come with ‘prime-select’, an Ubuntu enhancement that makes it easy to swap between the power of the Nvidia card and the efficiency of intel, although a reboot is required going from Intel to Nvidia.  Optimus is only enabled when Hybrid graphics mode is set in BIOS.

Of course, the easiest approach is to set Discrete Graphics in the BIOS.  With the Discrete setting, the laptop directly runs external displays and the laptop’s panel from nvidia.  The OS doesn’t see intel graphics at all. This is definitely the simplest way to work. However, to access battery saving mode (intel graphics), you need to reboot and reconfigure the BIOS back to Hybrid, and then the system goes through a reconfiguration boot, which is a bit slower than normal.

Keeping Hybrid mode on a bit less cumbersome (but not much). Note that xubuntu isn't mapping the display brightness control keys properly when you boot in Discrete mode. There's an easy fix below.

There is an alternative software configuration which does what the Windows drivers do: turns on the nvidia card when needed without needing to logout or reboot.  The linux version is bumblebee but the installation tutorials are long so I haven’t bothered. Also, it doesn't work with the Nvidia drivers, you must use Nouveau. 

 Notes

  1. KDE, Unity & Gnome didn't work with my three screens in 16.04 and 16.04.1 in hybrid graphics mode. Xubuntu did, because the compositor in xfce uses xrender, which works with Optimus when handing off to the Intel card used to drive the laptop panel. Gnome and Unity as shipped with 16.04 & 16.04.1 use an OpenGL-based compositor, which doesn’t work with the Optimus setup (the external monitors work, but not the laptop panel; this is a known bug https://bugs.freedesktop.org/show_bug.cgi?id=69101).
    But Ubuntu 17.04 in Gnome (using X, not wayland) works fine with the three monitors, so the bug has been fixed (although the bug report is still open). I assume this fix will arrive in 16.04.3. In any case, discrete mode (Nvidia card only) will be fine.


You can use nvidia-settings (a GUI tool) to make sure you are using the nvidia card or to change to the intel driver, or the command line:  The command-line equivalent is
sudo prime-select


At this point, everything should just work but there are some tweaks below for a much better experience.

  1. Some good tweaks: trackpad
    The trackpad does not respond well to small, slow movements, the sort of precise movements you may want to make. It acts jerky. It’s not a hardware problem, but a problem of default settings. Small movements get accelarated.

    I've now swapped to libinput drivers because the accidental-touch detection is good, but when using the synaptics driver, I had this script as executable, and I had xfce run it at session startup (Settings -> Session and Startup 0-> Application Autostart)


#!/bin/bash
# this is run by xfce startup apps
# xinput --list-props 13

DEVICE="SynPS/2 Synaptics TouchPad"
xinput --set-prop "$DEVICE" "Device Accel Profile" 6
xinput --set-prop "$DEVICE" "Device Accel Constant Deceleration" 12
xinput --set-prop "$DEVICE" "Device Accel Velocity Scaling" 10
xinput --set-prop "$DEVICE" "Synaptics Scrolling Distance" -114 -114
xinput --set-prop "$DEVICE" "Synaptics Palm Detection" 1

xinput --set-prop "$DEVICE" "Synaptics Palm Dimensions" 3, 3

 

Note: a more modern approach is to use libinput; it's under active development. I have swapped to this. Palm rejection is automated, and with ths driver I can get natural scrolling working everywhere on all devices, which I didn't manage previously. The driver is part of X so it is updated in the point updates. This means that Ubuntu 16.04.2 has the same version that released in 16.10. If use use the PPAs I mentioned at the top, you'll get even more recent versions. Finally I have 'natural scroll' (or reverse scroll) working everywhere. It's enabled in the script below *AND TURNED OFF* in the Settings app. Palm rejection works very well, I have touch to tap on permanently now. The driver is much less configurable, but I will stick with libinput.

Using libinput means installing the package xserver-xorg-input-libinput-hwe-16.04.

Ubuntu will automatically switch to this driver, you don't need to do anything else (thta is, you don't need to uninstall any existing packages) . Note that the HWE packages are how you make sure you are uisng 16.04.2. See https://wiki.ubuntu.com/Kernel/LTSEnablementStack

 Libinput version of the P50 tweaks for mouse and trackpad

#!/bin/bash
# this is run by xfce session startup

DEVICE="SynPS/2 Synaptics TouchPad"
xinput --set-prop "$DEVICE" "libinput Accel Speed" -0.95 #very low to get smooth pointer behaviour, min is -1
xinput --set-prop "$DEVICE" "libinput Natural Scrolling Enabled" 1
xinput --set-prop "$DEVICE" "libinput Tapping Enabled" 1
xinput --set-prop "$DEVICE" "libinput Disable While Typing Enabled" 1

#slow down mouse
DEVICE=" USB OPTICAL MOUSE"

xinput --set-prop "$DEVICE" "libinput Natural Scrolling Enabled" 1

DEVICE="TPPS/2 IBM TrackPoint"
xinput --set-prop "$DEVICE" "libinput Natural Scrolling Enabled" 1

~
~

 

  1. Nvidia tweaks: there were some ugly tearing effects on all monitors. Tearing is fixed with this script, which I also run on session start. It is all one line.

    #!/bin/bash
    nvidia-settings --assign CurrentMetaMode="$(nvidia-settings -q CurrentMetaMode -t|tr '\n' ' '|sed -e 's/.*:: \(.*\)/\1\n/g' -e 's/}/, ForceCompositionPipeline = On}/g')" > /dev/null                                                                      
    Read more here: http://www.thelinuxrain.com/articles/got-tearing-with-proprietary-nvidia-try-this

This script activates ForceCompositionPipeline. There are different ways of doing this, such as changing xorg.conf, but my script works and changing xorg.conf is a bit more complex with Optimus so I’ll just stick with this script. It’s also settable from the GUI control panel (see bottom of screen shot):


I have the semi-official Ubuntu nvidia PPA (see top) and I follow the latest release. It’s been great for me with 375, 378, 381. Note that the 378 version also includes a nvidia settings control panel which finally shows your laptop screen as well as the external monitors in Optimus mode… not a big deal since all monitors are visible in the xfce Displays setting, but a small improvement. See screen shot above. However, the 378 driver will not get the May fixes for Optimus; the 375 driver did (it's LTS) and the 381 driver did too.


Optimus & Prime Sync to end tearing on the laptop panel

In Optimus mode, you will see tearing on the laptop panel with the 'out of the box settings/. The v-sync in XFCE compositor settings makes no difference to this. It’s due to a missing feature in xwindows which was only added in v1.19, which is not part of Ubuntu 16.04.1, 16.04.2 or 16.10. This feature is known as Prime Synchronization.

Prime Sync is possible in 17.04 and will be backported in 16.04.3 (I expect this around July/August 2017).

However, as of May 2017, it's now available in one of the PPAs I referred to at the start (https://launchpad.net/~canonical-x/+archive/ubuntu/x-staging).

Make sure you are on 16.04.2 (the HWE stack) first.

You need the LTS 375.66 driver (or later) or the 381 driver; these have important Prime Sync bug fixes which are not in earlier releases. Driver 378 is in the middle of these two releases but it is end of life and not fixed.

You need to make a one-line config file too.

I put full instructions here: https://askubuntu.com/questions/853473/upgrade-xorg-1-19-on-ubuntu-16-04/893122#893122

See https://devtalk.nvidia.com/default/topic/957814/linux/prime-and-prime-synchronization/

[Note: the 375.66 driver still has some kernel-panic bugs with Prime Sync, we are waiting for a new driver release...]

 

  1. Intel tweaks
    When running in intel-mode (sudo prime-select intel) I still had some tearing. This is fixed by creating a file /usr/share/X11/xorg.conf.d/20-intel.conf

Section "Device"

Identifier  "Intel Graphics"

  Driver      "intel"

  Option      "TearFree"    "true"

EndSection

 

Also note that you need the package xserver-xorg-video-intel installed. The package manager says you are encouraged not to use this module if your hardware is more recent that 2007! However, without it, the intel module is not loaded and tear free is not enabled. And if you are using 16.04.2, the module will be xserver-xorg-video-intel-hwe-16.04

There may be smarter ways of settings this, I don’t know. Unfortunately, you can’t leave this file in place if you switch back to prime-select nvidia: the laptop panel won’t display. I have a script tim_prime intel|nvidia, which renames this file if I am going to run nvidia and reinstates it if I am switching to nvidia. It then calls prime-select for me. I am primitive shell scripter but here it is. I use this instead of prime-select.

#!/bin/bash

function intel_off()

{

rm /usr/share/X11/xorg.conf.d/20-intel.conf

 

}

 

function intel_on()

{

cp /usr/share/X11/xorg.conf.d/20-intel.conf_off \

/usr/share/X11/xorg.conf.d/20-intel.conf

}



while [ "$1" != "" ]; do

PARAM=$1

case $PARAM in

intel)

echo 'intel'

intel_on

prime-select intel

;;

nvidia)

echo 'nvidia'

intel_off

prime-select nvidia

;;

esac

shift

done


  1. Longer battery service life by not charging to 100%
    ThinkPad battery bios can configured so that it stops charging at less than 100%. This should give a longer useful life to the battery. ThinkPads have done this for years. I picked up a five year-old W520 with the original battery, and it was still holding a 70% charge so I'm convinced.
    Visit http://www.thinkwiki.org/wiki/Tpacpi-bat and install Tpacpi-bat via the PPA.

    Install tlp from the ubuntu repositories. In the config file /etc/efault/tlp
    I have these settings

# Battery charge thresholds (ThinkPad only, tp-smapi or acpi-call kernel module

# required). Charging starts when the remaining capacity falls below the

# START_CHARGE_TRESH value and stops when exceeding the STOP_CHARGE_TRESH value.

# Main / Internal battery (values in %)

START_CHARGE_THRESH_BAT0=75

STOP_CHARGE_THRESH_BAT0=80



sudo tld fullrecharge will do a one-time full charge of the battery

Other Points

 

Printing: At home and work I have HP printers & scanners; these have always worked great with Linux and they still do, particularly if you use the HPLIP software (in the Ubuntu repositories). I use the wifi all over the place, it’s been flawless. 

Using Discrete Graphics from BIOS: Display brightness keyboard control

If you choose discrete graphics from the BIOS, there is no tearing on the intel panel (assuming the startup scripts above)

However, the brightness keys don’t work.

 

The brightness can be set like so

nvidia-settings -a BacklightBrightness[DP-4]=70 (This sets the brightness to 70%)

Or via xbacklight which can easily be mapped to keys

 

DP-4 is the name of my laptop panel. Yours may be different. It’s easy to see this from the Nvidia control panel. I used xfce to map increase and decrease to Super F5 & F6 (Super is the Windows key)

 Fonts

I have calibri installed. In 12pt it looked bad, this is turned off via a ~/.fonts.conf file as per https://askubuntu.com/questions/594976/how-to-get-calibri-font-to-display-nicely