diff --git a/Makefile b/Makefile deleted file mode 100644 index 35fe73f..0000000 --- a/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -all: install - -install: - install -d /usr/local/sbin/ - install -d /etc/systemd/system/ - install -m 700 lenovo_fix.py /usr/local/sbin/ - install -m 644 systemd/lenovo_fix.service /etc/systemd/system/ - @if test -f /etc/lenovo_fix.conf; then \ - echo "/etc/lenovo_fix.conf already exists; overwrite manually"; \ - else \ - install -m 644 etc/lenovo_fix.conf /etc/; \ - fi diff --git a/README.md b/README.md index d9e160a..422f5cf 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Workaround for Linux throttling issues on Lenovo T480 / T480s / X1C6 notebooks a This script forces the CPU package power limit (PL1/2) to **44 W** (29 W on battery) and the temperature trip point to **97 'C** (85 'C on battery) by overriding default values in MSR and MCHBAR every 5 seconds (30 on battery) to block the Embedded Controller from resetting these values to default. ## Requirements -The python module `python-periphery` is used for accessing the MCHBAR register by memory mapped I/O. +The python module `python-periphery` is used for accessing the MCHBAR register by memory mapped I/O. ## Installation ``` diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..fca5835 --- /dev/null +++ b/install.sh @@ -0,0 +1,34 @@ +#!/bin/sh + +INSTALL_DIR="/opt/lenovo_fix" + +systemctl stop lenovo_fix.service &>/dev/null + +mkdir -p "$INSTALL_DIR" &>/dev/null +set -e + +cd "$(dirname "$0")" + +echo "Copying config file..." +if [ ! -f /etc/lenovo_fix.conf ]; then + cp etc/lenovo_fix.conf /etc +else + echo "Config file already exists, skipping." +fi + +echo "Copying systemd service file..." +cp systemd/lenovo_fix.service /etc/systemd/system + +echo "Building virtualenv..." +cp requirements.txt lenovo_fix.py "$INSTALL_DIR" +cd "$INSTALL_DIR" +virtualenv -p /usr/bin/python3 venv +source venv/bin/activate +pip install -r requirements.txt + +echo "Enabling and starting systemd service..." +systemctl daemon-reload +systemctl enable lenovo_fix.service +systemctl restart lenovo_fix.service + +echo "All done." diff --git a/lenovo_fix.py b/lenovo_fix.py index 8902614..e7a5bfc 100755 --- a/lenovo_fix.py +++ b/lenovo_fix.py @@ -1,6 +1,6 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 -import ConfigParser +import configparser import dbus import glob import os @@ -49,8 +49,8 @@ def is_on_battery(): def calc_time_window_vars(t): - for Y in xrange(2**5): - for Z in xrange(2**2): + for Y in range(2**5): + for Z in range(2**2): if t <= (2**Y) * (1. + Z / 4.) * 0.000977: return (Y, Z) raise Exception('Unable to find a good combination!') @@ -70,7 +70,7 @@ def calc_undervolt_msr(plane, offset): def load_config(): - config = ConfigParser.ConfigParser() + config = configparser.ConfigParser() config.read(CONFIG_PATH) for power_source in ('AC', 'BATTERY'): diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..18a101f --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +configparser==3.5.0 +dbus-python==1.2.4 +PyGObject==3.28.2 +python-periphery==1.1.1 diff --git a/systemd/lenovo_fix.service b/systemd/lenovo_fix.service index 0735e88..4c78dca 100644 --- a/systemd/lenovo_fix.service +++ b/systemd/lenovo_fix.service @@ -3,7 +3,7 @@ Description=Fix Lenovo T480/T480s/X1C6 throttling on Linux [Service] Type=simple -ExecStart=/usr/local/sbin/lenovo_fix.py +ExecStart=/opt/lenovo_fix/venv/bin/python3 /opt/lenovo_fix/lenovo_fix.py [Install] -WantedBy=multi-user.target \ No newline at end of file +WantedBy=multi-user.target