4

I'm running a dual-boot Ubuntu MATE 16.04.3 LTS and Windows on a Thinkpad T430 (Core i7 dual-core, nominal 2.9 GHz clock, 8 GB RAM, 9-cell internal battery and 9-cell Slice battery). My battery life is excellent, as much as 10 hours of normal use on a full charge.

I recently had performance issues playing a game (Kerbal Space Program) on AC power, and found that the computer had been left in Power Saving mode, causing the CPU to run at lower clock speed than is necessary when I'm not trying to aggressively conserve energy. This probably occurred before I purchased the extended batteries, when I was trying to aggressively increase battery life with the original 6-cell battery.

I can easily switch the CPU back into Performance mode using the CPU Frequency Scaling Monitor widget that I've mounted in the system bar (which separately controls clock management of the real and virtual cores). I've examined the Power window of system settings and don't see any way to tell the OS to automatically switch between Power Saving (which I'd want when on battery power) and Performance (which I'd prefer when on AC power).

This similar question refering to end-of-life Ubuntu 14.10 may not be correct for my exact hardware. I can't tell if I have a Sandy Bridge CPU.

Zeiss Ikon
  • 5,248

3 Answers3

5
  1. Create a file /opt/system_cupmode.sh using sudo

  2. Run the following command to give it the needed permissions

    sudo chmod +x /opt/system_cupmode.sh
    
  3. Open the file and add the following code:

    #!/bin/bash
    # This script will switch cpu mode to performance on charging automatically
    # Author: @saleh_awal
    

    tFile=/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor if on_ac_power; then

    charging on

    if grep -qi "powersave" $tFile; then echo performance | tee /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor else echo "already updated to performance" fi else

    charging off

    if grep -qi "performance" $tFile; then echo powersave | tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor else echo "already updated to powersave" fi fi

  4. Add a cronjob to your root user as follow:

    sudo crontab -e
    

    then add this line at the bottom of the file which will run the code every 10 seconds

    */10 * * * * /opt/system_cupmode.sh
    
Pablo Bianchi
  • 17,371
Saleh Abdulaziz
  • 161
  • 1
  • 5
1

if you're here looking for a more recent answer that works on 24.04, I got you.

I actually made this into a .deb file that can be found here https://github.com/snek-the-great/autopower

as detailed above, set up and make executable /opt/systemcupmode.sh

sudo touch /opt/systemcupmode.sh && sudo chmod+x /opt/systemcupmode.sh && sudo nano /opt/systemcupmode.sh

Then, use this updated code:

#!/bin/bash
# This script will switch cpu mode to performance on charging automatically
# Author: SnekTheGreat

function on_ac_power() { battery_state=$(upower -i /org/freedesktop/UPower/devices/battery_BAT0 | grep -m 1 state: | cut -d ':' -f 2)

if [[ "$battery_state" == " charging" || "$battery_state" == " fully-charged" ]]; then

    return 0
else
    return 1
fi

}

tFile="/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor"

if ! on_ac_power; then # Charging on echo "System is on AC power" if grep -qi "power" "$tFile"; then sudo powerprofilesctl set performance echo "Switched to performance mode" else echo "Already in performance mode" fi else # Charging off echo "System is on battery" if grep -qi "power" "$tFile"; then sudo powerprofilesctl set power-saver echo "Switched to power-saver mode" else echo "Already in power-saver mode" fi fi

This code uses powerprofilesctl as opposed to tee, and should work on all devices, even multi-core ones. Some tweaking may be needed based on your system.

After you've finished the file, add it as a root cron job:

sudo crontab -e
          • /opt/systemcupmode.sh

Hope this helps! -Snek

snek
  • 11
0

I did some research. Its results is below.

I'm using Ivy Bridge i7-3537U on MATE with the same widget. My other CPU is Haswell i7-4790. According to sysfs they have only two governors

$ cat /sys/devices/system/cpu/cpufreq/policy0/scaling_available_g‌​overnors
performance powersave

It uses new intel_pstate driver.

Older CPU such as my Clarksfield i7-740QM are driven by acpi-cpufreq driver, it have 5 governors (conservative ondemand userspace powersave performance).

The current driver may be checked by cpufreq-info -d (from cpufrequtils package).

You can check your CPU with lscpu. I think you can monitor CPU actual frequencies with i7z or i7z_GUI (installable with sudo apt-get install i7z i7z-gui) or powertop (sudo apt-get install powertop, see Frequency stats tab).

On other thread it is explained how to switch off the intel_pstate driver. I tried so with my Haswell and Ivy Bridge CPUs, but I get very close results in Intel's LINPACK test.

I can conclude the following:

  • intel_pstate powersave governor is equivalent to the old acpi-cpufreq ondemand one;
  • it seems that you have already got peak performance from your CPU.
N0rbert
  • 103,263