DEV Community

samsepi0l
samsepi0l

Posted on

Linux configuration guide for Thinkpad x1 Carbon 6th Gen (2018)

Linux configuration guide for Thinkpad x1 Carbon 6th Gen (2018)

This guide workable for Lenovo ThinkPad Ultrabook X1 Carbon Gen6 (20KH006HRT) After these steps, laptop works around 8-10 hourse on medium load.

Install Ubuntu 18.04

If touchpad andr/or trackpoint don't work on Ubuntu installer, add 'psmouse.synaptics_intertouch=1' to loader.

Install latest version of Linux Kernel

Firstly, after instalation, update Linux Kernel (because in kernels 4.17.x power management has improved) using UKUU:

$ sudo add-apt-repository ppa:teejee2008/ppa
$ sudo apt-get update
$ sudo apt-get install ukuu
$ sudo ukuu --check
$ sudo ukuu --install-latest
Enter fullscreen mode Exit fullscreen mode

Touchpad & Trackpoint

  1. Edit the /etc/modprobe.d/blacklist.conf file and comment out following line:
# blacklist i2c_i801
Enter fullscreen mode Exit fullscreen mode
  1. Edit the /etc/default/grub file and change line:
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
Enter fullscreen mode Exit fullscreen mode

to

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash psmouse.synaptics_intertouch=1"
Enter fullscreen mode Exit fullscreen mode
  1. update grub:
$ sudo update-grub
Enter fullscreen mode Exit fullscreen mode
  1. install xserver-synaptics:
$ sudo apt-get install xserver-xorg-input-synaptics
Enter fullscreen mode Exit fullscreen mode
  1. Copy wakeup-control script from this repo to /lib/systemd/system-sleep/ for wakeup touchpad/trackpoint after sleep.

Deep sleep

  1. Reboot, enter your BIOS/UEFI. Go to Config - Thunderbolt (TM) 3 - set Thunerbolt BIOS Assist Mode to Enabled. It has also been reported that Security - Secure Boot must be disabled.

  2. Install iasl (Intel's compiler/decompiler for ACPI machine language) and cpio from your distribution.

  3. Get a dump of your ACPI DSDT table.

$ cat /sys/firmware/acpi/tables/DSDT > dsdt.aml
Enter fullscreen mode Exit fullscreen mode
  1. Decompile the dump, which will generate a .dsl source based on the .aml ACPI machine language dump.
$ iasl -d dsdt.aml
Enter fullscreen mode Exit fullscreen mode
  1. Apply X1Y3_S3_DSDT.patch it against dsdt.dsl:
$ patch --verbose < X1C6_S3_DSDT.patch
Enter fullscreen mode Exit fullscreen mode

Note: Hunk 6 may fail due to different specified memory regions. In this case, simply edit the (almost fully patched) dsdt.dsl file, search for and entirely delete the two lines reading solely the word "One". You can look at hunk 6 in the patch file to see how the lines above and below look like if you're unsure.

Plan B: If this does not work (patch is rejected): It has been the case, that certain UEFI settings may lead to different DSDT images. This means that it may be possible that the above patch doesn't work at all with your decompiled DSL. If that is the case, don't worry: Go through the .patch file in your editor, and change your dsdt.dsl by hand. This means locating the lines which are removed in the patch and removing them in your dsl. The patch contains only one section at the end which adds a few lines - these are important and make the sleep magic happen.

  1. Make sure that the hex number at the end of the first non-commented line is incremented by one (reading DefinitionBlock, should be around line 21). E.g., if it was 0x00000000 change it to 0x00000001. Otherwise, the kernel won't inject the new DSDT table.

  2. Recompile your patched version of the .dsl source.

$ iasl -ve -tc dsdt.dsl
Enter fullscreen mode Exit fullscreen mode
  1. There shouldn't be any errors. When recompilation was successful, iasl will have built a new binary .aml file including the S3 patch. Now we have to create a CPIO archive with the correct structure, which GRUB can load on boot (much like initrd is loaded). We name the final image acpi_override and copy it into /boot/.
$ mkdir -p kernel/firmware/acpi
$ cp dsdt.aml kernel/firmware/acpi
$ find kernel | cpio -H newc --create > acpi_override
$ cp acpi_override /boot
Enter fullscreen mode Exit fullscreen mode
  1. We yet have to tell GRUB to load our new DSDT table on boot in its configuration file. In Ubuntu, to allow this change to persist through kernel updates, you should add this to linux_entry() function initrd call in /etc/grub.d/10_linux:
--- 10_linux~   2018-08-07 21:24:52.058669051 +0200
+++ 10_linux    2018-08-07 21:24:07.210436901 +0200
@@ -198,7 +198,7 @@
 EOF
     fi
     sed "s/^/$submenu_indentation/" << EOF
-   initrd  ${rel_dirname}/${initrd}
+   initrd  /boot/acpi_override  ${rel_dirname}/${initrd}
 EOF
   fi
   sed "s/^/$submenu_indentation/" << EOF
Enter fullscreen mode Exit fullscreen mode

Note: GRUB updates might still overwrite this file (haven't had a GRUB update yet), but maybe it'll help to move this to eg. 11_linux to simply redefine linux_entry() function.

  1. Moreover, GRUB needs to boot the kernel with a parameter setting the deep sleep state as default. The best place to do this is /etc/default/grub, since that file is not going to be overwritten when the GRUB config becomes regenerated. Simply add mem_sleep_default=deep to the GRUB_CMDLINE_LINUX_DEFAULT configuration option. It should look somewhat like that:
GRUB_CMDLINE_LINUX_DEFAULT="quiet mem_sleep_default=deep"
Enter fullscreen mode Exit fullscreen mode
  1. Reboot

If everything worked, you shouldn't see any boot errors and the kernel will confirm that S3 is working. The output of the following commands should look the same on your machine:

$ dmesg | grep ACPI | grep supports"
  [    0.213668] ACPI: (supports S0 S3 S4 S5)
$ cat /sys/power/mem_sleep
  s2idle [deep]
Enter fullscreen mode Exit fullscreen mode

In most setups, simply closing the lid will probably trigger deep sleep. If you're using a systemd-based distribution, you can also verify if it works on the command line:

$ systemctl suspend -i
Enter fullscreen mode Exit fullscreen mode

low cTDP and trip temperature in Linux

This problem is related to thermal throttling on Linux, that is set much below the Windows values. This will cause your laptop to run much slower than it could under heavy stress.

Before you attempt to apply this solution, please make sure that the problem still exists when you read it. To do so, open a Linux terminal and run following commands:

$ sudo apt-get install msr-tools
$ sudo rdmsr -f 29:24 -d 0x1a2
Enter fullscreen mode Exit fullscreen mode

If you see 3 as a result value (or 15 when running on battery), you don’t have to do anything. Otherwise:

  1. Disable Secure Boot in the BIOS (won’t work otherwise)

  2. Run this command:

sudo apt install git virtualenv build-essential python3-dev \
  libdbus-glib-1-dev libgirepository1.0-dev libcairo2-dev
Enter fullscreen mode Exit fullscreen mode
  1. Install lenovo-throttling-fix:
$ cd lenovo-throttling-fix/
$ sudo ./install.sh
Enter fullscreen mode Exit fullscreen mode

Check again, that the result from running the rdmsr command is 3

If you want to change the default values, you need to edit the /etc/lenovo_fix file and set the Trip_Temp_C for both battery and AC the way you want:

[BATTERY]
# Other options here...
PL2_Tdp_W: 40
Trip_Temp_C: 75

[AC]
# Other options here...
PL1_Tdp_W: 34
PL2_Tdp_W: 40
Trip_Temp_C: 90
Enter fullscreen mode Exit fullscreen mode

CPU undervolting

The amazing Lenovo Throttling fix script supports also the undervolting. To enable it, please edit the /etc/lenovo_fix.conf again and update the [UNDERVOLT] section. In my case, this settings proven to be stable:

[UNDERVOLT]
# CPU core voltage offset (mV)
CORE: -110
# Integrated GPU voltage offset (mV)
GPU: -90
# CPU cache voltage offset (mV)
CACHE: -110
# System Agent voltage offset (mV)
UNCORE: -90
# Analog I/O voltage offset (mV)
ANALOGIO: 0
Enter fullscreen mode Exit fullscreen mode

Battery charging thresholds

$ sudo apt-get install tlp tlp-rdw acpi-call-dkms tp-smapi-dkms acpi-call-dkms
Enter fullscreen mode Exit fullscreen mode

After that just edit the /etc/default/tlp file and edit following values:

# Uncomment both of them if commented out
START_CHARGE_THRESH_BAT0=45
STOP_CHARGE_THRESH_BAT0=95
Enter fullscreen mode Exit fullscreen mode

Reboot, run:

sudo tlp-stat | grep tpacpi-bat
Enter fullscreen mode Exit fullscreen mode

and check if the values are as you expect:

tpacpi-bat.BAT0.startThreshold          = 45 [%]
tpacpi-bat.BAT0.stopThreshold           = 95 [%]
Enter fullscreen mode Exit fullscreen mode

You can change these thresholds anytime, and apply changes using command:

$ sudo tlp start
Enter fullscreen mode Exit fullscreen mode

Note, that if you need to have your laptop fully charged, you can achieve that by running following command while connected to AC:

$ tlp fullcharge
Enter fullscreen mode Exit fullscreen mode

Top comments (0)